/** * @param array $fleetDetails * @param CombatParty $party * @return CombatPlayer[] */ private function createFleets($fleetDetails, $party) { $players = array(); foreach ($party->getPlayers() as $player) { $clone = clone $player; foreach ($clone->getFleets() as $fleet) { $fleetData = $fleetDetails[$fleet->getCombatIndex()]; foreach ($fleetData as $type => $techData) { $lost = isset($techData['lost']) ? $techData['lost'] : 0; $fleet->addTechnologyState(TechnologyFactory::create($type), $techData['ships'], $lost); } } $players[$player->getId()] = $clone; } return $players; }
/** * @param array $rawPlayers */ private function loadParty($rawPlayers) { $playerIdMapping = array(); $players = array(); foreach ($rawPlayers as $combat_index => $fleetData) { $rawPlayer = $fleetData['fleet_owner']; $playerId = isset($playerIdMapping[$rawPlayer]) ? $playerIdMapping[$rawPlayer] : false; //Check if player already exists, if not create it & add it if ($playerId === false) { $playerId = $this->player_id_count++; $playerIdMapping[$rawPlayer] = $playerId; $players[$playerId] = new CombatPlayer($rawPlayer, $playerId); $players[$playerId]->setCombatTechnologies($fleetData['fleet_armor_percentage'], $fleetData['fleet_shield_percentage'], $fleetData['fleet_weapon_percentage']); $players[$playerId]->setAlliance(new Alliance($fleetData['fleet_owner_alliance_tag'], $fleetData['fleet_owner_alliance'])); } $player = $players[$playerId]; $planet = new Planet($fleetData['fleet_owner_planet_type'], $fleetData['fleet_owner_coordinates'], $fleetData['fleet_owner_planet_name']); $fleet = new CombatFleet($planet, $combat_index); foreach ($fleetData['fleet_composition'] as $rawTechnology) { $technology = TechnologyFactory::create($rawTechnology['ship_type']); $fleet->addTechnologyState($technology, $rawTechnology['count']); } $player->addFleet($fleet); } return $players; }
/** * @param string $api_data * @return CombatReport */ public static function createSpyReport($api_data) { $generic = $api_data['generic']; $details = $api_data['details']; $spyreport = new self($generic['sr_id'], $generic['activity'], $generic['attacker_name'], $generic['attacker_planet_coordinates'], $generic['attacker_planet_name'], $generic['attacker_planet_type'], $generic['attacker_alliance_name'], $generic['attacker_alliance_tag'], $generic['defender_name'], $generic['defender_planet_coordinates'], $generic['defender_planet_name'], $generic['defender_planet_type'], $generic['defender_alliance_name'], $generic['defender_alliance_tag'], $generic['event_time'], $generic['event_timestamp'], $generic['loot_percentage'], $generic['spy_fail_chance'], $generic['total_defense_count'], $generic['total_ship_count']); if (isset($details['resources'])) { $spyreport->getDefender()->setResources(new Resources($details['resources']['metal'], $details['resources']['crystal'], $details['resources']['deuterium'])); } if ($generic['failed_buildings'] === false) { if (isset($details['buildings'])) { foreach ($details['buildings'] as $state) { $buildingState = new StateEconomy(TechnologyFactory::create($state['building_type']), $state['level']); $spyreport->getDefender()->addBuilding($buildingState); } } } if ($generic['failed_research'] === false) { if (isset($details['research'])) { foreach ($details['research'] as $state) { $researchState = new StateEconomy(TechnologyFactory::create($state['research_type']), $state['level']); $spyreport->getDefender()->addResearch($researchState); } } } if ($generic['failed_ships'] === false) { if (isset($details['ships'])) { foreach ($details['ships'] as $state) { $shipState = new StateCombat(TechnologyFactory::create($state['ship_type']), $state['count']); $spyreport->getDefender()->addShip($shipState); } } } if ($generic['failed_defense'] === false) { if (isset($details['defense'])) { foreach ($details['defense'] as $state) { $defenceState = new StateCombat(TechnologyFactory::create($state['defense_type']), $state['count']); $spyreport->getDefender()->addDefence($defenceState); } } } return $spyreport; }
private function setAttackerMissiles() { $state = new StateCombatWithLosses(TechnologyFactory::create(InterplanetaryMissile::TYPE), $this->attacker_lost_missiles, $this->attacker_lost_missiles); $this->attacker->addLostDefence($state); }