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');
 }
    function TargetEvent()
    {
        global $pricelist, $resource;
        $resourceIDs = array(901, 902, 903, 921);
        $debrisIDs = array(901, 902);
        $resQuery = array();
        $collectQuery = array();
        $collectedGoods = array();
        foreach ($debrisIDs as $debrisID) {
            $collectedGoods[$debrisID] = 0;
            $resQuery[] = 'der_' . $resource[$debrisID];
        }
        $sql = 'SELECT ' . implode(',', $resQuery) . ', (' . implode(' + ', $resQuery) . ') as total
		FROM %%PLANETS%% WHERE id = :planetId';
        $targetData = Database::get()->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id']));
        if (!empty($targetData['total'])) {
            $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
            $targetUser = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
            $targetUserFactors = getFactors($targetUser);
            $shipStorageFactor = 1 + $targetUserFactors['ShipStorage'];
            // Get fleet capacity
            $fleetData = FleetFunctions::unserialize($this->_fleet['fleet_array']);
            $recyclerStorage = 0;
            $otherFleetStorage = 0;
            foreach ($fleetData as $shipId => $shipAmount) {
                if ($shipId == 209 || $shipId == 219) {
                    $recyclerStorage += $pricelist[$shipId]['capacity'] * $shipAmount;
                } else {
                    $otherFleetStorage += $pricelist[$shipId]['capacity'] * $shipAmount;
                }
            }
            $recyclerStorage *= $shipStorageFactor;
            $otherFleetStorage *= $shipStorageFactor;
            $incomingGoods = 0;
            foreach ($resourceIDs as $resourceID) {
                $incomingGoods += $this->_fleet['fleet_resource_' . $resource[$resourceID]];
            }
            $totalStorage = $recyclerStorage + min(0, $otherFleetStorage - $incomingGoods);
            $param = array(':planetId' => $this->_fleet['fleet_end_id']);
            // fast way
            $collectFactor = min(1, $totalStorage / $targetData['total']);
            foreach ($debrisIDs as $debrisID) {
                $fleetColName = 'fleet_resource_' . $resource[$debrisID];
                $debrisColName = 'der_' . $resource[$debrisID];
                $collectedGoods[$debrisID] = ceil($targetData[$debrisColName] * $collectFactor);
                $collectQuery[] = $debrisColName . ' = GREATEST(0, ' . $debrisColName . ' - :' . $resource[$debrisID] . ')';
                $param[':' . $resource[$debrisID]] = $collectedGoods[$debrisID];
                $this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $collectedGoods[$debrisID]);
            }
            $sql = 'UPDATE %%PLANETS%% SET ' . implode(',', $collectQuery) . ' WHERE id = :planetId;';
            Database::get()->update($sql, $param);
        }
        $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
        $Message = sprintf($LNG['sys_recy_gotten'], pretty_number($collectedGoods[901]), $LNG['tech'][901], pretty_number($collectedGoods[902]), $LNG['tech'][902]);
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 5, $LNG['sys_recy_report'], $Message, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }
Example #4
0
    function TargetEvent()
    {
        $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
        $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
        $fleetArray = fleetAmountToArray($this->_fleet['fleet_array']);
        $duration = $this->_fleet['fleet_start_time'] - $this->_fleet['start_time'];
        require_once 'includes/classes/class.FleetFunctions.php';
        $fleetMaxSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $senderUser);
        $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
        $distance = FleetFunctions::GetTargetDistance(array($this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet']), array($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']));
        $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $fleetMaxSpeed, $senderUser, $SpeedFactor);
        $this->UpdateFleet('fleet_resource_elyrium', $this->_fleet['fleet_resource_elyrium'] + $consumption / 2);
        $LNG = $this->getLanguage($senderUser['lang']);
        $TargetUserID = $this->_fleet['fleet_target_owner'];
        $TargetMessage = '<div style="text-align : justify;">
    	' . $LNG['fleet_deploy_9'] . ' :
    </div>

    <div class="citation">
        <div class="guillemet ouvrir">«</div>
        <div class="guillemet fermer">»</div>
        
                ' . $LNG['fleet_deploy_10'] . ' Base Alpha 5 [' . $this->_fleet['fleet_end_system'] . ':' . $this->_fleet['fleet_end_planet'] . '] ' . $LNG['fleet_deploy_11'] . '
                <br>
        <div style="padding-left : 20px; padding-top : 10px;">
            — ' . $LNG['fleet_deploy_12'] . ' ' . date('d/m/Y H:i:s', TIMESTAMP) . '<br>
            — ' . $LNG['fleet_deploy_13'] . ' : Home001 [' . $this->_fleet['fleet_start_system'] . ':' . $this->_fleet['fleet_start_planet'] . ']<br>
            — ' . $LNG['fleet_deploy_14'] . ' : Base Alpha 5 [' . $this->_fleet['fleet_end_system'] . ':' . $this->_fleet['fleet_end_planet'] . '] <br>
        </div>
    </div>
  
                       <h3>' . $LNG['fleet_deploy_7'] . ' :</h3>
            <div class="conteneur_item" style="margin-top : 5px;">
                    <div class="element_item">
                        <img src="/media/ingame/image/metal.jpg">
                        ' . $LNG['tech'][901] . ' : <span class="orange">' . pretty_number($this->_fleet['fleet_resource_metal']) . '</span> ' . $LNG['lm_achat_units'] . '
                    </div>    
					<div class="element_item">
                        <img src="/media/ingame/image/oro.jpg">
                        ' . $LNG['tech'][902] . ' : <span class="orange">' . pretty_number($this->_fleet['fleet_resource_crystal']) . '</span> ' . $LNG['lm_achat_units'] . '
                    </div> 
					<div class="element_item">
                        <img src="/media/ingame/image/crystal.jpg">
                        ' . $LNG['tech'][903] . ' : <span class="orange">' . pretty_number($this->_fleet['fleet_resource_deuterium']) . '</span> ' . $LNG['lm_achat_units'] . '
                    </div> 
					<div class="element_item">
                        <img src="/media/ingame/image/elyrium.jpg">
                        ' . $LNG['tech'][904] . ' : <span class="orange">' . pretty_number($this->_fleet['fleet_resource_elyrium']) . '</span> ' . $LNG['lm_achat_units'] . '
                    </div> 
                        </div>
                                                    
    <div class="explication_utilisateur">
        ' . $LNG['fleet_deploy_15'] . '
    </div>';
        SendSimpleMessage($TargetUserID, 0, $this->_fleet['fleet_start_time'], 7, $LNG['sys_mess_tower_deploy_good'], $LNG['sys_stat_mess_stay'], $TargetMessage);
        $this->RestoreFleet(false);
    }
 public function show()
 {
     global $USER, $PLANET, $resource, $LNG, $reslist, $CONF;
     $this->tplObj->loadscript("jquery.countdown.js");
     $action = HTTP::_GP('action', '');
     $galaxyLeft = HTTP::_GP('galaxyLeft', '');
     $galaxyRight = HTTP::_GP('galaxyRight', '');
     $systemLeft = HTTP::_GP('systemLeft', '');
     $systemRight = HTTP::_GP('systemRight', '');
     $galaxy = min(max(HTTP::_GP('galaxy', (int) $PLANET['galaxy']), 1), Config::get('max_galaxy'));
     $system = min(max(HTTP::_GP('system', (int) $PLANET['system']), 1), Config::get('max_system'));
     $planet = min(max(HTTP::_GP('planet', (int) $PLANET['planet']), 1), Config::get('max_planets'));
     $type = HTTP::_GP('type', 1);
     $current = HTTP::_GP('current', 0);
     if (!empty($galaxyLeft)) {
         $galaxy = max($galaxy - 1, 1);
     } elseif (!empty($galaxyRight)) {
         $galaxy = min($galaxy + 1, Config::get('max_galaxy'));
     }
     if (!empty($systemLeft)) {
         $system = max($system - 1, 1);
     } elseif (!empty($systemRight)) {
         $system = min($system + 1, Config::get('max_system'));
     }
     if ($galaxy != $PLANET['galaxy'] || $system != $PLANET['system']) {
         if ($PLANET['deuterium'] < Config::get('deuterium_cost_galaxy')) {
             $this->printMessage($LNG['gl_no_deuterium_to_view_galaxy'], array("game.php?page=galaxy", 3));
             exit;
         } else {
             $PLANET['deuterium'] -= Config::get('deuterium_cost_galaxy');
         }
     }
     $targetDefensive = $reslist['defense'];
     $targetDefensive[] = 502;
     $MissleSelector[0] = $LNG['gl_all_defenses'];
     foreach ($targetDefensive as $Element) {
         $MissleSelector[$Element] = $LNG['tech'][$Element];
     }
     $galaxyRows = new GalaxyRows();
     $galaxyRows->setGalaxy($galaxy);
     $galaxyRows->setSystem($system);
     $Result = $galaxyRows->getGalaxyData();
     $tut_info = 1;
     $db_link = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 18) {
         $tut_info = 0;
         $db_link = 0;
     }
     $this->tplObj->loadscript('galaxy.js');
     $this->tplObj->assign_vars(array('man_p' => $USER['id_planet'], 'GalaxyRows' => $Result, 'tut_info' => $tut_info, 'db_link' => $db_link, 'planetcount' => $LNG['gl_populed_planets'], 'planetcount1' => count($Result), 'action' => $action, 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'type' => $type, 'current' => $current, 'maxfleetcount' => FleetFunctions::GetCurrentFleets($USER['id']), 'fleetmax' => FleetFunctions::GetMaxFleetSlots($USER), 'currentmip' => $PLANET[$resource[503]], 'grecyclers' => $PLANET[$resource[219]], 'recyclers' => $PLANET[$resource[209]], 'spyprobes' => $PLANET[$resource[210]], 'missile_count' => sprintf($LNG['gl_missil_to_launch'], $PLANET[$resource[503]]), 'spyShips' => array(210 => $USER['spio_anz']), 'settings_fleetactions' => $USER['settings_fleetactions'], 'current_galaxy' => $PLANET['galaxy'], 'immunity' => $LNG['gl_short_immunity'], 'current_system' => $PLANET['system'], 'current_planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type'], 'max_planets' => Config::get('max_planets'), 'MissleSelector' => $MissleSelector, 'ShortStatus' => array('vacation' => $LNG['gl_short_vacation'], 'banned' => $LNG['gl_short_ban'], 'inactive' => $LNG['gl_short_inactive'], 'longinactive' => $LNG['gl_short_long_inactive'], 'noob' => $LNG['gl_short_newbie'], 'strong' => $LNG['gl_short_strong'], 'enemy' => $LNG['gl_short_enemy'], 'friend' => $LNG['gl_short_friend'], 'member' => $LNG['gl_short_member'])));
     $this->display('page.galaxy2.default.tpl');
 }
Example #6
0
    public function show()
    {
        global $USER, $PLANET, $resource, $LNG, $reslist;
        $config = Config::get();
        $action = HTTP::_GP('action', '');
        $galaxyLeft = HTTP::_GP('galaxyLeft', '');
        $galaxyRight = HTTP::_GP('galaxyRight', '');
        $systemLeft = HTTP::_GP('systemLeft', '');
        $systemRight = HTTP::_GP('systemRight', '');
        $galaxy = min(max(HTTP::_GP('galaxy', (int) $PLANET['galaxy']), 1), $config->max_galaxy);
        $system = min(max(HTTP::_GP('system', (int) $PLANET['system']), 1), $config->max_system);
        $planet = min(max(HTTP::_GP('planet', (int) $PLANET['planet']), 1), $config->max_planets);
        $type = HTTP::_GP('type', 1);
        $current = HTTP::_GP('current', 0);
        if (!empty($galaxyLeft)) {
            $galaxy = max($galaxy - 1, 1);
        } elseif (!empty($galaxyRight)) {
            $galaxy = min($galaxy + 1, $config->max_galaxy);
        }
        if (!empty($systemLeft)) {
            $system = max($system - 1, 1);
        } elseif (!empty($systemRight)) {
            $system = min($system + 1, $config->max_system);
        }
        if ($galaxy != $PLANET['galaxy'] || $system != $PLANET['system']) {
            if ($PLANET['deuterium'] < $config->deuterium_cost_galaxy) {
                $this->printMessage($LNG['gl_no_deuterium_to_view_galaxy'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=galaxy')));
            } else {
                $PLANET['deuterium'] -= $config->deuterium_cost_galaxy;
            }
        }
        $targetDefensive = $reslist['defense'];
        $targetDefensive[] = 502;
        $missileSelector[0] = $LNG['gl_all_defenses'];
        foreach ($targetDefensive as $Element) {
            $missileSelector[$Element] = $LNG['tech'][$Element];
        }
        $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));
        $galaxyRows = new GalaxyRows();
        $galaxyRows->setGalaxy($galaxy);
        $galaxyRows->setSystem($system);
        $Result = $galaxyRows->getGalaxyData();
        $this->tplObj->loadscript('galaxy.js');
        $this->assign(array('GalaxyRows' => $Result, 'planetcount' => sprintf($LNG['gl_populed_planets'], count($Result)), 'action' => $action, 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'type' => $type, 'current' => $current, 'maxfleetcount' => FleetFunctions::GetCurrentFleets($USER['id']), 'fleetmax' => FleetFunctions::GetMaxFleetSlots($USER), 'currentmip' => $PLANET[$resource[503]], 'grecyclers' => $PLANET[$resource[219]], 'recyclers' => $PLANET[$resource[209]], 'spyprobes' => $PLANET[$resource[210]], 'missile_count' => sprintf($LNG['gl_missil_to_launch'], $PLANET[$resource[503]]), 'spyShips' => array(210 => $USER['spio_anz']), 'settings_fleetactions' => $USER['settings_fleetactions'], 'current_galaxy' => $PLANET['galaxy'], 'current_system' => $PLANET['system'], 'current_planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type'], 'max_planets' => $config->max_planets, 'missileSelector' => $missileSelector, 'ShortStatus' => array('vacation' => $LNG['gl_short_vacation'], 'banned' => $LNG['gl_short_ban'], 'inactive' => $LNG['gl_short_inactive'], 'longinactive' => $LNG['gl_short_long_inactive'], 'noob' => $LNG['gl_short_newbie'], 'strong' => $LNG['gl_short_strong'], 'enemy' => $LNG['gl_short_enemy'], 'friend' => $LNG['gl_short_friend'], 'member' => $LNG['gl_short_member'])));
        $this->display('page.galaxy.default.tpl');
    }
 function TargetEvent()
 {
     $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
     $senderUser = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
     $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
     $fleetArray = FleetFunctions::unserialize($this->_fleet['fleet_array']);
     $duration = $this->_fleet['fleet_start_time'] - $this->_fleet['start_time'];
     $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $distance = FleetFunctions::GetTargetDistance(array($this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet']), array($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']));
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $senderUser, $SpeedFactor);
     $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $consumption / 2);
     $LNG = $this->getLanguage($senderUser['lang']);
     $TargetUserID = $this->_fleet['fleet_target_owner'];
     $TargetMessage = sprintf($LNG['sys_stat_mess'], GetTargetAddressLink($this->_fleet, ''), pretty_number($this->_fleet['fleet_resource_metal']), $LNG['tech'][901], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['tech'][902], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['tech'][903]);
     PlayerUtil::sendMessage($TargetUserID, 0, $LNG['sys_mess_tower'], 5, $LNG['sys_stat_mess_stay'], $TargetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
     $this->RestoreFleet(false);
 }
