function show()
 {
     global $CONF, $LNG, $PLANET, $USER, $db, $resource, $UNI;
     //$PlanetRess = new ResourceUpdate();
     //$PlanetRess->CalcResource();
     //$PlanetRess->SavePlanetToDB();
     $this->tplObj->loadscript('p_trader.js');
     if ($_POST) {
         //if($_SESSION['last']['user_side'] != 'game.php?page=p_trade'){
         //	$this->printMessage("Page error, err nr 5.", true, array('game.php?page=ptrade', 2));
         //	die();
         //}
         //$PlanetRess = new ResourceUpdate();
         //$PlanetRess->CalcResource();
         //$PlanetRess->SavePlanetToDb();
         /*totalPoints
         		oldMetal
         		oldCrystal
         		oldDeuterium
         		newMetal
         		newCrystal
         		newDeuterium
         		*/
         $total_points = isset($_POST['totalPoints']) ? $_POST['totalPoints'] : 0;
         $new_metal = isset($_POST['newMetal']) ? $_POST['newMetal'] : 0;
         $new_crystal = isset($_POST['newCrystal']) ? $_POST['newCrystal'] : 0;
         $new_deuterium = isset($_POST['newDeuterium']) ? $_POST['newDeuterium'] : 0;
         $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
         $recalculate = $new_metal + 2 * $new_crystal + 4 * $new_deuterium;
         if ($recalculate != $total_points && $recalculate - $total_points > 2000) {
             $this->printMessage("Error with inputs.", true, array('game.php?page=PTrader', 2));
             die;
         }
         if ($new_metal < 0 || $new_crystal < 0 || $new_deuterium < 0) {
             $this->printMessage("ERROR with negative numbers.", true, array('game.php?page=PTrader', 2));
             die;
         }
         //	if($USER['antimatter'] < 250 && $USER['premium_reward_days'] < TIMESTAMP){
         //	$this->printMessage("Not enough antimatter.", true, array('game.php?page=PTrader', 2));
         //		die();
         //	}
         $PLANET['metal'] = $GLOBALS['DATABASE']->sql_escape($new_metal);
         $PLANET['crystal'] = $GLOBALS['DATABASE']->sql_escape($new_crystal);
         $PLANET['deuterium'] = $GLOBALS['DATABASE']->sql_escape($new_deuterium);
         $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " set `metal` = '" . $GLOBALS['DATABASE']->sql_escape($new_metal) . "', `crystal` = '" . $GLOBALS['DATABASE']->sql_escape($new_crystal) . "', `deuterium` = '" . $GLOBALS['DATABASE']->sql_escape($new_deuterium) . "' where `id` = '" . $PLANET['id'] . "' ;");
         if ($USER['premium_reward_days'] < TIMESTAMP) {
             //$GLOBALS['DATABASE']->query("UPDATE ".USERS." set `antimatter` = antimatter - '250' WHERE `id` = '".$USER['id']."' ;");
         }
         $this->printMessage("Exchange has been successfully made.", true, array('game.php?page=PTrader', 2));
         die;
     }
     $recalculate = $PLANET['metal'] + $PLANET['crystal'] * 2 + $PLANET['deuterium'] * 4;
     //$GLOBALS['DATABASE']->query("UPDATE ".USERS." set `ptrader_total` = '".$recalculate."' where `id` = '".$USER['id']."' ;");
     $_SESSION['total_p'] = $recalculate;
     $this->tplObj->assign_vars(array('total_points' => pretty_number(floattostring($recalculate)), 'total_points11' => floattostring($recalculate), 'planet_metal' => pretty_number($PLANET['metal']), 'planet_crystal' => pretty_number($PLANET['crystal']), 'planet_deuterium' => pretty_number($PLANET['deuterium']), 'planet_metal11' => $PLANET['metal'], 'planet_crystal11' => $PLANET['crystal'], 'planet_deuterium11' => $PLANET['deuterium'], 'planet_metal_t' => pretty_number($PLANET['metal']), 'planet_crystal_t' => pretty_number(floattostring($PLANET['crystal'] * 2)), 'planet_deuterium_t' => pretty_number(floattostring($PLANET['deuterium'] * 4))));
     $this->display('page.ptrader.default.tpl');
 }
示例#2
0
/**
 _  \_/ |\ | /¯¯\ \  / /\    |¯¯) |_¯ \  / /¯¯\ |  |   |´¯|¯` | /¯¯\ |\ |5
 ¯  /¯\ | \| \__/  \/ /--\   |¯¯\ |__  \/  \__/ |__ \_/   |   | \__/ | \|Core.
 * @author: Copyright (C) 2011 by Brayan Narvaez (Prinick) developer of xNova Revolution
 * @link: http://www.xnovarevolution.con.ar

 * @package 2Moons
 * @author Slaver <*****@*****.**>
 * @copyright 2009 Lucky <*****@*****.**> (XGProyecto)
 * @copyright 2011 Slaver <*****@*****.**> (Fork/2Moons)
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
 * @version 1.3 (2011-01-21)
 * @link http://code.google.com/p/2moons/

 * Please do not remove the credits
*/
function calculateSteal($attackFleets, $defenderPlanet, $ForSim = false)
{
    //Steal-Math by Slaver for 2Moons(http://www.titanspace.org) based on http://www.owiki.de/Beute
    global $pricelist, $db;
    $SortFleets = array();
    $Sumcapacity = '0';
    foreach ($attackFleets as $FleetID => $Attacker) {
        $SortFleets[$FleetID] = '0';
        foreach ($Attacker['detail'] as $Element => $amount) {
            $SortFleets[$FleetID] = bcadd($SortFleets[$FleetID], bcmul($pricelist[$Element]['capacity'], floattostring($amount)));
        }
        $SortFleets[$FleetID] = bcsub($SortFleets[$FleetID], $Attacker['fleet']['fleet_resource_metal']);
        $SortFleets[$FleetID] = bcsub($SortFleets[$FleetID], $Attacker['fleet']['fleet_resource_crystal']);
        $SortFleets[$FleetID] = bcsub($SortFleets[$FleetID], $Attacker['fleet']['fleet_resource_deuterium']);
        $SortFleets[$FleetID] = bcsub($SortFleets[$FleetID], $Attacker['fleet']['fleet_resource_norio']);
        $Sumcapacity = bcadd($Sumcapacity, $SortFleets[$FleetID]);
    }
    $AllCapacity = $Sumcapacity;
    // Step 1
    $booty['metal'] = min(bcdiv($Sumcapacity, 3), bcdiv(floattostring($defenderPlanet['metal']), 2));
    $Sumcapacity = bcsub($Sumcapacity, $booty['metal']);
    // Step 2
    $booty['crystal'] = min(bcdiv($Sumcapacity, 2), bcdiv(floattostring($defenderPlanet['crystal']), 2));
    $Sumcapacity = bcsub($Sumcapacity, $booty['crystal']);
    // Step 3
    $booty['deuterium'] = min($Sumcapacity, bcdiv(floattostring($defenderPlanet['deuterium']), 2));
    $Sumcapacity = bcsub($Sumcapacity, $booty['deuterium']);
    // Step 6
    $booty['norio'] = min(bcdiv($Sumcapacity, 2), bcdiv(floattostring($defenderPlanet['norio']), 2));
    $Sumcapacity = bcsub($Sumcapacity, $booty['norio']);
    // Step 4
    $oldMetalBooty = $booty['metal'];
    $booty['metal'] = bcadd($booty['metal'], min(bcdiv($Sumcapacity, 2), max(bcsub(bcdiv(floattostring($defenderPlanet['metal']), 2), $booty['metal']), 0)));
    $Sumcapacity = bcsub($Sumcapacity, bcsub($booty['metal'], $oldMetalBooty));
    // Step 5
    $booty['crystal'] = bcadd($booty['crystal'], min($Sumcapacity, max(bcsub(bcdiv(floattostring($defenderPlanet['crystal']), 2), $booty['crystal']), 0)));
    // Step 7
    $booty['norio'] = bcadd($booty['norio'], min($Sumcapacity, max(bcsub(bcdiv(floattostring($defenderPlanet['norio']), 2), $booty['norio']), 0)));
    if ($ForSim) {
        return $booty;
    }
    $Qry = "";
    foreach ($SortFleets as $FleetID => $Capacity) {
        $Factor = bcdiv($Capacity, $AllCapacity, 10);
        $Qry .= "UPDATE " . FLEETS . " SET ";
        $Qry .= "`fleet_resource_metal` = `fleet_resource_metal` + '" . bcmul($booty['metal'], $Factor, 0) . "', ";
        $Qry .= "`fleet_resource_crystal` = `fleet_resource_crystal` + '" . bcmul($booty['crystal'], $Factor, 0) . "', ";
        $Qry .= "`fleet_resource_deuterium` = `fleet_resource_deuterium` + '" . bcmul($booty['deuterium'], $Factor, 0) . "', ";
        $Qry .= "`fleet_resource_norio` = `fleet_resource_norio` + '" . bcmul($booty['norio'], $Factor, 0) . "' ";
        $Qry .= "WHERE fleet_id = '" . $FleetID . "';";
    }
    $db->multi_query($Qry);
    return $booty;
}
 public static function calculateAKSSteal($attackFleets, $defenderPlanet, $ForSim = false)
 {
     //Steal-Math by Slaver for 2Moons(http://code.google.com/p/2moons/) based on http://www.owiki.de/Beute
     global $pricelist;
     $SortFleets = array();
     foreach ($attackFleets as $FleetID => $Attacker) {
         foreach ($Attacker['detail'] as $Element => $amount) {
             $SortFleets[$FleetID] += $pricelist[$Element]['capacity'] * $amount;
         }
         $SortFleets[$FleetID] -= $Attacker['fleet']['fleet_resource_metal'] - $Attacker['fleet']['fleet_resource_crystal'] - $Attacker['fleet']['fleet_resource_deuterium'];
     }
     $Sumcapacity = array_sum($SortFleets);
     // Step 1
     $booty['metal'] = min($Sumcapacity / 3, $defenderPlanet['metal'] / 2);
     $Sumcapacity -= $booty['metal'];
     // Step 2
     $booty['crystal'] = min($Sumcapacity / 2, $defenderPlanet['crystal'] / 2);
     $Sumcapacity -= $booty['crystal'];
     // Step 3
     $booty['deuterium'] = min($Sumcapacity, $defenderPlanet['deuterium'] / 2);
     $Sumcapacity -= $booty['deuterium'];
     // Step 4
     $booty['tritium'] = min($Sumcapacity, $defenderPlanet['tritium'] / 2);
     $Sumcapacity -= $booty['tritium'];
     // Step 5
     $oldMetalBooty = $booty['metal'];
     $booty['metal'] += min($Sumcapacity / 2, max($defenderPlanet['metal'] / 2 - $booty['metal'], 0));
     $Sumcapacity += $oldMetalBooty - $booty['metal'];
     // Step 6
     $booty['crystal'] += min($Sumcapacity, max($defenderPlanet['crystal'] / 2 - $booty['crystal'], 0));
     $booty['metal'] = max($booty['metal'], 0);
     $booty['crystal'] = max($booty['crystal'], 0);
     $booty['deuterium'] = max($booty['deuterium'], 0);
     $booty['deuterium'] = max($booty['tritium'], 0);
     $steal = array_map('floor', $booty);
     if ($ForSim) {
         return $steal;
     }
     $AllCapacity = array_sum($SortFleets);
     $QryUpdateFleet = "";
     foreach ($SortFleets as $FleetID => $Capacity) {
         $QryUpdateFleet = "UPDATE {{table}} SET ";
         $QryUpdateFleet .= "`fleet_resource_metal` =  `fleet_resource_metal` + '" . floattostring($steal['metal'] * ($Capacity / $AllCapacity)) . "', ";
         $QryUpdateFleet .= "`fleet_resource_crystal` =  `fleet_resource_crystal` +'" . floattostring($steal['crystal'] * ($Capacity / $AllCapacity)) . "', ";
         $QryUpdateFleet .= "`fleet_resource_deuterium` =  `fleet_resource_deuterium` +'" . floattostring($steal['deuterium'] * ($Capacity / $AllCapacity)) . "', ";
         $QryUpdateFleet .= "`fleet_resource_tritium` =  `fleet_resource_tritium` +'" . floattostring($steal['tritium'] * ($Capacity / $AllCapacity)) . "' ";
         $QryUpdateFleet .= "WHERE fleet_id = '" . $FleetID . "' ";
         $QryUpdateFleet .= "LIMIT 1;";
         doquery($QryUpdateFleet, 'fleets');
     }
     return $steal;
 }
 function StoreGoodsToPlanet($Start = false)
 {
     global $db;
     $Qry = "UPDATE " . PLANETS . " SET ";
     $Qry .= "`metal` = `metal` + '" . floattostring($this->_fleet['fleet_resource_metal']) . "', ";
     $Qry .= "`crystal` = `crystal` + '" . floattostring($this->_fleet['fleet_resource_crystal']) . "', ";
     $Qry .= "`deuterium` = `deuterium` + '" . floattostring($this->_fleet['fleet_resource_deuterium']) . "' ";
     $Qry .= "WHERE ";
     $Qry .= "`id` = '" . ($Start == true ? $this->_fleet['fleet_start_id'] : $this->_fleet['fleet_end_id']) . "';";
     $db->query($Qry);
     $this->UpdateFleet('fleet_resource_metal', '0');
     $this->UpdateFleet('fleet_resource_crystal', '0');
     $this->UpdateFleet('fleet_resource_deuterium', '0');
 }
示例#5
0
function ShowQuickEditorPage()
{
    global $LNG, $db, $reslist, $resource;
    $action = request_var('action', '');
    $edit = request_var('edit', '');
    $id = request_var('id', 0);
    switch ($edit) {
        case 'planet':
            $DataIDs = array_merge($reslist['fleet'], $reslist['build'], $reslist['defense']);
            foreach ($DataIDs as $ID) {
                $SpecifyItemsPQ .= "`" . $resource[$ID] . "`,";
            }
            $PlanetData = $db->uniquequery("SELECT " . $SpecifyItemsPQ . " `name`, `id_owner`, `planet_type`, `galaxy`, `system`, `planet`, `destruyed`, `diameter`, `field_current`, `field_current`, `field_max`, `temp_min`, `temp_max`, `metal`, `crystal`, `deuterium` FROM " . PLANETS . " WHERE `id` = '" . $id . "';");
            $reslist['build'] = $reslist['allow'][$PlanetData['planet_type']];
            if ($action == 'send') {
                $QryUpdateString = "UPDATE " . PLANETS . " SET ";
                foreach ($DataIDs as $ID) {
                    $QryUpdateString .= "`" . $resource[$ID] . "` = '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "', ";
                }
                $QryUpdateString .= "`metal` = '" . floattostring(round(abs(request_var('metal', 0.0)), 0)) . "', ";
                $QryUpdateString .= "`crystal` = '" . floattostring(round(abs(request_var('crystal', 0.0)), 0)) . "', ";
                $QryUpdateString .= "`deuterium` = '" . floattostring(round(abs(request_var('deuterium', 0.0)), 0)) . "', ";
                $QryUpdateString .= "`field_max` = '" . request_var('field_max', 0) . "', ";
                $QryUpdateString .= "`name` = '" . $db->sql_escape(request_var('name', '')) . "' ";
                $QryUpdateString .= "WHERE `id` = '" . $id . "' LIMIT 1;";
                $db->query($QryUpdateString);
                exit(sprintf($LNG['qe_edit_sucess'], $PlanetData['name'], $PlanetData['galaxy'], $PlanetData['system'], $PlanetData['planet']));
            }
            $UserInfo = $db->uniquequery("SELECT `username` FROM " . USERS . " WHERE `id` = '" . $PlanetData['id_owner'] . "'");
            $build = $defense = $fleet = array();
            foreach ($reslist['build'] as $ID) {
                $build[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            foreach ($reslist['fleet'] as $ID) {
                $fleet[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            foreach ($reslist['defense'] as $ID) {
                $defense[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($PlanetData[$resource[$ID]]), 'input' => $PlanetData[$resource[$ID]]);
            }
            $template = new template();
            $template->page_header();
            $template->assign_vars(array('qe_resources' => $LNG['qe_resources'], 'Metal' => $LNG['Metal'], 'Crystal' => $LNG['Crystal'], 'Deuterium' => $LNG['Deuterium'], 'qe_defensive' => $LNG['qe_defensive'], 'qe_fleet' => $LNG['qe_fleet'], 'qe_build' => $LNG['qe_build'], 'qe_input' => $LNG['qe_input'], 'qe_count' => $LNG['qe_count'], 'qe_name' => $LNG['qe_name'], 'qe_reset' => $LNG['qe_reset'], 'qe_send' => $LNG['qe_send'], 'qe_temp' => $LNG['qe_temp'], 'qe_fields' => $LNG['qe_fields'], 'qe_owner' => $LNG['qe_owner'], 'qe_coords' => $LNG['qe_coords'], 'qe_id' => $LNG['qe_id'], 'qe_info' => $LNG['qe_info'], 'build' => $build, 'fleet' => $fleet, 'defense' => $defense, 'id' => $id, 'ownerid' => $PlanetData['id_owner'], 'ownername' => $UserInfo['username'], 'name' => $PlanetData['name'], 'galaxy' => $PlanetData['galaxy'], 'system' => $PlanetData['system'], 'planet' => $PlanetData['planet'], 'field_min' => $PlanetData['field_current'], 'field_max' => $PlanetData['field_max'], 'temp_min' => $PlanetData['temp_min'], 'temp_max' => $PlanetData['temp_max'], 'metal' => floattostring($PlanetData['metal']), 'crystal' => floattostring($PlanetData['crystal']), 'deuterium' => floattostring($PlanetData['deuterium']), 'metal_c' => pretty_number($PlanetData['metal']), 'crystal_c' => pretty_number($PlanetData['crystal']), 'deuterium_c' => pretty_number($PlanetData['deuterium'])));
            $template->show('adm/QuickEditorPlanet.tpl');
            break;
        case 'player':
            break;
    }
}
示例#6
0
 private function DoFleetJump()
 {
     global $USER, $PLANET, $resource, $LNG, $db, $reslist;
     if (!$_POST) {
         return false;
     }
     $RestString = $this->GetNextJumpWaitTime($PLANET);
     $NextJumpTime = $RestString['value'];
     $JumpTime = TIMESTAMP;
     if ($NextJumpTime != 0) {
         return $LNG['in_jump_gate_already_used'] . $RestString['string'];
     }
     $TargetPlanet = request_var('jmpto', 0);
     $TargetGate = $db->uniquequery("SELECT `id`, `last_jump_time` FROM " . PLANETS . " WHERE `id` = '" . $TargetPlanet . "' AND `sprungtor` > '0';");
     if (!isset($TargetGate)) {
         return $LNG['in_jump_gate_doesnt_have_one'];
     }
     $RestString = $this->GetNextJumpWaitTime($TargetGate);
     if ($RestString['value'] != 0) {
         return $LNG['in_jump_gate_not_ready_target'] . $RestString['string'];
     }
     $ShipArray = array();
     $SubQueryOri = "";
     $SubQueryDes = "";
     foreach ($reslist['fleet'] as $Ship) {
         $ShipArray[$Ship] = min(max(request_var('ship' . $Ship, 0.0), 0), $PLANET[$resource[$Ship]]);
         $SubQueryOri .= "`" . $resource[$Ship] . "` = `" . $resource[$Ship] . "` - '" . floattostring($ShipArray[$Ship]) . "', ";
         $SubQueryDes .= "`" . $resource[$Ship] . "` = `" . $resource[$Ship] . "` + '" . floattostring($ShipArray[$Ship]) . "', ";
         $PLANET[$resource[$Ship]] -= floattostring($ShipArray[$Ship]);
     }
     if (empty($SubQueryOri)) {
         return $LNG['in_jump_gate_error_data'];
     }
     $SQL = "UPDATE " . PLANETS . " SET ";
     $SQL .= $SubQueryOri;
     $SQL .= "`last_jump_time` = '" . $JumpTime . "' ";
     $SQL .= "WHERE ";
     $SQL .= "`id` = '" . $PLANET['id'] . "';";
     $SQL .= "UPDATE " . PLANETS . " SET ";
     $SQL .= $SubQueryDes;
     $SQL .= "`last_jump_time` = '" . $JumpTime . "' ";
     $SQL .= "WHERE ";
     $SQL .= "`id` = '" . $TargetGate['id'] . "';";
     $db->multi_query($SQL);
     $PLANET['last_jump_time'] = $JumpTime;
     $RestString = $this->GetNextJumpWaitTime($PLANET);
     return $LNG['in_jump_gate_done'] . $RestString['string'];
 }
 public static function calculateAKSSteal($attackFleets, $defenderPlanet, $ForSim = false)
 {
     //Steal-Math by Slaver for 2Moons(http://www.titanspace.org) based on http://www.owiki.de/Beute
     global $pricelist, $db;
     $SortFleets = array();
     foreach ($attackFleets as $FleetID => $Attacker) {
         foreach ($Attacker['detail'] as $Element => $amount) {
             if ($Element != 210) {
                 //fix probos capacity in attack by jstar
                 $SortFleets[$FleetID] += $pricelist[$Element]['capacity'] * $amount;
             }
         }
         $SortFleets[$FleetID] -= $Attacker['fleet']['fleet_resource_metal'] - $Attacker['fleet']['fleet_resource_crystal'] - $Attacker['fleet']['fleet_resource_deuterium'];
     }
     $Sumcapacity = array_sum($SortFleets);
     //FIX JTSAMPER
     $booty['deuterium'] = min($Sumcapacity / 3, $defenderPlanet['deuterium'] / 2);
     $Sumcapacity -= $booty['deuterium'];
     $booty['crystal'] = min($Sumcapacity / 2, $defenderPlanet['crystal'] / 2);
     $Sumcapacity -= $booty['crystal'];
     $booty['metal'] = min($Sumcapacity, $defenderPlanet['metal'] / 2);
     $Sumcapacity -= $booty['metal'];
     $oldMetalBooty = $booty['crystal'];
     $booty['crystal'] += min($Sumcapacity / 2, max($defenderPlanet['crystal'] / 2 - $booty['crystal'], 0));
     $Sumcapacity += $oldMetalBooty - $booty['crystal'];
     $booty['metal'] += min($Sumcapacity, max($defenderPlanet['metal'] / 2 - $booty['metal'], 0));
     $booty['metal'] = max($booty['metal'], 0);
     $booty['crystal'] = max($booty['crystal'], 0);
     $booty['deuterium'] = max($booty['deuterium'], 0);
     //END FIX
     $steal = array_map('floor', $booty);
     if ($ForSim) {
         return $steal;
     }
     $AllCapacity = array_sum($SortFleets);
     $QryUpdateFleet = "";
     foreach ($SortFleets as $FleetID => $Capacity) {
         $QryUpdateFleet = 'UPDATE {{table}} SET ';
         $QryUpdateFleet .= '`fleet_resource_metal` = `fleet_resource_metal` + ' . floattostring($steal['metal'] * ($Capacity / $AllCapacity)) . ', ';
         $QryUpdateFleet .= '`fleet_resource_crystal` = `fleet_resource_crystal` +' . floattostring($steal['crystal'] * ($Capacity / $AllCapacity)) . ', ';
         $QryUpdateFleet .= '`fleet_resource_deuterium` = `fleet_resource_deuterium` +' . floattostring($steal['deuterium'] * ($Capacity / $AllCapacity)) . ' ';
         $QryUpdateFleet .= 'WHERE fleet_id = ' . $FleetID . ' ';
         $QryUpdateFleet .= 'LIMIT 1;';
         doquery($QryUpdateFleet, 'fleets');
     }
     return $steal;
 }
 public function show()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $LNG;
     $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
     $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
     $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
     $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']);
     $mission = HTTP::_GP('target_mission', 0);
     $Fleet = array();
     $FleetRoom = 0;
     $allyInfo = $GLOBALS['DATABASE']->query("SELECT FleetCapa FROM `uni1_alliance` WHERE id = " . $USER['ally_id'] . ";");
     $allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo);
     $listorder = array(210, 212, 202, 203, 204, 205, 229, 209, 206, 207, 208, 217, 215, 213, 211, 220, 224, 219, 223, 225, 226, 214, 216, 230, 227, 228, 222, 218, 221);
     foreach ($listorder as $id => $ShipID) {
         $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0)));
         if ($amount < 1 || $ShipID == 212) {
             continue;
         }
         $Fleet[$ShipID] = $amount;
         $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount;
         $FleetRoom += $FleetRoom / 100 * getbonusOneBis(1207, $USER['academy_1207']) + $FleetRoom / 100 * $allyInfo['FleetCapa'];
     }
     foreach ($Fleet as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]]) {
             $this->printMessage($LNG['fl_not_all_ship_avalible']);
         }
     }
     $FleetRoom *= 1 + $USER['factor']['ShipStorage'];
     if (empty($Fleet)) {
         FleetFunctions::GotoFleetPage();
     }
     $FleetData = array('fleetroom' => floattostring($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME);
     $token = getRandomString();
     $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom);
     $shortcutList = $this->GetUserShotcut();
     $colonyList = $this->GetColonyList();
     $ACSList = $this->GetAvalibleACS();
     if (!empty($shortcutList)) {
         $shortcutAmount = max(array_keys($shortcutList));
     } else {
         $shortcutAmount = 0;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);');
     $this->tplObj->assign_vars(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3], 4 => $LNG['type_planet'][4]), 'fleetdata' => $FleetData));
     $this->display('page.fleetStep1.default.tpl');
 }
 function StoreGoodsToPlanet($Start = false)
 {
     global $db;
     $Qry = "UPDATE " . PLANETS . " SET ";
     $Qry .= "`metal` = `metal` + '" . floattostring($this->_fleet['fleet_resource_metal']) . "', ";
     $Qry .= "`crystal` = `crystal` + '" . floattostring($this->_fleet['fleet_resource_crystal']) . "', ";
     $Qry .= "`deuterium` = `deuterium` + '" . floattostring($this->_fleet['fleet_resource_deuterium']) . "' ";
     $Qry .= "WHERE ";
     if ($Start == true) {
         $Qry .= "`galaxy` = '" . $this->_fleet['fleet_start_galaxy'] . "' AND `system` = '" . $this->_fleet['fleet_start_system'] . "' AND `planet` = '" . $this->_fleet['fleet_start_planet'] . "' AND `planet_type` = '" . $this->_fleet['fleet_start_type'] . "' ";
     } else {
         $Qry .= "`galaxy` = '" . $this->_fleet['fleet_end_galaxy'] . "' AND `system` = '" . $this->_fleet['fleet_end_system'] . "' AND `planet` = '" . $this->_fleet['fleet_end_planet'] . "' AND `planet_type` = '" . $this->_fleet['fleet_end_type'] . "' ";
     }
     $Qry .= "LIMIT 1;";
     $db->query($Qry);
     $this->UpdateFleet('fleet_resource_metal', '0');
     $this->UpdateFleet('fleet_resource_crystal', '0');
     $this->UpdateFleet('fleet_resource_deuterium', '0');
 }
 public function show()
 {
     global $USER, $PLANET, $pricelist, $reslist, $LNG;
     $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
     $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
     $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
     $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']);
     $mission = HTTP::_GP('target_mission', 0);
     $Fleet = array();
     $FleetRoom = 0;
     foreach ($reslist['fleet'] as $id => $ShipID) {
         $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0)));
         if ($amount < 1 || $ShipID == 212) {
             continue;
         }
         $Fleet[$ShipID] = $amount;
         $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount;
     }
     $FleetRoom *= 1 + $USER['factor']['ShipStorage'];
     if (empty($Fleet)) {
         FleetFunctions::GotoFleetPage();
     }
     $FleetData = array('fleetroom' => floattostring($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME);
     $token = getRandomString();
     $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom);
     $shortcutList = $this->GetUserShotcut();
     $colonyList = $this->GetColonyList();
     $ACSList = $this->GetAvalibleACS();
     if (!empty($shortcutList)) {
         $shortcutAmount = max(array_keys($shortcutList));
     } else {
         $shortcutAmount = 0;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);');
     $this->assign(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3]), 'fleetdata' => $FleetData));
     $this->display('page.fleetStep1.default.tpl');
 }
