Beispiel #1
0
 //-------------------------------------------------------------------------
 PlanetResourceUpdate($targetUser, $targetPlanet, time());
 //----------------------- prepare players for battle ----------------------
 // attackers fleet sum
 $attackers = new PlayerGroup();
 if ($FleetRow['fleet_group'] != 0) {
     $fleets = doquery('SELECT * FROM {{table}} WHERE fleet_group=' . $FleetRow['fleet_group'], 'fleets');
     $attackers = getPlayerGroupFromQuery($fleets);
 } else {
     $attackers = getPlayerGroup($FleetRow);
 }
 //defenders fleet sum
 $def = doquery('SELECT * FROM {{table}} WHERE `fleet_end_galaxy` = ' . $FleetRow['fleet_end_galaxy'] . ' AND `fleet_end_system` = ' . $FleetRow['fleet_end_system'] . ' AND `fleet_end_type` = ' . $FleetRow['fleet_end_type'] . ' AND `fleet_end_planet` = ' . $FleetRow['fleet_end_planet'] . ' AND fleet_start_time<' . time() . ' AND fleet_end_stay>=' . time(), 'fleets');
 $defenders = getPlayerGroupFromQuery($def, true, $targetUser);
 //defenses sum
 $homeFleet = new HomeFleet(0);
 for ($i = DEFENSE_MIN_ID; $i < DEFENSE_MAX_ID; $i++) {
     if (isset($resource[$i]) && isset($targetPlanet[$resource[$i]])) {
         if ($targetPlanet[$resource[$i]] != 0) {
             $homeFleet->addShipType(getShipType($i, $targetPlanet[$resource[$i]]));
         }
     }
 }
 for ($i = SHIP_MIN_ID; $i < SHIP_MAX_ID; $i++) {
     if (isset($resource[$i]) && isset($targetPlanet[$resource[$i]])) {
         if ($targetPlanet[$resource[$i]] != 0) {
             $homeFleet->addShipType(getShipType($i, $targetPlanet[$resource[$i]]));
         }
     }
 }
 if (!$defenders->existPlayer($TargetUserID)) {
 /**
  * method attack_mission
  * param $fleet_row
  * return the attack result
  */
 public function attack_mission($fleet_row)
 {
     // null == use default handlers
     $errorHandler = null;
     $exceptionHandler = null;
     if ($fleet_row['fleet_mess'] == 0 && $fleet_row['fleet_start_time'] <= time()) {
         $base = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
         require $base . 'utils' . DIRECTORY_SEPARATOR . 'includer.php';
         $target_planet = parent::$db->query_fetch("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\tINNER 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\tINNER 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\tINNER 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\tWHERE `planet_galaxy` = " . (int) $fleet_row['fleet_end_galaxy'] . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_system` = " . (int) $fleet_row['fleet_end_system'] . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_type` = " . (int) $fleet_row['fleet_end_type'] . " AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`planet_planet` = " . (int) $fleet_row['fleet_end_planet'] . ";");
         if ($fleet_row['fleet_group'] > 0) {
             parent::$db->query("DELETE FROM `" . ACS_FLEETS . "`\n\t\t\t\t\t\t\t\t\t\tWHERE `acs_fleet_id` = '" . (int) $fleet_row['fleet_group'] . "'");
             parent::$db->query("UPDATE `" . FLEETS . "` SET\n\t\t\t\t\t\t\t\t\t\t`fleet_mess` = '1'\n\t\t\t\t\t\t\t\t\t\tWHERE `fleet_group` = '" . $fleet_row['fleet_group'] . "'");
         } else {
             parent::return_fleet($fleet_row['fleet_id']);
         }
         $target_user = doquery('SELECT * FROM {{table}} WHERE id=' . $target_planet['id_owner'], 'users', true);
         $target_userID = $target_user['id'];
         PlanetResourceUpdate($target_user, $target_planet, time());
         // attackers fleet sum
         $attackers = new PlayerGroup();
         if ($fleet_row['fleet_group'] != 0) {
             $fleets = doquery('SELECT * FROM {{table}} WHERE fleet_group=' . $fleet_row['fleet_group'], 'fleets');
             $attackers = get_player_group_from_query($fleets);
         } else {
             $attackers = get_player_group($fleet_row);
         }
         //defenders fleet sum
         $def = doquery('SELECT * FROM {{table}} WHERE `fleet_end_galaxy` = ' . $fleet_row['fleet_end_galaxy'] . ' AND `fleet_end_system` = ' . $fleet_row['fleet_end_system'] . ' AND `fleet_end_type` = ' . $fleet_row['fleet_end_type'] . ' AND `fleet_end_planet` = ' . $fleet_row['fleet_end_planet'] . ' AND fleet_start_time<' . time() . ' AND fleet_end_stay>=' . time(), 'fleets');
         $defenders = get_player_group_from_query($def, true, $target_user);
         //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->add(get_ship_type($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->add(get_ship_type($i, $target_planet[$this->_resource[$i]]));
                 }
             }
         }
         if (!$defenders->existPlayer($target_userID)) {
             $player = new Player($target_userID, array($homeFleet));
             $player->setTech($target_user['military_tech'], $target_user['shield_tech'], $target_user['defence_tech']);
             $defenders->addPlayer($player);
         } else {
             $defenders->getPlayer($target_userID)->addDefense($homeFleet);
         }
         //start of battle
         $battle = new Battle($attackers, $defenders);
         $startBattle = DebugManager::runDebugged(array($battle, 'startBattle'), $errorHandler, $exceptionHandler);
         $startBattle();
         //end of battle
         $report = $battle->getReport();
         $steal = $this->update_attackers($report->getPresentationAttackersFleetOnRound('START'), $report->getAfterBattleAttackers(), $target_planet);
         $this->update_defenders($report->getPresentationDefendersFleetOnRound('START'), $report->getAfterBattleDefenders(), $target_planet, $steal);
         $this->updateDebris($fleet_row, $report);
         $this->update_moon($fleet_row, $report, '', $target_userID, $target_planet);
         $this->send_message($fleet_row, $report);
     } elseif ($fleet_row['fleet_end_time'] <= time()) {
         $message = sprintf($this->_lang['sys_fleet_won'], $target_planet['planet_name'], Fleets_Lib::target_link($fleet_row, ''), Format_Lib::pretty_number($fleet_row['fleet_resource_metal']), $this->_lang['Metal'], Format_Lib::pretty_number($fleet_row['fleet_resource_crystal']), $this->_lang['Crystal'], Format_Lib::pretty_number($fleet_row['fleet_resource_deuterium']), $this->_lang['Deuterium']);
         Functions_Lib::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']);
     }
 }
Beispiel #3
0
 /**
  * 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->query_fetch("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()) {
         $base = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
         // require several stuff
         require $base . 'libraries' . DIRECTORY_SEPARATOR . 'battle_engine' . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR . 'includer.php';
         // require language implementation
         require $base . 'libraries' . DIRECTORY_SEPARATOR . '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->query_fetch("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::updateResource($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->query_fetch("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'], Fleets_Lib::target_link($fleet_row, ''), Format_Lib::pretty_number($fleet_row['fleet_resource_metal']), $this->_lang['Metal'], Format_Lib::pretty_number($fleet_row['fleet_resource_crystal']), $this->_lang['Crystal'], Format_Lib::pretty_number($fleet_row['fleet_resource_deuterium']), $this->_lang['Deuterium']);
         Functions_Lib::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']);
     }
 }