Example #8
0
function DeleteSelectedPlanet($planetID)
{
    $planetData = $GLOBALS['DATABASE']->getFirstRow("SELECT planet_type FROM " . PLANETS . " WHERE id = " . $planetID . " AND id NOT IN (SELECT id_planet FROM " . USERS . ");");
    if (empty($planetData)) {
        return false;
    }
    $fleetData = $GLOBALS['DATABASE']->query("SELECT fleet_id FROM " . FLEETS . " WHERE fleet_end_id = " . $planetID . ";");
    while ($FleetID = $GLOBALS['DATABASE']->fetch_array($fleetData)) {
        FleetFunctions::SendFleetBack(${$planetID}, $FleetID['fleet_id']);
    }
    $GLOBALS['DATABASE']->free_result($fleetData);
    if ($planetData['planet_type'] == 3) {
        $GLOBALS['DATABASE']->multi_query("DELETE FROM " . PLANETS . " WHERE id = " . $planetID . ";UPDATE " . PLANETS . " SET id_luna = 0 WHERE id_luna = " . $planetID . ";");
    } else {
        $GLOBALS['DATABASE']->query("DELETE FROM " . PLANETS . " WHERE id = " . $planetID . " OR id_luna = " . $planetID . ";");
    }
}
Example #9
0
 function TargetEvent()
 {
     $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
     $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
     $fleetArray = fleetAmountToArray($this->_fleet['fleet_array']);
     $duration = $this->_fleet['fleet_start_time'] - $this->_fleet['start_time'];
     require_once 'includes/classes/class.FleetFunctions.php';
     $fleetMaxSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $senderUser);
     $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $distance = FleetFunctions::GetTargetDistance(array($this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet']), array($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']));
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $fleetMaxSpeed, $senderUser, $SpeedFactor);
     $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $consumption / 2);
     $LNG = $this->getLanguage($senderUser['lang']);
     $TargetUserID = $this->_fleet['fleet_target_owner'];
     $TargetMessage = sprintf($LNG['sys_stat_mess'], GetTargetAdressLink($this->_fleet, ''), pretty_number($this->_fleet['fleet_resource_metal']), $LNG['tech'][901], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['tech'][902], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['tech'][903]);
     SendSimpleMessage($TargetUserID, 0, $this->_fleet['fleet_start_time'], 5, $LNG['sys_mess_tower'], $LNG['sys_stat_mess_stay'], $TargetMessage);
     $this->RestoreFleet(false);
 }
Example #10
0
 function mission()
 {
     global $LNG, $ProdGrid, $resource, $reslist, $CONF, $pricelist, $USER, $PLANET;
     require_once 'includes/classes/class.FleetFunctions.php';
     $cmdd = HTTP::_GP('cmdd', '');
     $missionDescription = '';
     if ($cmdd == 'deploy') {
         $missionDescription = "Par le biais de cette mission, vous pouvez baser des ressources, du matériel et de la population uniquement sur une des planètes de votre empire. \n                                        Contrairement à la mission « Transporter des ressources et/ou du matériel », les vaisseaux qui constituent la flotte envoyée ne reviendront pas \n                                        sur la planète de départ. En effet, ils resteront sur la planète de destination (<i>un aller simple sans retour</i>).<br><br>\n                                        Bien entendu, il est nécessaire de développer les soutes de vos vaisseaux pour pouvoir baser une grande quantité de marchandises.";
     } elseif ($cmdd == 'transport') {
         $missionDescription = "Par le biais de cette mission, vous pouvez transporter des ressources, du matériel et de la population sur une de vos planètes ou celle d'un allié. \n                                        Une fois la mission effectuée, les vaisseaux qui constituent votre flotte reviendront sur la planète de départ.<br><br>\n                                        Pour pouvoir envoyer des ressources et/ou du matériel à un autre joueur, vous devez auparavant envoyer un pacte à celui-ci. \n                                        C'est seulement une fois le pacte signé que vous pourrez effectuer des transferts.";
     } elseif ($cmdd == 'colonise') {
         $missionDescription = "Il est très important de coloniser d'autres planètes, cela permet d'accélérer le développement de votre empire\n                                        puisque vous posséderez plus de matière première, et des bâtiments miniers en plus grand nombre. Ainsi votre production\n                                        de ressources sera plus conséquente. Il y a aussi un autre avantage, vous pourrez régner sur une plus grande partie de l'univers.<br><br>\n                                        Pour effectuer cette mission, vous devez posséder au moins 10 scientifiques, et 100 soldats. \n                                        Faites attention à la position de vos colonies car vous pouvez coloniser que 9 planètes en plus de votre planète mère. \n                                        Les planètes sont colonisables du système solaire 1 à 2 700 inclus.";
     } elseif ($cmdd == 'contact') {
         $missionDescription = "Les pactes sont très utiles pour faire du commerce avec les autres joueurs de cet univers. Il n'est pas possible d'échanger des ressources \n                                        et/ou du matériel, si vous ne possédez pas de pacte signé avec le joueur concerné.<br><br>Cette mission permet d'envoyer un contingent \n                                        de 5 diplomates et 10 soldats pour rencontrer les dirigeants de la planète indiquée par les coordonnées renseignées.";
     } elseif ($cmdd == 'recycle') {
         $missionDescription = "Si une bataille spatiale vient de se produire et que vous souhaitez recycler les ruines des vaisseaux détruits en orbite, alors, \n                                        il suffit d'envoyer vos vaisseaux ruines vers la planète en question. Ces vaisseaux particuliers ne nécessitent pas d'avoir un équipage.<br><br>\n                                        Une fois en orbite autour de cette planète, ils recycleront les diverses ruines pour les transformer en ressources expoitables par votre peuple.";
     } elseif ($cmdd == 'deployfleets') {
         $missionDescription = "Par le biais de cette mission, vous pouvez baser des vaisseaux ruines sur une de vos planètes ou celle d'un allié. Si vous envoyez vos vaisseaux \n                                        ruines chez un allié, vous en perdrez le contrôle.<br><br>Pour pouvoir envoyer des vaisseaux ruines à un autre joueur, vous devez auparavant \n                                        envoyer un pacte à celui-ci. C'est seulement une fois le pacte signé que vous pourrez effectuer le basement.";
     } elseif ($cmdd == 'probe') {
         $missionDescription = "Un voisin vous inquiète, vous avez peur qu’il vous attaque ou bien il vous espionne régulièrement. Faites de même, envoyez vos sondes spatiales \n                                        vers ses planètes afin de découvrir les mystères qu’il cache chez lui. <br><br>Vous devez disposer d'une sonde spatiale pour effectuer cette mission. \n                                        De plus, il est possible de faire retour une fois la mission lancée, dans ce cas, la sonde spatiale revient à la base.<br><br>\n                                        Il est impossible de modifier la quantité de sonde à envoyer dans le formulaire ci-dessous.";
     } elseif ($cmdd == 'attack') {
         $missionDescription = "La puissance d'un empire se mesure à la puissance de sa flotte. Cependant, certaines flottes puissantes peuvent être détruites facilement suite à une mauvaise stratégie. \n                                        Montrez aux autres peuples qui vivent dans cette galaxie qu'il ne suffit pas d'avoir la plus grande flotte, il faut aussi savoir s'en servir convenablement.<br><br>\n                                        Utilisez votre flotte pour détruire et mettre en ruine celles des autres peuples, utilisez-là intelligement pour lutter contre des empires plus puissants que vous. \n                                        La stratégie et votre palmarés de combat feront de vous le peuple le plus respecté de cette univers.";
     }
     $colonyList = $this->GetColonyList();
     $FleetsOnPlanet = array();
     foreach ($reslist['fleet'] as $FleetID) {
         if ($PLANET[$resource[$FleetID]] == 0) {
             continue;
         }
         $FleetsOnPlanet[] = array('id' => $FleetID, 'speed' => FleetFunctions::GetFleetMaxSpeed($FleetID, $USER), 'count' => $PLANET[$resource[$FleetID]]);
     }
     $PopulationOnPlanet = array();
     foreach ($reslist['population'] as $populationID) {
         if ($PLANET[$resource[$populationID]] == 0) {
             continue;
         }
         $PopulationOnPlanet[] = array('id' => $populationID, 'count' => $PLANET[$resource[$populationID]]);
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->assign_vars(array('missionDescription' => $missionDescription, 'colonyList' => $colonyList, 'FleetsOnPlanet' => $FleetsOnPlanet, 'PopulationOnPlanet' => $PopulationOnPlanet));
     $this->display('page.center.mission.tpl');
 }
    function RestoreFleet($onStart = true)
    {
        global $resource;
        $fleetData = FleetFunctions::unserialize($this->_fleet['fleet_array']);
        $updateQuery = array();
        $param = array(':metal' => $this->_fleet['fleet_resource_metal'], ':crystal' => $this->_fleet['fleet_resource_crystal'], ':deuterium' => $this->_fleet['fleet_resource_deuterium'], ':darkmatter' => $this->_fleet['fleet_resource_darkmatter'], ':planetId' => $onStart == true ? $this->_fleet['fleet_start_id'] : $this->_fleet['fleet_end_id']);
        foreach ($fleetData as $shipId => $shipAmount) {
            $updateQuery[] = "p.`" . $resource[$shipId] . "` = p.`" . $resource[$shipId] . "` + :" . $resource[$shipId];
            $param[':' . $resource[$shipId]] = $shipAmount;
        }
        $sql = 'UPDATE %%PLANETS%% as p, %%USERS%% as u SET
		' . implode(', ', $updateQuery) . ',
		p.`metal` = p.`metal` + :metal,
		p.`crystal` = p.`crystal` + :crystal,
		p.`deuterium` = p.`deuterium` + :deuterium,
		u.`darkmatter` = u.`darkmatter` + :darkmatter
		WHERE p.`id` = :planetId AND u.id = p.id_owner;';
        Database::get()->update($sql, $param);
        $this->KillFleet();
    }
 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');
 }
    function checkTarget()
    {
        global $PLANET, $LNG, $USER, $resource;
        $targetGalaxy = HTTP::_GP('galaxy', 0);
        $targetSystem = HTTP::_GP('system', 0);
        $targetPlanet = HTTP::_GP('planet', 0);
        $targetPlanetType = HTTP::_GP('planet_type', 1);
        if ($targetGalaxy == $PLANET['galaxy'] && $targetSystem == $PLANET['system'] && $targetPlanet == $PLANET['planet'] && $targetPlanetType == $PLANET['planet_type']) {
            $this->sendJSON($LNG['fl_error_same_planet']);
        }
        // If target is expedition
        if ($targetPlanet != Config::get()->max_planets + 1) {
            $db = Database::get();
            $sql = "SELECT u.id, u.urlaubs_modus, u.user_lastip, u.authattack,\n            \tp.destruyed, p.der_metal, p.der_crystal, p.destruyed\n                FROM %%USERS%% as u, %%PLANETS%% as p WHERE\n                p.universe = :universe AND\n                p.galaxy = :targetGalaxy AND\n                p.system = :targetSystem AND\n                p.planet = :targetPlanet  AND\n                p.planet_type = :targetType AND\n                u.id = p.id_owner;";
            $planetData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet, ':targetType' => $targetPlanetType == 2 ? 1 : $targetPlanetType));
            if ($targetPlanetType == 3 && !isset($planetData)) {
                $this->sendJSON($LNG['fl_error_no_moon']);
            }
            if ($targetPlanetType != 2 && $planetData['urlaubs_modus']) {
                $this->sendJSON($LNG['fl_in_vacation_player']);
            }
            if ($planetData['id'] != $USER['id'] && Config::get()->adm_attack == 1 && $planetData['authattack'] > $USER['authlevel']) {
                $this->sendJSON($LNG['fl_admin_attack']);
            }
            if ($planetData['destruyed'] != 0) {
                $this->sendJSON($LNG['fl_error_not_avalible']);
            }
            if ($targetPlanetType == 2 && $planetData['der_metal'] == 0 && $planetData['der_crystal'] == 0) {
                $this->sendJSON($LNG['fl_error_empty_derbis']);
            }
            $sql = 'SELECT (
				(SELECT COUNT(*) FROM %%MULTI%% WHERE userID = :userID) +
				(SELECT COUNT(*) FROM %%MULTI%% WHERE userID = :dataID)
			) as count;';
            $multiCount = $db->selectSingle($sql, array(':userID' => $USER['id'], ':dataID' => $planetData['id']), 'count');
            if (ENABLE_MULTIALERT && $USER['id'] != $planetData['id'] && $USER['authlevel'] != AUTH_ADM && $USER['user_lastip'] == $planetData['user_lastip'] && $multiCount != 2) {
                $this->sendJSON($LNG['fl_multi_alarm']);
            }
        } else {
            if ($USER[$resource[124]] == 0) {
                $this->sendJSON($LNG['fl_target_not_exists']);
            }
            $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15, true);
            if ($activeExpedition >= FleetFunctions::getExpeditionLimit($USER)) {
                $this->sendJSON($LNG['fl_no_expedition_slot']);
            }
        }
        $this->sendJSON('OK');
    }
    public function show()
    {
        global $USER, $PLANET, $LNG, $reslist, $resource;
        $missileCount = $PLANET['interplanetary_misil'];
        $targetGalaxy = HTTP::_GP('galaxy', 0);
        $targetSystem = HTTP::_GP('system', 0);
        $targetPlanet = HTTP::_GP('planet', 0);
        $targetType = HTTP::_GP('type', 0);
        $anz = min(HTTP::_GP('SendMI', 0), $missileCount);
        $primaryTarget = HTTP::_GP('Target', 0);
        $db = Database::get();
        $sql = "SELECT id, id_owner FROM %%PLANETS%%\n        WHERE universe = :universe AND galaxy = :targetGalaxy\n        AND system = :targetSystem AND planet = :targetPlanet AND planet_type = :targetType;";
        $target = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet, ':targetType' => $targetType));
        $Range = FleetFunctions::GetMissileRange($USER[$resource[117]]);
        $systemMin = $PLANET['system'] - $Range;
        $systemMax = $PLANET['system'] + $Range;
        $error = "";
        if (IsVacationMode($USER)) {
            $error = $LNG['fl_vacation_mode_active'];
        } elseif ($PLANET['silo'] < 4) {
            $error = $LNG['ma_silo_level'];
        } elseif ($USER['impulse_motor_tech'] == 0) {
            $error = $LNG['ma_impulse_drive_required'];
        } elseif ($targetGalaxy != $PLANET['galaxy'] || $targetSystem < $systemMin || $targetSystem > $systemMax) {
            $error = $LNG['ma_not_send_other_galaxy'];
        } elseif (!$target) {
            $error = $LNG['ma_planet_doesnt_exists'];
        } elseif (!in_array($primaryTarget, $reslist['defense']) && $primaryTarget != 0) {
            $error = $LNG['ma_wrong_target'];
        } elseif ($missileCount == 0) {
            $error = $LNG['ma_no_missiles'];
        } elseif ($anz <= 0) {
            $error = $LNG['ma_add_missile_number'];
        }
        $targetUser = GetUserByID($target['id_owner'], array('onlinetime', 'banaday', 'urlaubs_modus', 'authattack'));
        if (Config::get()->adm_attack == 1 && $targetUser['authattack'] > $USER['authlevel']) {
            $error = $LNG['fl_admin_attack'];
        } elseif ($targetUser['urlaubs_modus']) {
            $error = $LNG['fl_in_vacation_player'];
        }
        $sql = "SELECT total_points FROM %%STATPOINTS%% WHERE stat_type = '1' AND id_owner = :ownerId;";
        $User2Points = $db->selectSingle($sql, array(':ownerId' => $target['id_owner']));
        $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, $User2Points, $targetUser);
        if ($IsNoobProtec['NoobPlayer']) {
            $error = $LNG['fl_week_player'];
        } elseif ($IsNoobProtec['StrongPlayer']) {
            $error = $LNG['fl_strong_player'];
        }
        if ($error != "") {
            $this->printMessage($error);
        }
        $Duration = FleetFunctions::GetMIPDuration($PLANET['system'], $targetSystem);
        $DefenseLabel = $primaryTarget == 0 ? $LNG['ma_all'] : $LNG['tech'][$primaryTarget];
        $fleetArray = array(503 => $anz);
        $fleetStartTime = TIMESTAMP + $Duration;
        $fleetStayTime = $fleetStartTime;
        $fleetEndTime = $fleetStartTime;
        $fleetResource = array(901 => 0, 902 => 0, 903 => 0);
        FleetFunctions::sendFleet($fleetArray, 10, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $target['id_owner'], $target['id'], $targetGalaxy, $targetSystem, $targetPlanet, $targetType, $fleetResource, $fleetStartTime, $fleetStayTime, $fleetEndTime, 0, $primaryTarget);
        $this->printMessage("<b>" . $anz . "</b>" . $LNG['ma_missiles_sended'] . $DefenseLabel);
    }
