Beispiel #1
0
 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);
                         }
                     }
                 }
             }
         }
     }
 }
 public function preRender()
 {
     parent::prerender();
     /* if ( isset( $_GET['p'] ) )
        {
            $_41448384 .= "villagesLinkPostfix";
        }
        if ( isset( $_GET['vid2'] ) )
        {
             $this->villagesLinkPostfix .= "&t=".$this->selectedTabIndex;
            $_41448784 .= "villagesLinkPostfix";
        } 
        if ( 0 < $this->selectedTabIndex )
        {
            $this->villagesLinkPostfix .= "&t=".$this->selectedTabIndex;   
           // $ && _41448984 .= "villagesLinkPostfix";
        }     */
 }
Beispiel #3
0
 function preRender()
 {
     parent::prerender();
     if (isset($_GET['p'])) {
         $this->villagesLinkPostfix .= '&p=' . intval($_GET['p']);
     }
     if (isset($_GET['vid2'])) {
         $this->villagesLinkPostfix .= '&vid2=' . intval($_GET['vid2']);
     }
     if (0 < $this->selectedTabIndex) {
         $this->villagesLinkPostfix .= '&t=' . $this->selectedTabIndex;
     }
 }
Beispiel #4
0
 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();
 }
Beispiel #5
0
 function preRender()
 {
     parent::prerender();
     if (isset($_GET['id'])) {
         $this->villagesLinkPostfix .= '&id=' . intval($_GET['id']);
     }
 }
Beispiel #6
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();
                 }
             }
         }
     }
 }
Beispiel #7
0
 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();
 }