private function buildPlayerGroup($tech, $fleets) { $playerObj = new Player(1); $playerObj->setName('bot'); $playerObj->setTech($tech['weapons'], $tech['shields'], $tech['armour']); foreach ($fleets as $idFleet => $fleet) { $fleetObj = new Fleet($idFleet); foreach ($fleet as $id => $count) { $count = floor($count); $id = floor($id); if ($count > 0 && $id > 0) { $fleetObj->addShipType($this->getShipType($id, $count)); } } if (!$fleetObj->isEmpty()) { $playerObj->addFleet($fleetObj); } } if ($playerObj->isEmpty()) { die("<meta http-equiv=\"refresh\" content=2;\"WebTest.php\">There should be at least an attacker and defender"); } $playerGroupObj = new PlayerGroup(); $playerGroupObj->addPlayer($playerObj); return $playerGroupObj; }
/** * Round::__construct() * Construct a new Round object. No side effects. * @param PlayerGroup: the attackers * @param PlayerGroup: the defenders * @param int: the round number * @return void */ public function __construct(PlayerGroup $attackers, PlayerGroup $defenders, $number) { $this->number = $number; $this->fire_a = new FireManager(); $this->fire_d = new FireManager(); $this->attackers = $attackers->cloneMe(); $this->defenders = $defenders->cloneMe(); }
/** * updatePlayers() * Update players array as default 2moons require. * OPBE keep the internal array data full to decrease memory size, so a PlayerGroup object don't have data about * empty users(an user is empty when fleets are empty and fleet is empty when the ships count is zero) * Instead, the old system require to have also array of zero: to update the array of users, after a round, we must iterate them * and check the corrispective OPBE value if empty. * * @param PlayerGroup $playerGroup * @param array &$players * @return null */ function updatePlayers(PlayerGroup $playerGroup, &$players) { $plyArray = array(); $amountArray = array(); foreach ($players as $idFleet => $info) { $players[$idFleet]['techs'] = getTechsFromArrayForReport($info['user']); foreach ($info['unit'] as $idShipType => $amount) { if ($playerGroup->existPlayer($info['player']['id'])) { $player = $playerGroup->getPlayer($info['player']['id']); if ($player->existFleet($idFleet)) { $fleet = $player->getFleet($idFleet); if ($fleet->existShipType($idShipType)) { $shipType = $fleet->getShipType($idShipType); //used to show life,power and shield of each ships in the report $plyArray[$idFleet][$idShipType] = array('def' => $shipType->getHull(), 'shield' => $shipType->getShield(), 'att' => $shipType->getPower()); $players[$idFleet]['unit'][$idShipType] = $shipType->getCount(); } else { $players[$idFleet]['unit'][$idShipType] = 0; } } else { $players[$idFleet]['unit'][$idShipType] = 0; } } else { $players[$idFleet]['unit'][$idShipType] = 0; } //initialization if (!isset($amountArray[$idFleet])) { $amountArray[$idFleet] = 0; } if (!isset($amountArray['total'])) { $amountArray['total'] = 0; } //increment $currentAmount = $players[$idFleet]['unit'][$idShipType]; $amountArray[$idFleet] = $amountArray[$idFleet] + $currentAmount; $amountArray['total'] = $amountArray['total'] + $currentAmount; } } return array($plyArray, $amountArray); }
/** * method getCapacity * param $players * return the attack result */ private function getCapacity(PlayerGroup $players) { $capacity = 0; foreach ($players->getIterator() as $idPlayer => $player) { foreach ($player->getIterator() as $idFleet => $fleet) { foreach ($fleet->getIterator() as $idShipType => $shipType) { $capacity += $shipType->getCount() * $this->_pricelist[$idShipType]['capacity']; } } } return $capacity; }
private function getPlayersLostShips(PlayerGroup $playersBefore, PlayerGroup $playersAfter) { $playersBefore_clone = $playersBefore->cloneMe(); foreach ($playersAfter->getIterator() as $idPlayer => $playerAfter) { foreach ($playerAfter->getIterator() as $idFleet => $fleet) { foreach ($fleet->getIterator() as $idShipType => $shipType) { $playersBefore_clone->decrement($idPlayer, $idFleet, $idShipType, $shipType->getCount()); } } } return $playersBefore_clone; }
/** * updatePlayers() * Update players array as default 2moons require. * OPBE keep the internal array data full to decrease memory size, so a PlayerGroup object don't have data about * empty users(an user is empty when fleets are empty and fleet is empty when the ships count is zero) * Instead, the old system require to have also array of zero: to update the array of users, after a round, we must iterate them * and check the corrispective OPBE value if empty. * * @param PlayerGroup $playerGroup * @param array &$players * @return null */ function updatePlayers(PlayerGroup $playerGroup, &$players) { $plyArray = array(); $amountArray = array(); foreach ($players as $idFleet => $info) { foreach ($info['unit'] as $idShipType => $amount) { if ($playerGroup->existPlayer($info['player']['id'])) { $player = $playerGroup->getPlayer($info['player']['id']); //used to show techs in the report .Empty player not exist in OPBE's result data $players[$idFleet]['techs'] = array($player->getWeaponsTech(), $player->getArmourTech(), $player->getShieldsTech()); if ($player->existFleet($idFleet)) { $fleet = $player->getFleet($idFleet); if ($fleet->existShipType($idShipType)) { $attackKrit = 1; //$attackKritChance = mt_rand(0,100); //$attackuser = getbonusOneBis(1103,$player['academy_1103']); //if(0 >= $attackKritChance){ //$attackKrit = 2; //} $shipType = $fleet->getShipType($idShipType); //used to show life,power and shield of each ships in the report $plyArray[$idFleet][$idShipType] = array('def' => $shipType->getHull(), 'shield' => $shipType->getShield(), 'att' => $shipType->getPower()); $players[$idFleet]['unit'][$idShipType] = $shipType->getCount(); $players[$idFleet]['unit_attKrit'][$idShipType] = $attackKrit; //$players[$idFleet]['unit_shieldKrit'][$idShipType] = $shipType->getFlagShildCrit(); } else { $players[$idFleet]['unit'][$idShipType] = 0; $players[$idFleet]['unit_attKrit'][$idShipType] = 1; //$players[$idFleet]['unit_shieldKrit'][$idShipType] = 1; } } else { $players[$idFleet]['unit'][$idShipType] = 0; $players[$idFleet]['unit_attKrit'][$idShipType] = 1; //$players[$idFleet]['unit_shieldKrit'][$idShipType] = 1; } } else { $players[$idFleet]['unit'][$idShipType] = 0; $players[$idFleet]['unit_attKrit'][$idShipType] = 1; //$players[$idFleet]['unit_shieldKrit'][$idShipType] = 1; $players[$idFleet]['techs'] = array(0, 0, 0); } //initialization if (!isset($amountArray[$idFleet])) { $amountArray[$idFleet] = 0; } if (!isset($amountArray['total'])) { $amountArray['total'] = 0; } //increment $currentAmount = $players[$idFleet]['unit'][$idShipType]; $amountArray[$idFleet] = $amountArray[$idFleet] + $currentAmount; $amountArray['total'] = $amountArray['total'] + $currentAmount; } } return array($plyArray, $amountArray); }