Example #15
0
 protected function inMissileRange()
 {
     global $USER, $PLANET, $resource;
     if ($this->galaxyRow['galaxy'] != $PLANET['galaxy']) {
         return false;
     }
     $Range = FleetFunctions::GetMissileRange($USER[$resource[117]]);
     $systemMin = $PLANET['system'] - $Range;
     $systemMax = $PLANET['system'] + $Range;
     return $this->galaxyRow['system'] >= $systemMin && $this->galaxyRow['system'] <= $systemMax;
 }
 public function show()
 {
     global $USER, $PLANET, $LNG, $resource, $dpath, $reslist, $requeriments, $CONF;
     $fmenge = isset($_POST['fmenge']) ? $_POST['fmenge'] : array();
     $action = HTTP::_GP('action', '');
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = unserialize($PLANET['b_building_id']);
         foreach ($CurrentQueue as $ElementArray) {
             if ($ElementArray[0] == 21 || $ElementArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     if (empty($ElementQueue)) {
         $Count = 0;
     } else {
         $Count = count($ElementQueue);
     }
     if ($USER['urlaubs_modus'] == 0) {
         if (!empty($fmenge) && $NotBuilding == true) {
             if (Config::get('max_elements_ships') != 0 && $Count >= Config::get('max_elements_ships')) {
                 $this->printMessage(sprintf($LNG['bd_max_builds'], Config::get('max_elements_ships')));
                 exit;
             }
             $this->BuildAuftr($fmenge);
         }
         if ($action == "delete") {
             $this->CancelAuftr();
         }
     }
     $elementInQueue = array();
     $ElementQueue = unserialize($PLANET['b_hangar_id']);
     $Buildlist = array();
     if (!empty($ElementQueue)) {
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $Element) {
             if (empty($Element)) {
                 continue;
             }
             $elementInQueue[$Element[0]] = true;
             $ElementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime, $Element[0]);
         }
         $this->tplObj->loadscript('bcmath.js');
         $this->tplObj->execscript('ShipyardInit();');
         $Buildlist = array('Queue' => $Shipyard, 'b_hangar_id_plus' => $PLANET['b_hangar'], 'pretty_time_b_hangar' => pretty_time(max($QueueTime - $PLANET['b_hangar'], 0)));
     }
     $mode = HTTP::_GP('mode', 'fleet');
     if ($mode != 'defense' && $PLANET['planet_type'] == 4) {
         $this->printMessage("You cant acces this page on a fortress");
     }
     if ($mode == 'defense' && $CONF['fleetconf'] == 1 && $CONF['purchase_bonus_timer'] > TIMESTAMP) {
         $elementALL = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422, 502, 503);
         $elementIDs = array(407, 408, 409, 411, 502, 503);
         $elementIDd = array(401, 402, 403, 420);
         $elementIDa = array(405, 404, 406, 416, 417, 421);
         $elementIDq = array(418, 412, 410, 413, 419, 414, 422, 415);
     } elseif ($mode == 'defense') {
         $elementALL = array(401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 416, 417, 418, 419, 420, 421, 422, 502, 503);
         $elementIDs = array(407, 408, 409, 411, 502, 503);
         $elementIDd = array(401, 402, 403);
         $elementIDa = array(405, 404, 406, 416, 417);
         $elementIDq = array(418, 412, 410, 413, 419, 414, 415);
     } elseif ($mode == 'fleet' && $CONF['fleetconf'] == 1 && $CONF['purchase_bonus_timer'] > TIMESTAMP) {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 220, 223);
         $elementIDd = array(212, 202, 203, 204, 205, 229);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219, 224);
         $elementIDq = array(225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     } elseif ($mode == 'fleet') {
         $elementALL = array(202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230);
         $elementIDs = array(208, 210, 220, 223);
         $elementIDd = array(212, 202, 203, 204, 205);
         $elementIDa = array(209, 206, 207, 217, 215, 213, 211, 219);
         $elementIDq = array(225, 226, 214, 216, 227, 228, 222, 218, 221);
     }
     $Missiles = array();
     $Domes = array();
     $Orbits = array();
     foreach ($reslist['missile'] as $elementID) {
         $Missiles[$elementID] = $PLANET[$resource[$elementID]];
     }
     foreach ($reslist['defense'] as $elementID) {
         $Domes[$elementID] = $PLANET[$resource[$elementID]];
         $Orbits[$elementID] = $PLANET[$resource[$elementID]];
     }
     $MaxMissiles = BuildFunctions::getMaxConstructibleRockets($USER, $PLANET, $Missiles);
     $MaxDomes = BuildFunctions::getMaxConstructibleDomes($USER, $PLANET, $Domes);
     $MaxOrbits = BuildFunctions::getMaxConstructibleOrbits($USER, $PLANET, $Orbits);
     foreach ($elementALL as $Element) {
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListall[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDs as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDq as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListq[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDa as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementLista[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     foreach ($elementIDd as $Element) {
         $AllTech = array();
         $GetAll = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_vars_requriements` WHERE elementID = " . $Element . " ;");
         if ($GLOBALS['DATABASE']->numRows($GetAll) > 0) {
             while ($x = $GLOBALS['DATABASE']->fetch_array($GetAll)) {
                 $AllTech[] = $x;
             }
         }
         $costRessources = BuildFunctions::getElementPrice($USER, $PLANET, $Element);
         $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costRessources);
         $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costRessources);
         $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costRessources);
         $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costRessources);
         if (isset($MaxMissiles[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]);
         }
         if (isset($MaxDomes[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxDomes[$Element]);
         }
         if (isset($MaxOrbits[$Element])) {
             $maxBuildable = min($maxBuildable, $MaxOrbits[$Element]);
         }
         $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0);
         $elementListd[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costRessources' => $costRessources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floattostring($maxBuildable), 'AlreadyBuild' => $AlreadyBuild, 'AllTech' => $AllTech, 'techacc' => BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element));
     }
     $manual_step_9 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9 && ($PLANET['misil_launcher'] < 25 || $PLANET['small_laser'] < 10)) {
         $manual_step_9 = 0;
     }
     $manual_step_10 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 9 && $PLANET['misil_launcher'] >= 25 && $PLANET['small_laser'] >= 10) {
         $manual_step_10 = 0;
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '11' WHERE `id` = " . $USER['id'] . ";");
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `experience_peace` = `experience_peace` + '650' WHERE `id` = '" . $USER['id'] . "';");
         require_once 'includes/classes/class.FleetFunctions.php';
         $rawfleetarray = array(204 => 8, 205 => 5, 206 => 3);
         $fleetRessource = array(901 => 0, 902 => 0, 903 => 0);
         FleetFunctions::sendFleet($rawfleetarray, '1', 1, 1, 1, 1, 1, 1, $PLANET['id_owner'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $fleetRessource, TIMESTAMP + 58, TIMESTAMP + 58, TIMESTAMP + 116, 0);
     }
     $manual_step_16 = 1;
     if ($USER['training'] == 0 && $USER['training_step'] == 16) {
         $manual_step_16 = 0;
     }
     if ($USER['training'] == 0 && $USER['training_step'] == 16 && $PLANET['recycler'] >= 5) {
         $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET `training_step` = '17' WHERE `id` = " . $USER['id'] . ";");
     }
     $this->tplObj->loadscript('shipyard.js');
     $this->tplObj->assign_vars(array('manual_step_16' => $manual_step_16, 'manual_step_10' => $manual_step_10, 'manual_step_9' => $manual_step_9, 'elementListall' => $elementListall, 'elementList' => $elementList, 'elementListd' => $elementListd, 'elementLista' => $elementLista, 'elementListq' => $elementListq, 'NotBuilding' => $NotBuilding, 'BuildList' => $Buildlist, 'maxlength' => strlen(Config::get('max_fleet_per_build')), 'mode' => $mode));
     $this->display('page.shipyard.default.tpl');
 }
 function show()
 {
     global $USER, $PLANET, $reslist, $resource;
     $Slots = HTTP::_GP('slots', 1);
     $BattleArray[0][0][109] = $USER[$resource[109]];
     $BattleArray[0][0][110] = $USER[$resource[110]];
     $BattleArray[0][0][111] = $USER[$resource[111]];
     if (empty($_REQUEST['battleinput'])) {
         foreach ($reslist['fleet'] as $ID) {
             if (FleetFunctions::GetFleetMaxSpeed($ID, $USER) > 0) {
                 // Add just flyable elements
                 $BattleArray[0][0][$ID] = $PLANET[$resource[$ID]];
             }
         }
     } else {
         $BattleArray = HTTP::_GP('battleinput', array());
     }
     if (isset($_REQUEST['im'])) {
         foreach ($_REQUEST['im'] as $ID => $Count) {
             $BattleArray[0][1][$ID] = floattostring($Count);
         }
     }
     $this->tplObj->loadscript('battlesim.js');
     $this->assign(array('Slots' => $Slots, 'battleinput' => $BattleArray, 'fleetList' => $reslist['fleet'], 'defensiveList' => $reslist['defense']));
     $this->display('page.battleSimulator.default.tpl');
 }
    public function show()
    {
        global $USER, $PLANET, $resource, $LNG, $pricelist;
        $UserDeuterium = $PLANET['deuterium'];
        $planetID = HTTP::_GP('planetID', 0);
        $targetMission = HTTP::_GP('mission', 0);
        $activeSlots = FleetFunctions::GetCurrentFleets($USER['id']);
        $maxSlots = FleetFunctions::GetMaxFleetSlots($USER);
        $this->returnData['slots'] = $activeSlots;
        if (IsVacationMode($USER)) {
            $this->sendData(620, $LNG['fa_vacation_mode_current']);
        }
        if (empty($planetID)) {
            $this->sendData(601, $LNG['fa_planet_not_exist']);
        }
        if ($maxSlots <= $activeSlots) {
            $this->sendData(612, $LNG['fa_no_more_slots']);
        }
        $fleetArray = array();
        $db = Database::get();
        switch ($targetMission) {
            case 6:
                if (!isModuleAvailable(MODULE_MISSION_SPY)) {
                    $this->sendData(699, $LNG['sys_module_inactive']);
                }
                $ships = min($USER['spio_anz'], $PLANET[$resource[210]]);
                if (empty($ships)) {
                    $this->sendData(611, $LNG['fa_no_spios']);
                }
                $fleetArray = array(210 => $ships);
                $this->returnData['ships'][210] = $PLANET[$resource[210]] - $ships;
                break;
            case 8:
                if (!isModuleAvailable(MODULE_MISSION_RECYCLE)) {
                    $this->sendData(699, $LNG['sys_module_inactive']);
                }
                $sql = "SELECT (der_metal + der_crystal) as sum FROM %%PLANETS%% WHERE id = :planetID;";
                $totalDebris = $db->selectSingle($sql, array(':planetID' => $planetID), 'sum');
                $recElementIDs = array(219, 209);
                $fleetArray = array();
                foreach ($recElementIDs as $elementID) {
                    $shipsNeed = min(ceil($totalDebris / $pricelist[$elementID]['capacity']), $PLANET[$resource[$elementID]]);
                    $totalDebris -= $shipsNeed * $pricelist[$elementID]['capacity'];
                    $fleetArray[$elementID] = $shipsNeed;
                    $this->returnData['ships'][$elementID] = $PLANET[$resource[$elementID]] - $shipsNeed;
                    if ($totalDebris <= 0) {
                        break;
                    }
                }
                if (empty($fleetArray)) {
                    $this->sendData(611, $LNG['fa_no_recyclers']);
                }
                break;
            default:
                $this->sendData(610, $LNG['fa_not_enough_probes']);
                break;
        }
        $fleetArray = array_filter($fleetArray);
        if (empty($fleetArray)) {
            $this->sendData(610, $LNG['fa_not_enough_probes']);
        }
        $sql = "SELECT planet.id_owner as id_owner,\n\t\tplanet.galaxy as galaxy,\n\t\tplanet.system as system,\n\t\tplanet.planet as planet,\n\t\tplanet.planet_type as planet_type,\n\t\ttotal_points, onlinetime, urlaubs_modus, banaday, authattack\n\t\tFROM %%PLANETS%% planet\n\t\tINNER JOIN %%USERS%% user ON planet.id_owner = user.id\n\t\tLEFT JOIN %%STATPOINTS%% as stat ON stat.id_owner = user.id AND stat.stat_type = '1'\n\t\tWHERE planet.id = :planetID;";
        $targetData = $db->selectSingle($sql, array(':planetID' => $planetID));
        if (empty($targetData)) {
            $this->sendData(601, $LNG['fa_planet_not_exist']);
        }
        if ($targetMission == 6) {
            if (Config::get()->adm_attack == 1 && $targetData['authattack'] > $USER['authlevel']) {
                $this->sendData(619, $LNG['fa_action_not_allowed']);
            }
            if (IsVacationMode($targetData)) {
                $this->sendData(605, $LNG['fa_vacation_mode']);
            }
            $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, $targetData, $targetData);
            if ($IsNoobProtec['NoobPlayer']) {
                $this->sendData(603, $LNG['fa_week_player']);
            }
            if ($IsNoobProtec['StrongPlayer']) {
                $this->sendData(604, $LNG['fa_strong_player']);
            }
            if ($USER['id'] == $targetData['id_owner']) {
                $this->sendData(618, $LNG['fa_not_spy_yourself']);
            }
        }
        $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
        $Distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetData['galaxy'], $targetData['system'], $targetData['planet']));
        $SpeedAllMin = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
        $Duration = FleetFunctions::GetMissionDuration(10, $SpeedAllMin, $Distance, $SpeedFactor, $USER);
        $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $Duration, $Distance, $USER, $SpeedFactor);
        $UserDeuterium -= $consumption;
        if ($UserDeuterium < 0) {
            $this->sendData(613, $LNG['fa_not_enough_fuel']);
        }
        if ($consumption > FleetFunctions::GetFleetRoom($fleetArray)) {
            $this->sendData(613, $LNG['fa_no_fleetroom']);
        }
        if (connection_aborted()) {
            exit;
        }
        $this->returnData['slots']++;
        $fleetResource = array(901 => 0, 902 => 0, 903 => 0);
        $fleetStartTime = $Duration + TIMESTAMP;
        $fleetStayTime = $fleetStartTime;
        $fleetEndTime = $fleetStayTime + $Duration;
        $shipID = array_keys($fleetArray);
        FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetData['id_owner'], $planetID, $targetData['galaxy'], $targetData['system'], $targetData['planet'], $targetData['planet_type'], $fleetResource, $fleetStartTime, $fleetStayTime, $fleetEndTime);
        $this->sendData(600, $LNG['fa_sending'] . " " . array_sum($fleetArray) . " " . $LNG['tech'][$shipID[0]] . " " . $LNG['gl_to'] . " " . $targetData['galaxy'] . ":" . $targetData['system'] . ":" . $targetData['planet'] . " ...");
    }
    function TargetEvent()
    {
        global $resource, $reslist;
        $db = Database::get();
        $fleetAttack = array();
        $fleetDefend = array();
        $userAttack = array();
        $userDefend = array();
        $incomingFleets = array();
        $stealResource = array(901 => 0, 902 => 0, 903 => 0);
        $debris = array();
        $planetDebris = array();
        $debrisResource = array(901, 902);
        $messageHTML = <<<HTML
<div class="raportMessage">
\t<table>
\t\t<tr>
\t\t\t<td colspan="2"><a href="game.php?page=raport&raport=%s" target="_blank"><span class="%s">%s %s (%s)</span></a></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td>%s</td><td><span class="%s">%s: %s</span>&nbsp;<span class="%s">%s: %s</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span class="reportSteal element901">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="reportSteal element902">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="reportSteal element903">%s</span></span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span class="reportDebris element901">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="reportDebris element902">%s</span></span></td>
\t\t</tr>
\t</table>
</div>
HTML;
        //Minize HTML
        $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML);
        $sql = "SELECT * FROM %%PLANETS%% WHERE id = :planetId;";
        $targetPlanet = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id']));
        $sql = "SELECT * FROM %%USERS%% WHERE id = :userId;";
        $targetUser = $db->selectSingle($sql, array(':userId' => $targetPlanet['id_owner']));
        $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']);
        $planetUpdater = new ResourceUpdate();
        list($targetUser, $targetPlanet) = $planetUpdater->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']);
        if ($this->_fleet['fleet_group'] != 0) {
            $sql = "DELETE FROM %%AKS%% WHERE id = :acsId;";
            $db->delete($sql, array(':acsId' => $this->_fleet['fleet_group']));
            $sql = "SELECT * FROM %%FLEETS%% WHERE fleet_group = :acsId;";
            $incomingFleetsResult = $db->select($sql, array(':acsId' => $this->_fleet['fleet_group']));
            foreach ($incomingFleetsResult as $incomingFleetRow) {
                $incomingFleets[$incomingFleetRow['fleet_id']] = $incomingFleetRow;
            }
            unset($incomingFleetsResult);
        } else {
            $incomingFleets = array($this->_fleet['fleet_id'] => $this->_fleet);
        }
        foreach ($incomingFleets as $fleetID => $fleetDetail) {
            $sql = "SELECT * FROM %%USERS%% WHERE id = :userId;";
            $fleetAttack[$fleetID]['player'] = $db->selectSingle($sql, array(':userId' => $fleetDetail['fleet_owner']));
            $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$fleetID]['player'], 'attack', $this->_fleet['fleet_start_time']);
            $fleetAttack[$fleetID]['fleetDetail'] = $fleetDetail;
            $fleetAttack[$fleetID]['unit'] = FleetFunctions::unserialize($fleetDetail['fleet_array']);
            $userAttack[$fleetAttack[$fleetID]['player']['id']] = $fleetAttack[$fleetID]['player']['username'];
        }
        $sql = "SELECT * FROM %%FLEETS%%\n\t\tWHERE fleet_mission\t\t= :mission\n\t\tAND fleet_end_id\t\t= :fleetEndId\n\t\tAND fleet_start_time \t<= :timeStamp\n\t\tAND fleet_end_stay \t\t>= :timeStamp;";
        $targetFleetsResult = $db->select($sql, array(':mission' => 5, ':fleetEndId' => $this->_fleet['fleet_end_id'], ':timeStamp' => TIMESTAMP));
        foreach ($targetFleetsResult as $fleetDetail) {
            $fleetID = $fleetDetail['fleet_id'];
            $sql = "SELECT * FROM %%USERS%% WHERE id = :userId;";
            $fleetDefend[$fleetID]['player'] = $db->selectSingle($sql, array(':userId' => $fleetDetail['fleet_owner']));
            $fleetDefend[$fleetID]['player']['factor'] = getFactors($fleetDefend[$fleetID]['player'], 'attack', $this->_fleet['fleet_start_time']);
            $fleetDefend[$fleetID]['fleetDetail'] = $fleetDetail;
            $fleetDefend[$fleetID]['unit'] = FleetFunctions::unserialize($fleetDetail['fleet_array']);
            $userDefend[$fleetDefend[$fleetID]['player']['id']] = $fleetDefend[$fleetID]['player']['username'];
        }
        unset($targetFleetsResult);
        $fleetDefend[0]['player'] = $targetUser;
        $fleetDefend[0]['player']['factor'] = getFactors($fleetDefend[0]['player'], 'attack', $this->_fleet['fleet_start_time']);
        $fleetDefend[0]['fleetDetail'] = array('fleet_start_galaxy' => $targetPlanet['galaxy'], 'fleet_start_system' => $targetPlanet['system'], 'fleet_start_planet' => $targetPlanet['planet'], 'fleet_start_type' => $targetPlanet['planet_type']);
        $fleetDefend[0]['unit'] = array();
        foreach (array_merge($reslist['fleet'], $reslist['defense']) as $elementID) {
            if (empty($targetPlanet[$resource[$elementID]])) {
                continue;
            }
            $fleetDefend[0]['unit'][$elementID] = $targetPlanet[$resource[$elementID]];
        }
        $userDefend[$fleetDefend[0]['player']['id']] = $fleetDefend[0]['player']['username'];
        require_once 'includes/classes/missions/functions/calculateAttack.php';
        $fleetIntoDebris = Config::get($this->_fleet['fleet_universe'])->Fleet_Cdr;
        $defIntoDebris = Config::get($this->_fleet['fleet_universe'])->Defs_Cdr;
        $combatResult = calculateAttack($fleetAttack, $fleetDefend, $fleetIntoDebris, $defIntoDebris);
        foreach ($fleetAttack as $fleetID => $fleetDetail) {
            $fleetArray = '';
            $totalCount = 0;
            $fleetDetail['unit'] = array_filter($fleetDetail['unit']);
            foreach ($fleetDetail['unit'] as $elementID => $amount) {
                $fleetArray .= $elementID . ',' . floattostring($amount) . ';';
                $totalCount += $amount;
            }
            if ($totalCount == 0) {
                if ($this->_fleet['fleet_id'] == $fleetID) {
                    $this->KillFleet();
                } else {
                    $sql = 'DELETE %%FLEETS%%, %%FLEETS_EVENT%%
					FROM %%FLEETS%%
					INNER JOIN %%FLEETS_EVENT%% ON fleetID = fleet_id
					WHERE fleet_id = :fleetId;';
                    $db->delete($sql, array(':fleetId' => $fleetID));
                }
                $sql = 'UPDATE %%LOG_FLEETS%% SET fleet_state = :fleetState WHERE fleet_id = :fleetId;';
                $db->update($sql, array(':fleetId' => $fleetID, ':fleetState' => FLEET_HOLD));
                unset($fleetAttack[$fleetID]);
            } elseif ($totalCount > 0) {
                $sql = "UPDATE %%FLEETS%% fleet, %%LOG_FLEETS%% log SET\n\t\t\t\tfleet.fleet_array\t= :fleetData,\n\t\t\t\tfleet.fleet_amount\t= :fleetCount,\n\t\t\t\tlog.fleet_array\t\t= :fleetData,\n\t\t\t\tlog.fleet_amount\t= :fleetCount\n\t\t\t\tWHERE log.fleet_id = :fleetId AND log.fleet_id = :fleetId;";
                $db->update($sql, array(':fleetData' => substr($fleetArray, 0, -1), ':fleetCount' => $totalCount, ':fleetId' => $fleetID));
            } else {
                throw new OutOfRangeException("Negative Fleet amount ....");
            }
        }
        foreach ($fleetDefend as $fleetID => $fleetDetail) {
            if ($fleetID != 0) {
                // Stay fleet
                $fleetArray = '';
                $totalCount = 0;
                $fleetDetail['unit'] = array_filter($fleetDetail['unit']);
                foreach ($fleetDetail['unit'] as $elementID => $amount) {
                    $fleetArray .= $elementID . ',' . floattostring($amount) . ';';
                    $totalCount += $amount;
                }
                if ($totalCount == 0) {
                    $sql = 'DELETE %%FLEETS%%, %%FLEETS_EVENT%%
					FROM %%FLEETS%%
					INNER JOIN %%FLEETS_EVENT%% ON fleetID = fleet_id
					WHERE fleet_id = :fleetId;';
                    $db->delete($sql, array(':fleetId' => $fleetID));
                    $sql = 'UPDATE %%LOG_FLEETS%% SET fleet_state = :fleetState WHERE fleet_id = :fleetId;';
                    $db->update($sql, array(':fleetId' => $fleetID, ':fleetState' => FLEET_HOLD));
                    unset($fleetAttack[$fleetID]);
                } elseif ($totalCount > 0) {
                    $sql = "UPDATE %%FLEETS%% fleet, %%LOG_FLEETS%% log SET\n\t\t\t\t\tfleet.fleet_array\t= :fleetData,\n\t\t\t\t\tfleet.fleet_amount\t= :fleetCount,\n\t\t\t\t\tlog.fleet_array\t\t= :fleetData,\n\t\t\t\t\tlog.fleet_amount\t= :fleetCount\n\t\t\t\t\tWHERE log.fleet_id = :fleetId AND log.fleet_id = :fleetId;";
                    $db->update($sql, array(':fleetData' => substr($fleetArray, 0, -1), ':fleetCount' => $totalCount, ':fleetId' => $fleetID));
                } else {
                    throw new OutOfRangeException("Negative Fleet amount ....");
                }
            } else {
                $params = array(':planetId' => $this->_fleet['fleet_end_id']);
                // Planet fleet
                $fleetArray = array();
                foreach ($fleetDetail['unit'] as $elementID => $amount) {
                    $fleetArray[] = '`' . $resource[$elementID] . '` = :' . $resource[$elementID];
                    $params[':' . $resource[$elementID]] = $amount;
                }
                if (!empty($fleetArray)) {
                    $sql = 'UPDATE %%PLANETS%% SET ' . implode(', ', $fleetArray) . ' WHERE id = :planetId;';
                    $db->update($sql, $params);
                }
            }
        }
        if ($combatResult['won'] == "a") {
            require_once 'includes/classes/missions/functions/calculateSteal.php';
            $stealResource = calculateSteal($fleetAttack, $targetPlanet);
        }
        if ($this->_fleet['fleet_end_type'] == 3) {
            // Use planet debris, if attack on moons
            $sql = "SELECT der_metal, der_crystal FROM %%PLANETS%% WHERE id_luna = :moonId;";
            $targetDebris = $db->selectSingle($sql, array(':moonId' => $this->_fleet['fleet_end_id']));
            $targetPlanet += $targetDebris;
        }
        foreach ($debrisResource as $elementID) {
            $debris[$elementID] = $combatResult['debris']['attacker'][$elementID] + $combatResult['debris']['defender'][$elementID];
            $planetDebris[$elementID] = $targetPlanet['der_' . $resource[$elementID]] + $debris[$elementID];
        }
        $reportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => NULL, 'moonDestroy' => true, 'moonName' => NULL, 'moonDestroyChance' => NULL, 'moonDestroySuccess' => NULL, 'fleetDestroyChance' => NULL, 'fleetDestroySuccess' => false);
        switch ($combatResult['won']) {
            case "a":
                $moonDestroyChance = round((100 - sqrt($targetPlanet['diameter'])) * sqrt($fleetAttack[$this->_fleet['fleet_id']]['unit'][214]), 1);
                // Max 100% | Min 0%
                $moonDestroyChance = min($moonDestroyChance, 100);
                $moonDestroyChance = max($moonDestroyChance, 0);
                $randChance = mt_rand(1, 100);
                if ($randChance <= $moonDestroyChance) {
                    $sql = 'SELECT id FROM %%PLANETS%% WHERE id_luna = :moonId;';
                    $planetID = $db->selectSingle($sql, array(':moonId' => $targetPlanet['id']), 'id');
                    $sql = 'UPDATE %%FLEETS%% SET
					fleet_start_type		= 1,
					fleet_start_id			= :planetId
					WHERE fleet_start_id	= :moonId;';
                    $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id']));
                    $sql = 'UPDATE %%FLEETS%% SET
					fleet_end_type	= 1,
					fleet_end_id	= :moonId,
					fleet_mission	= IF(fleet_mission = 9, 1, fleet_mission)
					WHERE fleet_end_id = :planetId
					AND fleet_id != :fleetId;';
                    $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id'], ':fleetId' => $this->_fleet['fleet_id']));
                    $sql = "UPDATE %%AKS%% SET target = :planetId WHERE target = :moonId;";
                    $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id']));
                    PlayerUtil::deletePlanet($targetPlanet['id']);
                    $reportInfo['moonDestroySuccess'] = 1;
                } else {
                    $reportInfo['moonDestroySuccess'] = 0;
                }
                $fleetDestroyChance = round(sqrt($targetPlanet['diameter']) / 2);
                $randChance = mt_rand(1, 100);
                if ($randChance <= $fleetDestroyChance) {
                    $this->KillFleet();
                    $reportInfo['fleetDestroySuccess'] = true;
                } else {
                    $reportInfo['fleetDestroySuccess'] = false;
                }
                $reportInfo['moonDestroyChance'] = $moonDestroyChance;
                $reportInfo['fleetDestroyChance'] = $fleetDestroyChance;
                // Win
                $attackStatus = 'wons';
                $defendStatus = 'loos';
                $class = array('raportWin', 'raportLose');
                break;
            case "r":
                // Lose
                $attackStatus = 'loos';
                $defendStatus = 'wons';
                $class = array('raportLose', 'raportWin');
                $reportInfo['moonDestroySuccess'] = -1;
                break;
            default:
                // Draw
                $attackStatus = 'draws';
                $defendStatus = 'draws';
                $class = array('raportDraw', 'raportDraw');
                $reportInfo['moonDestroySuccess'] = -1;
                break;
        }
        require_once 'includes/classes/missions/functions/GenerateReport.php';
        $reportData = GenerateReport($combatResult, $reportInfo);
        $reportID = md5(uniqid('', true) . TIMESTAMP);
        $sql = 'INSERT INTO %%RW%% SET
		rid 		= :reportId,
		raport 		= :reportData,
		time 		= :time,
		attacker	= :attackers,
		defender	= :defenders;';
        $db->insert($sql, array(':reportId' => $reportID, ':reportData' => serialize($reportData), ':time' => $this->_fleet['fleet_start_time'], ':attackers' => implode(',', array_keys($userAttack)), ':defenders' => implode(',', array_keys($userDefend))));
        $i = 0;
        foreach (array($userAttack, $userDefend) as $data) {
            $thisClass = $class[$i];
            foreach ($data as $userID => $userName) {
                $LNG = $this->getLanguage(NULL, $userID);
                $message = sprintf($messageHTML, $reportID, $thisClass[$i], $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $LNG['type_planet_short'][$this->_fleet['fleet_end_type']], $LNG['sys_lost'], $thisClass[0], $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $thisClass[1], $LNG['sys_attack_defender_pos'], pretty_number($combatResult['unitLost']['defender']), $LNG['sys_gain'], $LNG['tech'][901], pretty_number($stealResource[901]), $LNG['tech'][902], pretty_number($stealResource[902]), $LNG['tech'][903], pretty_number($stealResource[903]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902]));
                PlayerUtil::sendMessage($userID, 0, $LNG['sys_mess_tower'], 3, $LNG['sys_mess_attack_report'], $message, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
                $sql = "INSERT INTO %%TOPKB_USERS%% SET\n\t\t\t\trid\t\t\t= :reportId,\n\t\t\t\trole\t\t= :userRole,\n\t\t\t\tusername\t= :username,\n\t\t\t\tuid\t\t\t= :userId;";
                $db->insert($sql, array(':reportId' => $reportID, ':userRole' => 1, ':username' => $userName, ':userId' => $userID));
            }
            $i++;
        }
        if ($this->_fleet['fleet_end_type'] == 3) {
            $debrisType = 'id_luna';
        } else {
            $debrisType = 'id';
        }
        $sql = 'UPDATE %%PLANETS%% SET
		der_metal	= :metal,
		der_crystal	= :crystal
		WHERE ' . $debrisType . ' = :planetId;';
        $db->update($sql, array(':metal' => $planetDebris[901], ':crystal' => $planetDebris[902], ':planetId' => $this->_fleet['fleet_end_id']));
        $sql = 'UPDATE %%PLANETS%% SET
		metal		= metal - :metal,
		crystal		= crystal - :crystal,
		deuterium	= deuterium - :deuterium
		WHERE id = :planetId;';
        $db->update($sql, array(':metal' => $stealResource[901], ':crystal' => $stealResource[902], ':deuterium' => $stealResource[903], ':planetId' => $this->_fleet['fleet_end_id']));
        $sql = 'INSERT INTO %%TOPKB%% SET
		units 		= :units,
		rid			= :reportId,
		time		= :time,
		universe	= :universe,
		result		= :result;';
        $db->insert($sql, array(':units' => $combatResult['unitLost']['attacker'] + $combatResult['unitLost']['defender'], ':reportId' => $reportID, ':time' => $this->_fleet['fleet_start_time'], ':universe' => $this->_fleet['fleet_universe'], ':result' => $combatResult['won']));
        $sql = 'UPDATE %%USERS%% SET
		`' . $attackStatus . '` = `' . $attackStatus . '` + 1,
		kbmetal		= kbmetal + :debrisMetal,
		kbcrystal	= kbcrystal + :debrisCrystal,
		lostunits	= lostunits + :lostUnits,
		desunits	= desunits + :destroyedUnits
		WHERE id IN (' . implode(',', array_keys($userAttack)) . ');';
        $db->update($sql, array(':debrisMetal' => $debris[901], ':debrisCrystal' => $debris[902], ':lostUnits' => $combatResult['unitLost']['attacker'], ':destroyedUnits' => $combatResult['unitLost']['defender']));
        $sql = 'UPDATE %%USERS%% SET
		`' . $defendStatus . '` = `' . $defendStatus . '` + 1,
		kbmetal		= kbmetal + :debrisMetal,
		kbcrystal	= kbcrystal + :debrisCrystal,
		lostunits	= lostunits + :lostUnits,
		desunits	= desunits + :destroyedUnits
		WHERE id IN (' . implode(',', array_keys($userDefend)) . ');';
        $db->update($sql, array(':debrisMetal' => $debris[901], ':debrisCrystal' => $debris[902], ':lostUnits' => $combatResult['unitLost']['defender'], ':destroyedUnits' => $combatResult['unitLost']['attacker']));
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }
 function show()
 {
     global $USER, $PLANET, $LNG, $UNI;
     $this->tplObj->loadscript('flotten.js');
     $stats_sql = 'SELECT DISTINCT p.* FROM ' . PLANETS . ' as p
             WHERE p.`universe` = ' . $UNI . ' AND destruyed = 0 AND p.`id_owner` = ' . $USER['id'] . ' AND p.`id` != ' . $PLANET['id'] . '
             ;';
     $query = $GLOBALS['DATABASE']->query($stats_sql);
     $RangeList = array();
     while ($StatRow = $GLOBALS['DATABASE']->fetch_array($query)) {
         $slowestShip = 202;
         if ($StatRow['small_ship_cargo'] > 0) {
             $slowestShip = 202;
         } elseif ($StatRow['big_ship_cargo'] > 0) {
             $slowestShip = 203;
         } elseif ($StatRow['light_hunter'] > 0) {
             $slowestShip = 204;
         } elseif ($StatRow['heavy_hunter'] > 0) {
             $slowestShip = 205;
         } elseif ($StatRow['crusher'] > 0) {
             $slowestShip = 206;
         } elseif ($StatRow['battle_ship'] > 0) {
             $slowestShip = 207;
         } elseif ($StatRow['recycler'] > 0) {
             $slowestShip = 209;
         } elseif ($StatRow['bomber_ship'] > 0) {
             $slowestShip = 211;
         } elseif ($StatRow['destructor'] > 0) {
             $slowestShip = 213;
         } elseif ($StatRow['battleship'] > 0) {
             $slowestShip = 215;
         } elseif ($StatRow['galleon'] > 0) {
             $slowestShip = 225;
         } elseif ($StatRow['destroyer'] > 0) {
             $slowestShip = 226;
         } elseif ($StatRow['frigate'] > 0) {
             $slowestShip = 227;
         } elseif ($StatRow['black_wanderer'] > 0) {
             $slowestShip = 228;
         }
         $GameSpeedFactor = FleetFunctions::GetGameSpeedFactor();
         $MaxFleetSpeed = FleetFunctions::GetFleetMaxSpeed($slowestShip, $USER);
         $distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($StatRow['galaxy'], $StatRow['system'], $StatRow['planet']));
         $duration = FleetFunctions::GetMissionDuration(10, $MaxFleetSpeed, $distance, $GameSpeedFactor, $USER);
         $RangeList[] = array('name' => $StatRow['name'], 'id' => $StatRow['id'], 'galaxy' => $StatRow['galaxy'], 'system' => $StatRow['system'], 'planet' => $StatRow['planet'], 'metal' => pretty_number($StatRow['metal']), 'crystal' => pretty_number($StatRow['crystal']), 'deuterium' => pretty_number($StatRow['deuterium']), 'duration' => gmdate("H:i:s", round($duration)), 'small_ship_cargo' => pretty_number($StatRow['small_ship_cargo']), 'big_ship_cargo' => pretty_number($StatRow['big_ship_cargo']), 'light_hunter' => pretty_number($StatRow['light_hunter']), 'heavy_hunter' => pretty_number($StatRow['heavy_hunter']), 'crusher' => pretty_number($StatRow['crusher']), 'battle_ship' => pretty_number($StatRow['battle_ship']), 'recycler' => pretty_number($StatRow['recycler']), 'bomber_ship' => pretty_number($StatRow['bomber_ship']), 'destructor' => pretty_number($StatRow['destructor']), 'battleship' => pretty_number($StatRow['battleship']), 'galleon' => pretty_number($StatRow['galleon']), 'destroyer' => pretty_number($StatRow['destroyer']), 'frigate' => pretty_number($StatRow['frigate']), 'black_wanderer' => pretty_number($StatRow['black_wanderer']), 'lune_noir' => pretty_number($StatRow['lune_noir']));
     }
     $this->tplObj->assign_vars(array('RangeList' => $RangeList));
     $this->display('page.reducefleets.default.tpl');
 }
Example #21
0
 public static function deletePlanet($planetId)
 {
     $db = Database::get();
     $sql = 'SELECT id_owner, planet_type FROM %%PLANETS%% WHERE id = :planetId AND id NOT IN (SELECT id_planet FROM %%USERS%%);';
     $planetData = $db->selectSingle($sql, array(':planetId' => $planetId));
     if (empty($planetType)) {
         return false;
     }
     $sql = 'SELECT fleet_id FROM %%FLEETS%% WHERE fleet_end_id = :planetId;';
     $fleetIds = $db->select($sql, array(':planetId' => $planetId));
     foreach ($fleetIds as $fleetId) {
         FleetFunctions::SendFleetBack($planetData['id_owner'], $fleetId);
     }
     if ($planetData['planet_type'] == 3) {
         $sql = 'DELETE FROM %%PLANETS%% WHERE id = :planetId;';
         $db->delete($sql, array(':planetId' => $planetId));
         $sql = 'UPDATE %%PLANETS%% SET id_luna = :resetId WHERE id_luna = :planetId;';
         $db->update($sql, array(':resetId' => 0, ':planetId' => $planetId));
     } else {
         $sql = 'DELETE FROM %%PLANETS%% WHERE id = :planetId; OR id_luna = :planetId;';
         $db->delete($sql, array(':planetId' => $planetId));
     }
     return true;
 }
 public function show()
 {
     global $USER, $PLANET, $LNG, $CONF, $reslist, $resource, $UNI;
     $iraks = $PLANET['interplanetary_misil'];
     $targetGalaxy = HTTP::_GP('galaxy', 0);
     $targetSystem = HTTP::_GP('system', 0);
     $targetPlanet = HTTP::_GP('planet', 0);
     $targetType = HTTP::_GP('type', 0);
     $anz = min(HTTP::_GP('SendMI', 0), $iraks);
     $pziel = HTTP::_GP('Target', 0);
     $target = $GLOBALS['DATABASE']->getFirstRow("SELECT `id`, `id_owner` FROM " . PLANETS . " WHERE `universe` = '" . $UNI . "' AND  `galaxy` = '" . $targetGalaxy . "' AND `system` = '" . $targetSystem . "' AND `planet` = '" . $targetPlanet . "' AND `planet_type` = " . $targetType . ";");
     $Range = FleetFunctions::GetMissileRange($USER[$resource[117]]);
     $systemMin = $PLANET['system'] - $Range;
     $systemMax = $PLANET['system'] + $Range;
     $error = "";
     if (IsVacationMode($USER)) {
         $error = $LNG['fl_vacation_mode_active'];
     } elseif ($PLANET['silo'] < 4) {
         $error = $LNG['ma_silo_level'];
     } elseif ($USER['impulse_motor_tech'] == 0) {
         $error = $LNG['ma_impulse_drive_required'];
     } elseif ($targetGalaxy != $PLANET['galaxy'] || $targetSystem < $systemMin || $targetSystem > $systemMax) {
         $error = $LNG['ma_not_send_other_galaxy'];
     } elseif (!$target) {
         $error = $LNG['ma_planet_doesnt_exists'];
     } elseif (!in_array($pziel, $reslist['defense']) && $pziel != 0) {
         $error = $LNG['ma_wrong_target'];
     } elseif ($iraks == 0) {
         $error = $LNG['ma_no_missiles'];
     } elseif ($anz <= 0) {
         $error = $LNG['ma_add_missile_number'];
     }
     $targetUser = GetUserByID($target['id_owner'], array('onlinetime', 'banaday', 'urlaubs_modus', 'authattack'));
     if (Config::get('adm_attack') == 1 && $targetUser['authattack'] > $USER['authlevel']) {
         $error = $LNG['fl_admin_attack'];
     } elseif ($targetUser['urlaubs_modus']) {
         $error = $LNG['fl_in_vacation_player'];
     }
     $User2Points = $GLOBALS['DATABASE']->getFirstRow("SELECT `total_points` FROM " . STATPOINTS . " WHERE `stat_type` = '1' AND `id_owner` = '" . $target['id_owner'] . "';");
     $IsNoobProtec = CheckNoobProtec($USER, $User2Points, $targetUser);
     if ($IsNoobProtec['NoobPlayer']) {
         $error = $LNG['fl_week_player'];
     } elseif ($IsNoobProtec['StrongPlayer']) {
         $error = $LNG['fl_strong_player'];
     }
     if ($error != "") {
         $this->printMessage($error);
     }
     $Duration = FleetFunctions::GetMIPDuration($PLANET['system'], $targetSystem);
     $DefenseLabel = $pziel == 0 ? $LNG['ma_all'] : $LNG['tech'][$pziel];
     if (connection_aborted()) {
         exit;
     }
     $fleetArray = array(503 => $anz);
     $fleetStartTime = TIMESTAMP + $Duration;
     $fleetStayTime = $fleetStartTime;
     $fleetEndTime = $fleetStartTime;
     $fleetRessource = array(901 => 0, 902 => 0, 903 => 0);
     FleetFunctions::sendFleet($fleetArray, 10, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $target['id_owner'], $target['id'], $targetGalaxy, $targetSystem, $targetPlanet, $targetType, $fleetRessource, $fleetStartTime, $fleetStayTime, $fleetEndTime, 0, $pziel);
     $this->printMessage("<b>" . $anz . "</b>" . $LNG['ma_missiles_sended'] . $DefenseLabel);
 }
 public function show()
 {
     global $USER, $PLANET, $reslist, $resource, $LNG;
     $acsData = array();
     $FleetID = HTTP::_GP('fleetID', 0);
     $GetAction = HTTP::_GP('action', "");
     $db = Database::get();
     $this->tplObj->loadscript('flotten.js');
     if (!empty($FleetID) && !IsVacationMode($USER)) {
         switch ($GetAction) {
             case "sendfleetback":
                 FleetFunctions::SendFleetBack($USER, $FleetID);
                 break;
             case "acs":
                 $acsData = $this->getACSPageData($FleetID);
                 break;
         }
     }
     $techExpedition = $USER[$resource[124]];
     if ($techExpedition >= 1) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15, true);
         $maxExpedition = floor(sqrt($techExpedition));
     } else {
         $activeExpedition = 0;
         $maxExpedition = 0;
     }
     $maxFleetSlots = FleetFunctions::GetMaxFleetSlots($USER);
     $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
     $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
     $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
     $targetType = HTTP::_GP('planettype', (int) $PLANET['planet_type']);
     $targetMission = HTTP::_GP('target_mission', 0);
     $sql = "SELECT * FROM %%FLEETS%% WHERE fleet_owner = :userID AND fleet_mission <> 10 ORDER BY fleet_end_time ASC;";
     $fleetResult = $db->select($sql, array(':userID' => $USER['id']));
     $activeFleetSlots = $db->rowCount();
     $FlyingFleetList = array();
     foreach ($fleetResult as $fleetsRow) {
         $FleetList[$fleetsRow['fleet_id']] = FleetFunctions::unserialize($fleetsRow['fleet_array']);
         if ($fleetsRow['fleet_mission'] == 4 && $fleetsRow['fleet_mess'] == FLEET_OUTWARD) {
             $returnTime = $fleetsRow['fleet_start_time'];
         } else {
             $returnTime = $fleetsRow['fleet_end_time'];
         }
         $FlyingFleetList[] = array('id' => $fleetsRow['fleet_id'], 'mission' => $fleetsRow['fleet_mission'], 'state' => $fleetsRow['fleet_mess'], 'startGalaxy' => $fleetsRow['fleet_start_galaxy'], 'startSystem' => $fleetsRow['fleet_start_system'], 'startPlanet' => $fleetsRow['fleet_start_planet'], 'startTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_start_time'], $USER['timezone']), 'endGalaxy' => $fleetsRow['fleet_end_galaxy'], 'endSystem' => $fleetsRow['fleet_end_system'], 'endPlanet' => $fleetsRow['fleet_end_planet'], 'endTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_end_time'], $USER['timezone']), 'amount' => pretty_number($fleetsRow['fleet_amount']), 'returntime' => $returnTime, 'resttime' => $returnTime - TIMESTAMP, 'FleetList' => $FleetList[$fleetsRow['fleet_id']]);
     }
     $FleetsOnPlanet = array();
     foreach ($reslist['fleet'] as $FleetID) {
         if ($PLANET[$resource[$FleetID]] == 0) {
             continue;
         }
         $FleetsOnPlanet[] = array('id' => $FleetID, 'speed' => FleetFunctions::GetFleetMaxSpeed($FleetID, $USER), 'count' => $PLANET[$resource[$FleetID]]);
     }
     $this->assign(array('FleetsOnPlanet' => $FleetsOnPlanet, 'FlyingFleetList' => $FlyingFleetList, 'activeExpedition' => $activeExpedition, 'maxExpedition' => $maxExpedition, 'activeFleetSlots' => $activeFleetSlots, 'maxFleetSlots' => $maxFleetSlots, 'targetGalaxy' => $targetGalaxy, 'targetSystem' => $targetSystem, 'targetPlanet' => $targetPlanet, 'targetType' => $targetType, 'targetMission' => $targetMission, 'acsData' => $acsData, 'isVacation' => IsVacationMode($USER), 'bonusAttack' => $USER[$resource[109]] * 10 + (1 + abs($USER['factor']['Attack'])) * 100, 'bonusDefensive' => $USER[$resource[110]] * 10 + (1 + abs($USER['factor']['Defensive'])) * 100, 'bonusShield' => $USER[$resource[111]] * 10 + (1 + abs($USER['factor']['Shield'])) * 100, 'bonusCombustion' => $USER[$resource[115]] * 10, 'bonusImpulse' => $USER[$resource[117]] * 20, 'bonusHyperspace' => $USER[$resource[118]] * 30));
     $this->display('page.fleetTable.default.tpl');
 }
    function EndStayEvent()
    {
        global $pricelist, $reslist, $resource;
        $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
        $config = Config::get($this->_fleet['fleet_universe']);
        $expeditionPoints = array();
        foreach ($reslist['fleet'] as $shipId) {
            $expeditionPoints[$shipId] = ($pricelist[$shipId]['cost'][901] + $pricelist[$shipId]['cost'][902]) * 5 / 1000;
        }
        $fleetArray = FleetFunctions::unserialize($this->_fleet['fleet_array']);
        $fleetPoints = 0;
        $fleetCapacity = 0;
        foreach ($fleetArray as $shipId => $shipAmount) {
            $fleetCapacity += $shipAmount * $pricelist[$shipId]['capacity'];
            $fleetPoints += $shipAmount * $expeditionPoints[$shipId];
        }
        $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
        $GetEvent = mt_rand(1, 9);
        $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)];
        switch ($GetEvent) {
            case 1:
                $eventSize = mt_rand(0, 100);
                $factor = 0;
                if (10 < $eventSize) {
                    $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)];
                    $factor = mt_rand(10, 50);
                } elseif (0 < $eventSize && 10 >= $eventSize) {
                    $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)];
                    $factor = mt_rand(50, 100);
                } elseif (0 == $eventSize) {
                    $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)];
                    $factor = mt_rand(100, 200);
                }
                $chanceToFound = mt_rand(1, 6);
                if ($chanceToFound > 3) {
                    $resourceId = 901;
                } elseif ($chanceToFound > 1) {
                    $resourceId = 902;
                    $factor = $factor / 2;
                } else {
                    $resourceId = 903;
                    $factor = $factor / 3;
                }
                $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;";
                $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total');
                if ($topPoints > 5000000) {
                    $maxFactor = 12000;
                } elseif ($topPoints > 1000000) {
                    $maxFactor = 9000;
                } elseif ($topPoints > 100000) {
                    $maxFactor = 6000;
                } else {
                    $maxFactor = 2400;
                }
                $founded = round(min($maxFactor, max(200, $factor)) * $fleetPoints);
                $fleetColName = 'fleet_resource_' . $resource[$resourceId];
                $this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $founded);
                break;
            case 2:
                $eventSize = mt_rand(0, 100);
                $Size = 0;
                if (10 < $eventSize) {
                    $Size = mt_rand(100, 300);
                    $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)];
                } elseif (0 < $eventSize && 10 >= $eventSize) {
                    $Size = mt_rand(301, 600);
                    $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 3)];
                } elseif (0 == $eventSize) {
                    $Size = mt_rand(601, 3000);
                    $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)];
                }
                $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
                break;
            case 3:
                $eventSize = mt_rand(0, 100);
                $Size = 0;
                $Message = "";
                if (10 < $eventSize) {
                    $Size = mt_rand(10, 50);
                    $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)];
                } elseif (0 < $eventSize && 10 >= $eventSize) {
                    $Size = mt_rand(52, 100);
                    $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)];
                } elseif (0 == $eventSize) {
                    $Size = mt_rand(102, 200);
                    $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)];
                }
                $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;";
                $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total');
                $MaxPoints = $topPoints < 5000000 ? 4500 : 6000;
                $FoundShips = max(round($Size * min($fleetPoints, $MaxPoints)), 10000);
                $FoundShipMess = "";
                $NewFleetArray = "";
                $Found = array();
                foreach ($reslist['fleet'] as $ID) {
                    if (!isset($fleetArray[$ID]) || $ID == 208 || $ID == 209 || $ID == 214) {
                        continue;
                    }
                    $MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]));
                    if ($MaxFound <= 0) {
                        continue;
                    }
                    $Count = mt_rand(0, $MaxFound);
                    if ($Count <= 0) {
                        continue;
                    }
                    $Found[$ID] = $Count;
                    $FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]);
                    $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count);
                    if ($FoundShips <= 0) {
                        break;
                    }
                }
                if (empty($Found)) {
                    $FoundShipMess .= '<br><br>' . $LNG['sys_expe_found_ships_nothing'];
                }
                foreach ($fleetArray as $ID => $Count) {
                    if (!empty($Found[$ID])) {
                        $Count += $Found[$ID];
                    }
                    $NewFleetArray .= $ID . "," . floatToString($Count) . ';';
                }
                $Message .= $FoundShipMess;
                $this->UpdateFleet('fleet_array', $NewFleetArray);
                $this->UpdateFleet('fleet_amount', array_sum($fleetArray));
                break;
            case 4:
                $messageHTML = <<<HTML
<div class="raportMessage">
<table>
<tr>
<td colspan="2"><a href="CombatReport.php?raport=%s" target="_blank"><span class="%s">%s %s (%s)</span></a></td>
</tr>
<tr>
<td>%s</td><td><span class="%s">%s: %s</span>&nbsp;<span class="%s">%s: %s</span></td>
</tr>
<tr>
<td>%s</td><td><span>%s:&nbsp;<span class="raportSteal element901">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="raportSteal element902">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="raportSteal element903">%s</span></span></td>
</tr>
<tr>
<td>%s</td><td><span>%s:&nbsp;<span class="raportDebris element901">%s</span>&nbsp;</span><span>%s:&nbsp;<span class="raportDebris element902">%s</span></span></td>
</tr>
</table>
</div>
HTML;
                //Minize HTML
                $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML);
                // pirate or alien
                $attackType = mt_rand(1, 2);
                $eventSize = mt_rand(0, 100);
                $targetFleetData = array();
                if ($attackType == 1) {
                    $techBonus = -3;
                    $targetName = $LNG['sys_expe_attackname_1'];
                    $roundFunction = 'floor';
                    if (10 < $eventSize) {
                        $Message = $LNG['sys_expe_attack_1_1_5'];
                        $attackFactor = 30 + mt_rand(-3, 3) / 100;
                        $targetFleetData[204] = 5;
                    } elseif (0 < $eventSize && 10 >= $eventSize) {
                        $Message = $LNG['sys_expe_attack_1_2_3'];
                        $attackFactor = 50 + mt_rand(-5, 5) / 100;
                        $targetFleetData[206] = 3;
                    } else {
                        $Message = $LNG['sys_expe_attack_1_3_2'];
                        $attackFactor = 80 + mt_rand(-8, 8) / 100;
                        $targetFleetData[207] = 2;
                    }
                } else {
                    $techBonus = 3;
                    $targetName = $LNG['sys_expe_attackname_2'];
                    $roundFunction = 'ceil';
                    if (10 < $eventSize) {
                        $Message = $LNG['sys_expe_attack_1_1_5'];
                        $attackFactor = 40 + mt_rand(-4, 4) / 100;
                        $targetFleetData[204] = 5;
                    } elseif (0 < $eventSize && 10 >= $eventSize) {
                        $Message = $LNG['sys_expe_attack_1_3_3'];
                        $attackFactor = 60 + mt_rand(-6, 6) / 100;
                        $targetFleetData[215] = 3;
                    } else {
                        $Message = $LNG['sys_expe_attack_1_3_2'];
                        $attackFactor = 90 + mt_rand(-9, 9) / 100;
                        $targetFleetData[213] = 2;
                    }
                }
                foreach ($fleetArray as $shipId => $shipAmount) {
                    if (isset($targetFleetData[$shipId])) {
                        $targetFleetData[$shipId] = 0;
                    }
                    $targetFleetData[$shipId] = $roundFunction($shipAmount * $attackFactor);
                }
                $targetFleetData = array_filter($targetFleetData);
                $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
                $senderData = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
                $targetData = array('id' => 0, 'username' => $targetName, 'military_tech' => min($senderData['military_tech'] + $techBonus, 0), 'defence_tech' => min($senderData['defence_tech'] + $techBonus, 0), 'shield_tech' => min($senderData['shield_tech'] + $techBonus, 0), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0);
                $fleetID = $this->_fleet['fleet_id'];
                $fleetAttack[$fleetID]['fleetDetail'] = $this->_fleet;
                $fleetAttack[$fleetID]['player'] = $senderData;
                $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$this->_fleet['fleet_id']]['player'], 'attack', $this->_fleet['fleet_start_time']);
                $fleetAttack[$fleetID]['unit'] = $fleetArray;
                $fleetDefend = array();
                $fleetDefend[0]['fleetDetail'] = array('fleet_start_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_start_system' => $this->_fleet['fleet_end_system'], 'fleet_start_planet' => $this->_fleet['fleet_end_planet'], 'fleet_start_type' => 1, 'fleet_end_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_end_system' => $this->_fleet['fleet_end_system'], 'fleet_end_planet' => $this->_fleet['fleet_end_planet'], 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0);
                $bonusList = BuildFunctions::getBonusList();
                $fleetDefend[0]['player'] = $targetData;
                $fleetDefend[0]['player']['factor'] = ArrayUtil::combineArrayWithSingleElement($bonusList, 0);
                $fleetDefend[0]['unit'] = $targetFleetData;
                require_once 'includes/classes/missions/functions/calculateAttack.php';
                $combatResult = calculateAttack($fleetAttack, $fleetDefend, $config->Fleet_Cdr, $config->Defs_Cdr);
                $fleetArray = '';
                $totalCount = 0;
                $fleetAttack[$fleetID]['unit'] = array_filter($fleetAttack[$fleetID]['unit']);
                foreach ($fleetAttack[$fleetID]['unit'] as $element => $amount) {
                    $fleetArray .= $element . ',' . $amount . ';';
                    $totalCount += $amount;
                }
                if ($totalCount <= 0) {
                    $this->KillFleet();
                } else {
                    $this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1));
                    $this->UpdateFleet('fleet_amount', $totalCount);
                }
                require_once 'includes/classes/missions/functions/GenerateReport.php';
                $debrisResource = array(901, 902);
                $debris = array();
                foreach ($debrisResource as $elementID) {
                    $debris[$elementID] = 0;
                }
                $stealResource = array(901 => 0, 902 => 0, 903 => 0);
                $reportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => 0, 'moonDestroy' => false, 'moonName' => NULL, 'moonDestroyChance' => NULL, 'moonDestroySuccess' => NULL, 'fleetDestroyChance' => NULL, 'fleetDestroySuccess' => NULL);
                $reportData = GenerateReport($combatResult, $reportInfo);
                $reportID = md5(uniqid('', true) . TIMESTAMP);
                $sql = "INSERT INTO %%RW%% SET\n\t\t\t\trid\t\t\t= :reportId,\n\t\t\t\traport\t\t= :reportData,\n\t\t\t\ttime\t\t= :time,\n\t\t\t\tattacker\t= :attacker;";
                Database::get()->insert($sql, array(':reportId' => $reportID, ':reportData' => serialize($reportData), ':time' => $this->_fleet['fleet_start_time'], ':attacker' => $this->_fleet['fleet_owner']));
                switch ($combatResult['won']) {
                    case "a":
                        $attackClass = 'raportWin';
                        $defendClass = 'raportLose';
                        break;
                    case "r":
                        $attackClass = 'raportLose';
                        $defendClass = 'raportWin';
                        break;
                    default:
                        $attackClass = 'raportDraw';
                        $defendClass = 'raportDraw';
                        break;
                }
                $message = sprintf($messageHTML, $reportID, $attackClass, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $LNG['type_planet_short'][$this->_fleet['fleet_end_type']], $LNG['sys_lost'], $attackClass, $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $defendClass, $LNG['sys_attack_defender_pos'], pretty_number($combatResult['unitLost']['defender']), $LNG['sys_gain'], $LNG['tech'][901], pretty_number($stealResource[901]), $LNG['tech'][902], pretty_number($stealResource[902]), $LNG['tech'][903], pretty_number($stealResource[903]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902]));
                PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $message);
                break;
            case 5:
                $this->KillFleet();
                $Message = $LNG['sys_expe_lost_fleet_' . mt_rand(1, 4)];
                break;
            case 6:
                # http://owiki.de/Expedition#Ver.C3.A4nderte_Flugzeit
                $chance = mt_rand(0, 100);
                $Wrapper = array();
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 3;
                $Wrapper[] = 3;
                $Wrapper[] = 5;
                if ($chance < 75) {
                    // More return time
                    $normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'];
                    $stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time'];
                    $factor = $Wrapper[mt_rand(0, 9)];
                    $endTime = $this->_fleet['fleet_end_stay'] + $normalBackTime + $stayTime + $factor;
                    $this->UpdateFleet('fleet_end_time', $endTime);
                    $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)];
                } else {
                    $normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'];
                    $stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time'];
                    $factor = $Wrapper[mt_rand(0, 9)];
                    $endTime = max(1, $normalBackTime - $stayTime / 3 * $factor);
                    $this->UpdateFleet('fleet_end_time', $endTime);
                    $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)];
                }
                break;
        }
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 15, $LNG['sys_expe_report'], $Message, $this->_fleet['fleet_end_stay'], NULL, 1, $this->_fleet['fleet_universe']);
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }
Example #25
0
 function isFleetSlotFree()
 {
     global $FLEET;
     if (!isset($this->USER['slots'])) {
         $this->USER['slots'] = FleetFunctions::GetMaxFleetSlots($this->USER) - FleetFunctions::GetCurrentFleets($this->USER['id']);
     }
     return $this->USER['slots'];
 }
 public function show()
 {
     global $USER, $PLANET, $resource, $LNG, $CONF, $pricelist;
     $UserDeuterium = $PLANET['elyrium'];
     $planetID = HTTP::_GP('planetID', 0);
     $targetMission = HTTP::_GP('mission', 0);
     $galaxyC = HTTP::_GP('galaxyC', 0);
     $systemC = HTTP::_GP('systemC', 0);
     $planetC = HTTP::_GP('planetC', 0);
     if (IsVacationMode($USER)) {
         $this->sendData(620, $LNG['fa_vacation_mode_current']);
     }
     $fleetArray = array();
     switch ($targetMission) {
         case 14:
             if (!isModulAvalible(MODULE_MISSION_SPY)) {
                 $this->sendData('rouge', $LNG['sys_module_inactive']);
             }
             if ($PLANET['teleport_portal'] == 0) {
                 $this->sendData('rouge', $LNG['fleet_ajax_11']);
             }
             $ships = min($USER['spio_anz'], $PLANET[$resource[210]]);
             if (empty($ships)) {
                 $this->sendData('rouge', $LNG['fleet_ajax_22']);
             }
             $fleetArray = array(210 => $ships);
             $this->returnData['ships'][210] = $PLANET[$resource[210]] - $ships;
             break;
         case 7:
             if (!isModulAvalible(MODULE_MISSION_COLONY)) {
                 $this->sendData('rouge', $LNG['sys_module_inactive']);
             }
             if ($PLANET['teleport_portal'] == 0) {
                 $this->sendData('rouge', $LNG['fleet_ajax_11']);
             }
             if ($PLANET[$resource[303]] < 10 || $PLANET[$resource[306]] < 100) {
                 $this->sendData('rouge', sprintf($LNG['fleet_ajax_12'], $PLANET[$resource[303]], $PLANET[$resource[306]]));
             }
             $fleetArray = array(303 => 10, 306 => 100);
             break;
         default:
             $this->sendData('rouge', $LNG['fleet_ajax_22']);
             break;
     }
     $fleetArray = array_filter($fleetArray);
     if (empty($fleetArray)) {
         $this->sendData('rouge', $LNG['fleet_ajax_22']);
     }
     $iPlanetCount = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE `id_owner` = '" . $USER['id'] . "' AND `planet_type` = '1' AND `destruyed` = '0';");
     $MaxPlanets = PlayerUtil::maxPlanetCount($USER);
     if ($iPlanetCount >= $MaxPlanets && $targetMission == 7) {
         $this->sendData('rouge', $LNG['fleet_ajax_14']);
     }
     $targetData = $GLOBALS['DATABASE']->getFirstRow("SELECT planet.id_owner as id_owner, \n\t\t\t\t\t\t\t\t\t\tplanet.id as id, \n\t\t\t\t\t\t\t\t\t\tplanet.name as name, \n\t\t\t\t\t\t\t\t\t\tplanet.galaxy as galaxy, \n\t\t\t\t\t\t\t\t\t\tplanet.system as system, \n\t\t\t\t\t\t\t\t\t\tplanet.planet as planet,\n\t\t\t\t\t\t\t\t\t\tplanet.planet_type as planet_type, \n\t\t\t\t\t\t\t\t\t\tplanet.force_field_timer as force_field_timer, \n\t\t\t\t\t\t\t\t\t\tplanet.teleport_portal as teleport_portal, \n\t\t\t\t\t\t\t\t\t\ttotal_points, onlinetime, forcefield_tech, urlaubs_modus, banaday, authattack, user_deleted, username\n\t\t\t\t\t\t\t\t\t\tFROM " . PLANETS . " planet\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . USERS . " user ON planet.id_owner = user.id\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . STATPOINTS . " as stat ON stat.id_owner = user.id AND stat.stat_type = '1' \n\t\t\t\t\t\t\t\t\t\tWHERE planet.galaxy = " . $galaxyC . " AND planet.system = " . $systemC . " AND planet.planet = " . $planetC . ";");
     $BuddyCheck = $GLOBALS['DATABASE']->query("SELECT * FROM uni1_buddy WHERE (sender = '" . $USER['id'] . "' AND owner = '" . $targetData['id_owner'] . "' AND state = '1') OR (owner = '" . $USER['id'] . "' AND sender = '" . $targetData['id_owner'] . "' AND state = '1');");
     if ($targetMission == 1 || $targetMission == 6 || $targetMission == 3 || $targetMission == 14 || $targetMission == 13) {
         $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 ($targetData['id_owner'] == $xb['userID'] || $targetData['id_owner'] == $xb['secondID']) {
                     $this->sendData('rouge', '<span class=rouge>' . sprintf($LNG['fleet_multi_block'], $this->getUsername($targetData['id_owner'])) . '</span>');
                 }
             }
         }
         if ($GLOBALS['DATABASE']->numRows($BuddyCheck) >= 1) {
             $this->sendData('rouge', sprintf($LNG['fleet_pact'], $this->getUsername($targetData['id_owner'])));
         }
     }
     if ($targetMission == 14) {
         if ($targetData['id_owner'] == $USER['id']) {
             $this->sendData('rouge', $LNG['fleet_ajax_19']);
         }
         if ($targetData['force_field_timer'] > TIMESTAMP && $USER['virus_tech'] < $targetData['forcefield_tech']) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_21'], $this->getUsername($targetData['id_owner'])));
         }
         if ($targetData['teleport_portal'] == 0) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_18'], $targetData['name'], $targetData['system'], $targetData['planet']));
         }
         if ($targetData['user_deleted'] == 1) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_3'], $targetData['username']));
         }
         if ($targetData['banaday'] > TIMESTAMP) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_4'], $targetData['username']));
         }
         if (Config::get('adm_attack') == 1 && $targetData['authattack'] > $USER['authlevel']) {
             $this->sendData('rouge', $LNG['fa_action_not_allowed']);
         }
         if (IsVacationMode($targetData)) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_5'], $targetData['username']));
         }
         $IsNoobProtec = CheckNoobProtec($USER, $targetData, $targetData);
         if ($IsNoobProtec['NoobPlayer']) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_6'], $targetData['username']));
         }
         if ($IsNoobProtec['StrongPlayer']) {
             $this->sendData('rouge', sprintf($LNG['fleet_ajax_7'], $targetData['username']));
         }
         if ($USER['id'] == $targetData['id_owner']) {
             $this->sendData('rouge', $LNG['fleet_ajax_8']);
         }
     }
     if (connection_aborted()) {
         exit;
     }
     $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $Distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetData['galaxy'], $targetData['system'], $targetData['planet']));
     $SpeedAllMin = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
     $Duration = 1;
     $consumption = 0;
     $fleetRessource = array(901 => 0, 902 => 0, 903 => 0, 904 => 0);
     $fleetPopulation = array(301 => 0, 302 => 0, 303 => 0, 304 => 0, 305 => 0, 306 => 0, 307 => 0, 309 => 0);
     if ($targetMission == 7) {
         $targetData = array('id' => 0, 'id_owner' => 0, 'planettype' => 1);
     }
     $fleetStartTime = $Duration + TIMESTAMP;
     $fleetStayTime = $fleetStartTime;
     $fleetEndTime = $fleetStayTime + 1;
     $shipID = array_keys($fleetArray);
     if ($targetMission == 7) {
         FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetData['id_owner'], 0, $galaxyC, $systemC, $planetC, 1, $fleetRessource, $fleetPopulation, $fleetStartTime, $fleetStayTime, $fleetEndTime);
     } else {
         FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetData['id_owner'], $targetData['id'], $targetData['galaxy'], $targetData['system'], $targetData['planet'], $targetData['planet_type'], $fleetRessource, $fleetPopulation, $fleetStartTime, $fleetStayTime, $fleetEndTime);
     }
     if ($targetMission == 7) {
         $finalMsg = sprintf($LNG['fleet_ajax_10'], $systemC, $planetC);
     } else {
         $finalMsg = sprintf($LNG['fleet_ajax_17'], $targetData['name'], $targetData['system'], $targetData['planet'], $this->getUsername($targetData['id_owner']));
     }
     $this->sendData('vert', $finalMsg);
 }
    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');
    }
 function checkTarget()
 {
     global $PLANET, $LNG, $UNI, $CONF, $USER, $resource;
     $TargetGalaxy = HTTP::_GP('galaxy', 0);
     $TargetSystem = HTTP::_GP('system', 0);
     $TargetPlanet = HTTP::_GP('planet', 0);
     $TargetPlanettype = HTTP::_GP('planet_type', 1);
     if ($TargetGalaxy == $PLANET['galaxy'] && $TargetSystem == $PLANET['system'] && $TargetPlanet == $PLANET['planet'] && $TargetPlanettype == $PLANET['planet_type']) {
         $this->sendJSON($LNG['fl_error_same_planet']);
     }
     if ($TargetPlanet != Config::get('max_planets') + 1) {
         $Data = $GLOBALS['DATABASE']->getFirstRow("SELECT u.id, u.urlaubs_modus, u.user_lastip, u.authattack, u.immunity_until, p.destruyed, p.planet_protection, p.der_metal, p.der_crystal, p.destruyed FROM " . USERS . " as u, " . PLANETS . " as p WHERE p.universe = " . $UNI . " AND p.galaxy = " . $TargetGalaxy . " AND p.system = " . $TargetSystem . " AND p.planet = " . $TargetPlanet . "  AND p.planet_type = '" . ($TargetPlanettype == 2 ? 1 : $TargetPlanettype) . "' AND u.id = p.id_owner;");
         if ($TargetPlanettype == 3 && !isset($Data)) {
             $this->sendJSON($LNG['fl_error_no_moon']);
         } elseif ($TargetPlanettype != 2 && $Data['urlaubs_modus']) {
             $this->sendJSON($LNG['fl_in_vacation_player']);
         } elseif ($TargetPlanettype != 2 && $Data['immunity_until'] > TIMESTAMP && $USER['id'] != $Data['id']) {
             $this->sendJSON($LNG['fl_in_immunity_player']);
         } elseif ($Data['id'] != $USER['id'] && Config::get('adm_attack') == 1 && $Data['authattack'] > $USER['authlevel']) {
             $this->sendJSON($LNG['fl_admin_attack']);
         } elseif ($Data['destruyed'] != 0) {
             $this->sendJSON($LNG['fl_error_not_avalible']);
         } elseif ($TargetPlanettype == 2 && $Data['der_metal'] == 0 && $Data['der_crystal'] == 0) {
             $this->sendJSON($LNG['fl_error_empty_derbis']);
         } elseif (ENABLE_MULTIALERT && $USER['id'] != $Data['id'] && $USER['authlevel'] != AUTH_ADM && $USER['user_lastip'] == $Data['user_lastip'] && $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $USER['id'] . ") + (SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $Data['id'] . ")") != 2) {
             $this->sendJSON($LNG['fl_multi_alarm']);
         }
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 20);
         if ($activeExpedition >= FleetFunctions::getFortressLimit($USER)) {
             $this->sendJSON($LNG['fl_no_expedition_slot']);
         }
     } else {
         if ($USER[$resource[124]] == 0) {
             $this->sendJSON($LNG['fl_target_not_exists']);
         }
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15);
         if ($activeExpedition >= FleetFunctions::getExpeditionLimit($USER)) {
             $this->sendJSON($LNG['fl_no_expedition_slot']);
         }
     }
     $this->sendJSON('OK');
 }
Example #29
0
 public static function MissilesAjax()
 {
     global $USER, $PLANET, $LNG, $CONF, $db, $reslist, $resource;
     include_once ROOT_PATH . 'includes/functions/IsVacationMode.' . PHP_EXT;
     $iraks = $PLANET['interplanetary_misil'];
     $TargetGalaxy = request_var('galaxy', 0);
     $TargetSystem = request_var('system', 0);
     $TargetPlanet = request_var('planet', 0);
     $anz = min(request_var('SendMI', 0), $iraks);
     $pziel = request_var('Target', "");
     $PlanetRess = new ResourceUpdate($USER, $PLANET);
     $Target = $db->uniquequery("SELECT `id_owner`, `id_level` FROM " . PLANETS . " WHERE `galaxy` = '" . $TargetGalaxy . "' AND `system` = '" . $TargetSystem . "' AND `planet` = '" . $TargetPlanet . "' AND `planet_type` = '1';");
     $Distance = abs($TargetSystem - $PLANET['system']);
     require_once ROOT_PATH . 'includes/classes/class.GalaxyRows.' . PHP_EXT;
     $GalaxyRows = new GalaxyRows();
     if (IsVacationMode($USER)) {
         $error = $LNG['fl_vacation_mode_active'];
     } elseif ($PLANET['silo'] < 4) {
         $error = $LNG['ma_silo_level'];
     } elseif ($USER['impulse_motor_tech'] == 0) {
         $error = $LNG['ma_impulse_drive_required'];
     } elseif ($TargetGalaxy != $PLANET['galaxy'] || $Distance > $GalaxyRows->GetMissileRange($USER[$resource[117]])) {
         $error = $LNG['ma_not_send_other_galaxy'];
     } elseif (!$Target) {
         $error = $LNG['ma_planet_doesnt_exists'];
     } elseif (!in_array($pziel, $reslist['defense']) && $pziel != 0) {
         $error = $LNG['ma_wrong_target'];
     } elseif ($iraks == 0) {
         $error = $LNG['ma_no_missiles'];
     } elseif ($anz == 0) {
         $error = $LNG['ma_add_missile_number'];
     } elseif ($Target['id_level'] > $USER['authlevel'] && $CONF['adm_attack'] == 0) {
         $error = $LNG['fl_admins_cannot_be_attacked'];
     }
     $TargetUser = GetUserByID($Target['id_owner'], array('onlinetime'));
     $UserPoints = $USER;
     $User2Points = $db->uniquequery("SELECT `total_points` FROM " . STATPOINTS . " WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '" . $Target['id_owner'] . "';");
     $IsNoobProtec = CheckNoobProtec($UserPoints, $User2Points, $TargetUser['onlinetime']);
     if ($IsNoobProtec['NoobPlayer']) {
         $error = $LNG['fl_week_player'];
     } elseif ($IsNoobProtec['StrongPlayer']) {
         $error = $LNG['fl_strong_player'];
     }
     $template = new template();
     $template->page_header();
     $template->page_topnav();
     $template->page_leftmenu();
     $template->page_planetmenu();
     $template->page_footer();
     if ($error != "") {
         $template->message($error);
         exit;
     }
     $SpeedFactor = parent::GetGameSpeedFactor();
     $Duration = max(round(30 + 60 * $Distance / $SpeedFactor), 30);
     $DefenseLabel = $pziel == 0 ? $LNG['ma_all'] : $LNG['tech'][$pziel];
     if (connection_aborted()) {
         exit;
     }
     $sql = "INSERT INTO " . FLEETS . " SET\r\n\t\t\t\tfleet_owner = '" . $USER['id'] . "',\r\n\t\t\t\tfleet_mission = '10',\r\n\t\t\t\tfleet_amount = '" . $anz . "',\r\n\t\t\t\tfleet_array = '503," . $anz . "',\r\n\t\t\t\tfleet_start_time = '" . (TIMESTAMP + $Duration) . "',\r\n\t\t\t\tfleet_start_galaxy = '" . $PLANET['galaxy'] . "',\r\n\t\t\t\tfleet_start_system = '" . $PLANET['system'] . "',\r\n\t\t\t\tfleet_start_planet ='" . $PLANET['planet'] . "',\r\n\t\t\t\tfleet_start_type = '1',\r\n\t\t\t\tfleet_end_time = '" . (TIMESTAMP + $Duration + 50) . "',\r\n\t\t\t\tfleet_end_stay = '0',\r\n\t\t\t\tfleet_end_galaxy = '" . $TargetGalaxy . "',\r\n\t\t\t\tfleet_end_system = '" . $TargetSystem . "',\r\n\t\t\t\tfleet_end_planet = '" . $TargetPlanet . "',\r\n\t\t\t\tfleet_end_type = '1',\r\n\t\t\t\tfleet_target_obj = '" . $db->sql_escape($pziel) . "',\r\n\t\t\t\tfleet_resource_metal = '0',\r\n\t\t\t\tfleet_resource_crystal = '0',\r\n\t\t\t\tfleet_resource_deuterium = '0',\r\n\t\t\t\tfleet_target_owner = '" . $Target["id_owner"] . "',\r\n\t\t\t\tfleet_group = '0',\r\n\t\t\t\tfleet_mess = '0',\r\n\t\t\t\tstart_time = " . TIMESTAMP . ";\r\n\t\t\t\tUPDATE " . PLANETS . " SET \r\n\t\t\t\tinterplanetary_misil = (interplanetary_misil - " . $anz . ") WHERE id = '" . $PLANET['id'] . "';";
     $db->multi_query($sql);
     $template->message("<b>" . $anz . "</b>" . $LNG['ma_missiles_sended'] . $DefenseLabel, "game.php?page=overview", 3);
 }
Example #30
0
    function TargetEvent()
    {
        global $pricelist, $reslist, $resource;
        $db = Database::get();
        $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;';
        $senderUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
        $targetUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_target_owner']));
        $sql = 'SELECT * FROM %%PLANETS%% WHERE id = :planetId;';
        $targetPlanet = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id']));
        $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;';
        $senderPlanetName = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name');
        $LNG = $this->getLanguage($senderUser['lang']);
        $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
        $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']);
        $planetUpdater = new ResourceUpdate();
        list($targetUser, $targetPlanet) = $planetUpdater->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']);
        $sql = 'SELECT * FROM %%FLEETS%% WHERE fleet_end_id = :planetId AND fleet_mission = 5 AND fleet_end_stay > :time;';
        $targetStayFleets = $db->select($sql, array(':planetId' => $this->_fleet['fleet_end_id'], ':time' => $this->_fleet['fleet_start_time']));
        foreach ($targetStayFleets as $fleetRow) {
            $fleetData = FleetFunctions::unserialize($fleetRow['fleet_array']);
            foreach ($fleetData as $shipId => $shipAmount) {
                $targetPlanet[$resource[$shipId]] += $shipAmount;
            }
        }
        $fleetAmount = $this->_fleet['fleet_amount'] * (1 + $senderUser['factor']['SpyPower']);
        $senderSpyTech = max($senderUser['spy_tech'], 1);
        $targetSpyTech = max($targetUser['spy_tech'], 1);
        $techDifference = abs($senderSpyTech - $targetSpyTech);
        $MinAmount = ($senderSpyTech > $targetSpyTech ? -1 : 1) * pow($techDifference * SPY_DIFFENCE_FACTOR, 2);
        $SpyFleet = $fleetAmount >= $MinAmount;
        $SpyDef = $fleetAmount >= $MinAmount + 1 * SPY_VIEW_FACTOR;
        $SpyBuild = $fleetAmount >= $MinAmount + 3 * SPY_VIEW_FACTOR;
        $SpyTechno = $fleetAmount >= $MinAmount + 5 * SPY_VIEW_FACTOR;
        $classIDs[900] = array_merge($reslist['resstype'][1], $reslist['resstype'][2]);
        if ($SpyFleet) {
            $classIDs[200] = $reslist['fleet'];
        }
        if ($SpyDef) {
            $classIDs[400] = array_merge($reslist['defense'], $reslist['missile']);
        }
        if ($SpyBuild) {
            $classIDs[0] = $reslist['build'];
        }
        if ($SpyTechno) {
            $classIDs[100] = $reslist['tech'];
        }
        $targetChance = mt_rand(0, min($fleetAmount / 4 * ($targetSpyTech / $senderSpyTech), 100));
        $spyChance = mt_rand(0, 100);
        $spyData = array();
        foreach ($classIDs as $classID => $elementIDs) {
            foreach ($elementIDs as $elementID) {
                if (isset($targetUser[$resource[$elementID]])) {
                    $spyData[$classID][$elementID] = $targetUser[$resource[$elementID]];
                } else {
                    $spyData[$classID][$elementID] = $targetPlanet[$resource[$elementID]];
                }
            }
            if ($senderUser['spyMessagesMode'] == 1) {
                $spyData[$classID] = array_filter($spyData[$classID]);
            }
        }
        // I'm use template class here, because i want to exclude HTML in PHP.
        require_once 'includes/classes/class.template.php';
        $template = new template();
        $template->caching = true;
        $template->compile_id = $senderUser['lang'];
        $template->loadFilter('output', 'trimwhitespace');
        list($tplDir) = $template->getTemplateDir();
        $template->setTemplateDir($tplDir . 'game/');
        $template->assign_vars(array('spyData' => $spyData, 'targetPlanet' => $targetPlanet, 'targetChance' => $targetChance, 'spyChance' => $spyChance, 'isBattleSim' => ENABLE_SIMULATOR_LINK == true && isModuleAvailable(MODULE_SIMULATOR), 'title' => sprintf($LNG['sys_mess_head'], $targetPlanet['name'], $targetPlanet['galaxy'], $targetPlanet['system'], $targetPlanet['planet'], _date($LNG['php_tdformat'], $this->_fleet['fleet_end_time'], $targetUser['timezone'], $LNG))));
        $template->assign_vars(array('LNG' => $LNG), false);
        $spyReport = $template->fetch('shared.mission.spyReport.tpl');
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_qg'], 0, $LNG['sys_mess_spy_report'], $spyReport, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        $LNG = $this->getLanguage($targetUser['lang']);
        $targetMessage = $LNG['sys_mess_spy_ennemyfleet'] . " " . $senderPlanetName;
        if ($this->_fleet['fleet_start_type'] == 3) {
            $targetMessage .= $LNG['sys_mess_spy_report_moon'] . ' ';
        }
        $text = '<a href="game.php?page=galaxy&amp;galaxy=%1$s&amp;system=%2$s">[%1$s:%2$s:%3$s]</a> %7$s
		%8$s <a href="game.php?page=galaxy&amp;galaxy=%4$s&amp;system=%5$s">[%4$s:%5$s:%6$s]</a> %9$s';
        $targetMessage .= sprintf($text, $this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $LNG['sys_mess_spy_seen_at'], $targetPlanet['name'], $LNG['sys_mess_spy_seen_at2']);
        PlayerUtil::sendMessage($this->_fleet['fleet_target_owner'], 0, $LNG['sys_mess_spy_control'], 0, $LNG['sys_mess_spy_activity'], $targetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        if ($targetChance >= $spyChance) {
            $config = Config::get($this->_fleet['fleet_universe']);
            $whereCol = $this->_fleet['fleet_end_type'] == 3 ? "id_luna" : "id";
            $sql = 'UPDATE %%PLANETS%% SET
			der_metal	= der_metal + :metal,
			der_crystal = der_crystal + :crystal
			WHERE ' . $whereCol . ' = :planetId;';
            $db->update($sql, array(':metal' => $fleetAmount * $pricelist[210]['cost'][901] * $config->Fleet_Cdr / 100, ':crystal' => $fleetAmount * $pricelist[210]['cost'][902] * $config->Fleet_Cdr / 100, ':planetId' => $this->_fleet['fleet_end_id']));
            $this->KillFleet();
        } else {
            $this->setState(FLEET_RETURN);
            $this->SaveFleet();
        }
    }