示例#11
0
 /** FLEET FUNCTIONS **/
 function SendFleet($FleetData)
 {
     $FleetData = array_merge(array('mission' => 3, 'galaxy' => 0, 'system' => 0, 'planet' => 0, 'planettype' => 0, 'fleetgroup' => 0, 'speed' => 10, 'metal' => 0, 'crystal' => 0, 'deuterium' => 0, 'holdingtime' => 0, 'fleet' => array()), $FleetData);
     $mission = $FleetData['mission'];
     $galaxy = $FleetData['galaxy'];
     $system = $FleetData['system'];
     $planet = $FleetData['planet'];
     $planettype = $FleetData['planettype'];
     $fleet_group = $FleetData['fleetgroup'];
     $GenFleetSpeed = $FleetData['speed'];
     $TransportMetal = $FleetData['metal'];
     $TransportCrystal = $FleetData['crystal'];
     $TransportDeuterium = $FleetData['deuterium'];
     $holdingtime = $FleetData['holdingtime'];
     $rawfleetarray = $FleetData['fleet'];
     if ($planettype != 1 && $planettype != 3) {
         return false;
     }
     if ($this->PLANET['galaxy'] == $galaxy && $this->PLANET['system'] == $system && $this->PLANET['planet'] == $planet && $this->PLANET['planet_type'] == $planettype) {
         return false;
     }
     if ($galaxy > $CONF['max_galaxy'] || $galaxy < 1 || $system > $CONF['max_system'] || $system < 1 || $planet > $CONF['max_planets'] + 1 || $planet < 1) {
         return false;
     }
     if (empty($mission)) {
         return false;
     }
     $ActualFleets = parent::GetCurrentFleets($USER['id']);
     if (parent::GetMaxFleetSlots($USER) <= $ActualFleets) {
         return false;
     }
     $fleet_group_mr = 0;
     if (!empty($fleet_group) && $mission == 2) {
         $aks_count_mr = $db->uniquequery("SELECT COUNT(*) as state FROM " . AKS . " WHERE `id` = '" . $fleet_group . "' AND `eingeladen` LIKE '%" . $USER['id'] . "%';");
         if ($aks_count_mr['state'] > 0) {
             $fleet_group_mr = $fleet_group;
         } else {
             $mission = 1;
         }
     }
     $ActualFleets = parent::GetCurrentFleets($USER['id']);
     $TargetPlanet = $db->uniquequery("SELECT `id`, `id_owner`,`destruyed`,`ally_deposit` FROM " . PLANETS . " WHERE `universe` = '" . $UNI . "' AND `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND `planet_type` = '" . ($planettype == 2 ? 1 : $planettype) . "';");
     if ($mission != 15 && $TargetPlanet["destruyed"] != 0 || $mission != 15 && $mission != 7 && empty($TargetPlanet['id_owner'])) {
         return false;
     }
     $MyDBRec = $USER;
     $FleetArray = parent::GetFleetArray($rawfleetarray);
     if (!is_array($FleetArray)) {
         return false;
     }
     $FleetStorage = 0;
     $FleetShipCount = 0;
     $fleet_array = "";
     $FleetSubQRY = "";
     foreach ($FleetArray as $Ship => $Count) {
         if ($Count > $this->PLANET[$resource[$Ship]] || $Count < 0) {
             return false;
         }
         $FleetStorage += $pricelist[$Ship]["capacity"] * $Count;
         $FleetShipCount += $Count;
         $fleet_array .= $Ship . "," . $Count . ";";
         $FleetSubQRY .= "`" . $resource[$Ship] . "` = `" . $resource[$Ship] . "` - '" . floattostring($Count) . "', ";
     }
     $error = 0;
     $fleetmission = $mission;
     $YourPlanet = false;
     $UsedPlanet = false;
     if ($mission == 11) {
         $maxexpde = parent::GetCurrentFleets($USER['id'], 11);
         if ($maxexpde >= $CONF['max_dm_missions']) {
             return false;
         }
     } elseif ($mission == 15) {
         $MaxExpedition = $USER[$resource[124]];
         if ($MaxExpedition == 0) {
             return false;
         }
         $ExpeditionEnCours = parent::GetCurrentFleets($USER['id'], 15);
         $EnvoiMaxExpedition = floor(sqrt($MaxExpedition));
         if ($ExpeditionEnCours >= $EnvoiMaxExpedition) {
             return false;
         }
     }
     $YourPlanet = isset($TargetPlanet['id_owner']) && $TargetPlanet['id_owner'] == $USER['id'] ? true : false;
     $UsedPlanet = isset($TargetPlanet['id_owner']) ? true : false;
     $HeDBRec = $YourPlanet ? $MyDBRec : GetUserByID($TargetPlanet['id_owner'], array('id', 'onlinetime', 'ally_id', 'urlaubs_modus', 'banaday', 'authattack'));
     if ($HeDBRec['urlaubs_modus'] && $mission != 8) {
         return false;
     }
     if (!$YourPlanet && ($mission == 1 || $mission == 2 || $mission == 5 || $mission == 6 || $mission == 9)) {
         if ($CONF['adm_attack'] == 1 && $UsedPlanet['authattack'] > $USER['authlevel']) {
             return false;
         }
         $UserPoints = $USER;
         $User2Points = $db->uniquequery("SELECT `total_points` FROM " . STATPOINTS . " WHERE `stat_type` = '1' AND `id_owner` = '" . $HeDBRec['id'] . "';");
         $IsNoobProtec = CheckNoobProtec($UserPoints, $User2Points, $HeDBRec);
         if ($IsNoobProtec['NoobPlayer']) {
             return false;
         } elseif ($IsNoobProtec['StrongPlayer']) {
             return false;
         }
     }
     if ($mission == 5) {
         if ($TargetPlanet['ally_deposit'] < 1) {
             return false;
         }
         $buddy = $db->uniquequery("SELECT COUNT(*) as state FROM " . BUDDY . " WHERE `active` = '1' AND (`owner` = '" . $HeDBRec['id'] . "' AND `sender` = '" . $MyDBRec['id'] . "') OR (`owner` = '" . $MyDBRec['id'] . "' AND `sender` = '" . $HeDBRec['id'] . "');");
         if ($HeDBRec['ally_id'] != $MyDBRec['ally_id'] && $buddy['state'] == 0) {
             return false;
         }
     }
     if (!parent::CheckUserSpeed($GenFleetSpeed) || !array_key_exists($mission, parent::GetAvailableMissions(array('CurrentUser' => $USER, 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'planettype' => $planettype, 'IsAKS' => $fleet_group, 'Ship' => $FleetArray)))) {
         return false;
     }
     $MaxFleetSpeed = parent::GetFleetMaxSpeed($FleetArray, $USER);
     $SpeedFactor = parent::GetGameSpeedFactor();
     $distance = parent::GetTargetDistance($this->PLANET['galaxy'], $galaxy, $this->PLANET['system'], $system, $this->PLANET['planet'], $planet);
     $duration = parent::GetMissionDuration($GenFleetSpeed, $MaxFleetSpeed, $distance, $SpeedFactor, $USER);
     $consumption = parent::GetFleetConsumption($FleetArray, $duration, $distance, $MaxFleetSpeed, $USER, $SpeedFactor);
     $fleet['start_time'] = $duration + TIMESTAMP;
     if ($mission == 15) {
         $StayDuration = max($holdingtime, 1) * 3600 / $CONF['halt_speed'];
         $StayTime = $fleet['start_time'] + $StayDuration;
     } elseif ($mission == 5) {
         $StayDuration = $holdingtime * 3600;
         $StayTime = $fleet['start_time'] + $StayDuration;
     } elseif ($mission == 11) {
         $StayDuration = 3600 / $CONF['halt_speed'];
         $StayTime = $fleet['start_time'] + $StayDuration;
     } else {
         $StayDuration = 0;
         $StayTime = 0;
     }
     $fleet['end_time'] = $StayDuration + 2 * $duration + TIMESTAMP;
     $FleetStorage -= $consumption;
     $PlanetRess = new ResourceUpdate();
     $PlanetRess->CalcResource();
     $TransportMetal = min($TransportMetal, $this->PLANET['metal']);
     $TransportCrystal = min($TransportCrystal, $this->PLANET['crystal']);
     $TransportDeuterium = min($TransportDeuterium, $this->PLANET['deuterium'] - $consumption);
     $StorageNeeded = $TransportMetal + $TransportCrystal + $TransportDeuterium;
     $StockMetal = $this->PLANET['metal'];
     $StockCrystal = $this->PLANET['crystal'];
     $StockDeuterium = $this->PLANET['deuterium'];
     $StockDeuterium -= $consumption;
     if ($this->PLANET['deuterium'] < $consumption) {
         return false;
     }
     if ($StorageNeeded > $FleetStorage) {
         return false;
     }
     $this->PLANET['metal'] -= $TransportMetal;
     $this->PLANET['crystal'] -= $TransportCrystal;
     $this->PLANET['deuterium'] -= $TransportDeuterium + $consumption;
     if ($fleet_group_mr != 0) {
         $AksStartTime = $db->uniquequery("SELECT MAX(`fleet_start_time`) AS Start FROM " . FLEETS . " WHERE `fleet_group` = '" . $fleet_group_mr . "' AND '" . $CONF['max_fleets_per_acs'] . "' > (SELECT COUNT(*) FROM " . FLEETS . " WHERE `fleet_group` = '" . $fleet_group_mr . "');");
         if (isset($AksStartTime)) {
             if ($AksStartTime['Start'] >= $fleet['start_time']) {
                 $fleet['end_time'] += $AksStartTime['Start'] - $fleet['start_time'];
                 $fleet['start_time'] = $AksStartTime['Start'];
             } else {
                 $SQLFleets = "UPDATE " . FLEETS . " SET ";
                 $SQLFleets .= "`fleet_start_time` = '" . $fleet['start_time'] . "', ";
                 $SQLFleets .= "`fleet_end_time` = fleet_end_time + '" . ($fleet['start_time'] - $AksStartTime['Start']) . "' ";
                 $SQLFleets .= "WHERE ";
                 $SQLFleets .= "`fleet_group` = '" . $fleet_group_mr . "';";
                 $db->query($SQLFleets);
                 $fleet['end_time'] += $fleet['start_time'] - $AksStartTime['Start'];
             }
         } else {
             $mission = 1;
         }
     }
     $QryInsertFleet = "LOCK TABLE " . FLEETS . " WRITE, " . PLANETS . " WRITE;\n\t\t\t\t\t\t\tINSERT INTO " . FLEETS . " SET \n\t\t\t\t\t\t\t`fleet_owner` = '" . $USER['id'] . "', \n\t\t\t\t\t\t\t`fleet_mission` = '" . $mission . "',\n\t\t\t\t\t\t\t`fleet_amount` = '" . $FleetShipCount . "',\n\t\t\t\t\t\t    `fleet_array` = '" . $fleet_array . "',\n\t\t\t\t\t\t    `fleet_universe` = '" . $UNI . "',\n\t\t\t\t\t\t\t`fleet_start_time` = '" . $fleet['start_time'] . "',\n\t\t\t\t\t\t\t`fleet_start_id` = '" . $this->PLANET['id'] . "',\n\t\t\t\t\t\t\t`fleet_start_galaxy` = '" . $this->PLANET['galaxy'] . "',\n\t\t\t\t\t\t\t`fleet_start_system` = '" . $this->PLANET['system'] . "',\n\t\t\t\t\t\t\t`fleet_start_planet` = '" . $this->PLANET['planet'] . "',\n\t\t\t\t\t\t\t`fleet_start_type` = '" . $this->PLANET['planet_type'] . "',\n\t\t\t\t\t\t\t`fleet_end_time` = '" . $fleet['end_time'] . "',\n\t\t\t\t\t\t\t`fleet_end_stay` = '" . $StayTime . "',\n\t\t\t\t\t\t\t`fleet_end_id` = '" . (int) $TargetPlanet['id'] . "',\n\t\t\t\t\t\t\t`fleet_end_galaxy` = '" . $galaxy . "',\n\t\t\t\t\t\t\t`fleet_end_system` = '" . $system . "',\n\t\t\t\t\t\t\t`fleet_end_planet` = '" . $planet . "',\n\t\t\t\t\t\t\t`fleet_end_type` = '" . $planettype . "',\n\t\t\t\t\t\t\t`fleet_resource_metal` = '" . floattostring($TransportMetal) . "',\n\t\t\t\t\t\t\t`fleet_resource_crystal` = '" . floattostring($TransportCrystal) . "',\n\t\t\t\t\t\t\t`fleet_resource_deuterium` = '" . floattostring($TransportDeuterium) . "',\n\t\t\t\t\t\t\t`fleet_target_owner` = '" . ($planettype == 2 ? 0 : (int) $TargetPlanet['id_owner']) . "',\n\t\t\t\t\t\t\t`fleet_group` = '" . $fleet_group_mr . "',\n\t\t\t\t\t\t\t`start_time` = '" . TIMESTAMP . "';\n\t\t\t\t\t\t\tUPDATE `" . PLANETS . "` SET\n\t\t\t\t\t\t\t" . substr($FleetSubQRY, 0, -2) . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id` = " . $this->PLANET['id'] . " LIMIT 1;\n\t\t\t\t\t\t\tUNLOCK TABLES;";
     $db->multi_query($QryInsertFleet);
     return true;
 }
 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');
 }
示例#13
0
 private function Menus()
 {
     global $PLANET, $LNG, $USER, $CONF;
     //PlanetMenu
     if (empty($this->UserPlanets)) {
         $this->getplanets();
     }
     $this->loadscript("planetmenu.js");
     $this->loadscript("topnav.js");
     $this->execscript("PlanetMenu();");
     $this->phpself = "?page=" . request_var('page', '') . "&amp;mode=" . request_var('mode', '');
     $PlanetSelect = array();
     $Scripttime = array();
     foreach ($this->UserPlanets as $CurPlanetID => $PlanetQuery) {
         if (!empty($PlanetQuery['b_building_id'])) {
             $QueueArray = explode(";", $PlanetQuery['b_building_id']);
             $ActualCount = count($QueueArray);
             for ($ID = 0; $ID < $ActualCount; $ID++) {
                 $ListIDArray = explode(",", $QueueArray[$ID]);
                 if ($ListIDArray[3] > TIMESTAMP) {
                     $Scripttime[$PlanetQuery['id']][] = $ListIDArray[3];
                 }
             }
         }
         $Planetlist[$PlanetQuery['id']] = array('url' => $this->phpself . "&amp;cp=" . $PlanetQuery['id'], 'name' => $PlanetQuery['name'] . ($PlanetQuery['planet_type'] == 3 ? " (" . $LNG['fcm_moon'] . ")" : ""), 'image' => $PlanetQuery['image'], 'galaxy' => $PlanetQuery['galaxy'], 'system' => $PlanetQuery['system'], 'planet' => $PlanetQuery['planet'], 'ptype' => $PlanetQuery['planet_type']);
         $PlanetSelect[$this->phpself . "&amp;cp=" . $PlanetQuery['id']] = $PlanetQuery['name'] . ($PlanetQuery['planet_type'] == 3 ? " (" . $LNG['fcm_moon'] . ")" : "") . "&nbsp;[" . $PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]&nbsp;&nbsp;";
     }
     if ($USER['urlaubs_modus'] == 1) {
         $CONF['metal_basic_income'] = 0;
         $CONF['crystal_basic_income'] = 0;
         $CONF['deuterium_basic_income'] = 0;
         $CONF['norio_basic_income'] = 0;
     }
     $this->assign_vars(array('PlanetMenu' => $Planetlist, 'show_planetmenu' => $LNG['show_planetmenu'], 'current_pid' => $PLANET['id'], 'Scripttime' => json_encode($Scripttime), 'lm_overview' => $LNG['lm_overview'], 'lm_empire' => $LNG['lm_empire'], 'lm_buildings' => $LNG['lm_buildings'], 'lm_resources' => $LNG['lm_resources'], 'lm_trader' => $LNG['lm_trader'], 'lm_fleettrader' => $LNG['lm_fleettrader'], 'lm_research' => $LNG['lm_research'], 'lm_shipshard' => $LNG['lm_shipshard'], 'lm_fleet' => $LNG['lm_fleet'], 'lm_technology' => $LNG['lm_technology'], 'lm_galaxy' => $LNG['lm_galaxy'], 'lm_defenses' => $LNG['lm_defenses'], 'lm_alliance' => $LNG['lm_alliance'], 'lm_forums' => $LNG['lm_forums'], 'lm_officiers' => $LNG['lm_officiers'], 'lm_statistics' => $LNG['lm_statistics'], 'lm_records' => $LNG['lm_records'], 'lm_topkb' => $LNG['lm_topkb'], 'lm_search' => $LNG['lm_search'], 'lm_battlesim' => $LNG['lm_battlesim'], 'lm_messages' => $LNG['lm_messages'], 'lm_notes' => $LNG['lm_notes'], 'lm_buddylist' => $LNG['lm_buddylist'], 'lm_chat' => $LNG['lm_chat'], 'lm_support' => $LNG['lm_support'], 'lm_faq' => $LNG['lm_faq'], 'lm_options' => $LNG['lm_options'], 'lm_banned' => $LNG['lm_banned'], 'lm_rules' => $LNG['lm_rules'], 'lm_logout' => $LNG['lm_logout'], 'new_message' => $USER['new_message'], 'forum_url' => $CONF['forum_url'], 'lm_administration' => $LNG['lm_administration'], 'topnav' => true, 'metal' => $PLANET['metal'], 'crystal' => $PLANET['crystal'], 'deuterium' => $PLANET['deuterium'], 'norio' => $PLANET['norio'], 'energy' => $PLANET["energy_max"] + $PLANET["energy_used"] < 0 ? colorRed(pretty_number($PLANET["energy_max"] + $PLANET["energy_used"]) . "/" . pretty_number($PLANET["energy_max"])) : pretty_number($PLANET["energy_max"] + $PLANET["energy_used"]) . "/" . pretty_number($PLANET["energy_max"]), 'darkmatter' => pretty_number($USER["darkmatter"]), 'metal_max' => shortly_number($PLANET["metal_max"]), 'crystal_max' => shortly_number($PLANET["crystal_max"]), 'deuterium_max' => shortly_number($PLANET["deuterium_max"]), 'norio_max' => shortly_number($PLANET["norio_max"]), 'alt_metal_max' => pretty_number($PLANET["metal_max"]), 'alt_crystal_max' => pretty_number($PLANET["crystal_max"]), 'alt_deuterium_max' => pretty_number($PLANET["deuterium_max"]), 'alt_norio_max' => pretty_number($PLANET["norio_max"]), 'js_metal_max' => floattostring($PLANET["metal_max"]), 'js_crystal_max' => floattostring($PLANET["crystal_max"]), 'js_deuterium_max' => floattostring($PLANET["deuterium_max"]), 'js_norio_max' => floattostring($PLANET["norio_max"]), 'js_metal_hr' => $PLANET['planet_type'] == 1 ? floattostring($PLANET['metal_perhour'] + $CONF['metal_basic_income'] * $CONF['resource_multiplier']) : 0, 'js_crystal_hr' => $PLANET['planet_type'] == 1 ? floattostring($PLANET['crystal_perhour'] + $CONF['crystal_basic_income'] * $CONF['resource_multiplier']) : 0, 'js_deuterium_hr' => $PLANET['planet_type'] == 1 ? floattostring($PLANET['deuterium_perhour'] + $CONF['deuterium_basic_income'] * $CONF['resource_multiplier']) : 0, 'js_norio_hr' => $PLANET['planet_type'] == 1 ? floattostring($PLANET['norio_perhour'] + $CONF['norio_basic_income'] * $CONF['resource_multiplier']) : 0, 'current_planet' => $this->phpself . "&amp;cp=" . $PLANET['id'], 'tn_vacation_mode' => $LNG['tn_vacation_mode'], 'closed' => !$CONF['game_disable'] ? $LNG['ov_closed'] : false, 'vacation' => $USER['urlaubs_modus'] ? date(TDFORMAT, $USER['urlaubs_until']) : false, 'delete' => $USER['db_deaktjava'] ? sprintf($LNG['tn_delete_mode'], date(TDFORMAT, strtotime("+7 day", $USER['db_deaktjava']))) : false, 'image' => $PLANET['image'], 'settings_tnstor' => $USER['settings_tnstor'], 'PlanetSelect' => $PlanetSelect, 'Metal' => $LNG['Metal'], 'Crystal' => $LNG['Crystal'], 'Deuterium' => $LNG['Deuterium'], 'Norio' => $LNG['Norio'], 'Darkmatter' => $LNG['Darkmatter'], 'Energy' => $LNG['Energy']));
 }
 function show()
 {
     global $USER, $PLANET, $LNG, $LANG, $CONF, $UNI;
     $max_users_tickets = 10;
     $ticket_price_metal = 50000000;
     $ticket_price_crystal = 50000000;
     $ticket_price_deuterium = 50000000;
     $this->tplObj->loadscript('jquery.countdown.js');
     $ticket_prize_dm = $CONF['lottery_prize'];
     if ($_POST) {
         $tickets = HTTP::_GP('tickets', 0);
         if ($tickets <= 0 || $tickets > 10) {
             $this->printMessage("Hack attempt , F**K YOU");
             die;
         }
         $cautare = $GLOBALS['DATABASE']->query("SELECT *from `uni1_loteria` where `id` = '" . $USER['id'] . "' ;");
         if ($GLOBALS['DATABASE']->numRows($cautare) > 0) {
             $cautare2 = $GLOBALS['DATABASE']->query("SELECT SUM(tickets) as total_tickets from `uni1_loteria` where `id` = '" . $USER['id'] . "' ;");
             $cautare2 = $GLOBALS['DATABASE']->fetch_array($cautare2);
             if ($cautare2['total_tickets'] + $tickets > $max_users_tickets) {
                 $this->printMessage($LNG['MaximumAB'], true, array('game.php?page=lottery', 2));
                 die;
             }
         }
         $cost['metal'] = $tickets * $ticket_price_metal;
         $cost['crystal'] = $tickets * $ticket_price_crystal;
         $cost['deuterium'] = $tickets * $ticket_price_deuterium;
         if ($PLANET['metal'] < $cost['metal'] || $PLANET['crystal'] < $cost['crystal'] || $PLANET['deuterium'] < $cost['deuterium']) {
             $this->printMessage($LNG['NotEnoRes'], true, array('game.php?page=lottery', 2));
             die;
         } else {
             $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `metal` = `metal` - '" . $cost['metal'] . "', `crystal` = `crystal` - '" . $cost['crystal'] . "', `deuterium` = `deuterium` - '" . $cost['deuterium'] . "' where `id` = '" . $PLANET['id'] . "' AND `universe` = " . $UNI . " ;");
             $GLOBALS['DATABASE']->query("INSERT INTO `uni1_loteria` VALUES ('" . $USER['id'] . "','" . $USER['username'] . "','" . $tickets . "') ;");
             $this->printMessage($LNG['boti'], true, array('game.php?page=lottery', 2));
             die;
         }
     }
     $total_users = $GLOBALS['DATABASE']->query("SELECT DISTINCT `id` from `uni1_loteria` ;");
     $total_users = $GLOBALS['DATABASE']->numRows($total_users);
     if ($CONF['lottery_time'] < TIMESTAMP) {
         if ($total_users < $CONF['lottery_min']) {
             $GLOBALS['DATABASE']->query("UPDATE " . CONFIG . " set `lottery_prize` = `lottery_prize` + 250 ");
             $time = TIMESTAMP + 24 * 60 * 60;
             $GLOBALS['DATABASE']->query("UPDATE `uni1_config` SET `lottery_time` = " . $time . " where `uni` = " . $UNI . ";");
             $this->printMessage("Lottery Postponing from the lack of lottery users.", true, array('game.php?page=lottery', 2));
             die;
         }
         $get_tickets = $GLOBALS['DATABASE']->query("SELECT *FROM `uni1_loteria` ");
         if ($GLOBALS['DATABASE']->numRows($get_tickets) > 0) {
             $user_array = array();
             $diferent_users = $GLOBALS['DATABASE']->query("SELECT DISTINCT `id` from `uni1_loteria` ;");
             while ($s = $GLOBALS['DATABASE']->fetch_array($diferent_users)) {
                 $user_array[] = $s['id'];
             }
             $random = rand(0, count($user_array) - 1);
             do {
                 $random1 = rand(0, count($user_array) - 1);
             } while ($random1 == $random);
             do {
                 $random2 = rand(0, count($user_array) - 1);
             } while ($random2 == $random1 || $random2 == $random);
             $total_user = $GLOBALS['DATABASE']->query("SELECT SUM(tickets) as sum_tickets, user from `uni1_loteria` where `id` = '" . $user_array[$random] . "' ;");
             $total_user1 = $GLOBALS['DATABASE']->query("SELECT SUM(tickets) as sum_tickets, user from `uni1_loteria` where `id` = '" . $user_array[$random1] . "' ;");
             $total_user2 = $GLOBALS['DATABASE']->query("SELECT SUM(tickets) as sum_tickets, user from `uni1_loteria` where `id` = '" . $user_array[$random2] . "' ;");
             $total_user = $GLOBALS['DATABASE']->fetch_array($total_user);
             $total_user1 = $GLOBALS['DATABASE']->fetch_array($total_user1);
             $total_user2 = $GLOBALS['DATABASE']->fetch_array($total_user2);
             $total_user_prize = $ticket_prize_dm * $total_user['sum_tickets'];
             $total_user_prize1 = $ticket_prize_dm / 2 * $total_user1['sum_tickets'];
             $total_user_prize2 = $ticket_prize_dm / 4 * $total_user2['sum_tickets'];
             if ($USER['id'] == $user_array[$random]) {
                 $USER['darkmatter'] += $total_user_prize;
             } else {
                 $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `darkmatter` = `darkmatter` + " . $total_user_prize . " where `id` = '" . $user_array[$random] . "' AND `universe` = '" . $UNI . "';");
             }
             if ($USER['id'] == $user_array[$random1]) {
                 $USER['darkmatter'] += $total_user_prize1;
             } else {
                 $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `darkmatter` = `darkmatter` + " . $total_user_prize1 . " where `id` = '" . $user_array[$random1] . "' AND `universe` = '" . $UNI . "';");
             }
             if ($USER['id'] == $user_array[$random2]) {
                 $USER['darkmatter'] += $total_user_prize2;
             } else {
                 $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `darkmatter` = `darkmatter` + " . $total_user_prize2 . " where `id` = '" . $user_array[$random2] . "' AND `universe` = '" . $UNI . "';");
             }
             $GLOBALS['DATABASE']->query("TRUNCATE TABLE `uni1_loteria_log`;");
             $GLOBALS['DATABASE']->query("INSERT INTO `uni1_loteria_log` VALUES('" . $total_user['user'] . "','" . TIMESTAMP . "','" . $total_user_prize . "') ");
             $GLOBALS['DATABASE']->query("INSERT INTO `uni1_loteria_log` VALUES('" . $total_user1['user'] . "','" . TIMESTAMP . "','" . $total_user_prize1 . "') ");
             $GLOBALS['DATABASE']->query("INSERT INTO `uni1_loteria_log` VALUES('" . $total_user2['user'] . "','" . TIMESTAMP . "','" . $total_user_prize2 . "') ");
             $GLOBALS['DATABASE']->query("TRUNCATE TABLE `uni1_loteria`;");
             SendSimpleMessage($user_array[$random], $user_array[$random], TIMESTAMP, 1, 'Lotery', 'You just won', 'You just won ' . $total_user_prize . ' DM in the lotery');
             //Enviamos el mensaje
             SendSimpleMessage($user_array[$random1], $user_array[$random1], TIMESTAMP, 1, 'Lotery', 'You just won', 'You just won ' . $total_user_prize1 . ' DM in the lotery');
             SendSimpleMessage($user_array[$random2], $user_array[$random2], TIMESTAMP, 1, 'Lotery', 'You just won', 'You just won ' . $total_user_prize2 . ' DM in the lotery');
             $time = TIMESTAMP + 24 * 60 * 60;
             $GLOBALS['DATABASE']->query("UPDATE `uni1_config` SET `lottery_time` = " . $time . " where `uni` = " . $UNI . ";");
             $this->printMessage("Lottery restarting.", true, array('game.php?page=lottery', 2));
             die;
         } else {
             $time = TIMESTAMP + 24 * 60 * 60;
             $GLOBALS['DATABASE']->query("UPDATE `uni1_config` SET `lottery_time` = " . $time . " ;");
             $this->printMessage("No tickets, postponing 2.", true, array('game.php?page=lottery', 2));
             die;
         }
     } else {
         $secs = $CONF['lottery_time'] - TIMESTAMP;
         $diferent_users = $GLOBALS['DATABASE']->query("SELECT DISTINCT `id` from `uni1_loteria` ;");
         if ($GLOBALS['DATABASE']->numRows($diferent_users) > 0) {
             $lista = '<div class="ally_contents"><tr><td>Username</td><td>Tickets Bought</td></tr>';
             while ($s = $GLOBALS['DATABASE']->fetch_array($diferent_users)) {
                 $total_user = $GLOBALS['DATABASE']->query("SELECT user,SUM(tickets) as sum_tickets from `uni1_loteria` where `id` = '" . $s['id'] . "' ;");
                 $total_user = $GLOBALS['DATABASE']->fetch_array($total_user);
                 $lista .= '<tr><td>' . $total_user['user'] . '</td><td>' . $total_user['sum_tickets'] . '</td></tr>';
             }
             $lista .= '</div>';
         } else {
             $lista = "<p><font color='red'>There are no tickets bought</font></p>";
         }
         $castigatori = $GLOBALS['DATABASE']->query("SELECT *FROM `uni1_loteria_log` ORDER BY `time` DESC LIMIT 5");
         if ($GLOBALS['DATABASE']->numRows($castigatori) > 0) {
             $lista_winners = "<table style='width:100%'><tr><td>Winner</td><td>Time</td><td>DM WON</td></tr>";
             while ($x = $GLOBALS['DATABASE']->fetch_array($castigatori)) {
                 $lista_winners .= "<tr><td>" . $x['username'] . "</td><td>" . gmdate("M d Y H:i:s", $x['time']) . "</td><td>" . $x['prize'] . "</td></tr>";
             }
             $lista_winners .= "</table>";
         } else {
             $lista_winners = $LNG['NoWinners'];
         }
         $this->tplObj->assign_vars(array('metal_p' => pretty_number(floattostring($ticket_price_metal)), 'crystal_p' => pretty_number(floattostring($ticket_price_crystal)), 'deuterium_p' => pretty_number(floattostring($ticket_price_deuterium)), 'dm_win' => $ticket_prize_dm, 'secs' => $secs, 'user_lists' => $lista, 'max_tickets_per_player' => $max_users_tickets, 'winners' => $lista_winners, 'minimum_users' => $CONF['lottery_min']));
         $this->display('page.lottery.default.tpl');
     }
 }
    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();
    }
示例#16
0
 public static function sendFleet($fleetArray, $fleetMission, $fleetStartOwner, $fleetStartPlanetID, $fleetStartPlanetGalaxy, $fleetStartPlanetSystem, $fleetStartPlanetPlanet, $fleetStartPlanetType, $fleetTargetOwner, $fleetTargetPlanetID, $fleetTargetPlanetGalaxy, $fleetTargetPlanetSystem, $fleetTargetPlanetPlanet, $fleetTargetPlanetType, $fleetRessource, $fleetPopulation, $fleetStartTime, $fleetStayTime, $fleetEndTime, $fleetGroup = 0, $missleTarget = 0)
 {
     global $resource, $UNI;
     $fleetShipCount = array_sum($fleetArray);
     $fleetData = array();
     $planetQuery = "";
     foreach ($fleetArray as $ShipID => $ShipCount) {
         $fleetData[] = $ShipID . ',' . floattostring($ShipCount);
         $planetQuery[] = $resource[$ShipID] . " = " . $resource[$ShipID] . " - " . floattostring($ShipCount);
     }
     $SQL = "LOCK TABLE " . LOG_FLEETS . " WRITE, " . FLEETS_EVENT . " WRITE, " . FLEETS . " WRITE, " . PLANETS . " WRITE;\n\t\t\t\t   UPDATE " . PLANETS . " SET " . implode(", ", $planetQuery) . " WHERE id = " . $fleetStartPlanetID . ";\n\t\t\t\t   INSERT INTO " . FLEETS . " SET\n\t\t\t\t   fleet_owner              = " . $fleetStartOwner . ",\n\t\t\t\t   fleet_target_owner       = " . $fleetTargetOwner . ",\n\t\t\t\t   fleet_mission            = " . $fleetMission . ",\n\t\t\t\t   fleet_amount             = " . $fleetShipCount . ",\n\t\t\t\t   fleet_array              = '" . implode(';', $fleetData) . "',\n\t\t\t\t   fleet_universe\t        = " . $UNI . ",\n\t\t\t\t   fleet_start_time         = " . $fleetStartTime . ",\n\t\t\t\t   fleet_end_stay           = " . $fleetStayTime . ",\n\t\t\t\t   fleet_end_time           = " . $fleetEndTime . ",\n\t\t\t\t   fleet_start_id           = " . $fleetStartPlanetID . ",\n\t\t\t\t   fleet_start_galaxy       = " . $fleetStartPlanetGalaxy . ",\n\t\t\t\t   fleet_start_system       = " . $fleetStartPlanetSystem . ",\n\t\t\t\t   fleet_start_planet       = " . $fleetStartPlanetPlanet . ",\n\t\t\t\t   fleet_start_type         = " . $fleetStartPlanetType . ",\n\t\t\t\t   fleet_end_id             = " . $fleetTargetPlanetID . ",\n\t\t\t\t   fleet_end_galaxy         = " . $fleetTargetPlanetGalaxy . ",\n\t\t\t\t   fleet_end_system         = " . $fleetTargetPlanetSystem . ",\n\t\t\t\t   fleet_end_planet         = " . $fleetTargetPlanetPlanet . ",\n\t\t\t\t   fleet_end_type           = " . $fleetTargetPlanetType . ",\n\t\t\t\t   fleet_resource_metal     = " . $fleetRessource[901] . ",\n\t\t\t\t   fleet_resource_crystal   = " . $fleetRessource[902] . ",\n\t\t\t\t   fleet_resource_deuterium = " . $fleetRessource[903] . ",\n\t\t\t\t   fleet_resource_elyrium = " . $fleetRessource[904] . ",\n\t\t\t\t   fleet_population_301 = " . $fleetPopulation[301] . ",\n\t\t\t\t   fleet_population_302 = " . $fleetPopulation[302] . ",\n\t\t\t\t   fleet_population_303 = " . $fleetPopulation[303] . ",\n\t\t\t\t   fleet_population_304 = " . $fleetPopulation[304] . ",\n\t\t\t\t   fleet_population_305 = " . $fleetPopulation[305] . ",\n\t\t\t\t   fleet_population_306 = " . $fleetPopulation[306] . ",\n\t\t\t\t   fleet_population_307 = " . $fleetPopulation[307] . ",\n\t\t\t\t   fleet_population_309 = " . $fleetPopulation[309] . ",\n\t\t\t\t   fleet_group              = " . $fleetGroup . ",\n\t\t\t\t   fleet_target_obj         = " . $missleTarget . ",\n\t\t\t\t   start_time               = " . TIMESTAMP . ";\n\t\t\t\t   SET @fleetID = LAST_INSERT_ID();\n                   INSERT INTO " . FLEETS_EVENT . " SET \n\t\t\t\t   fleetID                  = @fleetID,\n\t\t\t\t   `time`                   = " . $fleetStartTime . ";\n\t\t\t\t   INSERT INTO " . LOG_FLEETS . " SET \n\t\t\t\t   fleet_id                 = @fleetID, \n\t\t\t\t   fleet_owner              = " . $fleetStartOwner . ",\n\t\t\t\t   fleet_target_owner       = " . $fleetTargetOwner . ",\n\t\t\t\t   fleet_mission            = " . $fleetMission . ",\n\t\t\t\t   fleet_amount             = " . $fleetShipCount . ",\n\t\t\t\t   fleet_array              = '" . implode(',', $fleetData) . "',\n\t\t\t\t   fleet_universe\t        = " . $UNI . ",\n\t\t\t\t   fleet_start_time         = " . $fleetStartTime . ",\n\t\t\t\t   fleet_end_stay           = " . $fleetStayTime . ",\n\t\t\t\t   fleet_end_time           = " . $fleetEndTime . ",\n\t\t\t\t   fleet_start_id           = " . $fleetStartPlanetID . ",\n\t\t\t\t   fleet_start_galaxy       = " . $fleetStartPlanetGalaxy . ",\n\t\t\t\t   fleet_start_system       = " . $fleetStartPlanetSystem . ",\n\t\t\t\t   fleet_start_planet       = " . $fleetStartPlanetPlanet . ",\n\t\t\t\t   fleet_start_type         = " . $fleetStartPlanetType . ",\n\t\t\t\t   fleet_end_id             = " . $fleetTargetPlanetID . ",\n\t\t\t\t   fleet_end_galaxy         = " . $fleetTargetPlanetGalaxy . ",\n\t\t\t\t   fleet_end_system         = " . $fleetTargetPlanetSystem . ",\n\t\t\t\t   fleet_end_planet         = " . $fleetTargetPlanetPlanet . ",\n\t\t\t\t   fleet_end_type           = " . $fleetTargetPlanetType . ",\n\t\t\t\t   fleet_resource_metal     = " . $fleetRessource[901] . ",\n\t\t\t\t   fleet_resource_crystal   = " . $fleetRessource[902] . ",\n\t\t\t\t   fleet_resource_deuterium = " . $fleetRessource[903] . ",\n\t\t\t\t   fleet_resource_elyrium = " . $fleetRessource[904] . ",\n\t\t\t\t   fleet_population_301 = " . $fleetPopulation[301] . ",\n\t\t\t\t   fleet_population_302 = " . $fleetPopulation[302] . ",\n\t\t\t\t   fleet_population_303 = " . $fleetPopulation[303] . ",\n\t\t\t\t   fleet_population_304 = " . $fleetPopulation[304] . ",\n\t\t\t\t   fleet_population_305 = " . $fleetPopulation[305] . ",\n\t\t\t\t   fleet_population_306 = " . $fleetPopulation[306] . ",\n\t\t\t\t   fleet_population_307 = " . $fleetPopulation[307] . ",\n\t\t\t\t   fleet_population_309 = " . $fleetPopulation[309] . ",\n\t\t\t\t   fleet_group              = " . $fleetGroup . ",\n\t\t\t\t   fleet_target_obj         = " . $missleTarget . ",\n\t\t\t\t   start_time               = " . TIMESTAMP . ";\n\t\t\t\t   UNLOCK TABLES;";
     $GLOBALS['DATABASE']->multi_query($SQL);
 }
示例#17
0
function ShowAccountEditorPage()
{
    global $USER, $db, $LNG, $reslist, $resource, $UNI;
    $template = new template();
    switch ($_GET['edit']) {
        case 'resources':
            $id = request_var('id', 0);
            $id_dark = request_var('id_dark', 0);
            $metal = floattostring(round(abs(request_var('metal', 0.0)), 0));
            $cristal = floattostring(round(abs(request_var('cristal', 0.0)), 0));
            $deut = floattostring(round(abs(request_var('deut', 0.0)), 0));
            $norio = floattostring(round(abs(request_var('norio', 0.0)), 0));
            $dark = request_var('dark', 0);
            if ($_POST) {
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`metal` = `metal` + '" . $metal . "', ";
                    $SQL .= "`crystal` = `crystal` + '" . $cristal . "', ";
                    $SQL .= "`deuterium` = `deuterium` + '" . $deut . "', ";
                    $SQL .= "`norio` = `norio` + '" . $norio . "' ";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` + '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "' AND `universe` = '" . $_SESSION['adminuni'] . "' ";
                        $db->query($SQL);
                    }
                    $template->message($LNG['ad_add_sucess'], '?page=accounteditor&edit=resources');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`metal` = `metal` - '" . $metal . "', ";
                    $SQL .= "`crystal` = `crystal` - '" . $cristal . "', ";
                    $SQL .= "`deuterium` = `deuterium` - '" . $deut . "', ";
                    $SQL .= "`norio` = `norio` - '" . $norio . "' ";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` - '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "';";
                        $db->query($SQL);
                    }
                    $template->message($LNG['ad_delete_sucess'], '?page=accounteditor&edit=resources');
                }
                exit;
            }
            $template->assign_vars(array('button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'Metal' => $LNG['Metal'], 'Crystal' => $LNG['Crystal'], 'Deuterium' => $LNG['Deuterium'], 'Norio' => $LNG['Norio'], 'Darkmatter' => $LNG['Darkmatter'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_user' => $LNG['input_id_user'], 'resources_title' => $LNG['resources_title'], 'input_id_p_m' => $LNG['input_id_p_m']));
            $template->show('adm/AccountEditorPageResources.tpl');
            break;
        case 'ships':
            if ($_POST) {
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_add_sucess_ships'], '?page=accounteditor&edit=ships');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_delete_sucess_ships'], '?page=accounteditor&edit=ships');
                }
                exit;
            }
            $parse['ships'] = "";
            foreach ($reslist['fleet'] as $ID) {
                $INPUT[$ID] = array('name' => $LNG['tech'][$ID], 'type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT, 'button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_p_m' => $LNG['input_id_p_m'], 'ships_title' => $LNG['ad_ships_title'], 'ad_number' => $LNG['ad_number'], 'ships_count' => $LNG['ad_count']));
            $template->show('adm/AccountEditorPageShips.tpl');
            break;
        case 'defenses':
            if ($_POST) {
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_add_defenses_succes'], '?page=accounteditor&edit=defenses');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $Name = $LNG['log_nomoree'];
                    $template->message($LNG['ad_delete_defenses_succes'], '?page=accounteditor&edit=defenses');
                }
                exit;
            }
            foreach ($reslist['defense'] as $ID) {
                $INPUT[$ID] = array('name' => $LNG['tech'][$ID], 'type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT, 'button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_p_m' => $LNG['input_id_p_m'], 'defenses_title' => $LNG['ad_defenses_title'], 'ad_number' => $LNG['ad_number'], 'defenses_count' => $LNG['ad_count']));
            $template->show('adm/AccountEditorPageDefenses.tpl');
            break;
            break;
        case 'buildings':
            if ($_POST) {
                $PlanetData = $db->uniquequery("SELECT `planet_type` FROM " . PLANETS . " WHERE `id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                if (!isset($PlanetData)) {
                    $template->message($LNG['ad_add_not_exist'], '?page=accounteditor&edit=buildings');
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_add_succes'], '?page=accounteditor&edit=buildings');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_delete_succes'], '?page=accounteditor&edit=buildings');
                }
                exit;
            }
            foreach ($reslist['build'] as $ID) {
                $INPUT[$ID] = array('name' => $LNG['tech'][$ID], 'type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT, 'button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_p_m' => $LNG['input_id_p_m'], 'buildings_title' => $LNG['ad_buildings_title'], 'ad_number' => $LNG['ad_number'], 'ad_levels' => $LNG['ad_levels']));
            $template->show('adm/AccountEditorPageBuilds.tpl');
            break;
        case 'researchs':
            if ($_POST) {
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_add_succes'], '?page=accounteditor&edit=researchs');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_delete_succes'], '?page=accounteditor&edit=researchs');
                }
                exit;
            }
            foreach ($reslist['tech'] as $ID) {
                $INPUT[$ID] = array('name' => $LNG['tech'][$ID], 'type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT, 'button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_user' => $LNG['input_id_user'], 'research_title' => $LNG['ad_research_title'], 'ad_number' => $LNG['ad_number'], 'research_count' => $LNG['ad_count']));
            $template->show('adm/AccountEditorPageResearch.tpl');
            break;
        case 'personal':
            if ($_POST) {
                $id = request_var('id', 0);
                $username = request_var('username', '', UTF8_SUPPORT);
                $password = request_var('password', '', true);
                $email = request_var('email', '');
                $email_2 = request_var('email_2', '');
                $vacation = request_var('vacation', '');
                $PersonalQuery = "UPDATE " . USERS . " SET ";
                if (!empty($username) && $id != 1) {
                    $PersonalQuery .= "`username` = '" . $db->sql_escape($username) . "', ";
                }
                if (!empty($email) && $id != 1) {
                    $PersonalQuery .= "`email` = '" . $db->sql_escape($email) . "', ";
                }
                if (!empty($email_2) && $id != 1) {
                    $PersonalQuery .= "`email_2` = '" . $db->sql_escape($email_2) . "', ";
                }
                if (!empty($password) && $id != 1) {
                    $PersonalQuery .= "`password` = '" . $db->sql_escape(md5($password)) . "', ";
                }
                $Answer = 0;
                $TimeAns = 0;
                if ($vacation == 'yes') {
                    $Answer = 1;
                    $TimeAns = TIMESTAMP + $_POST['d'] * 86400 + $_POST['h'] * 3600 + $_POST['m'] * 60 + $_POST['s'];
                }
                $PersonalQuery .= "`urlaubs_modus` = '" . $Answer . "', `urlaubs_until` = '" . $TimeAns . "' ";
                $PersonalQuery .= "WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "'";
                $db->query($PersonalQuery);
                $template->message($LNG['ad_personal_succes'], '?page=accounteditor&edit=personal');
                exit;
            }
            $template->assign_vars(array('button_submit' => $LNG['button_submit'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id' => $LNG['input_id'], 'ad_personal_vacat' => $LNG['ad_personal_vacat'], 'ad_personal_email2' => $LNG['ad_personal_email2'], 'ad_personal_email' => $LNG['ad_personal_email'], 'ad_personal_pass' => $LNG['ad_personal_pass'], 'ad_personal_name' => $LNG['ad_personal_name'], 'ad_personal_title' => $LNG['ad_personal_title'], 'time_seconds' => $LNG['time_seconds'], 'time_minutes' => $LNG['time_minutes'], 'time_hours' => $LNG['time_hours'], 'time_days' => $LNG['time_days'], 'Selector' => array('' => $LNG['select_option'], 'yes' => $LNG['one_is_yes'][1], 'no' => $LNG['one_is_yes'][0])));
            $template->show('adm/AccountEditorPagePersonal.tpl');
            break;
        case 'officiers':
            if ($_POST) {
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['dmfunc'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_offi_succes_add'], '?page=accounteditor&edit=officiers');
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['dmfunc'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . floattostring(round(abs(request_var($resource[$ID], 0.0)), 0)) . "'";
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . request_var('id', 0) . "' AND `universe` = '" . $_SESSION['adminuni'] . "';";
                    $db->query($SQL);
                    $template->message($LNG['ad_offi_succes_delete'], '?page=accounteditor&edit=officiers');
                }
                exit;
            }
            foreach ($reslist['dmfunc'] as $ID) {
                $INPUT[$ID] = array('name' => $LNG['tech'][$ID], 'type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT, 'button_reset' => $LNG['button_reset'], 'button_delete' => $LNG['button_delete'], 'button_add' => $LNG['button_add'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'input_id_user' => $LNG['input_id_user'], 'officiers_title' => $LNG['ad_offi_title'], 'ad_number' => $LNG['ad_number'], 'officiers_count' => $LNG['ad_count']));
            $template->show('adm/AccountEditorPageOfficiers.tpl');
            break;
        case 'planets':
            if ($_POST) {
                $id = request_var('id', 0);
                $name = request_var('name', '', UTF8_SUPPORT);
                $diameter = request_var('diameter', 0);
                $fields = request_var('fields', 0);
                $buildings = request_var('0_buildings', '');
                $ships = request_var('0_ships', '');
                $defenses = request_var('0_defenses', '');
                $c_hangar = request_var('0_c_hangar', '');
                $c_buildings = request_var('0_c_buildings', '');
                $change_pos = request_var('change_position', '');
                $galaxy = request_var('g', 0);
                $system = request_var('s', 0);
                $planet = request_var('p', 0);
                if (!empty($name)) {
                    $db->query("UPDATE " . PLANETS . " SET `name` = '" . $db->sql_escape($name) . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($buildings == 'on') {
                    foreach ($reslist['build'] as $ID) {
                        $BUILD[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $db->query("UPDATE " . PLANETS . " SET " . implode(', ', $BUILD) . " WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($ships == 'on') {
                    foreach ($reslist['fleet'] as $ID) {
                        $SHIPS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $db->query("UPDATE " . PLANETS . " SET " . implode(', ', $SHIPS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($defenses == 'on') {
                    foreach ($reslist['defense'] as $ID) {
                        $DEFS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $db->query("UPDATE " . PLANETS . " SET " . implode(', ', $DEFS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($c_hangar == 'on') {
                    $db->query("UPDATE " . PLANETS . " SET `b_hangar` = '0', `b_hangar_plus` = '0', `b_hangar_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($c_buildings == 'on') {
                    $db->query("UPDATE " . PLANETS . " SET `b_building` = '0', `b_building_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if (!empty($diameter)) {
                    $db->query("UPDATE " . PLANETS . " SET `diameter` = '" . $diameter . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if (!empty($fields)) {
                    $db->query("UPDATE " . PLANETS . " SET `field_max` = '" . $fields . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if ($change_pos == 'on' && $galaxy > 0 && $system > 0 && $planet > 0 && $galaxy <= MAX_GALAXY_IN_WORLD && $system <= MAX_SYSTEM_IN_GALAXY && $planet <= MAX_PLANET_IN_SYSTEM) {
                    $P = $db->uniquequery("SELECT galaxy,system,planet,planet_type FROM " . PLANETS . " WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                    if ($P['planet_type'] == '1') {
                        if (CheckPlanetIfExist($galaxy, $system, $planet, $UNI, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets3'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $db->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                    } else {
                        if (CheckPlanetIfExist($galaxy, $system, $planet, $UNI, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets5'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $Target = $db->uniquequery("SELECT id_luna FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND `planet_type` = '1';");
                        if ($Target['id_luna'] != '0') {
                            $template->message($LNG['ad_pla_error_planets4'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $db->multi_query("UPDATE " . PLANETS . " SET `id_luna` = '0' WHERE `galaxy` = '" . $P['galaxy'] . "' AND `system` = '" . $P['system'] . "' AND `planet` = '" . $P['planet'] . "' AND `planet_type` = '1';UPDATE " . PLANETS . " SET `id_luna` = '" . $id . "'  WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND planet_type = '1';UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                        $QMOON2 = $db->uniquequery("SELECT id_level, id_owner FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "';");
                        $db->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "', `id_owner` = '" . $QMOON2['id_owner'] . "', `id_level` = '" . $QMOON2['id_level'] . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "' AND `planet_type` = '3';");
                    }
                }
                $template->message($LNG['ad_pla_succes'], '?page=accounteditor&edit=planets');
                exit;
            }
            $template->assign_vars(array('button_submit' => $LNG['button_submit'], 'button_reset' => $LNG['button_reset'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'ad_pla_title' => $LNG['ad_pla_title'], 'input_id_p_m' => $LNG['input_id_p_m'], 'ad_pla_edit_name' => $LNG['ad_pla_edit_name'], 'ad_pla_edit_diameter' => $LNG['ad_pla_edit_diameter'], 'ad_pla_edit_fields' => $LNG['ad_pla_edit_fields'], 'ad_pla_delete_b' => $LNG['ad_pla_delete_b'], 'ad_pla_delete_s' => $LNG['ad_pla_delete_s'], 'ad_pla_delete_d' => $LNG['ad_pla_delete_d'], 'ad_pla_delete_hd' => $LNG['ad_pla_delete_hd'], 'ad_pla_delete_cb' => $LNG['ad_pla_delete_cb'], 'ad_pla_title_l' => $LNG['ad_pla_title_l'], 'ad_pla_change_p' => $LNG['ad_pla_change_p'], 'ad_pla_change_pp' => $LNG['ad_pla_change_pp']));
            $template->show('adm/AccountEditorPagePlanets.tpl');
            break;
        case 'alliances':
            if ($_POST) {
                $id = request_var('id', 0);
                $name = request_var('name', '', UTF8_SUPPORT);
                $changeleader = request_var('changeleader', 0);
                $tag = request_var('tag', '', UTF8_SUPPORT);
                $externo = request_var('externo', '', true);
                $interno = request_var('interno', '', true);
                $solicitud = request_var('solicitud', '', true);
                $delete = request_var('delete', '');
                $delete_u = request_var('delete_u', '');
                #$QueryF	=	$db->uniquequery("SELECT * FROM ".ALLIANCE." WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';");
                $QueryF = $db->uniquequery("SELECT * FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';");
                if (!empty($name)) {
                    #$db->multi_query("UPDATE ".ALLIANCE." SET `ally_name` = '".$name."' WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';UPDATE ".USERS." SET `ally_name` = '".$name."' WHERE `ally_id` = '".$id."';");
                    $db->multi_query("UPDATE " . ALLIANCE . " SET `ally_name` = '" . $name . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';UPDATE " . USERS . " SET `ally_name` = '" . $name . "' WHERE `ally_id` = '" . $id . "';");
                }
                if (!empty($tag)) {
                    #$db->query("UPDATE ".ALLIANCE." SET `ally_tag` = '".$tag."' WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';");
                    $db->query("UPDATE " . ALLIANCE . " SET `ally_tag` = '" . $tag . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';");
                }
                $QueryF2 = $db->uniquequery("SELECT ally_id FROM " . USERS . " WHERE `id` = '" . $changeleader . "';");
                #$db->multi_query("UPDATE ".ALLIANCE." SET `ally_owner` = '".$changeleader."' WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';UPDATE ".USERS." SET `ally_rank_id` = '0' WHERE `id` = '".$changeleader."';");
                $db->multi_query("UPDATE " . ALLIANCE . " SET `ally_owner` = '" . $changeleader . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';UPDATE " . USERS . " SET `ally_rank_id` = '0' WHERE `id` = '" . $changeleader . "';");
                if (!empty($externo)) {
                    #$db->query("UPDATE ".ALLIANCE." SET `ally_description` = '".$externo."' WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';");
                    $db->query("UPDATE " . ALLIANCE . " SET `ally_description` = '" . $externo . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if (!empty($interno)) {
                    #$db->query("UPDATE ".ALLIANCE." SET `ally_text` = '".$interno."' WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';");
                    $db->query("UPDATE " . ALLIANCE . " SET `ally_text` = '" . $interno . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';");
                }
                if (!empty($solicitud)) {
                    $db->query("UPDATE " . ALLIANCE . " SET `ally_request` = '" . $solicitud . "' WHERE `id` = '" . $id . "' AND `universe` = '" . $_SESSION['adminuni'] . "';");
                }
                #$db->query("UPDATE ".ALLIANCE." SET `ally_request` = '".$solicitud."' WHERE `id` = '".$id."' AND `ally_universe` = '".$_SESSION['adminuni']."';");
                if ($delete == 'on') {
                    #$db->multi_query("DELETE FROM ".ALLIANCE." WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';UPDATE ".USERS." SET `ally_id` = '0', `ally_name` = '', `ally_request` = '0', `ally_rank_id` = '0', `ally_register_time` = '0', `ally_request` = '0' WHERE `ally_id` = '".$id."';");
                    $db->multi_query("DELETE FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_name` = '', `ally_request` = '0', `ally_rank_id` = '0', `ally_register_time` = '0', `ally_request` = '0' WHERE `ally_id` = '" . $id . "';");
                }
                if (!empty($delete_u)) {
                    #$db->multi_query("UPDATE ".ALLIANCE." SET `ally_members` = ally_members - 1 WHERE `id` = '".$id."' AND `universe` = '".$_SESSION['adminuni']."';UPDATE ".USERS." SET `ally_id` = '0', `ally_name` = '', `ally_request` = '0', `ally_rank_id` = '0', `ally_register_time` = '0', `ally_request` = '0' WHERE `id` = '".$delete_u."' AND `ally_id` = '".$id."';");
                    $db->multi_query("UPDATE " . ALLIANCE . " SET `ally_members` = ally_members - 1 WHERE `id` = '" . $id . "' AND `ally_universe` = '" . $_SESSION['adminuni'] . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_name` = '', `ally_request` = '0', `ally_rank_id` = '0', `ally_register_time` = '0', `ally_request` = '0' WHERE `id` = '" . $delete_u . "' AND `ally_id` = '" . $id . "';");
                }
                $template->message($LNG['ad_ally_succes'], '?page=accounteditor&edit=alliances');
                exit;
            }
            $template->assign_vars(array('button_submit' => $LNG['button_submit'], 'ad_back_to_menu' => $LNG['ad_back_to_menu'], 'ad_pla_title' => $LNG['ad_pla_title'], 'ad_ally_title' => $LNG['ad_ally_title'], 'input_id_ally' => $LNG['input_id_ally'], 'ad_ally_change_id' => $LNG['ad_ally_change_id'], 'ad_ally_name' => $LNG['ad_ally_name'], 'ad_ally_tag' => $LNG['ad_ally_tag'], 'ad_ally_delete_u' => $LNG['ad_ally_delete_u'], 'ad_ally_user_id' => $LNG['ad_ally_user_id'], 'ad_ally_delete' => $LNG['ad_ally_delete'], 'ad_ally_text1' => $LNG['ad_ally_text1'], 'ad_ally_text2' => $LNG['ad_ally_text2'], 'ad_ally_text3' => $LNG['ad_ally_text3']));
            $template->show('adm/AccountEditorPageAlliance.tpl');
            break;
        default:
            $template->assign_vars(array('ad_editor_personal' => $LNG['ad_editor_personal'], 'ad_editor_alliances' => $LNG['ad_editor_alliances'], 'ad_editor_planets' => $LNG['ad_editor_planets'], 'ad_editor_resources' => $LNG['ad_editor_resources'], 'ad_editor_officiers' => $LNG['ad_editor_officiers'], 'ad_editor_researchs' => $LNG['ad_editor_researchs'], 'ad_editor_defenses' => $LNG['ad_editor_defenses'], 'ad_editor_ships' => $LNG['ad_editor_ships'], 'ad_editor_buildings' => $LNG['ad_editor_buildings'], 'ad_editor_title' => $LNG['ad_editor_title']));
            $template->show('adm/AccountEditorPageMenu.tpl');
            break;
    }
}
 private function CreateFleetPopupedFleetLink($fleetRow, $Text, $FleetType)
 {
     global $LNG, $USER, $resource;
     $SpyTech = $USER[$resource[106]];
     $Owner = $fleetRow['fleet_owner'] == $this->UserID;
     $FleetRec = explode(';', $fleetRow['fleet_array']);
     $FleetPopup = '<a href="#" data-tooltip-content="<table style=\'width:200px\'>';
     $textForBlind = '';
     if ($this->IsPhalanx || $SpyTech >= 4 || $Owner) {
         if ($SpyTech < 8 && !$Owner) {
             $FleetPopup .= '<tr><td style=\'width:100%;color:white\'>' . $LNG['cff_aproaching'] . $fleetRow['fleet_amount'] . $LNG['cff_ships'] . ':</td></tr>';
             $textForBlind = $LNG['cff_aproaching'] . $fleetRow['fleet_amount'] . $LNG['cff_ships'] . ': ';
         }
         $shipsData = array();
         foreach ($FleetRec as $Item => $Group) {
             if (empty($Group)) {
                 continue;
             }
             $Ship = explode(',', $Group);
             if ($Owner) {
                 $FleetPopup .= '<tr><td style=\'width:50%;color:white\'>' . $LNG['tech'][$Ship[0]] . ':</td><td style=\'width:50%;color:white\'>' . pretty_number($Ship[1]) . '</td></tr>';
                 $shipsData[] = floattostring($Ship[1]) . ' ' . $LNG['tech'][$Ship[0]];
             } else {
                 if ($SpyTech >= 8) {
                     $FleetPopup .= '<tr><td style=\'width:50%;color:white\'>' . $LNG['tech'][$Ship[0]] . ':</td><td style=\'width:50%;color:white\'>' . pretty_number($Ship[1]) . '</td></tr>';
                     $shipsData[] = floattostring($Ship[1]) . ' ' . $LNG['tech'][$Ship[0]];
                 } else {
                     $FleetPopup .= '<tr><td style=\'width:100%;color:white\'>' . $LNG['tech'][$Ship[0]] . '</td></tr>';
                     $shipsData[] = $LNG['tech'][$Ship[0]];
                 }
             }
         }
         $textForBlind .= implode('; ', $shipsData);
     } else {
         $FleetPopup .= '<tr><td style=\'width:100%;color:white\'>' . $LNG['cff_no_fleet_data'] . '</span></td></tr>';
         $textForBlind = $LNG['cff_no_fleet_data'];
     }
     $FleetPopup .= '</table>" class="tooltip ' . $FleetType . '">' . $Text . '</a>';
     return $FleetPopup;
 }
 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');
 }
示例#20
0
 public final function MakeStats()
 {
     global $db, $CONF;
     $this->DeleteSome();
     $AllyPoints = array();
     $UserPoints = array();
     $TotalData = $this->GetUsersInfosFromDB();
     $FinalSQL = 'TRUNCATE TABLE ' . STATPOINTS . ';';
     $FinalSQL .= "INSERT INTO " . STATPOINTS . " (`id_owner`, `id_ally`, `stat_type`, `universe`, `tech_old_rank`, `tech_points`, `tech_count`, `build_old_rank`, `build_points`, `build_count`, `defs_old_rank`, `defs_points`, `defs_count`, `fleet_old_rank`, `fleet_points`, `fleet_count`, `total_old_rank`, `total_points`, `total_count`) VALUES ";
     while ($PlanetData = $db->fetch_array($TotalData['Planets'])) {
         if (in_array($CONF['stat'], array(1, 2)) && $PlanetData['authlevel'] >= $CONF['stat_level'] || !empty($PlanetData['bana'])) {
             continue;
         }
         if (!isset($UserPoints[$PlanetData['id_owner']])) {
             $UserPoints[$PlanetData['id_owner']]['build']['count'] = $UserPoints[$PlanetData['id_owner']]['build']['points'] = $UserPoints[$PlanetData['id_owner']]['fleet']['count'] = $UserPoints[$PlanetData['id_owner']]['fleet']['points'] = $UserPoints[$PlanetData['id_owner']]['defense']['count'] = $UserPoints[$PlanetData['id_owner']]['defense']['points'] = 0;
         }
         $BuildPoints = $this->GetBuildPoints($PlanetData);
         $FleetPoints = $this->GetFleetPoints($PlanetData);
         $DefensePoints = $this->GetDefensePoints($PlanetData);
         $UserPoints[$PlanetData['id_owner']]['build']['count'] += $BuildPoints['count'];
         $UserPoints[$PlanetData['id_owner']]['build']['points'] += $BuildPoints['points'];
         $UserPoints[$PlanetData['id_owner']]['fleet']['count'] += $FleetPoints['count'];
         $UserPoints[$PlanetData['id_owner']]['fleet']['points'] += $FleetPoints['points'];
         $UserPoints[$PlanetData['id_owner']]['defense']['count'] += $DefensePoints['count'];
         $UserPoints[$PlanetData['id_owner']]['defense']['points'] += $DefensePoints['points'];
     }
     $db->free_result($TotalData['Planets']);
     $UniData = array();
     while ($UserData = $db->fetch_array($TotalData['Users'])) {
         if (!isset($UniData[$UserData['universe']])) {
             $UniData[$UserData['universe']] = 0;
         }
         $UniData[$UserData['universe']]++;
         if (in_array($CONF['stat'], array(1, 2)) && $UserData['authlevel'] >= $CONF['stat_level'] || !empty($UserData['bana'])) {
             $FinalSQL .= "(" . $UserData['id'] . "," . $UserData['ally_id'] . ",1," . $UserData['universe'] . ",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), ";
             continue;
         }
         $TechnoPoints = $this->GetTechnoPoints($UserData);
         $UserPoints[$UserData['id']]['techno']['count'] = $TechnoPoints['count'];
         $UserPoints[$UserData['id']]['techno']['points'] = $TechnoPoints['points'];
         if (isset($TotalData['Fleets'][$UserData['id']])) {
             foreach ($TotalData['Fleets'][$UserData['id']] as $FleetArray) {
                 $FlyingFleetPoints = $this->GetFlyingFleetPoints($FleetArray);
                 $UserPoints[$UserData['id']]['fleet']['count'] += $FlyingFleetPoints['count'];
                 $UserPoints[$UserData['id']]['fleet']['points'] += $FlyingFleetPoints['points'];
             }
         }
         $UserPoints[$UserData['id']]['total']['count'] = $UserPoints[$UserData['id']]['techno']['count'] + $UserPoints[$UserData['id']]['build']['count'] + $UserPoints[$UserData['id']]['defense']['count'] + $UserPoints[$UserData['id']]['fleet']['count'];
         $UserPoints[$UserData['id']]['total']['points'] = $UserPoints[$UserData['id']]['techno']['points'] + $UserPoints[$UserData['id']]['build']['points'] + $UserPoints[$UserData['id']]['defense']['points'] + $UserPoints[$UserData['id']]['fleet']['points'];
         if ($UserData['ally_id'] != 0) {
             if (!isset($AllyPoints[$UserData['ally_id']])) {
                 $AllyPoints[$UserData['ally_id']]['build']['count'] = $AllyPoints[$UserData['ally_id']]['build']['points'] = $AllyPoints[$UserData['ally_id']]['fleet']['count'] = $AllyPoints[$UserData['ally_id']]['fleet']['points'] = $AllyPoints[$UserData['ally_id']]['defense']['count'] = $AllyPoints[$UserData['ally_id']]['defense']['points'] = $AllyPoints[$UserData['ally_id']]['techno']['count'] = $AllyPoints[$UserData['ally_id']]['techno']['points'] = $AllyPoints[$UserData['ally_id']]['total']['count'] = $AllyPoints[$UserData['ally_id']]['total']['points'] = 0;
             }
             $AllyPoints[$UserData['ally_id']]['build']['count'] += $UserPoints[$UserData['id']]['build']['count'];
             $AllyPoints[$UserData['ally_id']]['build']['points'] += $UserPoints[$UserData['id']]['build']['points'];
             $AllyPoints[$UserData['ally_id']]['fleet']['count'] += $UserPoints[$UserData['id']]['fleet']['count'];
             $AllyPoints[$UserData['ally_id']]['fleet']['points'] += $UserPoints[$UserData['id']]['fleet']['points'];
             $AllyPoints[$UserData['ally_id']]['defense']['count'] += $UserPoints[$UserData['id']]['defense']['count'];
             $AllyPoints[$UserData['ally_id']]['defense']['points'] += $UserPoints[$UserData['id']]['defense']['points'];
             $AllyPoints[$UserData['ally_id']]['techno']['count'] += $UserPoints[$UserData['id']]['techno']['count'];
             $AllyPoints[$UserData['ally_id']]['techno']['points'] += $UserPoints[$UserData['id']]['techno']['points'];
             $AllyPoints[$UserData['ally_id']]['total']['count'] += $UserPoints[$UserData['id']]['total']['count'];
             $AllyPoints[$UserData['ally_id']]['total']['points'] += $UserPoints[$UserData['id']]['total']['points'];
         }
         $FinalSQL .= "('" . $UserData['id'] . "','" . $UserData['ally_id'] . "', 1, " . $UserData['universe'] . ", '" . (int) $UserData['old_tech_rank'] . "', '" . floattostring($UserPoints[$UserData['id']]['techno']['points']) . "', '" . floattostring($UserPoints[$UserData['id']]['techno']['count']) . "', '" . (int) $UserData['old_build_rank'] . "','" . floattostring($UserPoints[$UserData['id']]['build']['points']) . "', '" . floattostring($UserPoints[$UserData['id']]['build']['count']) . "', '" . (int) $UserData['old_defs_rank'] . "', '" . floattostring($UserPoints[$UserData['id']]['defense']['points']) . "', '" . floattostring($UserPoints[$UserData['id']]['defense']['count']) . "', '" . (int) $UserData['old_fleet_rank'] . "', '" . floattostring($UserPoints[$UserData['id']]['fleet']['points']) . "', '" . floattostring($UserPoints[$UserData['id']]['fleet']['count']) . "', '" . (int) $UserData['old_total_rank'] . "', '" . floattostring($UserPoints[$UserData['id']]['total']['points']) . "', '" . floattostring($UserPoints[$UserData['id']]['total']['count']) . "'), ";
     }
     $db->free_result($TotalData['Users']);
     $FinalSQL = substr($FinalSQL, 0, -2) . ';';
     $this->SaveDataIntoDB($FinalSQL);
     unset($UserPoints);
     if (count($AllyPoints) != 0) {
         $AllySQL = "INSERT INTO " . STATPOINTS . " (`id_owner`, `id_ally`, `stat_type`, `universe`, `tech_old_rank`, `tech_points`, `tech_count`, `build_old_rank`, `build_points`, `build_count`, `defs_old_rank`, `defs_points`, `defs_count`, `fleet_old_rank`, `fleet_points`, `fleet_count`, `total_old_rank`, `total_points`, `total_count`) VALUES ";
         while ($AllianceData = $db->fetch_array($TotalData['Alliance'])) {
             $AllySQL .= "('" . $AllianceData['id'] . "', 0, 2, " . $AllianceData['ally_universe'] . ",'" . (int) $AllyPoints['old_tech_rank'] . "', '" . floattostring($AllyPoints[$AllianceData['id']]['techno']['points']) . "', '" . floattostring($AllyPoints[$AllianceData['id']]['techno']['count']) . "', '" . (int) $AllianceData['old_build_rank'] . "', '" . floattostring($AllyPoints[$AllianceData['id']]['build']['points']) . "', '" . floattostring($AllyPoints[$AllianceData['id']]['build']['count']) . "', '" . (int) $AllianceData['old_defs_rank'] . "', '" . floattostring($AllyPoints[$AllianceData['id']]['defense']['points']) . "', '" . floattostring($AllyPoints[$AllianceData['id']]['defense']['count']) . "', '" . (int) $AllianceData['old_fleet_rank'] . "', '" . floattostring($AllyPoints[$AllianceData['id']]['fleet']['points']) . "', '" . floattostring($AllyPoints[$AllianceData['id']]['fleet']['count']) . "', '" . (int) $AllianceData['old_total_rank'] . "', '" . floattostring($AllyPoints[$AllianceData['id']]['total']['points']) . "', '" . floattostring($AllyPoints[$AllianceData['id']]['total']['count']) . "'), ";
         }
         unset($AllyPoints);
         $AllySQL = substr($AllySQL, 0, -2) . ';';
         $this->SaveDataIntoDB($AllySQL);
     }
     $db->free_result($TotalData['Alliance']);
     $RankSQL = $this->SetNewRanks();
     $this->SaveDataIntoDB($RankSQL);
     $this->CheckUniverseAccounts($UniData);
     $this->BuildRecordCache();
     $this->AnotherCronJobs();
     return $this->SomeStatsInfos();
 }
示例#21
0
    function EndStayEvent()
    {
        global $pricelist, $reslist;
        $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
        $expeditionPoints = array();
        foreach ($reslist['fleet'] as $ID) {
            $expeditionPoints[$ID] = ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]) / 1000000;
        }
        $expeditionPoints[202] = 12;
        $expeditionPoints[203] = 47;
        $expeditionPoints[204] = 12;
        $expeditionPoints[205] = 110;
        $expeditionPoints[206] = 47;
        $expeditionPoints[207] = 160;
        $fleetRaw = explode(";", $this->_fleet['fleet_array']);
        $fleetPoints = 0;
        $fleetCapacity = 0;
        $find_stardust = 5;
        $fleetArray = array();
        $stardustCount = $GLOBALS['DATABASE']->query("SELECT COUNT(planetarium) as planetarium FROM " . PLANETS . " WHERE id_owner = " . $this->_fleet['fleet_end_id'] . ";");
        $stardustCount = $GLOBALS['DATABASE']->fetch_array($stardustCount);
        $find_stardust = $find_stardust + $stardustCount['planetarium'];
        foreach ($fleetRaw as $Group) {
            if (empty($Group)) {
                continue;
            }
            $Class = explode(",", $Group);
            $fleetArray[$Class[0]] = $Class[1];
            $fleetCapacity += $Class[1] * $pricelist[$Class[0]]['capacity'];
            $fleetPoints += $Class[1] * $expeditionPoints[$Class[0]];
        }
        $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
        /*if($GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['purchase_bonus_timer'] > TIMESTAMP || $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['cosmonaute'] == 1){
        		$GetEvent       = mt_rand(1,7);
        		}else{
        		$GetEvent       = mt_rand(1,6);
        		} */
        $GetEvent = mt_rand(1, 7);
        $combat_bonus = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
        $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)];
        $chancetogetstar = mt_rand(0, 100);
        if ($chancetogetstar < $find_stardust) {
            $find_stardust = 1;
        } else {
            $find_stardust = 0;
        }
        switch ($GetEvent) {
            case 1:
                $WitchFound = mt_rand(1, 3);
                $FindSize = mt_rand(0, 100);
                $Factor = 0;
                if (10 < $FindSize) {
                    $Factor = mt_rand(100, 500) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Factor = mt_rand(520, 1000) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)];
                } elseif (0 == $FindSize) {
                    $Factor = mt_rand(1020, 2000) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)];
                }
                $StatFactor = $GLOBALS['DATABASE']->getFirstRow("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1 AND `universe` = '" . $this->_fleet['fleet_universe'] . "';");
                $MaxPoints = $StatFactor['total'] < 5000000 ? 9000 : 12000;
                $Size = min($Factor * MAX(MIN($fleetPoints / 1000, $MaxPoints), 200), $fleetCapacity);
                switch ($WitchFound) {
                    case 1:
                        $this->UpdateFleet('fleet_resource_metal', $this->_fleet['fleet_resource_metal'] + $Size);
                        break;
                    case 2:
                        $this->UpdateFleet('fleet_resource_crystal', $this->_fleet['fleet_resource_crystal'] + $Size);
                        break;
                    case 3:
                        $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $Size);
                        break;
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                $INFOR = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_users` WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                if ($GLOBALS['DATABASE']->numRows($INFOR) > 0) {
                    while ($xkf = mysqli_fetch_assoc($INFOR)) {
                        $ACTUA = $xkf['expedition_count'];
                        $ACTUAL = 10 * $xkf['achievements_misc_expe'] + 10;
                        $expe_lvl = $xkf['achievements_misc_expe'] + 1;
                        $expe_reward_points = 50;
                        $expe_reward_am = 50;
                        $expe_reward_points = $expe_reward_points + $xkf['achievements_misc_expe'] * $expe_reward_points;
                        $expe_reward_am = $expe_reward_am + $xkf['achievements_misc_expe'] * $expe_reward_am;
                    }
                    if ($ACTUA == $ACTUAL) {
                        $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET achievements_misc_expe = achievements_misc_expe + '1', antimatter = antimatter + " . $expe_reward_am . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                        $msg = '<img alt="" style="float:left; width:60px; margin-right:6px;" src="styles/images/achiev/ach_expedition.png">reached: <span class="achiev_mes_head">expeditions lvl. ' . $expe_lvl . '</span><br> received:<br> ' . $expe_reward_am . ' antimatter <br> ' . $expe_reward_points . ' achievement points';
                        SendSimpleMessage($this->_fleet['fleet_owner'], '', TIMESTAMP, 4, 'System', 'Achievements', $msg);
                    }
                }
                break;
            case 2:
                $FindSize = mt_rand(0, 100);
                $Size = 0;
                if (10 < $FindSize) {
                    $Size = mt_rand(1000, 3000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Size = mt_rand(3001, 6000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 3)];
                } elseif (0 == $FindSize) {
                    $Size = mt_rand(6001, 30000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)];
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
                break;
            case 3:
                $FindSize = mt_rand(0, 100);
                $Size = 0;
                $Message = "";
                if (10 < $FindSize) {
                    $Size = mt_rand(100, 500);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Size = mt_rand(520, 1000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)];
                } elseif (0 == $FindSize) {
                    $Size = mt_rand(1020, 2000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)];
                }
                $StatFactor = $GLOBALS['DATABASE']->getFirstCell("SELECT MAX(total_points) FROM `" . STATPOINTS . "` WHERE `stat_type` = 1 AND `universe` = '" . $this->_fleet['fleet_universe'] . "';");
                $MaxPoints = $StatFactor < 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:
                $Chance = mt_rand(1, 2);
                if ($Chance == 1) {
                    $Points = array(-6, -8, -10);
                    $Which = 1;
                    $Def = -3;
                    $Name = $LNG['sys_expe_attackname_1'];
                    $Add = 0;
                    $Rand = array(5, 3, 2);
                    $DefenderFleetArray = "204,5;206,3;207,2;";
                } else {
                    $Points = array(-7, -9, -11);
                    $Which = 2;
                    $Def = 3;
                    $Name = $LNG['sys_expe_attackname_2'];
                    $Add = 0.1;
                    $Rand = array(4, 3, 2);
                    $DefenderFleetArray = "205,5;215,3;213,2;";
                }
                $messageHTML = <<<HTML
<div class="raportMessage">
<table>
<tr>
<td colspan="2"><a href="CombatReport.php?raport=%s" target="_blank"><span %s>%s %s (%s)</span></a></td>
</tr>
<tr>
<td>%s</td><td><span %s>%s: %s</span>&nbsp;<span %s>%s: %s</span></td>
</tr>
<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span style="color:#a47d7a;">%s</span>&nbsp;</span><span>%s:&nbsp;<span style="color:#5ca6aa;">%s</span>&nbsp;</span><span>%s:&nbsp;<span style="color:#339966;">%s</span></span></td>
\t\t</tr>
<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span style="color:#a47d7a;">%s</font>&nbsp;</span><span>%s:&nbsp;<span style="color:#5ca6aa;">%s</span></span></td>
\t\t</tr>
</table>
</div>
HTML;
                //Minize HTML
                $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML);
                $FindSize = mt_rand(0, 100);
                $maxAttack = 0;
                if (10 < $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_1_' . $Rand[0]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[0], abs($Points[0])) * 0.01;
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_2_' . $Rand[1]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[1], abs($Points[1])) * 0.01;
                } elseif (0 == $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_3_' . $Rand[2]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[2], abs($Points[2])) * 0.01;
                }
                foreach ($fleetArray as $ID => $count) {
                    $DefenderFleetArray .= $ID . "," . round($count * $maxAttack) . ";";
                }
                $AttackerTechno = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                $DefenderTechno = array('id' => 0, 'username' => $Name, 'military_tech' => min($AttackerTechno['military_tech'] + $Def, 0), 'defence_tech' => min($AttackerTechno['defence_tech'] + $Def, 0), 'shield_tech' => min($AttackerTechno['shield_tech'] + $Def, 0), 'laser_tech' => 0, 'ion_tech' => 0, 'plasma_tech' => 0, 'gravity_tech' => 0, 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0, 'experience_combat_level' => min($AttackerTechno['experience_combat_level'], 0), 'academy_1101' => 0, 'academy_1102' => 0, 'academy_1301' => 0, 'academy_1302' => 0, 'academy_1103' => 0, 'academy_1108' => 0, 'academy_1109' => 0, 'academy_1110' => 0, 'academy_1111' => 0, 'academy_1303' => 0, 'academy_1311' => 0);
                $fleetID = $this->_fleet['fleet_id'];
                $fleetAttack[$fleetID]['fleetDetail'] = $this->_fleet;
                $fleetAttack[$fleetID]['player'] = $AttackerTechno;
                $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$this->_fleet['fleet_id']]['player'], 'attack', $this->_fleet['fleet_start_time']);
                $fleetAttack[$fleetID]['unit'] = array();
                $temp = explode(';', $this->_fleet['fleet_array']);
                foreach ($temp as $temp2) {
                    $temp2 = explode(',', $temp2);
                    if ($temp2[0] < 100) {
                        continue;
                    }
                    if (!isset($fleetAttack[$fleetID]['unit'][$temp2[0]])) {
                        $fleetAttack[$fleetID]['unit'][$temp2[0]] = 0;
                    }
                    $fleetAttack[$fleetID]['unit'][$temp2[0]] += $temp2[1];
                }
                $fleetDefend = array();
                $defRowDef = explode(';', $DefenderFleetArray);
                foreach ($defRowDef as $Element) {
                    $Element = explode(',', $Element);
                    if ($Element[0] < 100) {
                        continue;
                    }
                    if (!isset($fleetDefend[0]['unit'][$Element[0]])) {
                        $fleetDefend[0]['unit'][$Element[0]] = 0;
                    }
                    $fleetDefend[0]['unit'][$Element[0]] += $Element[1];
                }
                $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);
                $fleetDefend[0]['player'] = $DefenderTechno;
                $fleetDefend[0]['player']['factor'] = 0;
                require_once 'calculateAttack.php';
                $fleetIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Fleet_Cdr'];
                $defIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Defs_Cdr'];
                $combatResult = calculateAttack($fleetAttack, $fleetDefend, $fleetIntoDebris, $defIntoDebris);
                $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 'GenerateReport.php';
                $debrisRessource = array(901, 902);
                foreach ($debrisRessource as $elementID) {
                    $debris[$elementID] = 0;
                }
                $stealResource = array(901 => 0, 902 => 0, 903 => 0);
                $raportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => 0, 'moonDestroy' => false, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => null);
                $raportData = GenerateReport($combatResult, $raportInfo);
                $raportID = md5(uniqid('', true) . TIMESTAMP);
                $sqlQuery = "INSERT INTO " . RW . " SET rid = '" . $raportID . "', raport = '" . serialize($raportData) . "', time = '" . $this->_fleet['fleet_start_time'] . "', attacker = '" . $this->_fleet['fleet_owner'] . "';";
                $GLOBALS['DATABASE']->query($sqlQuery);
                switch ($combatResult['won']) {
                    case "a":
                        $attackClass = 'style="color:green;"';
                        $defendClass = 'style="color:red;"';
                        break;
                    case "w":
                        $attackClass = 'style="color:orange;"';
                        $defendClass = 'style="color:orange;"';
                        break;
                    case "r":
                        $attackClass = 'style="color:red;"';
                        $defendClass = 'style="color:green;"';
                        break;
                }
                $message = sprintf($messageHTML, $raportID, $attackClass, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $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['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]));
                if ($combatResult['won'] == 'a') {
                    $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                    $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                }
                SendSimpleMessage($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
                $MoreTime = 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 ($MoreTime < 75) {
                    $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) * $Wrapper[mt_rand(0, 9)]));
                    $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)];
                } else {
                    $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_stay'] + max(1, $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'] - ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) / 3 * $Wrapper[mt_rand(0, 9)]));
                    $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)];
                }
                break;
            case 7:
                $FindSize = mt_rand(0, 100);
                if (30 < $FindSize) {
                    $Message = 'You found one frisbee';
                    $varis = 'frisbee';
                } elseif (10 < $FindSize && 30 >= $FindSize) {
                    $Message = 'You found one alien';
                    $varis = 'alien';
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Message = 'You found one rocket';
                    $varis = 'rocket';
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set " . $varis . " = " . $varis . " + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                break;
        }
        SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }
示例#22
0
    function TargetEvent()
    {
        global $resource, $reslist;
        $fleetAttack = array();
        $fleetDefend = array();
        $userAttack = array();
        $userDefend = array();
        $stealResource = array(901 => 0, 902 => 0, 903 => 0, 904 => 0);
        $debris = array();
        $planetDebris = array();
        $raportInfo = array();
        $TargetOwner = $this->_fleet['fleet_target_owner'];
        $StartOwner = $this->_fleet['fleet_owner'];
        $debrisRessource = array(901, 902, 903);
        $SelectCount = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM uni1_buddy WHERE (sender = " . $this->_fleet['fleet_target_owner'] . " AND owner = " . $this->_fleet['fleet_owner'] . " AND state = '1') OR (sender = " . $this->_fleet['fleet_owner'] . " AND owner = " . $this->_fleet['fleet_target_owner'] . " AND state = '1');");
        if ($SelectCount > 0) {
            $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
            $LNG = $this->getLanguage($senderUser['lang']);
            $TheMessage = '<div style="text-align : justify;">
        ' . sprintf($LNG['ls_fts_colo_1'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $LNG['type_missionbis'][$this->_fleet['fleet_mission']]) . '
    </div>
  
    <div class="citation">
        <div class="guillemet ouvrir">«</div>
        <div class="guillemet fermer">»</div>
        
        ' . $LNG['ls_fts_colo_2'] . ' :
        <ul style="text-align : left;">
            <li>' . $LNG['ls_fts_colo_3'] . '</li>
            <li>' . $LNG['ls_fts_colo_4'] . '</li>
            <li>' . $LNG['ls_fts_colo_5'] . '</li>
            <li>' . $LNG['ls_fts_colo_6'] . '</li>
            <li>' . $LNG['ls_fts_colo_7'] . '</li>
            <li>' . $LNG['ls_fts_colo_8'] . '</li>
        </ul>
    </div>
        
    <div class="explication_utilisateur">
        ' . $LNG['ls_fts_colo_9'] . '
    </div>';
            SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_start_time'], 7, $LNG['sys_colo_mess_from_text1'], sprintf($LNG['sys_colo_mess_report1'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $TheMessage);
            $this->setState(FLEET_RETURN);
        } else {
            $messageHTML = <<<HTML
<div class="raportMessage">
\t<table>
\t\t<tr>
\t\t\t<td colspan="2"><a href="CombatReport.php?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="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>%s:&nbsp;<span class="raportSteal element904">%s</span></span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<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>%s:&nbsp;<span class="raportDebris element903">%s</span></span></td>
\t\t</tr>
\t</table>
</div>
HTML;
            //Minize HTML
            $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML);
            $targetPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE id = '" . $this->_fleet['fleet_end_id'] . "';");
            $targetUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = '" . $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) {
                $GLOBALS['DATABASE']->query("DELETE FROM " . AKS . " WHERE id = '" . $this->_fleet['fleet_group'] . "';");
                $incomingFleetsResult = $GLOBALS['DATABASE']->query("SELECT * FROM " . FLEETS . " WHERE fleet_group = '" . $this->_fleet['fleet_group'] . "';");
                while ($incomingFleetsRow = $GLOBALS['DATABASE']->fetch_array($incomingFleetsResult)) {
                    $incomingFleets[$incomingFleetsRow['fleet_id']] = $incomingFleetsRow;
                }
                $GLOBALS['DATABASE']->free_result($incomingFleetsResult);
            } else {
                $incomingFleets = array($this->_fleet['fleet_id'] => $this->_fleet);
            }
            foreach ($incomingFleets as $fleetID => $fleetDetail) {
                $fleetAttack[$fleetID]['fleetDetail'] = $fleetDetail;
                $fleetAttack[$fleetID]['player'] = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = '" . $fleetDetail['fleet_owner'] . "';");
                $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$fleetID]['player'], 'attack', $this->_fleet['fleet_start_time']);
                $fleetAttack[$fleetID]['unit'] = fleetAmountToArray($fleetDetail['fleet_array'] . ';306,' . $fleetDetail['fleet_population_306'] . ';307,' . $fleetDetail['fleet_population_307']);
                $userAttack[$fleetAttack[$fleetID]['player']['id']] = $fleetAttack[$fleetID]['player']['username'];
            }
            $targetFleetsResult = $GLOBALS['DATABASE']->query("SELECT * FROM " . FLEETS . " WHERE fleet_mission = '5' AND fleet_end_id = '" . $this->_fleet['fleet_end_id'] . "' AND fleet_start_time <= '" . TIMESTAMP . "' AND fleet_end_stay >= '" . TIMESTAMP . "';");
            while ($fleetDetail = $GLOBALS['DATABASE']->fetch_array($targetFleetsResult)) {
                $fleetID = $fleetDetail['fleet_id'];
                $fleetDefend[$fleetID]['fleetDetail'] = $fleetDetail;
                $fleetDefend[$fleetID]['player'] = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = '" . $fleetDetail['fleet_owner'] . "';");
                $fleetDefend[$fleetID]['player']['factor'] = getFactors($fleetDefend[$fleetID]['player'], 'attack', $this->_fleet['fleet_start_time']);
                $fleetDefend[$fleetID]['unit'] = fleetAmountToArray($fleetDetail['fleet_array']);
                $userDefend[$fleetDefend[$fleetID]['player']['id']] = $fleetDefend[$fleetID]['player']['username'];
            }
            $GLOBALS['DATABASE']->free_result($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();
            $avaible_fleets = array(202, 203, 209, 223, 219, 210, 204, 205, 206, 207, 211, 214, 215, 216);
            $avaible_def = array(401, 402, 403, 404, 405, 406, 407, 408);
            $avaible_pop = array(306, 307);
            foreach (array_merge($avaible_fleets, $avaible_def, $avaible_pop) 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 'calculateAttack.php';
            $fleetIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Fleet_Cdr'];
            $defIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Defs_Cdr'];
            $combatResult = calculateAttack($fleetAttack, $fleetDefend, $fleetIntoDebris, $defIntoDebris);
            $sqlQuery = "";
            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 {
                        $sqlQuery .= "DELETE FROM " . FLEETS . " WHERE fleet_id = " . $fleetID . ";";
                        $sqlQuery .= "DELETE FROM " . FLEETS_EVENT . " WHERE fleetID = " . $fleetID . ";";
                    }
                    $sqlQuery .= "UPDATE " . LOG_FLEETS . " SET fleet_state = 2 WHERE fleet_id = '" . $fleetID . "';";
                } elseif ($totalCount > 0) {
                    $sqlQuery .= "UPDATE " . FLEETS . " SET fleet_array = '" . substr($fleetArray, 0, -1) . "', fleet_amount = '" . $totalCount . "' WHERE fleet_id = '" . $fleetID . "';";
                    $sqlQuery .= "UPDATE " . LOG_FLEETS . " SET fleet_array = '" . substr($fleetArray, 0, -1) . "', fleet_amount = '" . $totalCount . "', fleet_state = 1 WHERE fleet_id = '" . $fleetID . "';";
                } else {
                    throw new Exception("Negative Fleet amount ....");
                }
            }
            foreach ($fleetDefend as $fleetID => $fleetDetail) {
                if ($fleetID != 0) {
                    $fleetArray = '';
                    $totalCount = 0;
                    $fleetDetail['unit'] = array_filter($fleetDetail['unit']);
                    foreach ($fleetDetail['unit'] as $elementID => $amount) {
                        $fleetArray .= $elementID . ',' . floattostring($amount) . ';';
                        $totalCount += $amount;
                    }
                    if ($totalCount == 0) {
                        $sqlQuery .= "DELETE FROM " . FLEETS . " WHERE fleet_id = " . $fleetID . ";";
                        $sqlQuery .= "DELETE FROM " . FLEETS_EVENT . " WHERE fleetID = " . $fleetID . ";";
                        $sqlQuery .= "UPDATE " . LOG_FLEETS . " SET fleet_state = 2 WHERE fleet_id = '" . $fleetID . "';";
                    } elseif ($totalCount > 0) {
                        $sqlQuery .= "UPDATE " . FLEETS . " SET fleet_array = '" . substr($fleetArray, 0, -1) . "', fleet_amount = '" . $totalCount . "' WHERE fleet_id = '" . $fleetID . "';";
                        $sqlQuery .= "UPDATE " . LOG_FLEETS . " SET fleet_array = '" . substr($fleetArray, 0, -1) . "', fleet_amount = '" . $totalCount . "', fleet_state = 1 WHERE fleet_id = '" . $fleetID . "';";
                    } else {
                        throw new Exception("Negative Fleet amount ....");
                    }
                } else {
                    $fleetArray = array();
                    foreach ($fleetDetail['unit'] as $elementID => $amount) {
                        $fleetArray[] = $resource[$elementID] . " = " . $amount;
                    }
                    if (!empty($fleetArray)) {
                        $sqlQuery .= "UPDATE " . PLANETS . " SET " . implode(', ', $fleetArray) . " WHERE id = '" . $this->_fleet['fleet_end_id'] . "';";
                    }
                }
            }
            $GLOBALS['DATABASE']->multi_query($sqlQuery);
            if ($combatResult['won'] == "a") {
                require_once 'calculateSteal.php';
                $stealResource = calculateSteal($fleetAttack, $targetPlanet);
            }
            if ($this->_fleet['fleet_end_type'] == 3) {
                // Use planet debris, if attack on moons
                $targetPlanet = array_merge($targetPlanet, $GLOBALS['DATABASE']->getFirstRow("SELECT der_metal, der_crystal, der_deuterium FROM " . PLANETS . " WHERE id_luna = " . $this->_fleet['fleet_end_id'] . ";"));
            }
            foreach ($debrisRessource as $elementID) {
                $debris[$elementID] = $combatResult['debris']['attacker'][$elementID] + $combatResult['debris']['defender'][$elementID];
                $planetDebris[$elementID] = $targetPlanet['der_' . $resource[$elementID]] + $debris[$elementID];
            }
            $debrisTotal = array_sum($debris);
            $moonFactor = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['moon_factor'];
            $maxMoonChance = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['moon_chance'];
            if ($targetPlanet['id_luna'] == 0 && $targetPlanet['planet_type'] == 1) {
                $chanceCreateMoon = round($debrisTotal / 100000 * $moonFactor);
                $chanceCreateMoon = min($chanceCreateMoon, $maxMoonChance);
            } else {
                $chanceCreateMoon = 0;
            }
            $raportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => $chanceCreateMoon, 'moonDestroy' => false, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => null);
            $randChance = mt_rand(1, 100);
            if ($randChance <= $chanceCreateMoon) {
                require_once 'includes/functions/CreateOneMoonRecord.php';
                $LNG = $this->getLanguage($targetUser['lang']);
                $raportInfo['moonName'] = $LNG['type_planet'][3];
                /* CreateOneMoonRecord(
                				$this->_fleet['fleet_end_galaxy'],
                				$this->_fleet['fleet_end_system'],
                				$this->_fleet['fleet_end_planet'],
                				$this->_fleet['fleet_universe'],
                				$targetUser['id'],
                				$raportInfo['moonName'],
                				$chanceCreateMoon,
                				$this->_fleet['fleet_start_time']
                			); */
                if ($GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['debris_moon'] == 1) {
                    foreach ($debrisRessource as $elementID) {
                        $planetDebris[$elementID] = 0;
                    }
                }
            }
            require_once 'GenerateReport.php';
            $raportData = GenerateReport($combatResult, $raportInfo);
            switch ($combatResult['won']) {
                case "a":
                    $attackStatus = 'wons';
                    $defendStatus = 'loos';
                    $attackClass = 'raportWin';
                    $defendClass = 'raportLose';
                    break;
                case "w":
                    $attackStatus = 'draws';
                    $defendStatus = 'draws';
                    $attackClass = 'raportDraw';
                    $defendClass = 'raportDraw';
                    break;
                case "r":
                    $attackStatus = 'loos';
                    $defendStatus = 'wons';
                    $attackClass = 'raportLose';
                    $defendClass = 'raportWin';
                    break;
            }
            $raportID = md5(uniqid('', true) . TIMESTAMP);
            $sqlQuery = "INSERT INTO " . RW . " SET \n\t\trid = '" . $raportID . "',\n\t\traport = '" . serialize($raportData) . "',\n\t\ttime = '" . $this->_fleet['fleet_start_time'] . "',\n\t\tattacker = '" . implode(',', array_keys($userAttack)) . "',\n\t\tdefender = '" . implode(',', array_keys($userDefend)) . "';";
            $GLOBALS['DATABASE']->query($sqlQuery);
            $sqlQuery = "";
            foreach ($userAttack as $userID => $userName) {
                $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $userID . ";");
                $LNG = $this->getLanguage($senderUser['lang']);
                $message = sprintf($messageHTML, $raportID, $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['tech'][904], pretty_number($stealResource[904]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902]), $LNG['tech'][903], pretty_number($debris[903]));
                if ($combatResult['won'] == 'a') {
                    $FromSend = sprintf($LNG['sys_mess_tower_space_battle_won'], $this->getUsername($TargetOwner));
                } elseif ($combatResult['won'] == 'r') {
                    $FromSend = sprintf($LNG['sys_mess_tower_space_battle_lost'], $this->getUsername($TargetOwner));
                } else {
                    $FromSend = $LNG['sys_mess_tower'];
                }
                SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $FromSend, $LNG['sys_mess_attack_report'], $message);
                $sqlQuery .= "INSERT INTO " . TOPKB_USERS . " SET ";
                $sqlQuery .= "rid = '" . $raportID . "', ";
                $sqlQuery .= "role = 1, ";
                $sqlQuery .= "username = '******'DATABASE']->escape($userName) . "', ";
                $sqlQuery .= "uid = " . $userID . ";";
            }
            foreach ($userDefend as $userID => $userName) {
                $senderUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $userID . ";");
                $LNG = $this->getLanguage($senderUser['lang']);
                $message = sprintf($messageHTML, $raportID, $defendClass, $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'], $defendClass, $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $attackClass, $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['tech'][904], pretty_number($stealResource[904]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902]), $LNG['tech'][903], pretty_number($debris[903]));
                if ($combatResult['won'] == 'a') {
                    $FromSend = sprintf($LNG['sys_mess_tower_space_battle_won'], $this->getUsername($StartOwner));
                } elseif ($combatResult['won'] == 'r') {
                    $FromSend = sprintf($LNG['sys_mess_tower_space_battle_lost'], $this->getUsername($StartOwner));
                } else {
                    $FromSend = $LNG['sys_mess_tower'];
                }
                SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $FromSend, $LNG['sys_mess_attack_report'], $message);
                $sqlQuery .= "INSERT INTO " . TOPKB_USERS . " SET ";
                $sqlQuery .= "rid = '" . $raportID . "', ";
                $sqlQuery .= "role = 2, ";
                $sqlQuery .= "username = '******'DATABASE']->escape($userName) . "', ";
                $sqlQuery .= "uid = " . $userID . ";";
            }
            if ($this->_fleet['fleet_end_type'] == 3) {
                $debrisType = 'id_luna';
            } else {
                $debrisType = 'id';
            }
            $sqlQuery .= "UPDATE " . PLANETS . " SET\n\t\t\t\t\t\tder_metal = " . $planetDebris[901] . ",\n\t\t\t\t\t\tder_crystal = " . $planetDebris[902] . ",\n\t\t\t\t\t\tder_deuterium = " . $planetDebris[903] . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t" . $debrisType . " = " . $this->_fleet['fleet_end_id'] . ";\n\t\t\t\t\t\tUPDATE " . PLANETS . " SET\n\t\t\t\t\t\tmetal = metal - " . $stealResource[901] . ",\n\t\t\t\t\t\tcrystal = crystal - " . $stealResource[902] . ",\n\t\t\t\t\t\tdeuterium = deuterium - " . $stealResource[903] . ",\n\t\t\t\t\t\telyrium = elyrium - " . $stealResource[904] . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tid = " . $this->_fleet['fleet_end_id'] . ";\n\t\t\t\t\t\tINSERT INTO " . TOPKB . " SET\n\t\t\t\t\t\tunits = " . ($combatResult['unitLost']['attacker'] + $combatResult['unitLost']['defender']) . ",\n\t\t\t\t\t\trid = '" . $raportID . "',\n\t\t\t\t\t\ttime = " . $this->_fleet['fleet_start_time'] . ",\n\t\t\t\t\t\tuniverse = " . $this->_fleet['fleet_universe'] . ",\n\t\t\t\t\t\tresult = '" . $combatResult['won'] . "';\n\t\t\t\t\t\tUPDATE " . USERS . " SET\n\t\t\t\t\t\t" . $attackStatus . " = " . $attackStatus . " + 1,\n\t\t\t\t\t\tkbmetal = kbmetal + " . $debris[901] . ",\n\t\t\t\t\t\tkbcrystal = kbcrystal + " . $debris[902] . ",\n\t\t\t\t\t\tkbdeuterium = kbdeuterium + " . $debris[903] . ",\n\t\t\t\t\t\tlostunits = lostunits + " . $combatResult['unitLost']['attacker'] . ",\n\t\t\t\t\t\tdesunits = desunits + " . $combatResult['unitLost']['defender'] . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tid IN (" . implode(',', array_keys($userAttack)) . ");\n\t\t\t\t\t\tUPDATE " . USERS . " SET\n\t\t\t\t\t\t" . $defendStatus . " = " . $defendStatus . " + 1,\n\t\t\t\t\t\tkbmetal = kbmetal + " . $debris[901] . ",\n\t\t\t\t\t\tkbcrystal = kbcrystal + " . $debris[902] . ",\n\t\t\t\t\t\tkbdeuterium = kbdeuterium + " . $debris[903] . ",\n\t\t\t\t\t\tlostunits = lostunits + " . $combatResult['unitLost']['defender'] . ",\n\t\t\t\t\t\tdesunits = desunits + " . $combatResult['unitLost']['attacker'] . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tid IN (" . implode(',', array_keys($userDefend)) . ");";
            $GLOBALS['DATABASE']->multi_query($sqlQuery);
            $this->setState(FLEET_RETURN);
        }
        $this->SaveFleet();
    }
示例#23
0
function ShowBattleSimPage()
{
    global $USER, $PLANET, $reslist, $pricelist, $LNG, $db, $ExtraDM, $LANG, $CONF;
    $action = request_var('action', '');
    $Slots = request_var('slots', 1);
    if (isset($_REQUEST['im'])) {
        $Array = $_REQUEST['im'];
        foreach ($Array as $ID => $Count) {
            $BattleArray[0][1][$ID] = floattostring($Count);
        }
    } elseif (isset($_REQUEST['battleinput'])) {
        $BattleArray = $_REQUEST['battleinput'];
    } else {
        $BattleArray = array();
    }
    if ($action == 'send') {
        $Counts = array(0, 0);
        foreach ($BattleArray as $BattleSlotID => $BattleSlot) {
            if (isset($BattleSlot[0]) && (array_sum($BattleSlot[0]) > 0 || $BattleSlotID == 0)) {
                $Att = mt_rand(1, 1000);
                $attack[$Att]['fleet'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'metal' => 0, 'crystal' => 0, 'deuterium' => 0);
                $attack[$Att]['user'] = array('username' => $LNG['bs_atter'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[0][109], 'defence_tech' => $BattleSlot[0][110], 'shield_tech' => $BattleSlot[0][111], 0, 'dm_defensive' => 0, 'dm_attack' => 0);
                foreach ($BattleSlot[0] as $ID => $Count) {
                    if (!in_array($ID, $reslist['fleet']) || $BattleSlot[0][$ID] <= 0) {
                        unset($BattleSlot[0][$ID]);
                    }
                }
                if ($Counts[0] == 0 && $BattleSlotID != 0) {
                    exit('ERROR');
                }
                $Counts[0] = $Counts[0] + array_sum($BattleSlot[1]);
                $attack[$Att]['detail'] = $BattleSlot[0];
            }
            if (isset($BattleSlot[1]) && (array_sum($BattleSlot[1]) > 0 || $BattleSlotID == 0)) {
                $Def = mt_rand(1, 1000);
                $defense[$Def]['fleet'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'metal' => 0, 'crystal' => 0, 'deuterium' => 0);
                $defense[$Def]['user'] = array('username' => $LNG['bs_deffer'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[1][109], 'defence_tech' => $BattleSlot[1][110], 'shield_tech' => $BattleSlot[1][111], 0, 'dm_defensive' => 0, 'dm_attack' => 0);
                foreach ($BattleSlot[1] as $ID => $Count) {
                    if (!in_array($ID, $reslist['fleet']) && !in_array($ID, $reslist['defense'])) {
                        unset($BattleSlot[1][$ID]);
                    }
                }
                if ($Countd[1] == 0 && $BattleSlotID != 0) {
                    exit('ERROR');
                }
                $Countd[1] = $Countd[1] + array_sum($BattleSlot[1]);
                $defense[$Def]['def'] = $BattleSlot[1];
            }
        }
        $LANG->includeLang(array('FLEET'));
        require_once ROOT_PATH . 'includes/classes/missions/calculateAttack.php';
        require_once ROOT_PATH . 'includes/classes/missions/calculateSteal.php';
        require_once ROOT_PATH . 'includes/classes/missions/GenerateReport.php';
        $start = microtime(true);
        $result = calculateAttack($attack, $defense, $CONF['Fleet_Cdr'], $CONF['Defs_Cdr']);
        $totaltime = microtime(true) - $start;
        $steal = $result['won'] == "a" ? calculateSteal($attack, array('metal' => $BattleArray[0][1][1], 'crystal' => $BattleArray[0][1][2], 'deuterium' => $BattleArray[0][1][3]), true) : array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);
        $FleetDebris = $result['debree']['att'][0] + $result['debree']['def'][0] + $result['debree']['att'][1] + $result['debree']['def'][1];
        $StrAttackerUnits = sprintf($LNG['sys_attacker_lostunits'], $result['lost']['att']);
        $StrDefenderUnits = sprintf($LNG['sys_defender_lostunits'], $result['lost']['def']);
        $StrRuins = sprintf($LNG['sys_gcdrunits'], $result['debree']['def'][0] + $result['debree']['att'][0], $LNG['Metal'], $result['debree']['def'][1] + $result['debree']['att'][1], $LNG['Crystal']);
        $DebrisField = $StrAttackerUnits . "<br>" . $StrDefenderUnits . "<br>" . $StrRuins;
        $MoonChance = min(round($FleetDebris / 100000, 0), 20);
        $AllSteal = array_sum($steal);
        $RaportInfo = sprintf($LNG['bs_derbis_raport'], ceil($FleetDebris / $pricelist[219]['capacity']), $LNG['tech'][219], ceil($FleetDebris / $pricelist[209]['capacity']), $LNG['tech'][209]) . "<br>";
        $RaportInfo .= sprintf($LNG['bs_steal_raport'], ceil($AllSteal / $pricelist[202]['capacity']), $LNG['tech'][202], ceil($AllSteal / $pricelist[203]['capacity']), $LNG['tech'][203], ceil($AllSteal / $pricelist[217]['capacity']), $LNG['tech'][217]) . "<br>";
        $INFO['moon']['battlesim'] = $RaportInfo;
        $INFO['steal'] = $steal;
        $INFO['fleet_start_time'] = TIMESTAMP;
        $INFO['moon']['des'] = 0;
        $INFO['moon']['chance'] = $MoonChance;
        $raport = GenerateReport($result, $INFO);
        $rid = md5(microtime(true));
        file_put_contents(ROOT_PATH . 'raports/raport_' . $rid . '.php', '<?php' . "\n" . '$raport = ' . $raport . ';' . "\n" . '?>');
        $SQLQuery = "INSERT INTO " . RW . " SET ";
        $SQLQuery .= "`time` = '" . TIMESTAMP . "', ";
        $SQLQuery .= "`owners` = '" . $USER['id'] . ",0', ";
        $SQLQuery .= "`rid` = '" . $rid . "';";
        $db->query($SQLQuery);
        echo $rid;
        exit;
    }
    $PlanetRess = new ResourceUpdate();
    $PlanetRess->CalcResource();
    $PlanetRess->SavePlanetToDB();
    foreach ($reslist['fleet'] as $ID) {
        $GetFleet[$ID] = $LNG['tech'][$ID];
    }
    foreach ($reslist['defense'] as $ID) {
        if ($ID >= 501) {
            break;
        }
        $GetDef[$ID] = $LNG['tech'][$ID];
    }
    $template = new template();
    $template->loadscript('battlesim.js');
    $template->assign_vars(array('lm_battlesim' => $LNG['lm_battlesim'], 'bs_names' => $LNG['bs_names'], 'bs_atter' => $LNG['bs_atter'], 'bs_deffer' => $LNG['bs_deffer'], 'bs_steal' => $LNG['bs_steal'], 'bs_techno' => $LNG['bs_techno'], 'bs_send' => $LNG['bs_send'], 'bs_cancel' => $LNG['bs_cancel'], 'bs_wait' => $LNG['bs_wait'], 'Metal' => $LNG['Metal'], 'Crystal' => $LNG['Crystal'], 'Deuterium' => $LNG['Deuterium'], 'attack_tech' => $LNG['tech'][109], 'shield_tech' => $LNG['tech'][110], 'tank_tech' => $LNG['tech'][111], 'GetFleet' => $GetFleet, 'GetDef' => $GetDef, 'Slots' => $Slots, 'battleinput' => $BattleArray));
    $template->show("battlesim.tpl");
}
示例#24
0
function pretty_number($n, $dec = 0)
{
    return number_format(floattostring($n, $dec), 0, ',', '.');
}
 function sendExpo()
 {
     global $LNG, $ProdGrid, $resource, $reslist, $CONF, $pricelist, $USER, $PLANET;
     $Type_search = HTTP::_GP('type_fouille', '');
     $Popu = array();
     $endtime = 0;
     if ($Type_search == 1) {
         $endtime = rand(7200, 9000);
     } elseif ($Type_search == 2) {
         $endtime = rand(14400, 16200);
     } elseif ($Type_search == 3) {
         $endtime = rand(21600, 23400);
     }
     foreach ($reslist['population'] as $id => $popID) {
         $amount = max(0, round(HTTP::_GP('population' . $popID, 0.0, 0.0)));
         if ($amount < 1) {
             continue;
         }
         $Popu[$popID] = $amount;
     }
     //if (empty($Popu))
     //FleetFunctions::GotoFleetPage();
     $token = getRandomString();
     $_SESSION['population'][$token] = array('time' => TIMESTAMP, 'population' => $Popu);
     $fleetArray = $_SESSION['population'][$token]['population'];
     foreach ($fleetArray as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]]) {
             $this->printMessage('<span class="rouge">' . $LNG['ls_explora_27'] . '</span>');
         }
     }
     foreach ($fleetArray as $ShipID => $ShipCount) {
         $fleetData[] = $ShipID . ',' . floattostring($ShipCount);
         $planetQuery[] = $resource[$ShipID] . " = " . $resource[$ShipID] . " - " . floattostring($ShipCount);
         $PLANET[$resource[$ShipID]] -= floattostring($ShipCount);
     }
     $SQL = "LOCK TABLE uni1_explorations WRITE, " . USERS . " WRITE, " . PLANETS . " WRITE;\n\t\t\t\t   UPDATE " . PLANETS . " SET " . implode(", ", $planetQuery) . " WHERE id = " . $PLANET['id'] . ";\n\t\t\t\t   UPDATE " . USERS . " SET max_explore = max_explore + 1 WHERE id = " . $USER['id'] . ";\n\t\t\t\t   INSERT INTO uni1_explorations SET\n\t\t\t\t   userID              = " . $USER['id'] . ",\n\t\t\t\t   state              = '1',\n\t\t\t\t   type_of_search              = " . $Type_search . ",\n\t\t\t\t   start_planet_name              = '" . $PLANET['name'] . "',\n\t\t\t\t   start_system              = " . $PLANET['system'] . ",\n\t\t\t\t   start_planet              = " . $PLANET['planet'] . ",\n\t\t\t\t   end_planet_name              = '" . $PLANET['name'] . "',\n\t\t\t\t   start_time              = " . TIMESTAMP . ",\n\t\t\t\t   emd_time              = " . (TIMESTAMP + $endtime) . ",\n\t\t\t\t   population_array              = '" . implode(';', $fleetData) . "',\n\t\t\t\t   ships_array              = '" . implode(';', $fleetData) . "';\n\t\t\t\t   SET @explorationID = LAST_INSERT_ID();\n\t\t\t\t   UNLOCK TABLES;";
     $GLOBALS['DATABASE']->multi_query($SQL);
     $this->printMessage('<span class="vert">' . $LNG['ls_explora_26'] . '</span>', true, array('game.php?page=Explorations', 3));
     $this->tplObj->assign_vars(array());
     $this->display('page.explorations.busy.tpl');
 }
示例#26
0
 function EndStayEvent()
 {
     global $pricelist, $CONF, $db, $reslist;
     $LNG = $this->GetUserLang($this->_fleet['fleet_owner']);
     foreach ($reslist['fleet'] as $ID) {
         $Expowert[$ID] = ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']) / 1000;
     }
     $Expowert[202] = 12;
     $Expowert[203] = 47;
     $Expowert[204] = 12;
     $Expowert[205] = 110;
     $Expowert[206] = 47;
     $Expowert[207] = 160;
     $farray = explode(";", $this->_fleet['fleet_array']);
     $FleetPoints = 0;
     $FleetCapacity = 0;
     foreach ($farray as $Item => $Group) {
         if (empty($Group)) {
             continue;
         }
         $Class = explode(",", $Group);
         $FleetCount[$Class[0]] = $Class[1];
         $FleetCapacity += $Class[1] * $pricelist[$Class[0]]['capacity'];
         $FleetPoints += $Class[1] * $Expowert[$Class[0]];
     }
     $FleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
     $GetEvent = mt_rand(0, 10);
     switch ($GetEvent) {
         case 1:
             $WitchFound = mt_rand(1, 3);
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $WitchSize = 1;
                 $Factor = mt_rand(10, 50) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)];
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $WitchSize = 2;
                 $Factor = mt_rand(52, 100) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)];
             } elseif (0 == $FindSize) {
                 $WitchSize = 3;
                 $Factor = mt_rand(102, 200) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)];
             }
             $StatFactor = $db->uniquequery("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1;");
             $MaxPoints = $StatFactor['total'] < 5000000 ? 9000 : 12000;
             $Size = min($Factor * MAX(MIN($FleetPoints / 1000, $MaxPoints), 200), $FleetCapacity);
             switch ($WitchFound) {
                 case 1:
                     $this->UpdateFleet('fleet_resource_metal', $this->_fleet['fleet_resource_metal'] + $Size);
                     break;
                 case 2:
                     $this->UpdateFleet('fleet_resource_crystal', $this->_fleet['fleet_resource_crystal'] + $Size);
                     break;
                 case 3:
                     $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $Size);
                     break;
             }
             break;
         case 2:
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Size = mt_rand(100, 300);
                 $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)];
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Size = mt_rand(301, 600);
                 $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 4)];
             } elseif (0 == $FindSize) {
                 $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:
         default:
             unset($FleetCount[208]);
             unset($FleetCount[209]);
             unset($FleetCount[214]);
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Size = mt_rand(2, 50);
                 $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)];
                 $MaxFound = 300000;
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Size = mt_rand(51, 100);
                 $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)];
                 $MaxFound = 600000;
             } elseif (0 == $FindSize) {
                 $Size = mt_rand(101, 200);
                 $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)];
                 $MaxFound = 1200000;
             }
             $StatFactor = $db->uniquequery("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1;");
             $MaxPoints = $StatFactor['total'] < 5000000 ? 4500 : 6000;
             $FoundShips = max(min(round($Size * $FleetPoints), $MaxPoints), 10000);
             $MinFound = mt_rand(7000, 10000);
             $FoundShipMess = "";
             $NewFleetArray = "";
             $LNG += $this->GetUserLang($this->_fleet['fleet_owner'], 'TECH');
             foreach ($reslist['fleet'] as $ID) {
                 if (!isset($FleetCount[$ID])) {
                     continue;
                 }
                 $Count = mt_rand(1, floor($FoundShips / ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal'])));
                 $FleetCount[$ID] = bcadd($Count, $FleetCount[$ID]);
                 $NewFleetArray .= $ID . "," . floattostring($Count + $FleetCount[$ID]) . ";";
                 $FoundShips -= $Count * ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']);
                 $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count);
                 if ($FoundShips <= 0) {
                     break;
                 }
             }
             $Message .= $FoundShipMess;
             foreach ($FleetCount as $ID => $Count) {
                 if (empty($Count)) {
                     continue;
                 }
             }
             $this->UpdateFleet('fleet_array', $NewFleetArray);
             $this->UpdateFleet('fleet_amount', array_sum($FleetCount));
             break;
         case 4:
             $Chance = mt_rand(1, 2);
             if ($Chance == 1) {
                 $Points = array(-3, -5, -8);
                 $Which = 1;
                 $Def = -3;
                 $Name = $LNG['sys_expe_attackname_1'];
                 $Add = 0;
                 $Rand = array(5, 3, 2);
                 $DefenderFleetArray = "204,5;206,3;207,2;";
             } else {
                 $Points = array(-4, -6, -9);
                 $Which = 2;
                 $Def = 3;
                 $Name = $LNG['sys_expe_attackname_2'];
                 $Add = 0.1;
                 $Rand = array(4, 3, 2);
                 $DefenderFleetArray = "205,5;215,3;213,2;";
             }
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_1_' . $Rand[0]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[0], abs($Points[0])) * 0.01;
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_2_' . $Rand[1]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[1], abs($Points[1])) * 0.01;
             } elseif (0 == $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_3_' . $Rand[2]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[2], abs($Points[2])) * 0.01;
             }
             foreach ($FleetCount as $ID => $count) {
                 $DefenderFleetArray .= $ID . "," . round($count * $MaxAttackerPoints) . ";";
             }
             $AttackerTechno = $db->uniquequery('SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM ' . USERS . ' WHERE id=' . $this->_fleet['fleet_owner'] . ";");
             $DefenderTechno = array('id' => 0, 'username' => $Name, 'military_tech' => min($AttackerTechno['military_tech'] + $Def, 0), 'defence_tech' => min($AttackerTechno['defence_tech'] + $Def, 0), 'shield_tech' => min($AttackerTechno['shield_tech'] + $Def, 0), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0);
             $attackFleets[$this->_fleet['fleet_id']]['fleet'] = $this->_fleet;
             $attackFleets[$this->_fleet['fleet_id']]['user'] = $AttackerTechno;
             $attackFleets[$this->_fleet['fleet_id']]['detail'] = array();
             $temp = explode(';', $this->_fleet['fleet_array']);
             foreach ($temp as $temp2) {
                 $temp2 = explode(',', $temp2);
                 if ($temp2[0] < 100) {
                     continue;
                 }
                 if (!isset($attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]])) {
                     $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] = 0;
                 }
                 $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
             }
             $defense = array();
             $defRowDef = explode(';', $DefenderFleetArray);
             foreach ($defRowDef as $Element) {
                 $Element = explode(',', $Element);
                 if ($Element[0] < 100) {
                     continue;
                 }
                 if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]])) {
                     $defense[0][$Element[0]] = 0;
                 }
                 $defense[0]['def'][$Element[0]] += $Element[1];
             }
             $defense[0]['user'] = $DefenderTechno;
             require_once 'calculateAttack.' . PHP_EXT;
             $start = microtime(true);
             $result = calculateAttack($attackFleets, $defense);
             $totaltime = microtime(true) - $start;
             foreach ($attackFleets as $fleetID => $attacker) {
                 $fleetArray = '';
                 $totalCount = 0;
                 foreach ($attacker['detail'] as $element => $amount) {
                     if ($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 'GenerateReport.' . PHP_EXT;
             $raport = GenerateReport($result, $INFO);
             $rid = md5(microtime(true) . mt_rand(1, 100));
             file_put_contents(ROOT_PATH . 'raports/raport_' . $rid . '.php', '<?php' . "\n" . '$raport = ' . $raport . ';' . "\n" . '?>');
             $SQLQuery = "INSERT INTO " . RW . " SET `time` = '" . TIMESTAMP . "', `owners` = '" . $this->_fleet['fleet_owner'] . ",0', `rid` = '" . $rid . "', `raport` = '';";
             $db->query($SQLQuery);
             switch ($result['won']) {
                 case "r":
                     $ColorAtt = "red";
                     $ColorDef = "green";
                     break;
                 case "w":
                     $ColorAtt = "orange";
                     $ColorDef = "orange";
                 case "a":
                     $ColorAtt = "green";
                     $ColorDef = "red";
                     break;
             }
             $MessageAtt = sprintf('<a href="CombatReport.php?raport=%s" onclick="OpenPopup(\'CombatReport.php?raport=%s\', \'combat\', screen.width, screen.height);return false" target="combat"><center><font color="%s">%s %s</font></a><br><br><font color="%s">%s: %s</font> <font color="%s">%s: %s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font> %s:<font color="#f77542">%s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font><br></center>', $rid, $rid, $ColorAtt, $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']), $ColorAtt, $LNG['sys_perte_attaquant'], pretty_number($result['lost']['att']), $ColorDef, $LNG['sys_perte_defenseur'], pretty_number($result['lost']['def']), $LNG['sys_gain'], $LNG['Metal'], pretty_number($steal['metal']), $LNG['Crystal'], pretty_number($steal['crystal']), $LNG['Deuterium'], pretty_number($steal['deuterium']), $LNG['sys_debris'], $LNG['Metal'], pretty_number($result['debree']['att'][0] + $result['debree']['def'][0]), $LNG['Crystal'], pretty_number($result['debree']['att'][1] + $result['debree']['def'][1]));
             SendSimpleMessage($this->_fleet['fleet_owner'], '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageAtt);
             break;
         case 5:
             $this->KillFleet();
             $Message = $LNG['sys_expe_lost_fleet_' . mt_rand(1, 4)];
             break;
         case 6:
             $MoreTime = mt_rand(0, 100);
             if ($MoreTime < 75) {
                 $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_time'] - TIMESTAMP * mt_rand(1, 5) + TIMESTAMP);
                 $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)];
             } else {
                 $this->UpdateFleet('fleet_end_time', round($this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']) / 2));
                 $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)];
             }
             break;
         default:
             $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)];
             break;
     }
     SendSimpleMessage($this->_fleet['fleet_owner'], '', $this->_fleet['fleet_end_stay'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
     $this->UpdateFleet('fleet_mess', 1);
     $this->SaveFleet();
 }
示例#27
0
 public static function GetFleetShipInfo($FleetArray, $Player)
 {
     $FleetInfo = array();
     foreach ($FleetArray as $ShipID => $Amount) {
         $FleetInfo[$ShipID] = array('consumption' => self::GetShipConsumption($ShipID, $Player), 'speed' => self::GetFleetMaxSpeed($ShipID, $Player), 'amount' => floattostring($Amount));
     }
     return $FleetInfo;
 }
示例#28
0
 public function DefensesBuildingPage()
 {
     global $USER, $PLANET, $LNG, $resource, $dpath, $reslist;
     include_once ROOT_PATH . 'includes/functions/IsTechnologieAccessible.php';
     include_once ROOT_PATH . 'includes/functions/GetElementPrice.php';
     $template = new template();
     if ($PLANET[$resource[21]] == 0) {
         $template->message($LNG['bd_shipyard_required']);
         exit;
     }
     $fmenge = $_POST['fmenge'];
     $cancel = request_var('auftr', range(0, MAX_FLEET_OR_DEFS_IN_BUILD - 1));
     $action = request_var('action', '');
     $PlanetRess = new ResourceUpdate();
     $PlanetRess->CalcResource();
     $NotBuilding = true;
     if (!empty($PLANET['b_building_id'])) {
         $CurrentQueue = $PLANET['b_building_id'];
         $QueueArray = explode(";", $CurrentQueue);
         for ($i = 0; $i < count($QueueArray); $i++) {
             $ListIDArray = explode(",", $QueueArray[$i]);
             if ($ListIDArray[0] == 21 || $ListIDArray[0] == 15) {
                 $NotBuilding = false;
                 break;
             }
         }
     }
     if (isset($fmenge) && $NotBuilding == true && $USER['urlaubs_modus'] == 0) {
         $ebuild = explode(";", $PLANET['b_hangar_id']);
         if (count($ebuild) - 1 >= MAX_FLEET_OR_DEFS_IN_BUILD) {
             $template->message(sprintf($LNG['bd_max_builds'], MAX_FLEET_OR_DEFS_IN_BUILD), "?page=buildings&mode=fleet", 3);
             exit;
         }
         $Missiles[502] = $PLANET[$resource[502]];
         $Missiles[503] = $PLANET[$resource[503]];
         $SiloSize = $PLANET[$resource[44]];
         $MaxMissiles = $SiloSize * 10;
         $BuildQueue = $PLANET['b_hangar_id'];
         $BuildArray = explode(";", $BuildQueue);
         for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
             $ElmentArray = explode(",", $BuildArray[$QElement]);
             if (isset($Missiles[$ElmentArray[0]])) {
                 $Missiles[$ElmentArray[0]] += $ElmentArray[1];
             }
         }
         foreach ($fmenge as $Element => $Count) {
             if (empty($Count) || !in_array($Element, $reslist['defense'])) {
                 continue;
             }
             $Count = is_numeric($Count) ? $Count : 0;
             $Count = max(min($Count, MAX_FLEET_OR_DEFS_PER_ROW), 0);
             $MaxElements = $this->GetMaxConstructibleElements($Element);
             if (empty($Element) || empty($Count) || empty($MaxElements) || !IsTechnologieAccessible($USER, $PLANET, $Element)) {
                 continue;
             }
             if ($Element == 502 || $Element == 503) {
                 $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                 $MissilesSpace = $MaxMissiles - $ActuMissiles;
                 $Count = $Element == 502 ? min($Count, $MissilesSpace) : min($Count, floor($MissilesSpace / 2));
                 $Count = min($Count, $MaxElements);
                 $Missiles[$Element] += $Count;
             } elseif (in_array($Element, $reslist['one'])) {
                 $Count = $PLANET[$resource[$Element]] == 0 && strpos($PLANET['b_hangar_id'], $Element . ',') === false ? 1 : 0;
             } else {
                 $Count = min($Count, $MaxElements);
             }
             if ($Count < 1) {
                 continue;
             }
             $Ressource = $this->GetElementRessources($Element, $Count);
             $PLANET['metal'] -= $Ressource['metal'];
             $PLANET['crystal'] -= $Ressource['crystal'];
             $PLANET['deuterium'] -= $Ressource['deuterium'];
             $PLANET['norio'] -= $Ressource['norio'];
             $USER['darkmatter'] -= $Ressource['darkmatter'];
             $PLANET['b_hangar_id'] .= $Element . ',' . floattostring($Count) . ';';
         }
     }
     if ($action == "delete" && is_array($cancel) && $USER['urlaubs_modus'] == 0) {
         $this->CancelAuftr($cancel);
     }
     $PlanetRess->SavePlanetToDB();
     foreach ($reslist['defense'] as $Element) {
         if (!IsTechnologieAccessible($USER, $PLANET, $Element)) {
             continue;
         }
         $DefenseList[] = array('id' => $Element, 'name' => $LNG['tech'][$Element], 'descriptions' => $LNG['res']['descriptions'][$Element], 'price' => GetElementPrice($USER, $PLANET, $Element, false), 'restprice' => $this->GetRestPrice($Element), 'time' => pretty_time(GetBuildingTime($USER, $PLANET, $Element)), 'IsAvailable' => IsElementBuyable($USER, $PLANET, $Element, false), 'GetMaxAmount' => floattostring($this->GetMaxConstructibleElements($Element)), 'Available' => pretty_number($PLANET[$resource[$Element]]), 'AlreadyBuild' => in_array($Element, $reslist['one']) && (strpos($PLANET['b_hangar_id'], $Element . ",") !== false || $PLANET[$resource[$Element]] != 0) ? true : false);
     }
     $Buildlist = array();
     if (!empty($PLANET['b_hangar_id'])) {
         $ElementQueue = explode(';', $PLANET['b_hangar_id']);
         $Shipyard = array();
         $QueueTime = 0;
         foreach ($ElementQueue as $ElementLine => $Element) {
             if (empty($Element)) {
                 continue;
             }
             $Element = explode(',', $Element);
             $ElementTime = GetBuildingTime($USER, $PLANET, $Element[0]);
             $QueueTime += $ElementTime * $Element[1];
             $Shipyard[] = array($LNG['tech'][$Element[0]], $Element[1], $ElementTime);
         }
         $template->loadscript('bcmath.js');
         $template->loadscript('shipyard.js');
         $template->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)));
     }
     $template->assign_vars(array('DefenseList' => $DefenseList, 'NotBuilding' => $NotBuilding, 'bd_available' => $LNG['bd_available'], 'bd_remaining' => $LNG['bd_remaining'], 'fgf_time' => $LNG['fgf_time'], 'bd_build_ships' => $LNG['bd_build_ships'], 'bd_building_shipyard' => $LNG['bd_building_shipyard'], 'bd_protection_shield_only_one' => $LNG['bd_protection_shield_only_one'], 'bd_cancel_warning' => $LNG['bd_cancel_warning'], 'bd_cancel_send' => $LNG['bd_cancel_send'], 'bd_operating' => $LNG['bd_operating'], 'bd_actual_production' => $LNG['bd_actual_production'], 'BuildList' => json_encode($Buildlist), 'maxlength' => strlen(MAX_FLEET_OR_DEFS_PER_ROW)));
     $template->show("shipyard_defense.tpl");
 }
