public function load() { parent::load(); if ($this->isPost()) { if (!isset($_POST['a1']) || intval($_POST['a1']) != 1 && intval($_POST['a1']) != 2 && intval($_POST['a1']) != 3 && intval($_POST['a1']) != 7 && intval($_POST['a1']) != 6) { $this->errorText = war_sim_noattack; } else { if (!isset($_POST['ktyp']) || intval($_POST['ktyp']) != 1 && intval($_POST['ktyp']) != 2) { $this->errorText = war_sim_nobattletype; } else { if (!isset($_POST['a2']) || sizeof($_POST['a2']) == 0) { $this->errorText = war_sim_nodefense; } else { foreach ($_POST['a2'] as $tribeId => $v) { if ($tribeId != 1 && $tribeId != 2 && $tribeId != 3 && $tribeId != 4 && $tribeId != 7 && $tribeId != 6) { $this->errorText = war_sim_nodefense2; } } $this->troopsMetadata = $this->gameMetadata['troops']; $this->showTroopsTable = TRUE; $this->showWarResult = FALSE; if (!isset($_POST['t1'])) { return; } $m = new WarBattleModel(); if (isset($_POST['h_off_bonus1']) && 0 < intval($_POST['h_off_bonus1'])) { $this->showWarResult = TRUE; } $troops = array(); $troopsPower = array(); foreach ($_POST['t1'] as $tribeId => $troopArray) { foreach ($troopArray as $tid => $tnum) { if (0 < $tnum) { $this->showWarResult = TRUE; } $troops[$tid] = intval($tnum); $troopsPower[$tid] = 0; } } if (!$this->showWarResult) { return; } $peopleCount = isset($_POST['ew1']) ? intval($_POST['ew1']) : 0; $heroLevel = isset($_POST['h_off_bonus1']) ? intval($_POST['h_off_bonus1']) : 0; $wringerPower = isset($_POST['kata']) ? intval($_POST['kata']) : 0; $attackTroops = $m->_getTroopWithPower($troops, $troopsPower, TRUE, $heroLevel, $peopleCount, $wringerPower, 0); $peopleCount = isset($_POST['ew2']) ? intval($_POST['ew2']) : 0; $wallLevel = isset($_POST['wall1']) ? intval($_POST['wall1']) : 0; $totalDefensePower = 0; $defenseTroops = array(); foreach ($_POST['t2'] as $tribeId => $troopArray) { $troops = array(); $troopsPower = array(); foreach ($troopArray as $tid => $tnum) { $troops[$tid] = intval($tnum); $troopsPower[$tid] = isset($_POST['f2'], $_POST['f2'][$tribeId]) && isset($_POST['f2'][$tribeId][$tid]) ? intval($_POST['f2'][$tribeId][$tid]) : 0; } $defenseTroops[$tribeId] = $m->_getTroopWithPower($troops, $troopsPower, FALSE, 0, $peopleCount, 0, $wallLevel); $totalDefensePower += $defenseTroops[$tribeId]['total_power']; } $this->warResult = $m->getWarResult($attackTroops, $defenseTroops, $totalDefensePower, isset($_POST['ktyp']) && intval($_POST['ktyp']) == 2); $m->dispose(); } } } } }
public function executeWarResult($taskRow) { $taskRow['village_id'] = intval($taskRow['village_id']); $fromVillageRow = $this->_getVillageInfo($taskRow['village_id']); $toVillageRow = $this->_getVillageInfo($taskRow['to_village_id']); $paramsArray = explode("|", $taskRow['proc_params']); $troopsArrStr = explode(",", $paramsArray[0]); $troopsArray = array("troops" => array(), "onlyHero" => FALSE, "heroTroopId" => 0, "hasHero" => FALSE, "hasKing" => FALSE, "hasWallDest" => FALSE, "cropConsumption" => 0); $_onlyHero = TRUE; foreach ($troopsArrStr as $_t) { $tnum = explode(" ", $_t); $tid = explode(" ", $_t); list($tid, $tnum) = $tid; if ($tnum == 0 - 1) { $troopsArray['hasHero'] = TRUE; $troopsArray['heroTroopId'] = $tid; $tnum = 1; } else { $troopsArray['troops'][$tid] = $tnum; if (0 < $tnum) { $_onlyHero = FALSE; } else { continue; } if ($tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59) { $troopsArray['hasKing'] = TRUE; } if ($tid == 7 || $tid == 17 || $tid == 27 || $tid == 106 || $tid == 57) { $troopsArray['hasWallDest'] = TRUE; } } $tnum += $troopsArray['cropConsumption']; //fix still needed } if ($_onlyHero && $troopsArray['hasHero']) { $troopsArray['onlyHero'] = TRUE; } $procInfo = array("troopsArray" => $troopsArray, "hasHero" => $paramsArray[1] == 1, "spyAction" => $paramsArray[2], "catapultTarget" => $paramsArray[3], "harvestResources" => $paramsArray[4], "spyInfo" => $paramsArray[5], "catapultResult" => $paramsArray[6], "troopBack" => $paramsArray[7] == 1); if ($taskRow['proc_type'] == QS_CREATEVILLAGE && ($toVillageRow['is_oasis'] || 0 < intval($toVillageRow['player_id']))) { $taskRow['proc_type'] = QS_WAR_ATTACK_PLUNDER; } switch ($taskRow['proc_type']) { case QS_WAR_REINFORCE: require_once MODEL_PATH . DIRECTORY_SEPARATOR . "battles" . DIRECTORY_SEPARATOR . "reinforcement.php"; $reinforceModel = new ReInforcementBattleModel(); return $reinforceModel->handleReInforcement($taskRow, $toVillageRow, $fromVillageRow, $procInfo, $paramsArray[0]); case QS_WAR_ATTACK: break; case QS_WAR_ATTACK_PLUNDER: } require_once MODEL_PATH . DIRECTORY_SEPARATOR . "battles" . DIRECTORY_SEPARATOR . "war.php"; $warModel = new WarBattleModel(); return $warModel->handleWarAttack($taskRow, $toVillageRow, $fromVillageRow, $procInfo); switch ($taskRow['proc_type']) { case QS_WAR_ATTACK_SPY: require_once MODEL_PATH . DIRECTORY_SEPARATOR . "battles" . DIRECTORY_SEPARATOR . "spy.php"; $spyModel = new SpyBattleModel(); return $spyModel->handleWarSpy($taskRow, $toVillageRow, $fromVillageRow, $procInfo); case QS_CREATEVILLAGE: require_once MODEL_PATH . DIRECTORY_SEPARATOR . "battles" . DIRECTORY_SEPARATOR . "createnewvillage.php"; $newVillageModel = new NewVillageBattleModel(); return $newVillageModel->handleCreateNewVillage($taskRow, $toVillageRow, $fromVillageRow, $troopsArray['cropConsumption']); } return FALSE; }
function executeWarResult($taskRow) { global $GameMetadata; $taskRow['village_id'] = intval($taskRow['village_id']); $fromVillageRow = $this->_getVillageInfo($taskRow['village_id']); $toVillageRow = $this->_getVillageInfo($taskRow['to_village_id']); $paramsArray = explode('|', $taskRow['proc_params']); $troopsArrStr = explode(',', $paramsArray[0]); $troopsArray = array('troops' => array(), 'onlyHero' => FALSE, 'heroTroopId' => 0, 'hasHero' => FALSE, 'hasKing' => FALSE, 'hasWallDest' => FALSE, 'cropConsumption' => 0); $_onlyHero = TRUE; foreach ($troopsArrStr as $_t) { list($tid, $tnum) = explode(' ', $_t); if ($tnum == -1) { $troopsArray['hasHero'] = TRUE; $troopsArray['heroTroopId'] = $tid; $tnum = 1; } else { $troopsArray['troops'][$tid] = $tnum; if ($tnum > 0) { $_onlyHero = FALSE; } else { continue; } if ($tid == 9 || $tid == 19 || $tid == 29) { $troopsArray['hasKing'] = TRUE; } if ($tid == 7 || $tid == 17 || $tid == 27) { $troopsArray['hasWallDest'] = TRUE; } } $troopsArray['cropConsumption'] += $GameMetadata['troops'][$tid]['crop_consumption'] * $tnum; } if ($_onlyHero && $troopsArray['hasHero']) { $troopsArray['onlyHero'] = TRUE; } $procInfo = array('troopsArray' => $troopsArray, 'hasHero' => $paramsArray[1] == 1, 'spyAction' => $paramsArray[2], 'catapultTarget' => $paramsArray[3], 'harvestResources' => $paramsArray[4], 'spyInfo' => $paramsArray[5], 'catapultResult' => $paramsArray[6], 'troopBack' => $paramsArray[7] == 1); if ($taskRow['proc_type'] == QS_CREATEVILLAGE) { if ($toVillageRow['is_oasis'] || intval($toVillageRow['player_id']) > 0) { $taskRow['proc_type'] = QS_WAR_ATTACK_PLUNDER; } } switch ($taskRow['proc_type']) { case QS_WAR_REINFORCE: require_once MODEL_PATH . DIRECTORY_SEPARATOR . 'battles' . DIRECTORY_SEPARATOR . 'reinforcement.php'; $reinforceModel = new ReInforcementBattleModel(); return $reinforceModel->handleReInforcement($taskRow, $toVillageRow, $fromVillageRow, $procInfo, $paramsArray[0]); case QS_WAR_ATTACK: case QS_WAR_ATTACK_PLUNDER: require_once MODEL_PATH . DIRECTORY_SEPARATOR . 'battles' . DIRECTORY_SEPARATOR . 'war.php'; $warModel = new WarBattleModel(); return $warModel->handleWarAttack($taskRow, $toVillageRow, $fromVillageRow, $procInfo); case QS_WAR_ATTACK_SPY: require_once MODEL_PATH . DIRECTORY_SEPARATOR . 'battles' . DIRECTORY_SEPARATOR . 'spy.php'; $spyModel = new SpyBattleModel(); return $spyModel->handleWarSpy($taskRow, $toVillageRow, $fromVillageRow, $procInfo); case QS_CREATEVILLAGE: require_once MODEL_PATH . DIRECTORY_SEPARATOR . 'battles' . DIRECTORY_SEPARATOR . 'createnewvillage.php'; $newVillageModel = new NewVillageBattleModel(); return $newVillageModel->handleCreateNewVillage($taskRow, $toVillageRow, $fromVillageRow, $troopsArray['cropConsumption']); } return TRUE; }