コード例 #1
0
ファイル: village3.php プロジェクト: vcelis/tatar-wars
 function load()
 {
     parent::load();
     $villageId = isset($_GET['id']) && 0 < intval($_GET['id']) ? intval($_GET['id']) : 0;
     if ($villageId <= 0) {
         $this->redirect('map.php');
         return null;
     }
     $m = new VillageModel();
     $this->mapItemData = $m->getMapItemData($villageId);
     if (!is_array($this->mapItemData)) {
         $m->dispose();
         $this->redirect('map.php');
         return null;
     }
     if (0 < intval($this->mapItemData['player_id'])) {
         $this->pageState = $this->mapItemData['is_oasis'] ? 3 : 2;
         $this->mapItemData['playerType'] = $m->getPlayType(intval($this->mapItemData['player_id']));
     } else {
         $this->pageState = $this->mapItemData['is_oasis'] ? 4 : 1;
     }
     $this->lastReport = NULL;
     if ($this->pageState == 2 || $this->pageState == 3) {
         if ($this->mapItemData['player_id'] == $this->player->playerId || $this->mapItemData['alliance_id'] == $this->data['alliance_id'] && 0 < intval($this->data['alliance_id'])) {
             $this->lastReport = $m->getLatestReports($this->mapItemData['player_id'], $this->mapItemData['id']);
         } else {
             $fromPlayersId = 0 < intval($this->data['alliance_id']) ? $m->getAlliancePlayersId(intval($this->data['alliance_id'])) : $this->player->playerId;
             $this->lastReport = $m->getLatestReports2($fromPlayersId, $this->mapItemData['player_id'], $this->mapItemData['id']);
         }
         if ($this->pageState == 3) {
             $this->mapItemData['village_name'] = $m->getVillageName($this->mapItemData['parent_id']);
         }
     } else {
         if ($this->pageState == 1 || $this->pageState == 4) {
             $this->itemTroops = array();
             $t = $this->pageState == 1 ? $this->data['troops_num'] : $this->mapItemData['troops_num'];
             $incFactor = $this->pageState == 4 ? floor($this->mapItemData['elapsedTimeInSeconds'] / 86400) : 0;
             $t_arr = explode('|', $t);
             foreach ($t_arr as $t_str) {
                 $t2_arr = explode(':', $t_str);
                 if (0 - 1 < $t2_arr[0]) {
                     continue;
                 }
                 $t2_arr = explode(',', $t2_arr[1]);
                 foreach ($t2_arr as $t2_str) {
                     $t = explode(' ', $t2_str);
                     if ($t[0] == 99) {
                         continue;
                     }
                     $this->itemTroops[$t[0]] = $t[1] + $incFactor;
                     if ($this->pageState == 4 && 7 * intval($t[0]) < $this->itemTroops[$t[0]]) {
                         $this->itemTroops[$t[0]] = 7 * intval($t[0]);
                         continue;
                     }
                 }
             }
         }
     }
     $m->dispose();
 }
コード例 #2
0
 public function load()
 {
     parent::load();
     if ($this->buildingIndex == 0 - 1 && isset($_GET['id']) && is_numeric($_GET['id']) && isset($this->buildings[$_GET['id']])) {
         $this->buildingIndex = intval($_GET['id']);
     }
     $this->buildProperties = $this->getBuildingProperties($this->buildingIndex);
     if ($this->buildProperties == NULL) {
         $this->redirect("village1.php");
     } else {
         if ($this->buildProperties['emptyPlace']) {
             $this->villagesLinkPostfix .= "&id=" . $this->buildingIndex;
             $this->newBuilds = array("available" => array(), "soon" => array());
             foreach ($this->gameMetadata['items'] as $item_id => $build) {
                 if ($item_id <= 4 || !isset($build['for_tribe_id'][$this->tribeId])) {
                     continue;
                 }
                 $canBuild = $this->canCreateNewBuild($item_id);
                 if ($canBuild != 0 - 1) {
                     if ($canBuild) {
                         if (!isset($this->newBuilds['available'][$build['levels'][0]['time_consume']])) {
                             $this->newBuilds['available'][$build['levels'][0]['time_consume']] = array();
                         }
                         $this->newBuilds['available'][$build['levels'][0]['time_consume']][$item_id] = $build;
                     } else {
                         $dependencyCount = 0;
                         foreach ($build['pre_requests'] as $reqId => $reqValue) {
                             if ($reqValue != NULL) {
                                 $build['pre_requests_dependencyCount'][$reqId] = $reqValue - $this->_getMaxBuildingLevel($reqId);
                                 $dependencyCount += $build['pre_requests_dependencyCount'][$reqId];
                             }
                         }
                         if (!isset($this->newBuilds['soon'][$dependencyCount])) {
                             $this->newBuilds['soon'][$dependencyCount] = array();
                         }
                         $this->newBuilds['soon'][$dependencyCount][$item_id] = $build;
                     }
                 }
             }
             ksort($this->newBuilds['available'], SORT_NUMERIC);
             ksort($this->newBuilds['soon'], SORT_NUMERIC);
         } else {
             $bitemId = $this->buildProperties['building']['item_id'];
             $this->villagesLinkPostfix .= "&id=" . $this->buildingIndex;
             if (4 < $bitemId) {
                 $this->villagesLinkPostfix .= "&bid=" . $bitemId;
             }
             $this->buildingTribeFactor = isset($this->gameMetadata['items'][$bitemId]['for_tribe_id'][$this->data['tribe_id']]) ? $this->gameMetadata['items'][$bitemId]['for_tribe_id'][$this->data['tribe_id']] : 1;
             if ($this->buildings[$this->buildingIndex]['level'] == 0) {
                 return;
             }
             switch ($bitemId) {
                 case 12:
                 case 13:
                     $this->productionPane = FALSE;
                     $this->buildingView = "Blacksmith_Armoury";
                     $this->handleBlacksmithArmoury();
                     break;
                 case 15:
                     if (10 <= $this->buildings[$this->buildingIndex]['level']) {
                         $this->buildingView = "MainBuilding";
                         $this->handleMainBuilding();
                     }
                     break;
                 case 16:
                     $this->productionPane = FALSE;
                     $this->buildingView = "RallyPoint";
                     $this->handleRallyPoint();
                     break;
                 case 17:
                     $this->productionPane = FALSE;
                     $this->buildingView = "Marketplace";
                     $this->handleMarketplace();
                     break;
                 case 18:
                     $this->productionPane = FALSE;
                     $this->buildingView = "Embassy";
                     $this->handleEmbassy();
                     break;
                 case 19:
                 case 20:
                 case 21:
                 case 29:
                 case 30:
                 case 36:
                     $this->_getOnlyMyTroops();
                     $this->productionPane = $bitemId == 36;
                     $this->buildingView = "TroopBuilding";
                     $this->handleTroopBuilding();
                     break;
                 case 22:
                     $this->productionPane = FALSE;
                     $this->buildingView = "Academy";
                     $this->handleAcademy();
                     break;
                 case 23:
                     $this->productionPane = TRUE;
                     $this->buildingView = "Cranny";
                     break;
                 case 24:
                     $this->productionPane = FALSE;
                     $this->buildingView = "TownHall";
                     $this->handleTownHall();
                     break;
                 case 25:
                 case 26:
                     $this->productionPane = FALSE;
                     $this->buildingView = "Residence_Palace";
                     $this->handleResidencePalace();
                     break;
                 case 37:
                     $this->productionPane = FALSE;
                     $this->buildingView = "HerosMansion";
                     $this->handleHerosMansion();
                     break;
                 case 40:
                     $this->productionPane = FALSE;
                     break;
                 case 42:
                     $this->_getOnlyMyTroops();
                     $this->productionPane = TRUE;
                     $this->buildingView = "Warrior";
                     $this->handleWarrior();
             }
         }
     }
 }