示例#29
0
 public static function FleetAjax()
 {
     global $USER, $PLANET, $db, $resource, $LNG;
     $UserSpyProbes = $PLANET[$resource[210]];
     $UserRecycles = $PLANET[$resource[209]];
     $UserGRecycles = $PLANET[$resource[219]];
     $UserDeuterium = $PLANET['deuterium'];
     $UserMissiles = $PLANET['interplanetary_misil'];
     $thisgalaxy = $PLANET['galaxy'];
     $thissystem = $PLANET['system'];
     $thisplanet = $PLANET['planet'];
     $thisplanettype = $PLANET['planet_type'];
     $galaxy = request_var('galaxy', 0);
     $system = request_var('system', 0);
     $planet = request_var('planet', 0);
     $planettype = request_var('planettype', 0);
     $mission = request_var('mission', 0);
     $CurrentFlyingFleets = parent::GetCurrentFleets($USER['id']);
     switch ($mission) {
         case 6:
             $SpyProbes = request_var('ships', 0);
             $SpyProbes = min($SpyProbes, $PLANET[$resource[210]]);
             if (empty($SpyProbes)) {
                 exit($ResultMessage = "611; " . $LNG['fa_no_spios'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
             }
             $FleetArray = array(210 => $SpyProbes);
             break;
         case 8:
             $SRecycles = explode("|", request_var('ships', ''));
             $GRecycles = min($SRecycles[0], $PLANET[$resource[219]]);
             $Recycles = min($SRecycles[1], $PLANET[$resource[209]]);
             if (empty($Recycles) && empty($GRecycles)) {
                 exit($ResultMessage = "611; " . $LNG['fa_no_recyclers'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
             }
             $FleetArray = array(219 => $GRecycles, 209 => $Recycles);
             break;
         default:
             exit("610; " . $LNG['fa_not_enough_probes'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
             break;
     }
     parent::CleanFleetArray($FleetArray);
     if (empty($FleetArray)) {
         exit("610; " . $LNG['fa_not_enough_probes'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
     }
     if (parent::GetMaxFleetSlots($USER) <= $CurrentFlyingFleets) {
         $ResultMessage = "612; " . $LNG['fa_no_more_slots'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
         die($ResultMessage);
     }
     if ($galaxy > MAX_GALAXY_IN_WORLD || $galaxy < 1) {
         $ResultMessage = "602; " . $LNG['fa_galaxy_not_exist'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
         die($ResultMessage);
     }
     if ($system > MAX_SYSTEM_IN_GALAXY || $system < 1) {
         $ResultMessage = "602; " . $LNG['fa_system_not_exist'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
         die($ResultMessage);
     }
     if ($planet > MAX_PLANET_IN_SYSTEM || $planet < 1) {
         $ResultMessage = "602; " . $LNG['fa_planet_not_exist'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
         die($ResultMessage);
     }
     $QrySelectEnemy = "SELECT id_level, id_owner FROM " . PLANETS . " ";
     $QrySelectEnemy .= "WHERE ";
     $QrySelectEnemy .= "`galaxy` = '" . $galaxy . "' AND ";
     $QrySelectEnemy .= "`system` = '" . $system . "' AND ";
     $QrySelectEnemy .= "`planet` = '" . $planet . "' AND ";
     $QrySelectEnemy .= "`planet_type` = '" . $planettype . "';";
     $TargetRow = $db->uniquequery($QrySelectEnemy);
     if ($TargetRow['id_level'] > $USER['authlevel'] && $mission == 6 && $CONF['adm_attack'] == 0) {
         exit("619; " . $LNG['fa_action_not_allowed'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
     }
     $TargetUser = GetUserByID($TargetRow['id_owner'], array('id', 'onlinetime', 'urlaubs_modus'));
     if ($USER['urlaubs_modus'] == 1) {
         $ResultMessage = "620; " . $LNG['fa_vacation_mode_current'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
         die($ResultMessage);
     }
     if ($mission == 6) {
         $TargetVacat = $TargetUser['urlaubs_modus'];
         if ($TargetVacat) {
             $ResultMessage = "605; " . $LNG['fa_vacation_mode'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
             die($ResultMessage);
         }
         $UserPoints = $USER;
         $User2Points = $db->uniquequery("SELECT `total_points` FROM " . STATPOINTS . " WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '" . $TargetRow['id_owner'] . "';");
         $IsNoobProtec = CheckNoobProtec($UserPoints, $User2Points, $TargetUser['onlinetime']);
         if ($IsNoobProtec['NoobPlayer']) {
             exit("603; " . $LNG['fa_week_player'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
         } elseif ($IsNoobProtec['StrongPlayer']) {
             exit("604; " . $LNG['fa_strong_player'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
         }
         if (empty($TargetRow['id_owner'])) {
             $ResultMessage = "601; " . $LNG['fa_planet_not_exist'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
             die($ResultMessage);
         }
         if ($TargetRow["id_owner"] == $PLANET["id_owner"]) {
             $ResultMessage = "618; " . $LNG['fa_not_spy_yourself'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles;
             die($ResultMessage);
         }
     }
     $SpeedFactor = parent::GetGameSpeedFactor();
     $Distance = parent::GetTargetDistance($thisgalaxy, $galaxy, $thissystem, $system, $thisplanet, $planet);
     $SpeedAllMin = parent::GetFleetMaxSpeed($FleetArray, $USER);
     $Duration = parent::GetMissionDuration(10, $SpeedAllMin, $Distance, $SpeedFactor, $USER);
     $consumption = parent::GetFleetConsumption($FleetArray, $Duration, $Distance, $SpeedAllMin, $USER, $SpeedFactor);
     $UserDeuterium -= $consumption;
     if ($UserDeuterium < 0) {
         exit("613; " . $LNG['fa_not_enough_fuel'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
     } elseif ($consumption > parent::GetFleetRoom($FleetArray)) {
         exit("613; " . $LNG['fa_no_fleetroom'] . " |" . $CurrentFlyingFleets . " " . $UserSpyProbes . " " . $UserRecycles . " " . $UserGRecycles . " " . $UserMissiles);
     }
     $fleet['fly_time'] = $Duration;
     $fleet['start_time'] = $Duration + TIMESTAMP;
     $fleet['end_time'] = $Duration * 2 + TIMESTAMP;
     $FleetShipCount = 0;
     $FleetDBArray = "";
     $FleetSubQRY = "";
     foreach ($FleetArray as $Ship => $Count) {
         $FleetShipCount += $Count;
         $FleetDBArray .= $Ship . "," . $Count . ";";
         $FleetSubQRY .= "`" . $resource[$Ship] . "` = `" . $resource[$Ship] . "` - " . $Count . " , ";
     }
     if (connection_aborted()) {
         exit;
     }
     $QryUpdate = "LOCK TABLE " . FLEETS . " WRITE, " . PLANETS . " WRITE;";
     $QryUpdate .= "INSERT INTO " . FLEETS . " SET ";
     $QryUpdate .= "`fleet_owner` = '" . $USER['id'] . "', ";
     $QryUpdate .= "`fleet_mission` = '" . $mission . "', ";
     $QryUpdate .= "`fleet_amount` = '" . $FleetShipCount . "', ";
     $QryUpdate .= "`fleet_array` = '" . $FleetDBArray . "', ";
     $QryUpdate .= "`fleet_start_time` = '" . $fleet['start_time'] . "', ";
     $QryUpdate .= "`fleet_start_galaxy` = '" . $thisgalaxy . "', ";
     $QryUpdate .= "`fleet_start_system` = '" . $thissystem . "', ";
     $QryUpdate .= "`fleet_start_planet` = '" . $thisplanet . "', ";
     $QryUpdate .= "`fleet_start_type` = '" . $thisplanettype . "', ";
     $QryUpdate .= "`fleet_end_time` = '" . $fleet['end_time'] . "', ";
     $QryUpdate .= "`fleet_end_galaxy` = '" . $galaxy . "', ";
     $QryUpdate .= "`fleet_end_system` = '" . $system . "', ";
     $QryUpdate .= "`fleet_end_planet` = '" . $planet . "', ";
     $QryUpdate .= "`fleet_end_type` = '" . $planettype . "', ";
     $QryUpdate .= "`fleet_target_owner` = '" . $TargetRow['id_owner'] . "', ";
     $QryUpdate .= "`start_time` = '" . TIMESTAMP . "';";
     $QryUpdate .= "UPDATE " . PLANETS . " SET ";
     $QryUpdate .= $FleetSubQRY;
     $QryUpdate .= "`deuterium` = '" . floattostring($UserDeuterium) . "' ";
     $QryUpdate .= "WHERE ";
     $QryUpdate .= "`id` = '" . $PLANET['id'] . "';";
     $QryUpdate .= "UNLOCK TABLES;";
     $db->multi_query($QryUpdate);
     $CurrentFlyingFleets++;
     $ResultMessage = "600; " . $LNG['fa_sending'] . " " . $FleetShipCount . " " . $LNG['tech'][$Ship] . " a " . $galaxy . ":" . $system . ":" . $planet . "...|";
     $ResultMessage .= $CurrentFlyingFleets . " " . ($UserSpyProbes - $SpyProbes) . " " . ($UserRecycles - $Recycles) . " " . ($UserGRecycles - $GRecycles) . " " . $UserMissiles;
     die($ResultMessage);
 }
    public function SavePlanetToDB($USER = NULL, $PLANET = NULL)
    {
        global $resource, $reslist;
        if (is_null($USER)) {
            global $USER;
        }
        if (is_null($PLANET)) {
            global $PLANET;
        }
        $buildQueries = array();
        $params = array(':userId' => $USER['id'], ':planetId' => $PLANET['id'], ':metal' => $PLANET['metal'], ':crystal' => $PLANET['crystal'], ':deuterium' => $PLANET['deuterium'], ':ecoHash' => $PLANET['eco_hash'], ':lastUpdateTime' => $PLANET['last_update'], ':b_building' => $PLANET['b_building'], ':b_building_id' => $PLANET['b_building_id'], ':field_current' => $PLANET['field_current'], ':b_hangar_id' => $PLANET['b_hangar_id'], ':metal_perhour' => $PLANET['metal_perhour'], ':crystal_perhour' => $PLANET['crystal_perhour'], ':deuterium_perhour' => $PLANET['deuterium_perhour'], ':metal_max' => $PLANET['metal_max'], ':crystal_max' => $PLANET['crystal_max'], ':deuterium_max' => $PLANET['deuterium_max'], ':energy_used' => $PLANET['energy_used'], ':energy' => $PLANET['energy'], ':b_hangar' => $PLANET['b_hangar'], ':darkmatter' => $USER['darkmatter'], ':b_tech' => $USER['b_tech'], ':b_tech_id' => $USER['b_tech_id'], ':b_tech_planet' => $USER['b_tech_planet'], ':b_tech_queue' => $USER['b_tech_queue']);
        if (!empty($this->Builded)) {
            foreach ($this->Builded as $Element => $Count) {
                $Element = (int) $Element;
                if (empty($resource[$Element]) || empty($Count)) {
                    continue;
                }
                if (in_array($Element, $reslist['one'])) {
                    $buildQueries[] = ', p.' . $resource[$Element] . ' = :' . $resource[$Element];
                    $params[':' . $resource[$Element]] = '1';
                } elseif (isset($PLANET[$resource[$Element]])) {
                    $buildQueries[] = ', p.' . $resource[$Element] . ' = p.' . $resource[$Element] . ' + :' . $resource[$Element];
                    $params[':' . $resource[$Element]] = floattostring($Count);
                } elseif (isset($USER[$resource[$Element]])) {
                    $buildQueries[] = ', u.' . $resource[$Element] . ' = u.' . $resource[$Element] . ' + :' . $resource[$Element];
                    $params[':' . $resource[$Element]] = floattostring($Count);
                }
            }
        }
        $sql = 'UPDATE %%PLANETS%% as p,%%USERS%% as u SET
		p.metal				= :metal,
		p.crystal			= :crystal,
		p.deuterium			= :deuterium,
		p.eco_hash			= :ecoHash,
		p.last_update		= :lastUpdateTime,
		p.b_building		= :b_building,
		p.b_building_id 	= :b_building_id,
		p.field_current 	= :field_current,
		p.b_hangar_id		= :b_hangar_id,
		p.metal_perhour		= :metal_perhour,
		p.crystal_perhour	= :crystal_perhour,
		p.deuterium_perhour	= :deuterium_perhour,
		p.metal_max			= :metal_max,
		p.crystal_max		= :crystal_max,
		p.deuterium_max		= :deuterium_max,
		p.energy_used		= :energy_used,
		p.energy			= :energy,
		p.b_hangar			= :b_hangar,
		u.darkmatter		= :darkmatter,
		u.b_tech			= :b_tech,
		u.b_tech_id			= :b_tech_id,
		u.b_tech_planet		= :b_tech_planet,
		u.b_tech_queue		= :b_tech_queue
		' . implode("\n", $buildQueries) . '
		WHERE p.id = :planetId AND u.id = :userId;';
        Database::get()->update($sql, $params);
        $this->Builded = array();
        return array($USER, $PLANET);
    }