public function show()
 {
     global $USER, $PLANET, $LNG;
     $this->tplObj->loadscript('flotten.js');
     $targetGalaxy = HTTP::_GP('galaxy', 0);
     $targetSystem = HTTP::_GP('system', 0);
     $targetPlanet = HTTP::_GP('planet', 0);
     $targetType = HTTP::_GP('type', 0);
     $targetMission = HTTP::_GP('target_mission', 0);
     $fleetSpeed = HTTP::_GP('speed', 0);
     $fleetGroup = HTTP::_GP('fleet_group', 0);
     $token = HTTP::_GP('token', '');
     if (!isset($_SESSION['fleet'][$token])) {
         FleetFunctions::GotoFleetPage();
     }
     $fleetArray = $_SESSION['fleet'][$token]['fleet'];
     $db = Database::get();
     $sql = "SELECT id, id_owner, der_metal, der_crystal FROM %%PLANETS%% WHERE universe = :universe AND galaxy = :targetGalaxy AND system = :targetSystem AND planet = :targetPlanet AND planet_type = '1';";
     $targetPlanetData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet));
     if ($targetType == 2 && $targetPlanetData['der_metal'] == 0 && $targetPlanetData['der_crystal'] == 0) {
         $this->printMessage($LNG['fl_error_empty_derbis'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
     }
     $MisInfo = array();
     $MisInfo['galaxy'] = $targetGalaxy;
     $MisInfo['system'] = $targetSystem;
     $MisInfo['planet'] = $targetPlanet;
     $MisInfo['planettype'] = $targetType;
     $MisInfo['IsAKS'] = $fleetGroup;
     $MisInfo['Ship'] = $fleetArray;
     $MissionOutput = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData);
     if (empty($MissionOutput['MissionSelector'])) {
         $this->printMessage($LNG['fl_empty_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
     }
     $GameSpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $MaxFleetSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
     $distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetGalaxy, $targetSystem, $targetPlanet));
     $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $MaxFleetSpeed, $distance, $GameSpeedFactor, $USER);
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $USER, $GameSpeedFactor);
     if ($consumption > $PLANET['deuterium']) {
         $this->printMessage($LNG['fl_not_enough_deuterium'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
     }
     if (!FleetFunctions::CheckUserSpeed($fleetSpeed)) {
         FleetFunctions::GotoFleetPage(0);
     }
     $_SESSION['fleet'][$token]['speed'] = $MaxFleetSpeed;
     $_SESSION['fleet'][$token]['distance'] = $distance;
     $_SESSION['fleet'][$token]['targetGalaxy'] = $targetGalaxy;
     $_SESSION['fleet'][$token]['targetSystem'] = $targetSystem;
     $_SESSION['fleet'][$token]['targetPlanet'] = $targetPlanet;
     $_SESSION['fleet'][$token]['targetType'] = $targetType;
     $_SESSION['fleet'][$token]['fleetGroup'] = $fleetGroup;
     $_SESSION['fleet'][$token]['fleetSpeed'] = $fleetSpeed;
     if (!empty($fleet_group)) {
         $targetMission = 2;
     }
     $fleetData = array('fleetroom' => floatToString($_SESSION['fleet'][$token]['fleetRoom']), 'consumption' => floatToString($consumption));
     $this->tplObj->execscript('calculateTransportCapacity();');
     $this->assign(array('fleetdata' => $fleetData, 'consumption' => floatToString($consumption), 'mission' => $targetMission, 'galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'type' => $PLANET['planet_type'], 'MissionSelector' => $MissionOutput['MissionSelector'], 'StaySelector' => $MissionOutput['StayBlock'], 'fl_dm_alert_message' => sprintf($LNG['fl_dm_alert_message'], $LNG['type_mission'][11], $LNG['tech'][921]), 'fl_continue' => $LNG['fl_continue'], 'token' => $token));
     $this->display('page.fleetStep2.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $LNG, $UNI;
     $this->tplObj->loadscript('flotten.js');
     $targetGalaxy = HTTP::_GP('galaxy', 0);
     $targetSystem = HTTP::_GP('system', 0);
     $targetPlanet = HTTP::_GP('planet', 0);
     $targetType = HTTP::_GP('type', 0);
     $targetMission = HTTP::_GP('target_mission', 0);
     $fleetSpeed = HTTP::_GP('speed', 0);
     $fleetGroup = HTTP::_GP('fleet_group', 0);
     $token = HTTP::_GP('token', '');
     if (!isset($_SESSION['fleet'][$token])) {
         FleetFunctions::GotoFleetPage();
     }
     $fleetArray = $_SESSION['fleet'][$token]['fleet'];
     $targetPlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT `id`, `id_owner`, `der_metal`, `der_crystal`, `der_deuterium` FROM `" . PLANETS . "` WHERE `universe` = " . $UNI . " AND `galaxy` = " . $targetGalaxy . " AND `system` = " . $targetSystem . " AND `planet` = " . $targetPlanet . " AND `planet_type` = '1';");
     if ($targetType == 2 && $targetPlanetData['der_metal'] == 0 && $targetPlanetData['der_crystal'] == 0 && $targetPlanetData['der_deuterium'] == 0) {
         $this->printMessage($LNG['fl_error_empty_derbis']);
     }
     ##PlayerUnit::maxPlanetCount
     $MisInfo = array();
     $MisInfo['galaxy'] = $targetGalaxy;
     $MisInfo['system'] = $targetSystem;
     $MisInfo['planet'] = $targetPlanet;
     $MisInfo['planettype'] = $targetType;
     $MisInfo['IsAKS'] = $fleetGroup;
     $MisInfo['Ship'] = $fleetArray;
     $MissionOutput = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData);
     if (empty($MissionOutput['MissionSelector'])) {
         $this->printMessage($LNG['fl_empty_target']);
     }
     $GameSpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $MaxFleetSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
     $distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetGalaxy, $targetSystem, $targetPlanet));
     $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $MaxFleetSpeed, $distance, $GameSpeedFactor, $USER);
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $MaxFleetSpeed, $USER, $GameSpeedFactor);
     if ($consumption > $PLANET['deuterium']) {
         $this->printMessage($LNG['fl_not_enough_deuterium']);
     }
     if (!FleetFunctions::CheckUserSpeed($fleetSpeed)) {
         FleetFunctions::GotoFleetPage(0);
     }
     $_SESSION['fleet'][$token]['speed'] = $MaxFleetSpeed;
     $_SESSION['fleet'][$token]['distance'] = $distance;
     $_SESSION['fleet'][$token]['targetGalaxy'] = $targetGalaxy;
     $_SESSION['fleet'][$token]['targetSystem'] = $targetSystem;
     $_SESSION['fleet'][$token]['targetPlanet'] = $targetPlanet;
     $_SESSION['fleet'][$token]['targetType'] = $targetType;
     $_SESSION['fleet'][$token]['fleetGroup'] = $fleetGroup;
     $_SESSION['fleet'][$token]['fleetSpeed'] = $fleetSpeed;
     if (!empty($fleet_group)) {
         $targetMission = 2;
     }
     $fleetData = array('fleetroom' => floattostring($_SESSION['fleet'][$token]['fleetRoom']), 'consumption' => floattostring($consumption));
     $this->tplObj->execscript('calculateTransportCapacity();');
     $this->tplObj->assign_vars(array('fleetdata' => $fleetData, 'consumption' => floattostring($consumption), 'mission' => $targetMission, 'galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'type' => $PLANET['planet_type'], 'MissionSelector' => $MissionOutput['MissionSelector'], 'StaySelector' => $MissionOutput['StayBlock'], 'fl_dm_alert_message' => sprintf($LNG['fl_dm_alert_message'], $LNG['type_mission'][11], $LNG['tech'][921]), 'fl_continue' => $LNG['fl_continue'], 'token' => $token));
     $this->display('page.fleetStep2.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $LNG;
     $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
     $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
     $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
     $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']);
     $mission = HTTP::_GP('target_mission', 0);
     $Fleet = array();
     $FleetRoom = 0;
     $allyInfo = $GLOBALS['DATABASE']->query("SELECT FleetCapa FROM `uni1_alliance` WHERE id = " . $USER['ally_id'] . ";");
     $allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo);
     $listorder = array(210, 212, 202, 203, 204, 205, 229, 209, 206, 207, 208, 217, 215, 213, 211, 220, 224, 219, 223, 225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     foreach ($listorder as $id => $ShipID) {
         $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0)));
         if ($amount < 1 || $ShipID == 212) {
             continue;
         }
         $Fleet[$ShipID] = $amount;
         $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount;
         $FleetRoom += $FleetRoom / 100 * getbonusOneBis(1207, $USER['academy_1207']) + $FleetRoom / 100 * $allyInfo['FleetCapa'];
     }
     foreach ($Fleet as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]]) {
             $this->printMessage($LNG['fl_not_all_ship_avalible']);
         }
     }
     $FleetRoom *= 1 + $USER['factor']['ShipStorage'];
     if (empty($Fleet)) {
         FleetFunctions::GotoFleetPage();
     }
     $FleetData = array('fleetroom' => floattostring($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME);
     $token = getRandomString();
     $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom);
     $shortcutList = $this->GetUserShotcut();
     $colonyList = $this->GetColonyList();
     $ACSList = $this->GetAvalibleACS();
     if (!empty($shortcutList)) {
         $shortcutAmount = max(array_keys($shortcutList));
     } else {
         $shortcutAmount = 0;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);');
     $this->tplObj->assign_vars(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3], 4 => $LNG['type_planet'][4]), 'fleetdata' => $FleetData));
     $this->display('page.fleetStep1.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $pricelist, $reslist, $LNG;
     $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
     $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
     $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
     $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']);
     $mission = HTTP::_GP('target_mission', 0);
     $Fleet = array();
     $FleetRoom = 0;
     foreach ($reslist['fleet'] as $id => $ShipID) {
         $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0)));
         if ($amount < 1 || $ShipID == 212) {
             continue;
         }
         $Fleet[$ShipID] = $amount;
         $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount;
     }
     $FleetRoom *= 1 + $USER['factor']['ShipStorage'];
     if (empty($Fleet)) {
         FleetFunctions::GotoFleetPage();
     }
     $FleetData = array('fleetroom' => floatToString($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME);
     $token = getRandomString();
     $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom);
     $shortcutList = $this->GetUserShotcut();
     $colonyList = $this->GetColonyList();
     $ACSList = $this->GetAvalibleACS();
     if (!empty($shortcutList)) {
         $shortcutAmount = max(array_keys($shortcutList));
     } else {
         $shortcutAmount = 0;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);');
     $this->assign(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3]), 'fleetdata' => $FleetData));
     $this->display('page.fleetStep1.default.tpl');
 }
