예제 #1
0
 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;
 }
예제 #2
0
function getPlayerGroupFromQuery($result, $targetUser = false)
{
    $playerGroup = new PlayerGroup();
    while ($fleetRow = mysql_fetch_assoc($result)) {
        //making the current fleet object
        $serializedTypes = explode(';', $fleetRow['fleet_array']);
        $idPlayer = $fleetRow['fleet_owner'];
        $fleet = new Fleet($fleetRow['fleet_id']);
        foreach ($serializedTypes as $serializedType) {
            list($id, $count) = explode(',', $serializedType);
            if ($id != 0 && $count != 0) {
                $fleet->addShipType(getShipType($id, $count));
            }
        }
        //making the player object and add it to playerGroup object
        if (!$playerGroup->existPlayer($idPlayer)) {
            $player_info = $targetUser !== false && $targetUser['id'] == $idPlayer ? $targetUser : doquery("SELECT * FROM {{table}} WHERE id ={$idPlayer}", 'users', true);
            $player = new Player($idPlayer, array($fleet));
            $player->setTech($player_info['military_tech'], $player_info['shield_tech'], $player_info['defence_tech']);
            $player->setName($player_info['name']);
            $playerGroup->addPlayer($player);
        } else {
            $playerGroup->getPlayer($idPlayer)->addFleet($fleet);
        }
    }
    return $playerGroup;
}
예제 #3
0
 /**
  * method get_player_group_from_query
  * param $result
  * param $target_user
  * return the attack result
  */
 private function get_player_group_from_query($result, $target_user = false)
 {
     $playerGroup = new PlayerGroup();
     while ($fleet_row = parent::$db->fetch_assoc($result)) {
         //making the current fleet object
         $serializedTypes = explode(';', $fleet_row['fleet_array']);
         $idPlayer = $fleet_row['fleet_owner'];
         $fleet = new Fleet($fleet_row['fleet_id']);
         foreach ($serializedTypes as $serializedType) {
             list($id, $count) = explode(',', $serializedType);
             if ($id != 0 && $count != 0) {
                 $fleet->add(get_ship_type($id, $count));
             }
         }
         //making the player object and add it to playerGroup object
         if (!$playerGroup->existPlayer($idPlayer)) {
             if ($target_user !== FALSE && $target_user['id'] == $idPlayer) {
                 $player_info = $target_user;
             } else {
                 $player_info = parent::$db->query_fetch("SELECT `research_weapons_technology`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`research_shielding_technology`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`research_armour_technology`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . RESEARCH . "`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `research_user_id` = '" . $idPlayer . "';");
             }
             $player = new Player($idPlayer, array($fleet));
             $player->setTech($player_info['military_tech'], $player_info['shield_tech'], $player_info['defence_tech']);
             $playerGroup->addPlayer($player);
         } else {
             $playerGroup->getPlayer($idPlayer)->addFleet($fleet);
         }
     }
     return $playerGroup;
 }
예제 #4
0
 /**
  * getPlayerGroupFromQuery
  *
  * @param array   $result      Result
  * @param boolean $target_user Target User
  *
  * @return \PlayerGroup
  */
 private function getPlayerGroupFromQuery($result, $target_user = false)
 {
     $playerGroup = new PlayerGroup();
     while ($fleet_row = parent::$db->fetch_assoc($result)) {
         //making the current fleet object
         $serializedTypes = explode(';', $fleet_row['fleet_array']);
         $idPlayer = $fleet_row['fleet_owner'];
         $fleet = new Fleet($fleet_row['fleet_id']);
         foreach ($serializedTypes as $serializedType) {
             if (!empty($serializedType)) {
                 list($id, $count) = explode(',', $serializedType);
                 if ($id != 0 && $count != 0) {
                     $fleet->addShipType($this->getShipType($id, $count));
                 }
             }
         }
         //making the player object and add it to playerGroup object
         if (!$playerGroup->existPlayer($idPlayer)) {
             if ($target_user !== false && $target_user['user_id'] == $idPlayer) {
                 $player_info = $target_user;
             } else {
                 $player_info = parent::$db->query_fetch("SELECT u.user_name,\n                            r.research_weapons_technology,\n                            r.research_shielding_technology,\n                            r.research_armour_technology\n                        FROM " . USERS . " AS u\n                            INNER JOIN " . RESEARCH . " AS r ON r.research_user_id = u.user_id\n                        WHERE u.user_id = '" . $idPlayer . "';");
             }
             $player = new Player($idPlayer, array($fleet));
             $player->setTech($player_info['research_weapons_technology'], $player_info['research_shielding_technology'], $player_info['research_armour_technology']);
             $player->setName($player_info['user_name']);
             $playerGroup->addPlayer($player);
         } else {
             $playerGroup->getPlayer($idPlayer)->addFleet($fleet);
         }
     }
     return $playerGroup;
 }