Example #1
0
 private function doSearch()
 {
     $m = new MapModel();
     return $m->run($this->parameters);
 }
 /**
  * 初始化和收获,已经refill都要调用这个方法来验证
  * @param $item 数据库里的具体对象
  */
 function checkMultiProducts($item)
 {
     if (!$item) {
         return;
     }
     if (isset($item->start_time) && $item->start_time > 0) {
         // 这样才可以产出物品,如果没有这个值说明现在没有正在产出东西
         $prodcuts = $this->num_complete_raw_materials(unserialize($item->raw_materials), $item->id);
         $dbProducts = unserialize($item->products) ? unserialize($item->products) : array();
         $storeModel = new StoreModel($this->lang);
         $storeItem = $storeModel->getStoreById($item->id);
         // storeItem里的信息
         $collect_in = $storeItem->collect_in;
         // 收获的时间
         $num = min(self::MAX_PRODUCTS - count($dbProducts), min($prodcuts, floor((time() - $item->start_time) / $collect_in)));
         $decreaseMaterials = null;
         $this->debugMsg("this can product {$num}");
         if ($num <= 0) {
             // 能生产出来的最大的数量
             $num = 0;
         } else {
             $decreaseMaterials = $this->decreaseMaterials($item, $num);
         }
         $item->start_time += $num * $collect_in;
         $nowProducts = $this->num_complete_raw_materials($item->raw_materials, $item->id);
         if (count($dbProducts) == self::MAX_PRODUCTS) {
             //$nowProducts == 0 ||
             $item->start_time = 0;
             // 不能再生产了,如果当前已经是产到最大了,那么就不能再生产了,
             //当收获之后去验证这个,这样就可以生产了
             $this->debugMsg('不能再继续生产了');
         }
         $this->debugMsg("执行中..{$item->start_time}");
         $change = array('start_time' => $item->start_time);
         if ($decreaseMaterials) {
             $updata = array_merge($decreaseMaterials, $change);
             $map = new MapModel();
             $map->updateMapItem($this->uid, $item->x, $item->y, $updata);
             // 这个不知道是不是更新到数据库里了
             return $updata;
         }
     }
     return;
 }
Example #3
0
 public function load()
 {
     parent::load();
     if (isset($_GET['l']) && !$this->data['active_plus_account']) {
         exit(0);
     } else {
         $this->largeMap = isset($_GET['l']) && $this->data['active_plus_account'];
         $this->viewFile = $this->largeMap ? "map2.phtml" : "map.phtml";
         if ($this->largeMap) {
             $this->layoutViewFile = "layout" . DIRECTORY_SEPARATOR . "popup.phtml";
         }
         $this->rad = $this->largeMap ? 6 : 3;
         $map_size = $this->setupMetadata['map_size'];
         $this->x = $this->data['rel_x'];
         $this->y = $this->data['rel_y'];
         $m = new MapModel();
         $this->contractsAllianceId = array();
         if (0 < intval($this->data['alliance_id'])) {
             $cont = trim($m->getContractsAllianceId($this->data['alliance_id']));
             if ($cont != "") {
                 $_arr = explode(",", $cont);
                 foreach ($_arr as $contractAllianceId) {
                     list($aid, $pendingStatus) = $contractAllianceId;
                     $this->contractsAllianceId[$aid] = $pendingStatus;
                 }
             }
         }
         $_x = $this->data['rel_x'];
         $_y = $this->data['rel_y'];
         if ($this->isPost()) {
             $_x = intval($_POST['mxp']);
             $_y = intval($_POST['myp']);
         } else {
             if (isset($_GET['id']) && is_numeric($_GET['id'])) {
                 $m_vid = intval($_GET['id']);
                 if ($m_vid < 1) {
                     $m_vid = 1;
                 }
                 $_x = floor(($m_vid - 1) / $map_size);
                 $_y = $m_vid - ($_x * $map_size + 1);
             }
         }
         $map_matrix = $this->__getVillageMatrix($map_size, $_x, $_y, $this->rad);
         $map_matrix_arr = explode("|", $map_matrix);
         $matrixStr = $map_matrix_arr[0];
         $matrixStrArray = explode(",", $matrixStr);
         $this->directionsMatrix = explode(",", $map_matrix_arr[1]);
         $result = $m->getVillagesMatrix($matrixStr);
         while ($result->next()) {
             $this->matrixSet[$result->row['id']] = array("vid" => $result->row['id'], "x" => $result->row['rel_x'], "y" => $result->row['rel_y'], "image_num" => $result->row['image_num'], "player_id" => $result->row['player_id'], "tribe_id" => $result->row['tribe_id'], "alliance_id" => $result->row['alliance_id'], "player_name" => $result->row['player_name'], "village_name" => $result->row['village_name'], "alliance_name" => $result->row['alliance_name'], "people_count" => $result->row['people_count'], "is_oasis" => $result->row['is_oasis'], "field_maps_id" => $result->row['field_maps_id']);
         }
         $i = 0;
         $this->json = "";
         $sjson = "";
         $sortedArray = array();
         foreach ($matrixStrArray as $vid) {
             $mapItem = $this->matrixSet[$vid];
             $sortedArray[] = $mapItem;
             if ($sjson != "") {
                 $sjson .= ",";
             }
             $sjson .= sprintf("[%s,%s,%s,\"%s\",\"%s\",%s,%s", $mapItem['vid'], $mapItem['x'], $mapItem['y'], $this->getCssClassNameByItem($mapItem), $this->getMapAreaTitle($mapItem), $mapItem['player_id'] != "" ? 1 : 0, $mapItem['is_oasis']);
             if ($mapItem['player_id'] != "") {
                 $sjson .= sprintf(",%s,%s,\"%s\",\"%s\",\"%s\"", $mapItem['tribe_id'], $mapItem['people_count'], htmlspecialchars(str_replace("\\", "\\\\", $mapItem['player_name'])), htmlspecialchars(str_replace("\\", "\\\\", $mapItem['village_name'])), htmlspecialchars(str_replace("\\", "\\\\", $mapItem['alliance_name'])));
             } else {
                 if (!$mapItem['is_oasis']) {
                     $sjson .= "," . $mapItem['field_maps_id'];
                 }
             }
             $sjson .= "]";
             if (++$i % ($this->rad * 2 + 1) == 0) {
                 if ($this->json != "") {
                     $this->json .= ",";
                 }
                 $this->json .= "[" . $sjson . "]";
                 $sjson = "";
             }
         }
         $this->json = "[" . $this->json . "]";
         $this->matrixSet = $sortedArray;
         $centerIndex = 2 * ($this->rad + 1) * $this->rad;
         $this->x = $this->matrixSet[$centerIndex]['x'];
         $this->y = $this->matrixSet[$centerIndex]['y'];
         $this->stepDirectionsMatrix = array($this->matrixSet[$centerIndex - $this->rad * 2 - 1]['vid'], $this->matrixSet[$centerIndex + 1]['vid'], $this->matrixSet[$centerIndex + $this->rad * 2 + 1]['vid'], $this->matrixSet[$centerIndex - 1]['vid']);
         $m->dispose();
         if ($this->isCallback()) {
             echo $this->getClientScript();
             exit(0);
         }
     }
 }