/** * updateDefenders * * @param Battle $playerGroupBeforeBattle Player Group before battle * @param Battle $playerGroupAfterBattle Player Group after battle * @param array $target_planet Target planet * @param array $steal Stealed resources * * @return void */ private function updateDefenders($playerGroupBeforeBattle, $playerGroupAfterBattle, $target_planet, $steal) { $Xplayer = $Xfleet = $XshipType = null; $fleetArray = ''; $emptyFleets = array(); foreach ($playerGroupBeforeBattle->getIterator() as $idPlayer => $player) { $existPlayer = $playerGroupAfterBattle->existPlayer($idPlayer); if ($existPlayer) { $Xplayer = $playerGroupAfterBattle->getPlayer($idPlayer); } foreach ($player->getIterator() as $idFleet => $fleet) { $existFleet = $existPlayer && $Xplayer->existFleet($idFleet); if ($existFleet) { $Xfleet = $Xplayer->getFleet($idFleet); } else { $emptyFleets[] = $idFleet; } foreach ($fleet as $idShipType => $fighters) { $existShipType = $existFleet && $Xfleet->existShipType($idShipType); $amount = 0; if ($existShipType) { $XshipType = $Xfleet->getShipType($idShipType); $amount = $XshipType->getCount(); } $fleetArray .= '`' . $this->_resource[$idShipType] . '` = ' . $amount . ', '; } } } // Updating defenses and ships on planet parent::$db->query("UPDATE `" . PLANETS . "`, `" . SHIPS . "` SET\n " . $fleetArray . "\n `planet_metal` = `planet_metal` - " . $steal['metal'] . ",\n `planet_crystal` = `planet_crystal` - " . $steal['crystal'] . ",\n `planet_deuterium` = `planet_deuterium` - " . $steal['deuterium'] . "\n WHERE `planet_id` = '" . $target_planet['planet_id'] . "' AND\n `ship_planet_id` = '" . $target_planet['planet_id'] . "'"); // Updating flying fleets $id_string = implode(",", $emptyFleets); if (!empty($id_string)) { parent::$db->query("DELETE FROM `" . FLEETS . "`\n WHERE `fleed_id` IN (" . $id_string . ")"); } }