示例#5
0
 public static function ShowFleet3Page()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $CONF, $db, $LNG;
     include_once ROOT_PATH . 'includes/functions/IsVacationMode.' . PHP_EXT;
     $template = new template();
     $template->loadscript('flotten.js');
     $template->gotoside('?page=fleet');
     $template->page_header();
     $template->page_topnav();
     $template->page_leftmenu();
     $template->page_planetmenu();
     $template->page_footer();
     $mission = request_var('mission', 3);
     $galaxy = request_var('galaxy', 0);
     $system = request_var('system', 0);
     $planet = request_var('planet', 0);
     $planettype = request_var('planettype', 0);
     $fleet_group = request_var('fleet_group', 0);
     $GenFleetSpeed = request_var('speed', 0);
     $TransportMetal = round(request_var('metal', 0.0), 0);
     $TransportCrystal = round(request_var('crystal', 0.0), 0);
     $TransportDeuterium = round(request_var('deuterium', 0.0), 0);
     $holdingtime = request_var('holdingtime', 0);
     $rawfleetarray = request_var('usedfleet', '', true);
     $thisgalaxy = $PLANET['galaxy'];
     $thissystem = $PLANET['system'];
     $thisplanet = $PLANET['planet'];
     $thisplanettype = $PLANET['planet_type'];
     if (IsVacationMode($USER)) {
         exit($template->message($LNG['fl_vacation_mode_active'], 'game.php?page=overview', 2));
     }
     if ($_SESSION['db']['user_side'] != 'game.php?page=fleet2') {
         parent::GotoFleetPage();
     }
     if (!($planettype >= 1 || $planettype <= 3)) {
         parent::GotoFleetPage();
     }
     if ($PLANET['galaxy'] == $galaxy && $PLANET['system'] == $system && $PLANET['planet'] == $planet && $PLANET['planet_type'] == $planettype) {
         parent::GotoFleetPage();
     }
     if ($galaxy > MAX_GALAXY_IN_WORLD || $galaxy < 1 || $system > MAX_SYSTEM_IN_GALAXY || $system < 1 || $planet > MAX_PLANET_IN_SYSTEM + 1 || $planet < 1) {
         parent::GotoFleetPage();
     }
     if (empty($mission)) {
         parent::GotoFleetPage();
     }
     if (!is_numeric($TransportMetal) || !is_numeric($TransportCrystal) || !is_numeric($TransportDeuterium)) {
         parent::GotoFleetPage();
     }
     if ($TransportMetal + $TransportCrystal + $TransportDeuterium < 1 && $mission == 3) {
         $template->message("<font color=\"lime\"><b>" . $LNG['fl_empty_transport'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 1);
         exit;
     }
     $ActualFleets = parent::GetCurrentFleets($USER['id']);
     if (parent::GetMaxFleetSlots($USER) <= $ActualFleets) {
         $template->message($LNG['fl_no_slots'], "game." . PHP_EXT . "?page=fleet", 1);
         exit;
     }
     $fleet_group_mr = 0;
     if (!empty($fleet_group) && $mission == 2) {
         $aks_count_mr = $db->uniquequery("SELECT COUNT(*) as state FROM " . AKS . " WHERE `id` = '" . $fleet_group . "' AND `eingeladen` LIKE '%" . $USER['id'] . "%';");
         if ($aks_count_mr['state'] > 0) {
             $fleet_group_mr = $fleet_group;
         } else {
             $mission = 1;
         }
     }
     $ActualFleets = parent::GetCurrentFleets($USER['id']);
     $TargetPlanet = $db->uniquequery("SELECT `id_owner`,`id_level`,`destruyed`,`ally_deposit` FROM " . PLANETS . " WHERE `galaxy` = '" . $db->sql_escape($galaxy) . "' AND `system` = '" . $db->sql_escape($system) . "' AND `planet` = '" . $db->sql_escape($planet) . "' AND `planet_type` = '" . $db->sql_escape($planettype) . "';");
     if ($mission != 15 && $mission != 8 && $TargetPlanet["destruyed"] != 0 || $mission != 15 && $mission != 7 && $mission != 8 && empty($TargetPlanet['id_owner'])) {
         parent::GotoFleetPage();
     }
     $MyDBRec = $USER;
     $FleetArray = parent::GetFleetArray($rawfleetarray);
     if (!is_array($FleetArray)) {
         parent::GotoFleetPage();
     }
     $FleetStorage = 0;
     $FleetShipCount = 0;
     $fleet_array = "";
     $FleetSubQRY = "";
     foreach ($FleetArray as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]] || $Count < 0) {
             parent::GotoFleetPage();
         }
         $FleetStorage += $pricelist[$Ship]["capacity"] * $Count;
         $FleetShipCount += $Count;
         $fleet_array .= $Ship . "," . $Count . ";";
         $FleetSubQRY .= "`" . $resource[$Ship] . "` = `" . $resource[$Ship] . "` - '" . floattostring($Count) . "', ";
     }
     $error = 0;
     $fleetmission = $mission;
     $YourPlanet = false;
     $UsedPlanet = false;
     if ($mission == 11) {
         $maxexpde = parent::GetCurrentFleets($USER['id'], 11);
         if ($maxexpde >= MAX_DM_MISSIONS) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_expedition_fleets_limit'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
     } elseif ($mission == 15) {
         $MaxExpedition = $USER[$resource[124]];
         if ($MaxExpedition == 0) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_expedition_tech_required'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
         $ExpeditionEnCours = parent::GetCurrentFleets($USER['id'], 15);
         $EnvoiMaxExpedition = floor(sqrt($MaxExpedition));
         if ($ExpeditionEnCours >= $EnvoiMaxExpedition) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_expedition_fleets_limit'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
     }
     $YourPlanet = isset($TargetPlanet['id_owner']) && $TargetPlanet['id_owner'] == $USER['id'] ? true : false;
     $UsedPlanet = isset($TargetPlanet['id_owner']) ? true : false;
     $HeDBRec = $YourPlanet ? $MyDBRec : GetUserByID($TargetPlanet['id_owner'], array('id', 'onlinetime', 'ally_id', 'urlaubs_modus'));
     if ($HeDBRec['urlaubs_modus'] && $mission != 8) {
         $template->message("<font color=\"lime\"><b>" . $LNG['fl_in_vacation_player'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
         exit;
     }
     if (!$YourPlanet && ($mission == 1 || $mission == 2 || $mission == 5 || $mission == 6 || $mission == 9)) {
         if ($TargetPlanet['id_level'] > $USER['authlevel'] && $CONF['adm_attack'] == 0) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_admins_cannot_be_attacked'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
         $UserPoints = $USER;
         $User2Points = $db->uniquequery("SELECT `total_points` FROM " . STATPOINTS . " WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '" . $HeDBRec['id'] . "';");
         $IsNoobProtec = CheckNoobProtec($UserPoints, $User2Points, $HeDBRec['onlinetime']);
         if ($IsNoobProtec['NoobPlayer']) {
             $template->message("<font color=\"lime\"><b>" . $LNG['fl_week_player'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         } elseif ($IsNoobProtec['StrongPlayer']) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_strong_player'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
     }
     if ($mission == 5) {
         if ($TargetPlanet['ally_deposit'] < 1) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_not_ally_deposit'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
         $buddy = $db->uniquequery("SELECT COUNT(*) as state FROM " . BUDDY . " WHERE `active` = '1' AND (`owner` = '" . $HeDBRec['id'] . "' AND `sender` = '" . $MyDBRec['id'] . "') OR (`owner` = '" . $MyDBRec['id'] . "' AND `sender` = '" . $HeDBRec['id'] . "');");
         if ($HeDBRec['ally_id'] != $MyDBRec['ally_id'] && $buddy['state'] == 0) {
             $template->message("<font color=\"red\"><b>" . $LNG['fl_no_same_alliance'] . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
             exit;
         }
     }
     if (parent::CheckUserSpeed() || !array_key_exists($mission, parent::GetAvailableMissions(array('CurrentUser' => $USER, 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'planettype' => $planettype, 'IsAKS' => $fleet_group, 'Ship' => $FleetArray)))) {
         parent::GotoFleetPage();
     }
     $MaxFleetSpeed = parent::GetFleetMaxSpeed($FleetArray, $USER);
     $SpeedFactor = parent::GetGameSpeedFactor();
     $distance = parent::GetTargetDistance($thisgalaxy, $galaxy, $thissystem, $system, $thisplanet, $planet);
     $duration = parent::GetMissionDuration($GenFleetSpeed, $MaxFleetSpeed, $distance, $SpeedFactor, $USER);
     $consumption = parent::GetFleetConsumption($FleetArray, $duration, $distance, $MaxFleetSpeed, $USER, $SpeedFactor);
     $fleet['start_time'] = $duration + TIMESTAMP;
     if ($mission == 15) {
         $StayDuration = max($holdingtime, 1) * 3600 / $CONF['halt_speed'];
         $StayTime = $fleet['start_time'] + $StayDuration;
     } elseif ($mission == 5) {
         $StayDuration = $holdingtime * 3600;
         $StayTime = $fleet['start_time'] + $StayDuration;
     } elseif ($mission == 11) {
         $StayDuration = 3600 / $CONF['halt_speed'];
         $StayTime = $fleet['start_time'] + $StayDuration;
     } else {
         $StayDuration = 0;
         $StayTime = 0;
     }
     $fleet['end_time'] = $StayDuration + 2 * $duration + TIMESTAMP;
     $FleetStorage -= $consumption;
     $PlanetRess = new ResourceUpdate();
     $PlanetRess->CalcResource();
     $TransportMetal = min($TransportMetal, $PLANET['metal']);
     $TransportCrystal = min($TransportCrystal, $PLANET['crystal']);
     $TransportDeuterium = min($TransportDeuterium, $PLANET['deuterium'] - $consumption);
     $StorageNeeded = $TransportMetal + $TransportCrystal + $TransportDeuterium;
     $StockMetal = $PLANET['metal'];
     $StockCrystal = $PLANET['crystal'];
     $StockDeuterium = $PLANET['deuterium'];
     $StockDeuterium -= $consumption;
     if ($PLANET['deuterium'] < $consumption) {
         $template->message("<font color=\"red\"><b>" . sprintf($LNG['fl_no_enought_deuterium'], $LNG['Deuterium'], pretty_number($consumption - $PLANET['deuterium']), $LNG['Deuterium']) . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
         exit;
     }
     if ($StorageNeeded > $FleetStorage) {
         $template->message("<font color=\"red\"><b>" . $LNG['fl_no_enought_cargo_capacity'] . pretty_number($StorageNeeded - $FleetStorage) . "</b></font>", "game." . PHP_EXT . "?page=fleet", 2);
         exit;
     }
     if ($TargetPlanet['id_level'] > $USER['authlevel'] && $CONF['adm_attack'] == 0) {
         $template->message($LNG['fl_admins_cannot_be_attacked'], "game." . PHP_EXT . "?page=fleet", 2);
         exit;
     }
     $PLANET['metal'] -= $TransportMetal;
     $PLANET['crystal'] -= $TransportCrystal;
     $PLANET['deuterium'] -= $TransportDeuterium + $consumption;
     $PlanetRess->SavePlanetToDB();
     if (connection_aborted()) {
         exit;
     }
     if ($fleet_group_mr != 0) {
         $AksStartTime = $db->uniquequery("SELECT MAX(`fleet_start_time`) AS Start FROM " . FLEETS . " WHERE `fleet_group` = '" . $fleet_group_mr . "' AND '" . MAX_FLEETS_PER_ACS . "' > (SELECT COUNT(*) FROM " . FLEETS . " WHERE `fleet_group` = '" . $fleet_group_mr . "');");
         if (isset($AksStartTime)) {
             if ($AksStartTime['Start'] >= $fleet['start_time']) {
                 $fleet['end_time'] += $AksStartTime['Start'] - $fleet['start_time'];
                 $fleet['start_time'] = $AksStartTime['Start'];
             } else {
                 $QryUpdateFleets = "UPDATE " . FLEETS . " SET ";
                 $QryUpdateFleets .= "`fleet_start_time` = '" . $fleet['start_time'] . "', ";
                 $QryUpdateFleets .= "`fleet_end_time` = fleet_end_time + '" . ($fleet['start_time'] - $AksStartTime['Start']) . "' ";
                 $QryUpdateFleets .= "WHERE ";
                 $QryUpdateFleets .= "`fleet_group` = '" . $fleet_group_mr . "';";
                 $db->query($QryUpdateFleets);
                 $fleet['end_time'] += $fleet['start_time'] - $AksStartTime['Start'];
             }
         } else {
             $mission = 1;
         }
     }
     $QryInsertFleet = "LOCK TABLE " . FLEETS . " WRITE, " . PLANETS . " WRITE;\r\n\t\t\t\t\t\t\tINSERT INTO " . FLEETS . " SET \r\n\t\t\t\t\t\t\t`fleet_owner` = '" . $USER['id'] . "', \r\n\t\t\t\t\t\t\t`fleet_mission` = '" . $mission . "',\r\n\t\t\t\t\t\t\t`fleet_amount` = '" . $FleetShipCount . "',\r\n\t\t\t\t\t\t    `fleet_array` = '" . $fleet_array . "',\r\n\t\t\t\t\t\t\t`fleet_start_time` = '" . $fleet['start_time'] . "',\r\n\t\t\t\t\t\t\t`fleet_start_galaxy` = '" . $thisgalaxy . "',\r\n\t\t\t\t\t\t\t`fleet_start_system` = '" . $thissystem . "',\r\n\t\t\t\t\t\t\t`fleet_start_planet` = '" . $thisplanet . "',\r\n\t\t\t\t\t\t\t`fleet_start_type` = '" . $thisplanettype . "',\r\n\t\t\t\t\t\t\t`fleet_end_time` = '" . $fleet['end_time'] . "',\r\n\t\t\t\t\t\t\t`fleet_end_stay` = '" . $StayTime . "',\r\n\t\t\t\t\t\t\t`fleet_end_galaxy` = '" . $galaxy . "',\r\n\t\t\t\t\t\t\t`fleet_end_system` = '" . $system . "',\r\n\t\t\t\t\t\t\t`fleet_end_planet` = '" . $planet . "',\r\n\t\t\t\t\t\t\t`fleet_end_type` = '" . $planettype . "',\r\n\t\t\t\t\t\t\t`fleet_resource_metal` = '" . floattostring($TransportMetal) . "',\r\n\t\t\t\t\t\t\t`fleet_resource_crystal` = '" . floattostring($TransportCrystal) . "',\r\n\t\t\t\t\t\t\t`fleet_resource_deuterium` = '" . floattostring($TransportDeuterium) . "',\r\n\t\t\t\t\t\t\t`fleet_target_owner` = '" . $TargetPlanet['id_owner'] . "',\r\n\t\t\t\t\t\t\t`fleet_group` = '" . $fleet_group_mr . "',\r\n\t\t\t\t\t\t\t`start_time` = '" . TIMESTAMP . "';\r\n\t\t\t\t\t\t\tUPDATE `" . PLANETS . "` SET\r\n\t\t\t\t\t\t\t" . substr($FleetSubQRY, 0, -2) . "\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t`id` = " . $PLANET['id'] . " LIMIT 1;\r\n\t\t\t\t\t\t\tUNLOCK TABLES;";
     $db->multi_query($QryInsertFleet);
     foreach ($FleetArray as $Ship => $Count) {
         $FleetList[$LNG['tech'][$Ship]] = pretty_number($Count);
     }
     $template->assign_vars(array('mission' => $LNG['type_mission'][$mission], 'distance' => pretty_number($distance), 'consumption' => pretty_number($consumption), 'from' => $thisgalaxy . ":" . $thissystem . ":" . $thisplanet, 'destination' => $galaxy . ":" . $system . ":" . $planet, 'start_time' => date("M D d H:i:s", $fleet['start_time']), 'end_time' => date("M D d H:i:s", $fleet['end_time']), 'speedallsmin' => $MaxFleetSpeed, 'FleetList' => $FleetList, 'fl_fleet_sended' => $LNG['fl_fleet_sended'], 'fl_mission' => $LNG['fl_mission'], 'fl_from' => $LNG['fl_from'], 'fl_destiny' => $LNG['fl_destiny'], 'fl_distance' => $LNG['fl_distance'], 'fl_fleet_speed' => $LNG['fl_fleet_speed'], 'fl_fuel_consumption' => $LNG['fl_fuel_consumption'], 'fl_fromfl_destiny' => $LNG['fl_fromfl_destiny'], 'fl_arrival_time' => $LNG['fl_arrival_time'], 'fl_return_time' => $LNG['fl_return_time'], 'fl_fleet' => $LNG['fl_fleet']));
     $template->show('fleet3_table.tpl');
 }
    public function show()
    {
        global $USER, $PLANET, $resource, $LNG;
        if (IsVacationMode($USER)) {
            FleetFunctions::GotoFleetPage(0);
        }
        $targetMission = HTTP::_GP('mission', 3);
        $TransportMetal = max(0, round(HTTP::_GP('metal', 0.0)));
        $TransportCrystal = max(0, round(HTTP::_GP('crystal', 0.0)));
        $TransportDeuterium = max(0, round(HTTP::_GP('deuterium', 0.0)));
        $stayTime = HTTP::_GP('staytime', 0);
        $token = HTTP::_GP('token', '');
        $config = Config::get();
        if (!isset($_SESSION['fleet'][$token])) {
            FleetFunctions::GotoFleetPage(1);
        }
        if ($_SESSION['fleet'][$token]['time'] < TIMESTAMP - 600) {
            unset($_SESSION['fleet'][$token]);
            FleetFunctions::GotoFleetPage(0);
        }
        $formData = $_SESSION['fleet'][$token];
        unset($_SESSION['fleet'][$token]);
        $distance = $formData['distance'];
        $targetGalaxy = $formData['targetGalaxy'];
        $targetSystem = $formData['targetSystem'];
        $targetPlanet = $formData['targetPlanet'];
        $targetType = $formData['targetType'];
        $fleetGroup = $formData['fleetGroup'];
        $fleetArray = $formData['fleet'];
        $fleetStorage = $formData['fleetRoom'];
        $fleetSpeed = $formData['fleetSpeed'];
        if ($targetMission != 2) {
            $fleetGroup = 0;
        }
        if ($PLANET['galaxy'] == $targetGalaxy && $PLANET['system'] == $targetSystem && $PLANET['planet'] == $targetPlanet && $PLANET['planet_type'] == $targetType) {
            $this->printMessage($LNG['fl_error_same_planet'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
        }
        if ($targetGalaxy < 1 || $targetGalaxy > $config->max_galaxy || $targetSystem < 1 || $targetSystem > $config->max_system || $targetPlanet < 1 || $targetPlanet > $config->max_planets + 1 || $targetType !== 1 && $targetType !== 2 && $targetType !== 3) {
            $this->printMessage($LNG['fl_invalid_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
        }
        if ($targetMission == 3 && $TransportMetal + $TransportCrystal + $TransportDeuterium < 1) {
            $this->printMessage($LNG['fl_no_noresource'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet2')));
        }
        $ActualFleets = FleetFunctions::GetCurrentFleets($USER['id']);
        if (FleetFunctions::GetMaxFleetSlots($USER) <= $ActualFleets) {
            $this->printMessage($LNG['fl_no_slots'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
        }
        $ACSTime = 0;
        $db = Database::get();
        if (!empty($fleetGroup)) {
            $sql = "SELECT ankunft FROM %%USERS_ACS%% INNER JOIN %%AKS%% ON id = acsID\n\t\t\tWHERE acsID = :acsID AND :maxFleets > (SELECT COUNT(*) FROM %%FLEETS%% WHERE fleet_group = :acsID);";
            $ACSTime = $db->selectSingle($sql, array(':acsID' => $fleetGroup, ':maxFleets' => $config->max_fleets_per_acs), 'ankunft');
            if (empty($ACSTime)) {
                $fleetGroup = 0;
                $targetMission = 1;
            }
        }
        $sql = "SELECT id, id_owner, der_metal, der_crystal, destruyed, ally_deposit FROM %%PLANETS%% WHERE universe = :universe AND galaxy = :targetGalaxy AND system = :targetSystem AND planet = :targetPlanet AND planet_type = :targetType;";
        $targetPlanetData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet, ':targetType' => $targetType == 2 ? 1 : $targetType));
        if ($targetMission == 7) {
            if (!empty($targetPlanetData)) {
                $this->printMessage($LNG['fl_target_exists'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
            }
            if ($targetType != 1) {
                $this->printMessage($LNG['fl_only_planets_colonizable'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
            }
        }
        if ($targetMission == 7 || $targetMission == 15) {
            $targetPlanetData = array('id' => 0, 'id_owner' => 0, 'planettype' => 1);
        } else {
            if ($targetPlanetData["destruyed"] != 0) {
                $this->printMessage($LNG['fl_no_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
            }
            if (empty($targetPlanetData)) {
                $this->printMessage($LNG['fl_no_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
            }
        }
        foreach ($fleetArray as $Ship => $Count) {
            if ($Count > $PLANET[$resource[$Ship]]) {
                $this->printMessage($LNG['fl_not_all_ship_avalible'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
        }
        if ($targetMission == 11) {
            $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 11, true);
            $maxExpedition = FleetFunctions::getDMMissionLimit($USER);
            if ($activeExpedition >= $maxExpedition) {
                $this->printMessage($LNG['fl_no_expedition_slot'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
        } elseif ($targetMission == 15) {
            $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15, true);
            $maxExpedition = FleetFunctions::getExpeditionLimit($USER);
            if ($activeExpedition >= $maxExpedition) {
                $this->printMessage($LNG['fl_no_expedition_slot'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
        }
        $usedPlanet = isset($targetPlanetData['id_owner']);
        $myPlanet = $usedPlanet && $targetPlanetData['id_owner'] == $USER['id'];
        $targetPlayerData = array();
        if ($targetMission == 7 || $targetMission == 15) {
            $targetPlayerData = array('id' => 0, 'onlinetime' => TIMESTAMP, 'ally_id' => 0, 'urlaubs_modus' => 0, 'authattack' => 0, 'total_points' => 0);
        } elseif ($myPlanet) {
            $targetPlayerData = $USER;
        } elseif (!empty($targetPlanetData['id_owner'])) {
            $sql = "SELECT user.id, user.onlinetime, user.ally_id, user.urlaubs_modus, user.banaday, user.authattack,\n                stat.total_points\n                FROM %%USERS%% as user\n                LEFT JOIN %%STATPOINTS%% as stat ON stat.id_owner = user.id AND stat.stat_type = '1'\n                WHERE user.id = :ownerID;";
            $targetPlayerData = $db->selectSingle($sql, array(':ownerID' => $targetPlanetData['id_owner']));
        }
        if (empty($targetPlayerData)) {
            $this->printMessage($LNG['fl_empty_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
        }
        $MisInfo = array();
        $MisInfo['galaxy'] = $targetGalaxy;
        $MisInfo['system'] = $targetSystem;
        $MisInfo['planet'] = $targetPlanet;
        $MisInfo['planettype'] = $targetType;
        $MisInfo['IsAKS'] = $fleetGroup;
        $MisInfo['Ship'] = $fleetArray;
        $availableMissions = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData);
        if (!in_array($targetMission, $availableMissions['MissionSelector'])) {
            $this->printMessage($LNG['fl_invalid_mission'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet2')));
        }
        if ($targetMission != 8 && IsVacationMode($targetPlayerData)) {
            $this->printMessage($LNG['fl_target_exists'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1')));
        }
        if ($targetMission == 1 || $targetMission == 2 || $targetMission == 9) {
            if (FleetFunctions::CheckBash($targetPlanetData['id'])) {
                $this->printMessage($LNG['fl_bash_protection'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
        }
        if ($targetMission == 1 || $targetMission == 2 || $targetMission == 5 || $targetMission == 6 || $targetMission == 9) {
            if (Config::get()->adm_attack == 1 && $targetPlayerData['authattack'] > $USER['authlevel']) {
                $this->printMessage($LNG['fl_admin_attack'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
            $sql = 'SELECT total_points
			FROM %%STATPOINTS%%
			WHERE id_owner = :userId AND stat_type = :statType';
            $USER += Database::get()->selectSingle($sql, array(':userId' => $USER['id'], ':statType' => 1));
            $IsNoobProtec = CheckNoobProtec($USER, $targetPlayerData, $targetPlayerData);
            if ($IsNoobProtec['NoobPlayer']) {
                $this->printMessage($LNG['fl_player_is_noob'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
            if ($IsNoobProtec['StrongPlayer']) {
                $this->printMessage($LNG['fl_player_is_strong'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
        }
        if ($targetMission == 5) {
            if ($targetPlayerData['ally_id'] != $USER['ally_id']) {
                $sql = "SELECT COUNT(*) as state FROM %%BUDDY%%\n\t\t\t\tWHERE id NOT IN (SELECT id FROM %%BUDDY_REQUEST%% WHERE %%BUDDY_REQUEST%%.id = %%BUDDY%%.id) AND\n\t\t\t\t(owner = :ownerID AND sender = :userID) OR (owner = :userID AND sender = :ownerID);";
                $buddy = $db->selectSingle($sql, array(':ownerID' => $targetPlayerData['id'], ':userID' => $USER['id']), 'state');
                if ($buddy == 0) {
                    $this->printMessage($LNG['fl_no_same_alliance'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
                }
            }
        }
        $fleetMaxSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
        $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
        $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $fleetMaxSpeed, $distance, $SpeedFactor, $USER);
        $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $USER, $SpeedFactor);
        if ($PLANET[$resource[903]] < $consumption) {
            $this->printMessage($LNG['fl_not_enough_deuterium'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
        }
        $StayDuration = 0;
        if ($targetMission == 5 || $targetMission == 11 || $targetMission == 15) {
            if (!isset($availableMissions['StayBlock'][$stayTime])) {
                $this->printMessage($LNG['fl_hold_time_not_exists'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
            }
            $StayDuration = round($availableMissions['StayBlock'][$stayTime] * 3600, 0);
        }
        $fleetStorage -= $consumption;
        $fleetResource = array(901 => min($TransportMetal, floor($PLANET[$resource[901]])), 902 => min($TransportCrystal, floor($PLANET[$resource[902]])), 903 => min($TransportDeuterium, floor($PLANET[$resource[903]] - $consumption)));
        $StorageNeeded = array_sum($fleetResource);
        if ($StorageNeeded > $fleetStorage) {
            $this->printMessage($LNG['fl_not_enough_space'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable')));
        }
        $PLANET[$resource[901]] -= $fleetResource[901];
        $PLANET[$resource[902]] -= $fleetResource[902];
        $PLANET[$resource[903]] -= $fleetResource[903] + $consumption;
        $fleetStartTime = $duration + TIMESTAMP;
        $timeDifference = round(max(0, $fleetStartTime - $ACSTime));
        if ($fleetGroup != 0) {
            if ($timeDifference != 0) {
                FleetFunctions::setACSTime($timeDifference, $fleetGroup);
            } else {
                $fleetStartTime = $ACSTime;
            }
        }
        $fleetStayTime = $fleetStartTime + $StayDuration;
        $fleetEndTime = $fleetStayTime + $duration;
        FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetPlanetData['id_owner'], $targetPlanetData['id'], $targetGalaxy, $targetSystem, $targetPlanet, $targetType, $fleetResource, $fleetStartTime, $fleetStayTime, $fleetEndTime, $fleetGroup);
        foreach ($fleetArray as $Ship => $Count) {
            $fleetList[$LNG['tech'][$Ship]] = $Count;
        }
        $this->tplObj->gotoside('game.php?page=fleetTable');
        $this->assign(array('targetMission' => $targetMission, 'distance' => $distance, 'consumption' => $consumption, 'from' => $PLANET['galaxy'] . ":" . $PLANET['system'] . ":" . $PLANET['planet'], 'destination' => $targetGalaxy . ":" . $targetSystem . ":" . $targetPlanet, 'fleetStartTime' => _date($LNG['php_tdformat'], $fleetStartTime, $USER['timezone']), 'fleetEndTime' => _date($LNG['php_tdformat'], $fleetEndTime, $USER['timezone']), 'MaxFleetSpeed' => $fleetMaxSpeed, 'FleetList' => $fleetArray));
        $this->display('page.fleetStep3.default.tpl');
    }
 public function show()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $CONF, $LNG, $UNI;
     if (IsVacationMode($USER)) {
         FleetFunctions::GotoFleetPage(0);
     }
     $targetMission = HTTP::_GP('mission', 3);
     $TransportMetal = max(0, round(HTTP::_GP('metal', 0.0)));
     $TransportCrystal = max(0, round(HTTP::_GP('crystal', 0.0)));
     $TransportDeuterium = max(0, round(HTTP::_GP('deuterium', 0.0)));
     $TransportElyrium = max(0, round(HTTP::_GP('elyrium', 0.0)));
     $TransportPopulation301 = max(0, round(HTTP::_GP('population301', 0.0)));
     $TransportPopulation302 = max(0, round(HTTP::_GP('population302', 0.0)));
     $TransportPopulation303 = max(0, round(HTTP::_GP('population303', 0.0)));
     $TransportPopulation304 = max(0, round(HTTP::_GP('population304', 0.0)));
     $TransportPopulation305 = max(0, round(HTTP::_GP('population305', 0.0)));
     $TransportPopulation306 = max(0, round(HTTP::_GP('population306', 0.0)));
     $TransportPopulation307 = max(0, round(HTTP::_GP('population307', 0.0)));
     $TransportPopulation309 = max(0, round(HTTP::_GP('population309', 0.0)));
     $stayTime = HTTP::_GP('staytime', 0);
     $speed = HTTP::_GP('speed', 10);
     $token = HTTP::_GP('tokens', '');
     if (!isset($_SESSION['fleet'][$token])) {
         FleetFunctions::GotoFleetPage(1);
     }
     if ($_SESSION['fleet'][$token]['time'] < TIMESTAMP - 600) {
         unset($_SESSION['fleet'][$token]);
         FleetFunctions::GotoFleetPage(0);
     }
     $maxFleetSpeed = $_SESSION['fleet'][$token]['speed'];
     $distance = $_SESSION['fleet'][$token]['distance'];
     $targetGalaxy = $_SESSION['fleet'][$token]['targetGalaxy'];
     $targetSystem = $_SESSION['fleet'][$token]['targetSystem'];
     $targetPlanet = $_SESSION['fleet'][$token]['targetPlanet'];
     $targetType = $_SESSION['fleet'][$token]['targetType'];
     $fleetGroup = $_SESSION['fleet'][$token]['fleetGroup'];
     $fleetArray = $_SESSION['fleet'][$token]['fleet'];
     $fleetStorage = $_SESSION['fleet'][$token]['fleetRoom'];
     $fleetSpeed = $speed;
     unset($_SESSION['fleet'][$token]);
     if ($targetMission != 2) {
         $fleetGroup = 0;
     }
     if ($PLANET['galaxy'] == $targetGalaxy && $PLANET['system'] == $targetSystem && $PLANET['planet'] == $targetPlanet && $PLANET['planet_type'] == $targetType) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_error_same_planet'] . '</span>');
     }
     if ($targetGalaxy < 1 || $targetGalaxy > Config::get('max_galaxy') || $targetSystem < 1 || $targetSystem > Config::get('max_system') || $targetPlanet < 1 || $targetPlanet > Config::get('max_planets') + 1 || $targetType !== 1 && $targetType !== 2 && $targetType !== 3) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_invalid_target'] . '</span>');
     }
     if ($targetMission == 3 && $TransportMetal + $TransportCrystal + $TransportDeuterium + $TransportElyrium < 1) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_no_noresource'] . '</span>');
     }
     $ActualFleets = FleetFunctions::GetCurrentFleets($USER['id']);
     if (FleetFunctions::GetMaxFleetSlots($USER) <= $ActualFleets) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_no_slots'] . '</span>');
     }
     $ACSTime = 0;
     if (!empty($fleetGroup)) {
         $ACSTime = $GLOBALS['DATABASE']->getFirstCell("SELECT ankunft\n\t\t\tFROM " . USERS_ACS . " \n\t\t\tINNER JOIN " . AKS . " ON id = acsID\n\t\t\tWHERE acsID = " . $fleetGroup . "\n\t\t\tAND " . Config::get('max_fleets_per_acs') . " > (SELECT COUNT(*) FROM " . FLEETS . " WHERE fleet_group = " . $fleetGroup . ");");
         if (empty($ACSTime)) {
             $fleetGroup = 0;
             $targetMission = 1;
         }
     }
     $ActualFleets = FleetFunctions::GetCurrentFleets($USER['id']);
     $targetPlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT id, id_owner, der_metal, der_crystal, destruyed, ally_deposit FROM " . PLANETS . " WHERE universe = " . $UNI . " AND galaxy = " . $targetGalaxy . " AND system = " . $targetSystem . " AND planet = " . $targetPlanet . " AND planet_type = '" . ($targetType == 2 ? 1 : $targetType) . "';");
     if ($targetMission == 1 || $targetMission == 6 || $targetMission == 3 || $targetMission == 14) {
         $ipCheck = $GLOBALS['DATABASE']->query("SELECT userID, secondID FROM uni1_ipblock WHERE userID = " . $USER['id'] . " OR secondID = '" . $USER['id'] . "';");
         if ($GLOBALS['DATABASE']->numRows($ipCheck) > 0) {
             while ($xb = $GLOBALS['DATABASE']->fetch_array($ipCheck)) {
                 if ($targetPlanetData['id_owner'] == $xb['userID'] || $targetPlanetData['id_owner'] == $xb['secondID']) {
                     $this->printMessage(sprintf($LNG['fleet_multi_block'], $this->getUsername($targetPlanetData['id_owner'])));
                 }
             }
         }
     }
     if ($targetMission == 7) {
         if (isset($targetPlanetData)) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_target_exists'] . '</span>');
         }
         if ($targetType != 1) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_only_planets_colonizable'] . '</span>');
         }
     }
     if ($targetMission == 7 || $targetMission == 15) {
         $targetPlanetData = array('id' => 0, 'id_owner' => 0, 'planettype' => 1);
     } else {
         if ($targetPlanetData["destruyed"] != 0) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_no_target'] . '</span>');
         }
         if (!isset($targetPlanetData)) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_no_target'] . '</span>');
         }
     }
     foreach ($fleetArray as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]]) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_not_all_ship_avalible'] . '</span>');
         }
     }
     if ($targetMission == 11) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 11);
         $maxExpedition = FleetFunctions::getDMMissionLimit($USER);
         if ($activeExpedition >= $maxExpedition) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_no_expedition_slot'] . '</span>');
         }
     } elseif ($targetMission == 15) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15);
         $maxExpedition = FleetFunctions::getExpeditionLimit($USER);
         if ($activeExpedition >= $maxExpedition) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_no_expedition_slot'] . '</span>');
         }
     }
     $usedPlanet = isset($targetPlanetData['id_owner']);
     $myPlanet = $usedPlanet && $targetPlanetData['id_owner'] == $USER['id'];
     if ($targetMission == 7 || $targetMission == 15) {
         $targetPlayerData = array('id' => 0, 'onlinetime' => TIMESTAMP, 'ally_id' => 0, 'urlaubs_modus' => 0, 'authattack' => 0, 'total_points' => 0);
     } elseif ($myPlanet) {
         $targetPlayerData = $USER;
     } elseif (!empty($targetPlanetData['id_owner'])) {
         $targetPlayerData = $GLOBALS['DATABASE']->getFirstRow("SELECT \n\t\t\tuser.id, user.onlinetime, user.ally_id, user.urlaubs_modus, user.banaday, user.authattack, \n\t\t\tstat.total_points\n\t\t\tFROM " . USERS . " as user \n\t\t\tLEFT JOIN " . STATPOINTS . " as stat ON stat.id_owner = user.id AND stat.stat_type = '1' \n\t\t\tWHERE user.id = " . $targetPlanetData['id_owner'] . ";");
     } else {
         $this->printMessage('<span class="rouge">' . $LNG['fl_empty_target'] . '</span>');
     }
     $MisInfo = array();
     $MisInfo['galaxy'] = $targetGalaxy;
     $MisInfo['system'] = $targetSystem;
     $MisInfo['planet'] = $targetPlanet;
     $MisInfo['planettype'] = $targetType;
     $MisInfo['IsAKS'] = $fleetGroup;
     $MisInfo['Ship'] = $fleetArray;
     $avalibleMissions = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData);
     if (!in_array($targetMission, $avalibleMissions['MissionSelector'])) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_invalid_mission'] . '</span>');
     }
     if ($targetMission != 8 && IsVacationMode($targetPlayerData)) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_target_exists'] . '</span>');
     }
     if ($targetMission == 1 || $targetMission == 2 || $targetMission == 9) {
         if (FleetFunctions::CheckBash($targetPlanetData['id'])) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_bash_protection'] . '</span>');
         }
     }
     if ($targetMission == 1 || $targetMission == 2 || $targetMission == 5 || $targetMission == 6 || $targetMission == 9) {
         if (Config::get('adm_attack') == 1 && $targetPlayerData['authattack'] > $USER['authlevel']) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_admin_attack'] . '</span>');
         }
         $IsNoobProtec = CheckNoobProtec($USER, $targetPlayerData, $targetPlayerData);
         if ($IsNoobProtec['NoobPlayer']) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_player_is_noob'] . '</span>');
         }
         if ($IsNoobProtec['StrongPlayer']) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_player_is_strong'] . '</span>');
         }
     }
     if ($targetMission == 5) {
         if ($targetPlayerData['ally_id'] != $USER['ally_id']) {
             $buddy = $GLOBALS['DATABASE']->getFirstCell("\n\t\t\t\tSELECT COUNT(*) FROM " . BUDDY . " \n\t\t\t\tWHERE id NOT IN (SELECT id FROM " . BUDDY_REQUEST . " WHERE " . BUDDY_REQUEST . ".id = " . BUDDY . ".id) AND \n\t\t\t\t(owner = " . $targetPlayerData['id'] . " AND sender = " . $USER['id'] . ") OR\n\t\t\t\t(owner = " . $USER['id'] . " AND sender = " . $targetPlayerData['id'] . ");");
             if ($buddy == 0) {
                 $this->printMessage('<span class="rouge">' . $LNG['fl_no_same_alliance'] . '</span>');
             }
         }
     }
     $fleetMaxSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
     $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $fleetMaxSpeed, $distance, $SpeedFactor, $USER);
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $fleetMaxSpeed, $USER, $SpeedFactor);
     if ($PLANET[$resource[904]] < $consumption) {
         $this->printMessage('<span class="rouge">Not enough elyrium</span>');
     }
     $StayDuration = 0;
     if ($targetMission == 5 || $targetMission == 11 || $targetMission == 15) {
         if (!isset($avalibleMissions['StayBlock'][$stayTime])) {
             $this->printMessage('<span class="rouge">' . $LNG['fl_hold_time_not_exists'] . '</span>');
         }
         $StayDuration = round($avalibleMissions['StayBlock'][$stayTime] * 3600, 0);
     }
     $fleetStorage -= $consumption;
     $fleetRessource = array(901 => min($TransportMetal, floor($PLANET[$resource[901]])), 902 => min($TransportCrystal, floor($PLANET[$resource[902]])), 903 => min($TransportDeuterium, floor($PLANET[$resource[903]])), 904 => min($TransportElyrium, floor($PLANET[$resource[904]] - $consumption)));
     $Diplo = 0;
     $Soldi = 0;
     if ($targetMission == 12) {
         $Diplo = 5;
         $Soldi = 10;
     }
     $fleetPopulation = array(301 => min($TransportPopulation301, floor($PLANET[$resource[301]])), 302 => min($TransportPopulation302, floor($PLANET[$resource[302]])), 303 => min($TransportPopulation303, floor($PLANET[$resource[303]])), 304 => min($TransportPopulation304, floor($PLANET[$resource[304]])), 305 => min($TransportPopulation305 + $Diplo, floor($PLANET[$resource[305]])), 306 => min($TransportPopulation306 + $Soldi, floor($PLANET[$resource[306]])), 307 => min($TransportPopulation307, floor($PLANET[$resource[307]])), 309 => min($TransportPopulation309, floor($PLANET[$resource[309]])));
     $StorageNeeded = array_sum($fleetRessource);
     if ($StorageNeeded > $fleetStorage) {
         $this->printMessage('<span class="rouge">' . $LNG['fl_not_enough_space'] . '</span>');
     }
     $PLANET[$resource[901]] -= $fleetRessource[901];
     $PLANET[$resource[902]] -= $fleetRessource[902];
     $PLANET[$resource[903]] -= $fleetRessource[903];
     $PLANET[$resource[904]] -= $fleetRessource[904] + $consumption;
     $PLANET[$resource[301]] -= $fleetPopulation[301];
     $PLANET[$resource[302]] -= $fleetPopulation[302];
     $PLANET[$resource[303]] -= $fleetPopulation[303];
     $PLANET[$resource[304]] -= $fleetPopulation[304];
     $PLANET[$resource[305]] -= $fleetPopulation[305];
     $PLANET[$resource[306]] -= $fleetPopulation[306];
     $PLANET[$resource[307]] -= $fleetPopulation[307];
     $PLANET[$resource[309]] -= $fleetPopulation[309];
     if (connection_aborted()) {
         exit;
     }
     $fleetStartTime = $duration + TIMESTAMP;
     $timeDifference = round(max(0, $fleetStartTime - $ACSTime));
     if ($fleetGroup != 0) {
         if ($timeDifference != 0) {
             FleetFunctions::setACSTime($timeDifference, $fleetGroup);
         } else {
             $fleetStartTime = $ACSTime;
         }
     }
     $fleetStayTime = $fleetStartTime + $StayDuration;
     $fleetEndTime = $fleetStayTime + $duration;
     FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetPlanetData['id_owner'], $targetPlanetData['id'], $targetGalaxy, $targetSystem, $targetPlanet, $targetType, $fleetRessource, $fleetPopulation, $fleetStartTime, $fleetStayTime, $fleetEndTime, $fleetGroup);
     foreach ($fleetArray as $Ship => $Count) {
         $fleetList[$LNG['tech'][$Ship]] = $Count;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->gotoside('game.php?page=fleetTable');
     $this->tplObj->assign_vars(array('targetMission' => $targetMission, 'distance' => $distance, 'consumption' => $consumption, 'from' => $PLANET['galaxy'] . ":" . $PLANET['system'] . ":" . $PLANET['planet'], 'destination' => $targetGalaxy . ":" . $targetSystem . ":" . $targetPlanet, 'fleetStartTime' => _date($LNG['php_tdformat'], $fleetStartTime, $USER['timezone']), 'fleetEndTime' => _date($LNG['php_tdformat'], $fleetEndTime, $USER['timezone']), 'MaxFleetSpeed' => $fleetMaxSpeed, 'FleetList' => $fleetArray, 'arraysum' => array_sum($fleetArray)));
     $this->display('page.fleetStep3.default.tpl');
 }
 public function show()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $LNG;
     $PlanetCount = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE id != " . $PLANET['id'] . " AND id_owner = " . $USER['id'] . " AND destruyed = 0;");
     $targetGalaxy = HTTP::_GP('galaxy', '');
     $targetSystem = HTTP::_GP('system', '');
     $targetPlanet = HTTP::_GP('planet', '');
     $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']);
     $mission = HTTP::_GP('target_mission', 0);
     $missionText = '';
     $missionDesc = '';
     if ($mission != 0) {
         $missionText = $LNG['type_missionbis'][$mission];
     }
     if ($mission != 0) {
         $missionDesc = $LNG['type_missionDesc'][$mission];
     }
     $Fleet = array();
     $FleetRoom = 0;
     foreach ($reslist['fleet'] as $id => $ShipID) {
         $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0)));
         if ($amount < 1 || $ShipID == 212) {
             continue;
         }
         $Fleet[$ShipID] = $amount;
         $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount;
     }
     $FleetRoom *= 1 + $USER['factor']['ShipStorage'];
     if (empty($Fleet)) {
         FleetFunctions::GotoFleetPage();
     }
     $FleetData = array('fleetroom' => floattostring($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME);
     $token = getRandomString();
     $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom);
     $shortcutList = $this->GetUserShotcut();
     $colonyList = $this->GetColonyList();
     $ACSList = $this->GetAvalibleACS();
     if (!empty($shortcutList)) {
         $shortcutAmount = max(array_keys($shortcutList));
     } else {
         $shortcutAmount = 0;
     }
     $PopulationOnPlanet = array();
     $avaible_pop = array(301, 302, 303, 304, 305, 306, 307);
     foreach ($avaible_pop as $populationID) {
         $PopulationOnPlanet[] = array('id' => $populationID, 'count' => $PLANET[$resource[$populationID]]);
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->execscript('updateVars();calculateTransportCapacity();FleetTime();window.setInterval("FleetTime()", 1000);');
     $this->tplObj->assign_vars(array('token' => $token, 'missionText' => $missionText, 'missionDesc' => $missionDesc, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'PopulationOnPlanet' => $PopulationOnPlanet, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'PlanetCount' => $PlanetCount, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2]), 'fleetdata' => $FleetData));
     $this->display('page.fleetStep1.default.tpl');
 }