Пример #1
0
/**
 * 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);
}
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
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;
}
Пример #5
0
/**
 * 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);
}