/** * __construct() */ public function __construct() { $this->_lang = parent::$lang; if ($this->is_session_set()) { // Get user data and check it $this->set_user_data(); // Check game close FunctionsLib::check_server($this->_user_data); // Set the changed planet $this->set_planet(); // Get planet data and check it $this->set_planet_data(); // Update resources, ships, defenses & technologies UpdateResourcesLib::updateResources($this->_user_data, $this->_planet_data, time()); // Update buildings queue UpdateLib::updateBuildingsQueue($this->_planet_data, $this->_user_data); } }
/** * updateBuildingsQueue * * @param array $current_planet Current planet * @param array $current_user Current user * * @return void */ public static function updateBuildingsQueue(&$current_planet, &$current_user) { if ($current_planet['planet_b_building_id'] != 0) { while ($current_planet['planet_b_building_id'] != 0) { if ($current_planet['planet_b_building'] <= time()) { UpdateResourcesLib::updateResources($current_user, $current_planet, $current_planet['planet_b_building'], false); if (self::checkBuildingQueue($current_planet, $current_user)) { DevelopmentsLib::set_first_element($current_planet, $current_user); } } else { break; } } } }
/** * method make_update * param $fleet_row * param $galaxy * param $system * param $planet * param $type * return make a planet update, required before do other stuff */ protected function make_update($fleet_row, $galaxy, $system, $planet, $type) { $target_planet = parent::$db->queryFetch("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . PLANETS . "` AS p\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . BUILDINGS . "` AS b ON b.building_planet_id = p.`planet_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . DEFENSES . "` AS d ON d.defense_planet_id = p.`planet_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `" . SHIPS . "` AS s ON s.ship_planet_id = p.`planet_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `planet_galaxy` = " . $galaxy . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_system` = " . $system . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = " . $planet . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_type` = " . $type . ";"); $target_user = parent::$db->queryFetch("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . USERS . "` AS u\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . RESEARCH . " AS r ON r.research_user_id = u.user_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN " . PREMIUM . " AS pr ON pr.premium_user_id = u.user_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE u.`user_id` = " . $target_planet['planet_user_id']); UpdateResourcesLib::updateResources($target_user, $target_planet, time()); }
/** * attackMission * * @param array $fleet_row Fleet row * * @return void */ public function attackMission($fleet_row) { // null == use default handlers $errorHandler = null; $exceptionHandler = null; $target_planet = parent::$db->queryFetch("SELECT *\n FROM " . PLANETS . " AS p\n INNER JOIN " . BUILDINGS . " AS b ON b.building_planet_id = p.`planet_id`\n INNER JOIN " . SHIPS . " AS s ON s.ship_planet_id = p.`planet_id`\n INNER JOIN " . DEFENSES . " AS d ON d.defense_planet_id = p.`planet_id`\n WHERE `planet_galaxy` = " . (int) $fleet_row['fleet_end_galaxy'] . " AND\n `planet_system` = " . (int) $fleet_row['fleet_end_system'] . " AND\n `planet_type` = " . (int) $fleet_row['fleet_end_type'] . " AND\n `planet_planet` = " . (int) $fleet_row['fleet_end_planet'] . ";"); if ($fleet_row['fleet_mess'] == 0 && $fleet_row['fleet_start_time'] <= time()) { // require several stuff require XGP_ROOT . VENDOR_PATH . 'battle_engine' . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'includer.php'; // require language implementation require XGP_ROOT . LIB_PATH . 'missions' . DIRECTORY_SEPARATOR . 'attackLang.php'; // set language for the reports LangManager::getInstance()->setImplementation(new AttackLang($this->_lang)); if ($fleet_row['fleet_group'] > 0) { parent::$db->query("DELETE FROM `" . ACS_FLEETS . "`\n WHERE `acs_fleet_id` = '" . (int) $fleet_row['fleet_group'] . "'"); parent::$db->query("UPDATE `" . FLEETS . "` SET\n `fleet_mess` = '1'\n WHERE `fleet_group` = '" . $fleet_row['fleet_group'] . "'"); } else { parent::return_fleet($fleet_row['fleet_id']); } $targetUser = parent::$db->queryFetch("SELECT u.*,\n r.*,\n pr.*\n FROM " . USERS . " AS u\n INNER JOIN " . RESEARCH . " AS r ON r.research_user_id = u.user_id\n INNER JOIN " . PREMIUM . " AS pr ON pr.premium_user_id = u.user_id\n WHERE u.user_id = '" . intval($target_planet['planet_user_id']) . "';"); $target_userID = $targetUser['user_id']; UpdateResourcesLib::updateResources($targetUser, $target_planet, time()); //----------------------- prepare players for battle ---------------------- // attackers fleet sum $attackers = new PlayerGroup(); // If we have a ACS attack if ($fleet_row['fleet_group'] != 0) { $fleets = parent::$db->queryFetch("SELECT * FROM `" . FLEETS . "` WHERE `fleet_group` = '" . $fleet_row['fleet_group'] . "';"); $attackers = $this->getPlayerGroupFromQuery($fleets); } else { $attackers = $this->getPlayerGroup($fleet_row); } // defenders fleet sum $def = parent::$db->query("SELECT * FROM `" . FLEETS . "` \n WHERE `fleet_end_galaxy` = '" . $fleet_row['fleet_end_galaxy'] . "' AND \n `fleet_end_system` = '" . $fleet_row['fleet_end_system'] . "' AND \n `fleet_end_type` = '" . $fleet_row['fleet_end_type'] . "' AND \n `fleet_end_planet` = '" . $fleet_row['fleet_end_planet'] . "' AND\n `fleet_start_time` < '" . time() . "' AND \n `fleet_end_stay` >= '" . time() . "';"); $defenders = $this->getPlayerGroupFromQuery($def, $targetUser); //defenses sum $homeFleet = new HomeFleet(0); for ($i = self::DEFENSE_MIN_ID; $i < self::DEFENSE_MAX_ID; $i++) { if (isset($this->_resource[$i]) && isset($target_planet[$this->_resource[$i]])) { if ($target_planet[$this->_resource[$i]] != 0) { $homeFleet->addShipType($this->getShipType($i, $target_planet[$this->_resource[$i]])); } } } for ($i = self::SHIP_MIN_ID; $i < self::SHIP_MAX_ID; $i++) { if (isset($this->_resource[$i]) && isset($target_planet[$this->_resource[$i]])) { if ($target_planet[$this->_resource[$i]] != 0) { $homeFleet->addShipType($this->getShipType($i, $target_planet[$this->_resource[$i]])); } } } if (!$defenders->existPlayer($target_userID)) { $player = new Player($target_userID, array($homeFleet)); $player->setTech($targetUser['research_weapons_technology'], $targetUser['research_shielding_technology'], $targetUser['research_armour_technology']); $player->setName($targetUser['user_name']); $defenders->addPlayer($player); } else { $defenders->getPlayer($target_userID)->addDefense($homeFleet); } //------------------------------------------------------------------------- //------------------------------ battle ----------------------------------- $battle = new Battle($attackers, $defenders); $startBattle = DebugManager::runDebugged(array($battle, 'startBattle'), $errorHandler, $exceptionHandler); $startBattle(); //------------------------------------------------------------------------- //-------------------------- after battle stuff --------------------------- $report = $battle->getReport(); $steal = $this->updateAttackers($report->getPresentationAttackersFleetOnRound('START'), $report->getAfterBattleAttackers(), $target_planet); $report->setSteal($steal); $this->updateDefenders($report->getPresentationDefendersFleetOnRound('START'), $report->getAfterBattleDefenders(), $target_planet, $steal); $this->updateDebris($fleet_row, $report); $this->updateMoon($fleet_row, $report, '', $target_userID, $target_planet); $this->sendMessage($fleet_row, $report); } elseif ($fleet_row['fleet_end_time'] <= time()) { $message = sprintf($this->_lang['sys_fleet_won'], $target_planet['planet_name'], FleetsLib::target_link($fleet_row, ''), FormatLib::pretty_number($fleet_row['fleet_resource_metal']), $this->_lang['Metal'], FormatLib::pretty_number($fleet_row['fleet_resource_crystal']), $this->_lang['Crystal'], FormatLib::pretty_number($fleet_row['fleet_resource_deuterium']), $this->_lang['Deuterium']); FunctionsLib::send_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_end_time'], 1, $this->_lang['sys_mess_tower'], $this->_lang['sys_mess_fleetback'], $message); parent::restore_fleet($fleet_row); parent::remove_fleet($fleet_row['fleet_id']); } }