/** * Gestion du changement de carte. * * @return void */ public function index() { if (isset($this->data->action_map->item) && $this->data->action_map->item && !($obj = Item_Model::instance()->select($this->user->id, $this->data->action_map->item, 1))) { echo 'no'; return; } if ($this->data->action_map->prix && is_numeric($this->data->action_map->prix) && $this->user->argent >= $this->data->action_map->prix) { $this->user->argent -= $this->data->action_map->prix; } if (!$this->data->action_map->prix || $this->user->argent >= $this->data->action_map->prix) { $this->user->positionX = $this->data->action_map->x_move * 50 + 25; $this->user->positionY = $this->data->action_map->y_move * 50 + 25; $this->user->positionZ = $this->data->action_map->z_move * 50 + 25; $this->user->region_id = $this->data->action_map->id_region_move; $this->user->update(); History_Model::instance()->user_insert($this->user->id, $this->data->id, $this->data->action_map->id_region_move, 'change_map'); echo '<script>window.location.reload();</script>'; } }
/** * Methode : sauver les données d'un user et de ses objets */ public function save_items($idUser) { $this->auto_render = FALSE; if (!request::is_ajax()) { return false; } if (($value = $this->input->post('item')) !== FALSE) { $item = Item_Model::instance(); $item->user_delete_all($idUser); foreach ($value as $key => $row) { if ($row > 0) { for ($n = 0; $n < $row; $n++) { $item->user_insert($idUser, $key); } } } } }
public function __construct() { parent::__construct(); parent::access('item'); $this->item = Item_Model::instance(); }
/** * Générer un JSON * * @return void */ public function index($render = TRUE) { $json = new View('map/json'); $json->my = $this->user; if (!($this->region = Region_Model::instance()->select(array('id' => $this->user->region_id), 1))) { return FALSE; } $json->items = Item_Model::instance()->select(); $elements = $modules = $items = FALSE; if (($rows = Map_Model::instance()->select(array('region_id' => $this->region->id), FALSE)) !== FALSE) { $prenoms = Name_Model::instance()->select(); $listName = array(); foreach ($prenoms as $prenom) { $listName[] = ucfirst(mb_strtolower($prenom->prenom)); } $images = file::listing_dir(DOCROOT . 'images/character'); foreach ($rows as $row) { if (!$row->module_map && !$row->bot) { $elements[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "materials" : [ "' . $row->background_px . '", "' . $row->background_nx . '", "' . $row->background_py . '", "' . $row->background_ny . '", "' . $row->background_pz . '", "' . $row->background_nz . '" ] }'; } else { $data = @unserialize($row->action_map); $action = json_encode($data); if ($row->module_map == 'article') { $article = Article_Model::instance()->select(array('id_article' => $data->id_article, 'article_category_id' => 2, 'status' => 1), 1); $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : ' . json_encode($article->article) . ' }'; } elseif ($row->bot) { $v = new stdClass(); $v->id = 0; $v->name = $row->bot ? $row->title : $listName[array_rand($listName)]; $v->x = $row->x; $v->y = $row->y; $v->z = $row->z; $v->region_id = $row->region_id; $v->user_id = $this->user->id; if ($row->bot == 2) { $v->image = 'animals/bears.png'; } elseif ($row->bot == 3) { $v->image = 'animals/dog.png'; } else { $v->image = 'character/' . $images[array_rand($images)]; } $v->hp_max = 100; $v->hp = 100; $v->leak = 0; $v->type = $row->bot; $v->fixe = $row->bot && !$row->module_map ? 0 : 1; $v->argent = 1000; $v->xp = 10; $v->niveau = 0; $this->botFixe[] = $v; if ($row->module_map == 'quete') { $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }'; } } else { $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }'; } } } } $articles = Article_Model::instance()->select(array('region_id' => $this->region->id, 'article_category_id' => 2, 'status' => 1)); $articlesList = null; if ($articles) { foreach ($articles as $row) { $articlesList[] = json_encode($row->reponse ? $row->article . '<div class="reponse">' . $row->reponse . '</div>' : $row->article); } } $this->region->map = new stdClass(); $this->region->map->region = $this->region; $this->region->map->elements = $elements ? implode(',', $elements) : FALSE; $this->region->map->modules = $modules ? implode(',', $modules) : FALSE; $this->region->map->articles = $articlesList ? implode(',', $articlesList) : FALSE; $this->region->map->region->bots = $this->botFixe; $json->region = $this->region; $sounds = file::listing_dir(DOCROOT . 'audios', array('home.mp3')); $json->sounds = $sounds ? json_encode($sounds) : FALSE; return $json->render($render); }
/** * Méthode : */ public function index(&$view) { $view->items = Item_Model::instance()->select(); }