コード例 #3
0
ファイル: mywidgets.php プロジェクト: vcelis/tatar-wars
 function load()
 {
     parent::load();
     // finish the building tasks
     if (isset($_GET['bfs']) && isset($_GET['k']) && $_GET['k'] == $this->data['update_key'] && $this->data['gold_num'] >= $this->gameMetadata['plusTable'][5]['cost'] && !$this->isGameTransientStopped() && !$this->isGameOver()) {
         // complete the tasks, then decrease the gold number
         $this->queueModel->finishTasks($this->player->playerId, $this->gameMetadata['plusTable'][5]['cost']);
         $this->redirect($this->contentCssClass . '.php');
         return;
     }
     // check for update key
     if (isset($_GET['id']) && is_numeric($_GET['id']) && isset($_GET['k']) && $_GET['k'] == $this->data['update_key'] && !$this->isGameTransientStopped() && !$this->isGameOver()) {
         if (isset($_GET['d'])) {
             // task cancellation
             $this->queueModel->cancelTask($this->player->playerId, intval($_GET['id']));
         } else {
             if (isset($this->buildings[$_GET['id']])) {
                 // create or upgrade building
                 $buildProperties = $this->getBuildingProperties(intval($_GET['id']));
                 if ($buildProperties != NULL) {
                     $canAddTask = FALSE;
                     if ($buildProperties['emptyPlace']) {
                         // new building
                         $item_id = isset($_GET['b']) ? intval($_GET['b']) : 0;
                         $posIndex = intval($_GET['id']);
                         if ($posIndex == 39 && $item_id != 16 || $posIndex == 40 && $item_id != 31 && $item_id != 32 && $item_id != 33) {
                             return;
                         }
                         if ($this->data['is_special_village'] && ($posIndex == 25 || $posIndex == 26 || $posIndex == 29 || $posIndex == 30 || $posIndex == 33) && $item_id != 40) {
                             return;
                         }
                         if ($this->canCreateNewBuild($item_id) == 1) {
                             $canAddTask = TRUE;
                             $neededResources = $this->gameMetadata['items'][$item_id]['levels'][0]['resources'];
                             $calcConsume = intval($this->gameMetadata['items'][$item_id]['levels'][0]['time_consume'] / $this->gameSpeed * ($this->data['time_consume_percent'] / 100));
                         }
                     } else {
                         // upgrade building
                         $canAddTask = TRUE;
                         $item_id = $buildProperties['building']['item_id'];
                         $neededResources = $buildProperties['level']['resources'];
                         $calcConsume = $buildProperties['level']['calc_consume'];
                     }
                     if ($canAddTask && $this->needMoreUpgrades($neededResources, $item_id) == 0 && $this->isResourcesAvailable($neededResources)) {
                         $workerResult = $this->isWorkerBusy($item_id <= 4);
                         if (!$workerResult['isBusy']) {
                             // add the task into the queue
                             $newTask = new QueueTask(QS_BUILD_CREATEUPGRADE, $this->player->playerId, $calcConsume);
                             $newTask->villageId = $this->data['selected_village_id'];
                             $newTask->buildingId = $item_id;
                             $newTask->procParams = $item_id == 40 ? 25 : intval($_GET['id']);
                             $newTask->tag = $neededResources;
                             $this->queueModel->addTask($newTask);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: guide.php プロジェクト: vcelis/tatar-wars
 function load()
 {
     parent::load();
     $this->quiz = trim($this->data['guide_quiz']);
     if ($this->quiz == GUIDE_QUIZ_COMPLETED) {
         exit(0);
         return null;
     }
     $m = new GuideModel();
     $this->taskState = 0;
     if ($this->quiz == GUIDE_QUIZ_NOTSTARTED || $this->quiz == GUIDE_QUIZ_SUSPENDED) {
         $this->clientAction = 0 - 1;
         if (isset($_GET['v']) && $_GET['v'] == 'f') {
             if ($this->quiz == GUIDE_QUIZ_NOTSTARTED) {
                 $m->setGuideTask($this->player->playerId, GUIDE_QUIZ_SUSPENDED);
             }
             $m->dispose();
             exit(0);
             return null;
         }
         if (isset($_GET['v']) && $_GET['v'] == 'n') {
             $this->quiz = '1,200';
             $this->clientAction = 1;
             $m->setGuideTask($this->player->playerId, $this->quiz);
         } else {
             $this->taskNumber = isset($_GET['v']) && $_GET['v'] == 's' ? 1 : 0;
             if ($this->taskNumber == 1) {
                 $this->clientAction = 0;
                 $this->quiz = '0,1';
                 $m->setGuideTask($this->player->playerId, $this->quiz);
             }
             return null;
         }
     }
     $quizArray = explode(',', $this->quiz);
     $this->taskNumber = $quizArray[1];
     if ($this->taskNumber == 200) {
         if (isset($_GET['v'])) {
             if ($_GET['v'] == 'y') {
                 $this->taskNumber = 0;
                 $this->clientAction = 1;
                 $this->quiz = GUIDE_QUIZ_NOTSTARTED;
                 $m->setGuideTask($this->player->playerId, $this->quiz);
                 return null;
             }
             if ($_GET['v'] == 'c') {
                 $this->quiz = '0,201,0';
                 $quizArray = explode(',', $this->quiz);
                 $this->taskNumber = $quizArray[1];
                 $m->setGuideTask($this->player->playerId, $this->quiz);
             }
         }
     }
     if ($this->taskNumber == 201) {
         $this->handleNoQuiz($m, $quizArray[2]);
     } else {
         if ($quizArray[0] == 1) {
             $this->clientAction = $quizArray[0] = 0;
             $m->setGuideTask($this->player->playerId, implode(',', $quizArray));
             $this->newReadQuiz($this->taskNumber, $m, $quizArray);
         } else {
             $this->checkForQuiz($this->taskNumber, $m, $quizArray);
         }
     }
     $m->dispose();
 }
コード例 #5
0
 public function load()
 {
     parent::load();
     if ($this->rallyPointLevel <= 0) {
         $this->redirect("build.php?id=39");
     } else {
         if (isset($_GET['d1']) || isset($_GET['d2']) || isset($_GET['d3'])) {
             $this->pageState = 3;
             $this->handleTroopBack();
         } else {
             $m = new WarModel();
             $this->pageState = 1;
             $map_size = $this->setupMetadata['map_size'];
             $half_map_size = floor($map_size / 2);
             $this->hasHero = $this->data['hero_in_village_id'] == $this->data['selected_village_id'];
             $t_arr = explode("|", $this->data['troops_num']);
             foreach ($t_arr as $t_str) {
                 $t2_arr = explode(":", $t_str);
                 if ($t2_arr[0] == 0 - 1) {
                     $t2_arr = explode(",", $t2_arr[1]);
                     foreach ($t2_arr as $t2_str) {
                         $t = explode(" ", $t2_str);
                         if ($t[0] == 99) {
                             continue;
                         }
                         $this->troops[] = array("troopId" => $t[0], "number" => $t[1]);
                     }
                 }
             }
             $attackOptions1 = "";
             $sendTroops = FALSE;
             $playerData = NULL;
             $villageRow = NULL;
             if (!$this->isPost()) {
                 if (isset($_GET['id']) && is_numeric($_GET['id'])) {
                     $vid = intval($_GET['id']);
                     if ($vid < 1) {
                         $vid = 1;
                     }
                     $villageRow = $m->getVillageDataById($vid);
                 }
             } else {
                 if (isset($_POST['id'])) {
                     $sendTroops = !$this->isGameTransientStopped() && !$this->isGameOver();
                     $vid = intval($_POST['id']);
                     $villageRow = $m->getVillageDataById($vid);
                 } else {
                     if (isset($_POST['dname']) && trim($_POST['dname']) != "") {
                         $villageRow = $m->getVillageDataByName(trim($_POST['dname']));
                     } else {
                         if (isset($_POST['x'], $_POST['y']) && trim($_POST['x']) != "" && trim($_POST['y']) != "") {
                             $vid = $this->__getVillageId($map_size, $this->__getCoordInRange($map_size, intval($_POST['x'])), $this->__getCoordInRange($map_size, intval($_POST['y'])));
                             $villageRow = $m->getVillageDataById($vid);
                         }
                     }
                 }
             }
             if ($villageRow == NULL) {
                 if ($this->isPost()) {
                     $this->errorTable = v2v_p_entervillagedata;
                 }
             } else {
                 $this->disableFirstTwoAttack = intval($villageRow['player_id']) == 0 && $villageRow['is_oasis'];
                 $this->targetVillage['x'] = floor(($villageRow['id'] - 1) / $map_size);
                 $this->targetVillage['y'] = $villageRow['id'] - ($this->targetVillage['x'] * $map_size + 1);
                 if ($half_map_size < $this->targetVillage['x']) {
                     $this->targetVillage['x'] -= $map_size;
                 }
                 if ($half_map_size < $this->targetVillage['y']) {
                     $this->targetVillage['y'] -= $map_size;
                 }
                 if ($villageRow['id'] == $this->data['selected_village_id']) {
                     return;
                 }
                 if (0 < intval($villageRow['player_id']) && $m->getPlayType($villageRow['player_id']) == PLAYERTYPE_ADMIN) {
                     return;
                 }
                 $spyOnly = FALSE;
                 if (!$villageRow['is_oasis'] && intval($villageRow['player_id']) == 0) {
                     $this->transferType = 1;
                     $humanTroopId = 0;
                     $renderTroops = array();
                     foreach ($this->troops as $troop) {
                         $renderTroops[$troop['troopId']] = 0;
                         if ($troop['troopId'] == 10 || $troop['troopId'] == 20 || $troop['troopId'] == 30 || $troop['troopId'] == 109 || $troop['troopId'] == 60) {
                             $humanTroopId = $troop['troopId'];
                             $renderTroops[$humanTroopId] = $troop['number'];
                         }
                     }
                     $canBuildNewVillage = isset($renderTroops[$humanTroopId]) && 3 <= $renderTroops[$humanTroopId];
                     if ($canBuildNewVillage) {
                         $count = trim($this->data['child_villages_id']) == "" ? 0 : sizeof(explode(",", $this->data['child_villages_id']));
                         if (2 < $count) {
                             $this->errorTable = v2v_p_cannotbuildnewvill;
                         } else {
                             if (!$this->_canBuildNewVillage()) {
                                 $this->errorTable = v2v_p_cannotbuildnewvill1;
                             } else {
                                 if (!$this->isResourcesAvailable($this->newVillageResources)) {
                                     $this->errorTable = sprintf(v2v_p_cannotbuildnewvill2, $this->newVillageResources['1']);
                                 } else {
                                     if (!$m->hasNewVillageTask($this->player->playerId)) {
                                         break;
                                     } else {
                                         $this->errorTable = v2v_p_cannotbuildnewvill3;
                                     }
                                 }
                             }
                         }
                     } else {
                         do {
                             $this->errorTable = v2v_p_cannotbuildnewvill4;
                             return;
                         } while (0);
                         $this->pageState = 2;
                     }
                 } else {
                     if ($this->isPost()) {
                         if (!$villageRow['is_oasis'] && intval($villageRow['player_id']) == 0) {
                             $this->errorTable = v2v_p_novillagehere;
                         } else {
                             if (!isset($_POST['c']) || intval($_POST['c']) < 1 || 4 < intval($_POST['c'])) {
                                 return;
                             }
                             $this->transferType = $this->disableFirstTwoAttack ? 4 : intval($_POST['c']);
                             if (0 < intval($villageRow['player_id'])) {
                                 $playerData = $m->getPlayerDataById(intval($villageRow['player_id']));
                                 if ($playerData['is_blocked']) {
                                     $this->errorTable = v2v_p_playerwas_blocked;
                                 } else {
                                     if (0 < $playerData['protection_remain_sec']) {
                                         $this->errorTable = v2v_p_playerwas_inprotectedperiod;
                                     }
                                 }
                             } else {
                                 $totalTroopsCount = 0;
                                 $totalSpyTroopsCount = 0;
                                 $this->totalCatapultTroopsCount = 0;
                                 $hasTroopsSelected = FALSE;
                                 $renderTroops = array();
                                 if (isset($_POST['t'])) {
                                     foreach ($this->troops as $troop) {
                                         $num = 0;
                                         if (isset($_POST['t'][$troop['troopId']]) && 0 < intval($_POST['t'][$troop['troopId']])) {
                                             $num = $troop['number'] < $_POST['t'][$troop['troopId']] ? $troop['number'] : intval($_POST['t'][$troop['troopId']]);
                                         }
                                         $renderTroops[$troop['troopId']] = $num;
                                         $totalTroopsCount += $num;
                                         if (0 < $num) {
                                             $hasTroopsSelected = TRUE;
                                         }
                                         if ($troop['troopId'] == 4 || $troop['troopId'] == 14 || $troop['troopId'] == 23 || $troop['troopId'] == 103 || $troop['troopId'] == 54) {
                                             $totalSpyTroopsCount += $num;
                                         } else {
                                             if ($troop['troopId'] == 8 || $troop['troopId'] == 18 || $troop['troopId'] == 28 || $troop['troopId'] == 107 || $troop['troopId'] == 58) {
                                                 $this->totalCatapultTroopsCount += $num;
                                             }
                                         }
                                     }
                                 }
                                 if ($this->hasHero && isset($_POST['_t']) && intval($_POST['_t']) == 1) {
                                     $hasTroopsSelected = TRUE;
                                     $totalTroopsCount += 1;
                                 }
                                 $spyOnly = $totalSpyTroopsCount == $totalTroopsCount && ($this->transferType == 3 || $this->transferType == 4) && 0 < intval($villageRow['player_id']);
                                 if ($spyOnly) {
                                     $this->onlyOneSpyAction = $villageRow['is_oasis'];
                                 }
                                 $this->attackWithCatapult = 0 < $this->totalCatapultTroopsCount && $this->transferType == 3 && 0 < intval($villageRow['player_id']) && !$villageRow['is_oasis'];
                                 if ($this->attackWithCatapult) {
                                     if (10 <= $this->rallyPointLevel) {
                                         $this->catapultCanAttackLastIndex = sizeof($this->catapultCanAttack) - 1;
                                     } else {
                                         if (5 <= $this->rallyPointLevel) {
                                             $this->catapultCanAttackLastIndex = 11;
                                         } else {
                                             if (3 <= $this->rallyPointLevel) {
                                                 $this->catapultCanAttackLastIndex = 2;
                                             } else {
                                                 $this->catapultCanAttackLastIndex = 0;
                                             }
                                         }
                                     }
                                     $attackOptions1 = isset($_POST['dtg']) && $this->_containBuildingTarget($_POST['dtg']) ? intval($_POST['dtg']) : 0;
                                     if ($this->rallyPointLevel == 20 && 20 <= $this->totalCatapultTroopsCount) {
                                         $attackOptions1 = "2:" . ($attackOptions1 . " " . (isset($_POST['dtg1']) && $this->_containBuildingTarget($_POST['dtg1']) ? intval($_POST['dtg1']) : 0));
                                     } else {
                                         $attackOptions1 = "1:" . $attackOptions1;
                                     }
                                     $this->availableCatapultTargetsString = "";
                                     $selectComboTargetOptions = "";
                                     $i = 1;
                                     while ($i <= 9) {
                                         if ($this->_containBuildingTarget($i)) {
                                             $selectComboTargetOptions .= sprintf("<option value=\"%s\">%s</option>", $i, constant("item_" . $i));
                                         }
                                         ++$i;
                                     }
                                     if ($selectComboTargetOptions != "") {
                                         $this->availableCatapultTargetsString .= "<optgroup label=\"" . v2v_p_catapult_grp1 . "\">" . $selectComboTargetOptions . "</optgroup>";
                                     }
                                     $selectComboTargetOptions = "";
                                     $i = 10;
                                     while ($i <= 28) {
                                         if (($i == 10 || $i == 11 || $i == 15 || $i == 17 || $i == 18 || $i == 24 || $i == 25 || $i == 26 || $i == 28 || $i == 38 || $i == 39) && $this->_containBuildingTarget($i)) {
                                             $selectComboTargetOptions .= sprintf("<option value=\"%s\">%s</option>", $i, constant("item_" . $i));
                                         }
                                         ++$i;
                                     }
                                     if ($selectComboTargetOptions != "") {
                                         $this->availableCatapultTargetsString .= "<optgroup label=\"" . v2v_p_catapult_grp2 . "\">" . $selectComboTargetOptions . "</optgroup>";
                                     }
                                     $selectComboTargetOptions = "";
                                     $i = 12;
                                     while ($i <= 37) {
                                         if (($i == 12 || $i == 13 || $i == 14 || $i == 16 || $i == 19 || $i == 20 || $i == 21 || $i == 22 || $i == 35 || $i == 37) && $this->_containBuildingTarget($i)) {
                                             $selectComboTargetOptions .= sprintf("<option value=\"%s\">%s</option>", $i, constant("item_" . $i));
                                         }
                                         ++$i;
                                     }
                                     if ($selectComboTargetOptions != "") {
                                         $this->availableCatapultTargetsString .= "<optgroup label=\"" . v2v_p_catapult_grp3 . "\">" . $selectComboTargetOptions . "</optgroup>";
                                     }
                                 }
                                 if (!$hasTroopsSelected) {
                                     $this->errorTable = v2v_p_thereisnoattacktroops;
                                 } else {
                                     $this->pageState = 2;
                                 }
                             }
                         }
                     }
                 }
                 if ($this->pageState == 2) {
                     $this->targetVillage['transferType'] = $this->transferType == 1 ? v2v_p_attacktyp1 : $this->transferType == 2 ? v2v_p_attacktyp2 . " " : $this->transferType == 3 ? v2v_p_attacktyp3 : $this->transferType == 4 ? v2v_p_attacktyp4 : "";
                     if ($villageRow['is_oasis']) {
                         $this->targetVillage['villageName'] = $playerData != NULL ? v2v_p_placetyp1 : v2v_p_placetyp2;
                     } else {
                         $this->targetVillage['villageName'] = $playerData != NULL ? $villageRow['village_name'] : v2v_p_placetyp3;
                     }
                     $this->targetVillage['villageId'] = $villageRow['id'];
                     $this->targetVillage['playerName'] = $playerData != NULL ? $playerData['name'] : $villageRow['is_oasis'] ? v2v_p_monster : "";
                     $this->targetVillage['playerId'] = 0;
                     $this->targetVillage['troops'] = $renderTroops;
                     $this->targetVillage['hasHero'] = 1 < $this->transferType && $this->hasHero && isset($_POST['_t']) && intval($_POST['_t']) == 1;
                     $distance = WebHelper::getdistance($this->data['rel_x'], $this->data['rel_y'], $this->targetVillage['x'], $this->targetVillage['y'], $this->setupMetadata['map_size'] / 2);
                     $this->targetVillage['needed_time'] = intval($distance / $this->_getTheSlowestTroopSpeed($renderTroops) * 3600);
                     $this->targetVillage['spy'] = $spyOnly;
                 }
                 if ($sendTroops) {
                     $taskType = 0;
                     switch ($this->transferType) {
                         case 1:
                             $taskType = QS_CREATEVILLAGE;
                             break;
                         case 2:
                             $taskType = QS_WAR_REINFORCE;
                             break;
                         case 3:
                             $taskType = QS_WAR_ATTACK;
                             break;
                         case 4:
                             $taskType = QS_WAR_ATTACK_PLUNDER;
                             break;
                             return;
                     }
                     $spyAction = 0;
                     if ($spyOnly) {
                         $taskType = QS_WAR_ATTACK_SPY;
                         $spyAction = isset($_POST['spy']) && (intval($_POST['spy']) == 1 || intval($_POST['spy']) == 2) ? intval($_POST['spy']) : 1;
                         if ($this->onlyOneSpyAction) {
                             $spyAction = 1;
                         }
                     }
                     $troopsStr = "";
                     foreach ($this->targetVillage['troops'] as $tid => $tnum) {
                         if ($troopsStr != "") {
                             $troopsStr .= ",";
                         }
                         $troopsStr .= $tid . " " . $tnum;
                     }
                     if ($this->targetVillage['hasHero']) {
                         $troopsStr .= "," . $this->data['hero_troop_id'] . " -1";
                     }
                     $catapultTargets = $attackOptions1;
                     $carryResources = $taskType == QS_CREATEVILLAGE ? implode(" ", $this->newVillageResources) : "";
                     $procParams = $troopsStr . "|" . ($this->targetVillage['hasHero'] ? 1 : 0) . "|" . $spyAction . "|" . $catapultTargets . "|" . $carryResources . "|||0";
                     $newTask = new QueueTask($taskType, $this->player->playerId, $this->targetVillage['needed_time']);
                     $newTask->villageId = $this->data['selected_village_id'];
                     $newTask->toPlayerId = intval($villageRow['player_id']);
                     $newTask->toVillageId = $villageRow['id'];
                     $newTask->procParams = $procParams;
                     $newTask->tag = array("troops" => $this->targetVillage['troops'], "hasHero" => $this->targetVillage['hasHero'], "resources" => $taskType == QS_CREATEVILLAGE ? $this->newVillageResources : NULL);
                     $this->queueModel->addTask($newTask);
                     $m->dispose();
                     $this->redirect("build.php?id=39");
                 } else {
                     $m->dispose();
                 }
             }
         }
     }
 }
コード例 #6
0
ファイル: v2v.php プロジェクト: vcelis/tatar-wars
 function load()
 {
     parent::load();
     if ($this->rallyPointLevel <= 0) {
         $this->redirect('build.php?id=39');
         return null;
     }
     if (isset($_GET['d1']) or isset($_GET['d2']) or isset($_GET['d3'])) {
         $this->pageState = 3;
         $this->handleTroopBack();
         return null;
     }
     $m = new WarModel();
     $this->pageState = 1;
     $map_size = $this->setupMetadata['map_size'];
     $half_map_size = floor($map_size / 2);
     $this->hasHero = $this->data['hero_in_village_id'] == $this->data['selected_village_id'];
     $t_arr = explode('|', $this->data['troops_num']);
     foreach ($t_arr as $t_str) {
         $t2_arr = explode(':', $t_str);
         if ($t2_arr[0] == 0 - 1) {
             $t2_arr = explode(',', $t2_arr[1]);
             foreach ($t2_arr as $t2_str) {
                 $t = explode(' ', $t2_str);
                 if ($t[0] == 99) {
                     continue;
                 }
                 $this->troops[] = array('troopId' => $t[0], 'number' => $t[1]);
             }
             continue;
         }
     }
     $attackOptions1 = '';
     $sendTroops = FALSE;
     $playerData = NULL;
     $villageRow = NULL;
     if (!$this->isPost()) {
         if (isset($_GET['id']) and is_numeric($_GET['id'])) {
             $vid = intval($_GET['id']);
             if ($vid < 1) {
                 $vid = 1;
             }
             $villageRow = $m->getVillageDataById($vid);
         }
     } else {
         if (isset($_POST['id'])) {
             $sendTroops = (!$this->isGameTransientStopped() and !$this->isGameOver());
             $vid = intval($_POST['id']);
             $villageRow = $m->getVillageDataById($vid);
         } else {
             if (isset($_POST['dname']) and trim($_POST['dname']) != '') {
                 $villageRow = $m->getVillageDataByName(trim($_POST['dname']));
             } else {
                 if (isset($_POST['x']) and isset($_POST['y']) and trim($_POST['x']) != '' and trim($_POST['y']) != '') {
                     $vid = $this->__getVillageId($map_size, $this->__getCoordInRange($map_size, intval($_POST['x'])), $this->__getCoordInRange($map_size, intval($_POST['y'])));
                     $villageRow = $m->getVillageDataById($vid);
                 }
             }
         }
     }
     if ($villageRow == NULL) {
         if ($this->isPost()) {
             $this->errorTable = v2v_p_entervillagedata;
         }
         return null;
     }
     $this->disableFirstTwoAttack = (intval($villageRow['player_id']) == 0 and $villageRow['is_oasis']);
     $this->targetVillage['x'] = floor(($villageRow['id'] - 1) / $map_size);
     $this->targetVillage['y'] = $villageRow['id'] - ($this->targetVillage['x'] * $map_size + 1);
     if ($half_map_size < $this->targetVillage['x']) {
         $this->targetVillage['x'] -= $map_size;
     }
     if ($half_map_size < $this->targetVillage['y']) {
         $this->targetVillage['y'] -= $map_size;
     }
     if ($villageRow['id'] == $this->data['selected_village_id']) {
         return null;
     }
     if (0 < intval($villageRow['player_id']) and $m->getPlayType($villageRow['player_id']) == PLAYERTYPE_ADMIN) {
         return null;
     }
     $spyOnly = FALSE;
     if (!$villageRow['is_oasis'] and intval($villageRow['player_id']) == 0) {
         $this->transferType = 1;
         $humanTroopId = 0;
         $renderTroops = array();
         foreach ($this->troops as $troop) {
             $renderTroops[$troop['troopId']] = 0;
             if ($troop['troopId'] == 10 or $troop['troopId'] == 20 or $troop['troopId'] == 30 or $troop['troopId'] == 109 or $troop['troopId'] == 60 or $troop['troopId'] == 70 or $troop['troopId'] == 80) {
                 $humanTroopId = $troop['troopId'];
                 $renderTroops[$humanTroopId] = $troop['number'];
                 if ($renderTroops[$humanTroopId] >= 3) {
                     $renderTroops[$humanTroopId] = 3;
                 }
                 continue;
             }
         }
         $canBuildNewVillage = (isset($renderTroops[$humanTroopId]) and 3 <= $renderTroops[$humanTroopId]);
         if ($canBuildNewVillage) {
             $count = trim($this->data['child_villages_id']) == '' ? 0 : sizeof(explode(',', $this->data['child_villages_id']));
             if (1 < $count) {
                 $this->errorTable = v2v_p_cannotbuildnewvill;
                 return null;
             }
             if (!$this->_canBuildNewVillage()) {
                 $this->errorTable = v2v_p_cannotbuildnewvill1;
                 return null;
             }
             if (!$this->isResourcesAvailable($this->newVillageResources)) {
                 $this->errorTable = sprintf(v2v_p_cannotbuildnewvill2, $this->newVillageResources['1']);
                 return null;
             }
             if ($m->hasNewVillageTask($this->player->playerId)) {
                 $this->errorTable = v2v_p_cannotbuildnewvill3;
                 return null;
             }
         } else {
             $this->errorTable = v2v_p_cannotbuildnewvill4;
             return null;
         }
         $this->pageState = 2;
     } else {
         if ($this->isPost()) {
             if (!$villageRow['is_oasis'] and intval($villageRow['player_id']) == 0) {
                 $this->errorTable = v2v_p_novillagehere;
                 return null;
             }
             if (!isset($_POST['c']) or intval($_POST['c']) < 1 or 4 < intval($_POST['c'])) {
                 return null;
             }
             $this->transferType = $this->disableFirstTwoAttack ? 4 : intval($_POST['c']);
             if (0 < intval($villageRow['player_id'])) {
                 $playerData = $m->getPlayerDataById(intval($villageRow['player_id']));
                 if ($playerData['is_blocked']) {
                     $this->errorTable = v2v_p_playerwas_blocked;
                     return null;
                 }
                 if (0 < $playerData['protection_remain_sec']) {
                     if ($this->player->playerId != $villageRow['player_id']) {
                         $this->errorTable = v2v_p_playerwas_inprotectedperiod;
                         return null;
                     }
                 }
             }
             $totalTroopsCount = 0;
             $totalSpyTroopsCount = 0;
             $this->totalCatapultTroopsCount = 0;
             $hasTroopsSelected = FALSE;
             $renderTroops = array();
             if (isset($_POST['t'])) {
                 foreach ($this->troops as $troop) {
                     $num = 0;
                     if (isset($_POST['t'][$troop['troopId']]) and 0 < intval($_POST['t'][$troop['troopId']])) {
                         if (preg_match('/^[+-]?[0-9]+$/', $_POST['t'][$troop['troopId']]) == 0) {
                             exit;
                         }
                         $num = $troop['number'] < $_POST['t'][$troop['troopId']] ? $troop['number'] : intval($_POST['t'][$troop['troopId']]);
                     }
                     $renderTroops[$troop['troopId']] = $num;
                     $totalTroopsCount += $num;
                     if (0 < $num) {
                         $hasTroopsSelected = TRUE;
                     }
                     if ($troop['troopId'] == 4 or $troop['troopId'] == 14 or $troop['troopId'] == 23 or $troop['troopId'] == 103 or $troop['troopId'] == 54 or $troop['troopId'] == 64 or $troop['troopId'] == 74) {
                         $totalSpyTroopsCount += $num;
                         continue;
                     } else {
                         if ($troop['troopId'] == 8 or $troop['troopId'] == 18 or $troop['troopId'] == 28 or $troop['troopId'] == 107 or $troop['troopId'] == 58 or $troop['troopId'] == 68 or $troop['troopId'] == 78) {
                             $this->totalCatapultTroopsCount = $num;
                             //+= 'totalCatapultTroopsCount';
                             //= $num;
                             continue;
                         }
                         continue;
                     }
                 }
             }
             if ($this->hasHero and isset($_POST['_t']) and intval($_POST['_t']) == 1) {
                 $hasTroopsSelected = TRUE;
                 $totalTroopsCount += 1;
             }
             $spyOnly = ($totalSpyTroopsCount == $totalTroopsCount and ($this->transferType == 3 or $this->transferType == 4) and 0 < intval($villageRow['player_id']));
             if ($spyOnly) {
                 $this->onlyOneSpyAction = $villageRow['is_oasis'];
             }
             $this->attackWithCatapult = (0 < $this->totalCatapultTroopsCount and $this->transferType == 3 and 0 < intval($villageRow['player_id']) and !$villageRow['is_oasis']);
             if ($this->attackWithCatapult) {
                 if (10 <= $this->rallyPointLevel) {
                     $this->catapultCanAttackLastIndex = sizeof($this->catapultCanAttack) - 1;
                 } else {
                     if (5 <= $this->rallyPointLevel) {
                         $this->catapultCanAttackLastIndex = 11;
                     } else {
                         if (3 <= $this->rallyPointLevel) {
                             $this->catapultCanAttackLastIndex = 2;
                         } else {
                             $this->catapultCanAttackLastIndex = 0;
                         }
                     }
                 }
                 $attackOptions1 = (isset($_POST['dtg']) and $this->_containBuildingTarget($_POST['dtg'])) ? intval($_POST['dtg']) : 0;
                 if ($this->rallyPointLevel == 20 and 20 <= $this->totalCatapultTroopsCount) {
                     $attackOptions1 = '2:' . ($attackOptions1 . ' ' . ((isset($_POST['dtg1']) and $this->_containBuildingTarget($_POST['dtg1'])) ? intval($_POST['dtg1']) : 0));
                 } else {
                     $attackOptions1 = '1:' . $attackOptions1;
                 }
                 $this->availableCatapultTargetsString = '';
                 $selectComboTargetOptions = '';
                 $i = 1;
                 while ($i <= 9) {
                     if ($this->_containBuildingTarget($i)) {
                         $selectComboTargetOptions .= sprintf('<option value="%s">%s</option>', $i, constant('item_' . $i));
                     }
                     ++$i;
                 }
                 if ($selectComboTargetOptions != '') {
                     $this->availableCatapultTargetsString .= '<optgroup label="' . v2v_p_catapult_grp1 . '">' . $selectComboTargetOptions . '</optgroup>';
                 }
                 $selectComboTargetOptions = '';
                 $i = 10;
                 while ($i <= 28) {
                     if ($i == 10 or $i == 11 or $i == 15 or $i == 17 or $i == 18 or $i == 24 or $i == 25 or $i == 26 or $i == 28 or $i == 38 or $i == 39) {
                         if ($this->_containBuildingTarget($i)) {
                             $selectComboTargetOptions .= sprintf('<option value="%s">%s</option>', $i, constant('item_' . $i));
                         }
                     }
                     ++$i;
                 }
                 if ($selectComboTargetOptions != '') {
                     $this->availableCatapultTargetsString .= '<optgroup label="' . v2v_p_catapult_grp2 . '">' . $selectComboTargetOptions . '</optgroup>';
                 }
                 $selectComboTargetOptions = '';
                 $i = 12;
                 while ($i <= 37) {
                     if ($i == 12 or $i == 13 or $i == 14 or $i == 16 or $i == 19 or $i == 20 or $i == 21 or $i == 22 or $i == 35 or $i == 37) {
                         if ($this->_containBuildingTarget($i)) {
                             $selectComboTargetOptions .= sprintf('<option value="%s">%s</option>', $i, constant('item_' . $i));
                         }
                     }
                     ++$i;
                 }
                 if ($selectComboTargetOptions != '') {
                     $this->availableCatapultTargetsString .= '<optgroup label="' . v2v_p_catapult_grp3 . '">' . $selectComboTargetOptions . '</optgroup>';
                 }
             }
             if (!$hasTroopsSelected) {
                 $this->errorTable = v2v_p_thereisnoattacktroops;
                 return null;
             }
             $this->pageState = 2;
         }
     }
     if ($this->pageState == 2) {
         $this->targetVillage['transferType'] = $this->transferType == 1 ? v2v_p_attacktyp1 : ($this->transferType == 2 ? v2v_p_attacktyp2 . ' ' : ($this->transferType == 3 ? v2v_p_attacktyp3 : ($this->transferType == 4 ? v2v_p_attacktyp4 : '')));
         if ($villageRow['is_oasis']) {
             $this->targetVillage['villageName'] = $playerData != NULL ? v2v_p_placetyp1 : v2v_p_placetyp2;
         } else {
             $this->targetVillage['villageName'] = $playerData != NULL ? $villageRow['village_name'] : v2v_p_placetyp3;
         }
         $this->targetVillage['villageId'] = $villageRow['id'];
         $this->targetVillage['playerName'] = $playerData != NULL ? $playerData['name'] : ($villageRow['is_oasis'] ? v2v_p_monster : '');
         $this->targetVillage['playerId'] = $playerData != NULL ? $playerData['id'] : 0;
         $this->targetVillage['troops'] = $renderTroops;
         $this->targetVillage['hasHero'] = (1 < $this->transferType and $this->hasHero and isset($_POST['_t']) and intval($_POST['_t']) == 1);
         $distance = WebHelper::getdistance($this->data['rel_x'], $this->data['rel_y'], $this->targetVillage['x'], $this->targetVillage['y'], $this->setupMetadata['map_size'] / 2);
         $this->targetVillage['needed_time'] = intval($distance / $this->_getTheSlowestTroopSpeed($renderTroops) * 3600);
         $this->targetVillage['spy'] = $spyOnly;
     }
     if ($sendTroops) {
         $taskType = 0;
         switch ($this->transferType) {
             case 1:
                 $taskType = QS_CREATEVILLAGE;
                 break;
             case 2:
                 $taskType = QS_WAR_REINFORCE;
                 break;
             case 3:
                 $taskType = QS_WAR_ATTACK;
                 break;
             case 4:
                 $taskType = QS_WAR_ATTACK_PLUNDER;
                 break;
             default:
         }
         //return null;
         $spyAction = 0;
         if ($spyOnly) {
             $taskType = QS_WAR_ATTACK_SPY;
             $spyAction = (isset($_POST['spy']) and (intval($_POST['spy']) == 1 or intval($_POST['spy']) == 2)) ? intval($_POST['spy']) : 1;
             if ($this->onlyOneSpyAction) {
                 $spyAction = 1;
             }
         }
         $troopsStr = '';
         foreach ($this->targetVillage['troops'] as $tid => $tnum) {
             if ($troopsStr != '') {
                 $troopsStr .= ',';
             }
             $troopsStr .= $tid . ' ' . $tnum;
         }
         if ($this->targetVillage['hasHero']) {
             $troopsStr .= ',' . $this->data['hero_troop_id'] . ' -1';
         }
         $catapultTargets = $attackOptions1;
         $carryResources = $taskType == QS_CREATEVILLAGE ? implode(' ', $this->newVillageResources) : '';
         $procParams = $troopsStr . '|' . ($this->targetVillage['hasHero'] ? 1 : 0) . '|' . $spyAction . '|' . $catapultTargets . '|' . $carryResources . '|||0';
         $newTask = new QueueTask($taskType, $this->player->playerId, $this->targetVillage['needed_time']);
         $newTask->villageId = $this->data['selected_village_id'];
         $newTask->toPlayerId = intval($villageRow['player_id']);
         $newTask->toVillageId = $villageRow['id'];
         $newTask->procParams = $procParams;
         $newTask->tag = array('troops' => $this->targetVillage['troops'], 'hasHero' => $this->targetVillage['hasHero'], 'resources' => $taskType == QS_CREATEVILLAGE ? $this->newVillageResources : NULL);
         $this->queueModel->addTask($newTask);
         $m->dispose();
         $this->redirect('build.php?id=39');
         //return null;
     }
     $m->dispose();
 }