public function show() { global $USER, $PLANET, $LNG; $this->tplObj->loadscript('flotten.js'); $targetGalaxy = HTTP::_GP('galaxy', 0); $targetSystem = HTTP::_GP('system', 0); $targetPlanet = HTTP::_GP('planet', 0); $targetType = HTTP::_GP('type', 0); $targetMission = HTTP::_GP('target_mission', 0); $fleetSpeed = HTTP::_GP('speed', 0); $fleetGroup = HTTP::_GP('fleet_group', 0); $token = HTTP::_GP('token', ''); if (!isset($_SESSION['fleet'][$token])) { FleetFunctions::GotoFleetPage(); } $fleetArray = $_SESSION['fleet'][$token]['fleet']; $db = Database::get(); $sql = "SELECT id, id_owner, der_metal, der_crystal FROM %%PLANETS%% WHERE universe = :universe AND galaxy = :targetGalaxy AND system = :targetSystem AND planet = :targetPlanet AND planet_type = '1';"; $targetPlanetData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet)); if ($targetType == 2 && $targetPlanetData['der_metal'] == 0 && $targetPlanetData['der_crystal'] == 0) { $this->printMessage($LNG['fl_error_empty_derbis'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable'))); } $MisInfo = array(); $MisInfo['galaxy'] = $targetGalaxy; $MisInfo['system'] = $targetSystem; $MisInfo['planet'] = $targetPlanet; $MisInfo['planettype'] = $targetType; $MisInfo['IsAKS'] = $fleetGroup; $MisInfo['Ship'] = $fleetArray; $MissionOutput = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData); if (empty($MissionOutput['MissionSelector'])) { $this->printMessage($LNG['fl_empty_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable'))); } $GameSpeedFactor = FleetFunctions::GetGameSpeedFactor(); $MaxFleetSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER); $distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetGalaxy, $targetSystem, $targetPlanet)); $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $MaxFleetSpeed, $distance, $GameSpeedFactor, $USER); $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $USER, $GameSpeedFactor); if ($consumption > $PLANET['deuterium']) { $this->printMessage($LNG['fl_not_enough_deuterium'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable'))); } if (!FleetFunctions::CheckUserSpeed($fleetSpeed)) { FleetFunctions::GotoFleetPage(0); } $_SESSION['fleet'][$token]['speed'] = $MaxFleetSpeed; $_SESSION['fleet'][$token]['distance'] = $distance; $_SESSION['fleet'][$token]['targetGalaxy'] = $targetGalaxy; $_SESSION['fleet'][$token]['targetSystem'] = $targetSystem; $_SESSION['fleet'][$token]['targetPlanet'] = $targetPlanet; $_SESSION['fleet'][$token]['targetType'] = $targetType; $_SESSION['fleet'][$token]['fleetGroup'] = $fleetGroup; $_SESSION['fleet'][$token]['fleetSpeed'] = $fleetSpeed; if (!empty($fleet_group)) { $targetMission = 2; } $fleetData = array('fleetroom' => floatToString($_SESSION['fleet'][$token]['fleetRoom']), 'consumption' => floatToString($consumption)); $this->tplObj->execscript('calculateTransportCapacity();'); $this->assign(array('fleetdata' => $fleetData, 'consumption' => floatToString($consumption), 'mission' => $targetMission, 'galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'type' => $PLANET['planet_type'], 'MissionSelector' => $MissionOutput['MissionSelector'], 'StaySelector' => $MissionOutput['StayBlock'], 'fl_dm_alert_message' => sprintf($LNG['fl_dm_alert_message'], $LNG['type_mission'][11], $LNG['tech'][921]), 'fl_continue' => $LNG['fl_continue'], 'token' => $token)); $this->display('page.fleetStep2.default.tpl'); }
public function show() { global $USER, $PLANET, $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'); }
function ShowQuickEditorPage() { global $USER, $LNG, $reslist, $resource; $action = HTTP::_GP('action', ''); $edit = HTTP::_GP('edit', ''); $id = HTTP::_GP('id', 0); switch ($edit) { case 'planet': $DataIDs = array_merge($reslist['fleet'], $reslist['build'], $reslist['defense']); $SpecifyItemsPQ = ""; foreach ($DataIDs as $ID) { $SpecifyItemsPQ .= "`" . $resource[$ID] . "`,"; } $PlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT " . $SpecifyItemsPQ . " `name`, `id_owner`, `planet_type`, `galaxy`, `system`, `planet`, `destruyed`, `diameter`, `field_current`, `field_max`, `temp_min`, `temp_max`, `metal`, `crystal`, `deuterium` FROM " . PLANETS . " WHERE `id` = '" . $id . "';"); if ($action == 'send') { $SQL = "UPDATE " . PLANETS . " SET "; $Fields = $PlanetData['field_current']; foreach ($DataIDs as $ID) { $level = min(max(0, round(HTTP::_GP($resource[$ID], 0.0))), in_array($ID, $reslist['build']) ? 255 : 1.8446744073709552E+19); if (in_array($ID, $reslist['allow'][$PlanetData['planet_type']])) { $Fields += $level - $PlanetData[$resource[$ID]]; } $SQL .= "`" . $resource[$ID] . "` = " . $level . ", "; } $SQL .= "`metal` = " . max(0, round(HTTP::_GP('metal', 0.0))) . ", "; $SQL .= "`crystal` = " . max(0, round(HTTP::_GP('crystal', 0.0))) . ", "; $SQL .= "`deuterium` = " . max(0, round(HTTP::_GP('deuterium', 0.0))) . ", "; $SQL .= "`field_current` = '" . $Fields . "', "; $SQL .= "`field_max` = '" . HTTP::_GP('field_max', 0) . "', "; $SQL .= "`name` = '" . $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT)) . "', "; $SQL .= "`eco_hash` = '' "; $SQL .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';"; $GLOBALS['DATABASE']->query($SQL); $old = array(); $new = array(); foreach (array_merge($DataIDs, $reslist['resstype'][1]) as $IDs) { $old[$IDs] = $PlanetData[$resource[$IDs]]; $new[$IDs] = max(0, round(HTTP::_GP($resource[$IDs], 0.0))); } $old['field_max'] = $PlanetData['field_max']; $new['field_max'] = HTTP::_GP('field_max', 0); $LOG = new Log(2); $LOG->target = $id; $LOG->old = $old; $LOG->new = $new; $LOG->save(); exit(sprintf($LNG['qe_edit_planet_sucess'], $PlanetData['name'], $PlanetData['galaxy'], $PlanetData['system'], $PlanetData['planet'])); } $UserInfo = $GLOBALS['DATABASE']->getFirstRow("SELECT `username` FROM " . USERS . " WHERE `id` = '" . $PlanetData['id_owner'] . "' AND `universe` = '" . Universe::getEmulated() . "';"); $build = $defense = $fleet = array(); foreach ($reslist['allow'][$PlanetData['planet_type']] 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->assign_vars(array('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('QuickEditorPlanet.tpl'); break; case 'player': $DataIDs = array_merge($reslist['tech'], $reslist['officier']); $SpecifyItemsPQ = ""; foreach ($DataIDs as $ID) { $SpecifyItemsPQ .= "`" . $resource[$ID] . "`,"; } $UserData = $GLOBALS['DATABASE']->getFirstRow("SELECT " . $SpecifyItemsPQ . " `username`, `authlevel`, `galaxy`, `system`, `planet`, `id_planet`, `darkmatter`, `authattack`, `authlevel` FROM " . USERS . " WHERE `id` = '" . $id . "';"); $ChangePW = $USER['id'] == ROOT_USER || $id != ROOT_USER && $USER['authlevel'] > $UserData['authlevel']; if ($action == 'send') { $SQL = "UPDATE " . USERS . " SET "; foreach ($DataIDs as $ID) { $SQL .= "`" . $resource[$ID] . "` = " . min(abs(HTTP::_GP($resource[$ID], 0)), 255) . ", "; } $SQL .= "`darkmatter` = '" . max(HTTP::_GP('darkmatter', 0), 0) . "', "; if (!empty($_POST['password']) && $ChangePW) { $SQL .= "`password` = '" . PlayerUtil::cryptPassword(HTTP::_GP('password', '', true)) . "', "; } $SQL .= "`username` = '" . $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT)) . "', "; $SQL .= "`authattack` = '" . ($UserData['authlevel'] != AUTH_USR && HTTP::_GP('authattack', '') == 'on' ? $UserData['authlevel'] : 0) . "' "; $SQL .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';"; $GLOBALS['DATABASE']->query($SQL); $old = array(); $new = array(); $multi = HTTP::_GP('multi', 0); foreach ($DataIDs as $IDs) { $old[$IDs] = $UserData[$resource[$IDs]]; $new[$IDs] = abs(HTTP::_GP($resource[$IDs], 0)); } $old[921] = $UserData[$resource[921]]; $new[921] = abs(HTTP::_GP($resource[921], 0)); $old['username'] = $UserData['username']; $new['username'] = $GLOBALS['DATABASE']->sql_escape(HTTP::_GP('name', '', UTF8_SUPPORT)); $old['authattack'] = $UserData['authattack']; $new['authattack'] = $UserData['authlevel'] != AUTH_USR && HTTP::_GP('authattack', '') == 'on' ? $UserData['authlevel'] : 0; $old['multi'] = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $id . ";"); $new['authattack'] = $multi; if ($old['multi'] != $multi) { if ($multi == 0) { $GLOBALS['DATABASE']->query("DELETE FROM " . MULTI . " WHERE userID = " . (int) $id . ";"); } elseif ($multi == 1) { $GLOBALS['DATABASE']->query("INSERT INTO " . MULTI . " SET userID = " . (int) $id . ";"); } } $LOG = new Log(1); $LOG->target = $id; $LOG->old = $old; $LOG->new = $new; $LOG->save(); exit(sprintf($LNG['qe_edit_player_sucess'], $UserData['username'], $id)); } $PlanetInfo = $GLOBALS['DATABASE']->getFirstRow("SELECT `name` FROM " . PLANETS . " WHERE `id` = '" . $UserData['id_planet'] . "' AND `universe` = '" . Universe::getEmulated() . "';"); $tech = array(); $officier = array(); foreach ($reslist['tech'] as $ID) { $tech[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($UserData[$resource[$ID]]), 'input' => $UserData[$resource[$ID]]); } foreach ($reslist['officier'] as $ID) { $officier[] = array('type' => $resource[$ID], 'name' => $LNG['tech'][$ID], 'count' => pretty_number($UserData[$resource[$ID]]), 'input' => $UserData[$resource[$ID]]); } $template = new template(); $template->assign_vars(array('tech' => $tech, 'officier' => $officier, 'id' => $id, 'planetid' => $UserData['id_planet'], 'planetname' => $PlanetInfo['name'], 'name' => $UserData['username'], 'galaxy' => $UserData['galaxy'], 'system' => $UserData['system'], 'planet' => $UserData['planet'], 'authlevel' => $UserData['authlevel'], 'authattack' => $UserData['authattack'], 'multi' => $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $id . ";"), 'ChangePW' => $ChangePW, 'darkmatter' => floatToString($UserData['darkmatter']), 'darkmatter_c' => pretty_number($UserData['darkmatter']))); $template->show('QuickEditorUser.tpl'); break; } }
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'); }
function EndStayEvent() { global $pricelist, $reslist, $resource; $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']); $config = Config::get($this->_fleet['fleet_universe']); $expeditionPoints = array(); foreach ($reslist['fleet'] as $shipId) { $expeditionPoints[$shipId] = ($pricelist[$shipId]['cost'][901] + $pricelist[$shipId]['cost'][902]) * 5 / 1000; } $fleetArray = FleetFunctions::unserialize($this->_fleet['fleet_array']); $fleetPoints = 0; $fleetCapacity = 0; foreach ($fleetArray as $shipId => $shipAmount) { $fleetCapacity += $shipAmount * $pricelist[$shipId]['capacity']; $fleetPoints += $shipAmount * $expeditionPoints[$shipId]; } $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter']; $GetEvent = mt_rand(1, 9); $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)]; switch ($GetEvent) { case 1: $eventSize = mt_rand(0, 100); $factor = 0; if (10 < $eventSize) { $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)]; $factor = mt_rand(10, 50); } elseif (0 < $eventSize && 10 >= $eventSize) { $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)]; $factor = mt_rand(50, 100); } elseif (0 == $eventSize) { $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)]; $factor = mt_rand(100, 200); } $chanceToFound = mt_rand(1, 6); if ($chanceToFound > 3) { $resourceId = 901; } elseif ($chanceToFound > 1) { $resourceId = 902; $factor = $factor / 2; } else { $resourceId = 903; $factor = $factor / 3; } $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;"; $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total'); if ($topPoints > 5000000) { $maxFactor = 12000; } elseif ($topPoints > 1000000) { $maxFactor = 9000; } elseif ($topPoints > 100000) { $maxFactor = 6000; } else { $maxFactor = 2400; } $founded = round(min($maxFactor, max(200, $factor)) * $fleetPoints); $fleetColName = 'fleet_resource_' . $resource[$resourceId]; $this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $founded); break; case 2: $eventSize = mt_rand(0, 100); $Size = 0; if (10 < $eventSize) { $Size = mt_rand(100, 300); $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)]; } elseif (0 < $eventSize && 10 >= $eventSize) { $Size = mt_rand(301, 600); $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 3)]; } elseif (0 == $eventSize) { $Size = mt_rand(601, 3000); $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)]; } $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size); break; case 3: $eventSize = mt_rand(0, 100); $Size = 0; $Message = ""; if (10 < $eventSize) { $Size = mt_rand(10, 50); $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)]; } elseif (0 < $eventSize && 10 >= $eventSize) { $Size = mt_rand(52, 100); $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)]; } elseif (0 == $eventSize) { $Size = mt_rand(102, 200); $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)]; } $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;"; $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total'); $MaxPoints = $topPoints < 5000000 ? 4500 : 6000; $FoundShips = max(round($Size * min($fleetPoints, $MaxPoints)), 10000); $FoundShipMess = ""; $NewFleetArray = ""; $Found = array(); foreach ($reslist['fleet'] as $ID) { if (!isset($fleetArray[$ID]) || $ID == 208 || $ID == 209 || $ID == 214) { continue; } $MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902])); if ($MaxFound <= 0) { continue; } $Count = mt_rand(0, $MaxFound); if ($Count <= 0) { continue; } $Found[$ID] = $Count; $FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]); $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count); if ($FoundShips <= 0) { break; } } if (empty($Found)) { $FoundShipMess .= '<br><br>' . $LNG['sys_expe_found_ships_nothing']; } foreach ($fleetArray as $ID => $Count) { if (!empty($Found[$ID])) { $Count += $Found[$ID]; } $NewFleetArray .= $ID . "," . floatToString($Count) . ';'; } $Message .= $FoundShipMess; $this->UpdateFleet('fleet_array', $NewFleetArray); $this->UpdateFleet('fleet_amount', array_sum($fleetArray)); break; case 4: $messageHTML = <<<HTML <div class="raportMessage"> <table> <tr> <td colspan="2"><a href="CombatReport.php?raport=%s" target="_blank"><span class="%s">%s %s (%s)</span></a></td> </tr> <tr> <td>%s</td><td><span class="%s">%s: %s</span> <span class="%s">%s: %s</span></td> </tr> <tr> <td>%s</td><td><span>%s: <span class="raportSteal element901">%s</span> </span><span>%s: <span class="raportSteal element902">%s</span> </span><span>%s: <span class="raportSteal element903">%s</span></span></td> </tr> <tr> <td>%s</td><td><span>%s: <span class="raportDebris element901">%s</span> </span><span>%s: <span class="raportDebris element902">%s</span></span></td> </tr> </table> </div> HTML; //Minize HTML $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML); // pirate or alien $attackType = mt_rand(1, 2); $eventSize = mt_rand(0, 100); $targetFleetData = array(); if ($attackType == 1) { $techBonus = -3; $targetName = $LNG['sys_expe_attackname_1']; $roundFunction = 'floor'; if (10 < $eventSize) { $Message = $LNG['sys_expe_attack_1_1_5']; $attackFactor = 30 + mt_rand(-3, 3) / 100; $targetFleetData[204] = 5; } elseif (0 < $eventSize && 10 >= $eventSize) { $Message = $LNG['sys_expe_attack_1_2_3']; $attackFactor = 50 + mt_rand(-5, 5) / 100; $targetFleetData[206] = 3; } else { $Message = $LNG['sys_expe_attack_1_3_2']; $attackFactor = 80 + mt_rand(-8, 8) / 100; $targetFleetData[207] = 2; } } else { $techBonus = 3; $targetName = $LNG['sys_expe_attackname_2']; $roundFunction = 'ceil'; if (10 < $eventSize) { $Message = $LNG['sys_expe_attack_1_1_5']; $attackFactor = 40 + mt_rand(-4, 4) / 100; $targetFleetData[204] = 5; } elseif (0 < $eventSize && 10 >= $eventSize) { $Message = $LNG['sys_expe_attack_1_3_3']; $attackFactor = 60 + mt_rand(-6, 6) / 100; $targetFleetData[215] = 3; } else { $Message = $LNG['sys_expe_attack_1_3_2']; $attackFactor = 90 + mt_rand(-9, 9) / 100; $targetFleetData[213] = 2; } } foreach ($fleetArray as $shipId => $shipAmount) { if (isset($targetFleetData[$shipId])) { $targetFleetData[$shipId] = 0; } $targetFleetData[$shipId] = $roundFunction($shipAmount * $attackFactor); } $targetFleetData = array_filter($targetFleetData); $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;'; $senderData = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner'])); $targetData = array('id' => 0, 'username' => $targetName, 'military_tech' => min($senderData['military_tech'] + $techBonus, 0), 'defence_tech' => min($senderData['defence_tech'] + $techBonus, 0), 'shield_tech' => min($senderData['shield_tech'] + $techBonus, 0), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0); $fleetID = $this->_fleet['fleet_id']; $fleetAttack[$fleetID]['fleetDetail'] = $this->_fleet; $fleetAttack[$fleetID]['player'] = $senderData; $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$this->_fleet['fleet_id']]['player'], 'attack', $this->_fleet['fleet_start_time']); $fleetAttack[$fleetID]['unit'] = $fleetArray; $fleetDefend = array(); $fleetDefend[0]['fleetDetail'] = array('fleet_start_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_start_system' => $this->_fleet['fleet_end_system'], 'fleet_start_planet' => $this->_fleet['fleet_end_planet'], 'fleet_start_type' => 1, 'fleet_end_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_end_system' => $this->_fleet['fleet_end_system'], 'fleet_end_planet' => $this->_fleet['fleet_end_planet'], 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0); $bonusList = BuildFunctions::getBonusList(); $fleetDefend[0]['player'] = $targetData; $fleetDefend[0]['player']['factor'] = ArrayUtil::combineArrayWithSingleElement($bonusList, 0); $fleetDefend[0]['unit'] = $targetFleetData; require_once 'includes/classes/missions/functions/calculateAttack.php'; $combatResult = calculateAttack($fleetAttack, $fleetDefend, $config->Fleet_Cdr, $config->Defs_Cdr); $fleetArray = ''; $totalCount = 0; $fleetAttack[$fleetID]['unit'] = array_filter($fleetAttack[$fleetID]['unit']); foreach ($fleetAttack[$fleetID]['unit'] as $element => $amount) { $fleetArray .= $element . ',' . $amount . ';'; $totalCount += $amount; } if ($totalCount <= 0) { $this->KillFleet(); } else { $this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1)); $this->UpdateFleet('fleet_amount', $totalCount); } require_once 'includes/classes/missions/functions/GenerateReport.php'; $debrisResource = array(901, 902); $debris = array(); foreach ($debrisResource as $elementID) { $debris[$elementID] = 0; } $stealResource = array(901 => 0, 902 => 0, 903 => 0); $reportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => 0, 'moonDestroy' => false, 'moonName' => NULL, 'moonDestroyChance' => NULL, 'moonDestroySuccess' => NULL, 'fleetDestroyChance' => NULL, 'fleetDestroySuccess' => NULL); $reportData = GenerateReport($combatResult, $reportInfo); $reportID = md5(uniqid('', true) . TIMESTAMP); $sql = "INSERT INTO %%RW%% SET\n\t\t\t\trid\t\t\t= :reportId,\n\t\t\t\traport\t\t= :reportData,\n\t\t\t\ttime\t\t= :time,\n\t\t\t\tattacker\t= :attacker;"; Database::get()->insert($sql, array(':reportId' => $reportID, ':reportData' => serialize($reportData), ':time' => $this->_fleet['fleet_start_time'], ':attacker' => $this->_fleet['fleet_owner'])); switch ($combatResult['won']) { case "a": $attackClass = 'raportWin'; $defendClass = 'raportLose'; break; case "r": $attackClass = 'raportLose'; $defendClass = 'raportWin'; break; default: $attackClass = 'raportDraw'; $defendClass = 'raportDraw'; break; } $message = sprintf($messageHTML, $reportID, $attackClass, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $LNG['type_planet_short'][$this->_fleet['fleet_end_type']], $LNG['sys_lost'], $attackClass, $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $defendClass, $LNG['sys_attack_defender_pos'], pretty_number($combatResult['unitLost']['defender']), $LNG['sys_gain'], $LNG['tech'][901], pretty_number($stealResource[901]), $LNG['tech'][902], pretty_number($stealResource[902]), $LNG['tech'][903], pretty_number($stealResource[903]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902])); PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $message); break; case 5: $this->KillFleet(); $Message = $LNG['sys_expe_lost_fleet_' . mt_rand(1, 4)]; break; case 6: # http://owiki.de/Expedition#Ver.C3.A4nderte_Flugzeit $chance = mt_rand(0, 100); $Wrapper = array(); $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 2; $Wrapper[] = 3; $Wrapper[] = 3; $Wrapper[] = 5; if ($chance < 75) { // More return time $normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']; $stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']; $factor = $Wrapper[mt_rand(0, 9)]; $endTime = $this->_fleet['fleet_end_stay'] + $normalBackTime + $stayTime + $factor; $this->UpdateFleet('fleet_end_time', $endTime); $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)]; } else { $normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']; $stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']; $factor = $Wrapper[mt_rand(0, 9)]; $endTime = max(1, $normalBackTime - $stayTime / 3 * $factor); $this->UpdateFleet('fleet_end_time', $endTime); $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)]; } break; } PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 15, $LNG['sys_expe_report'], $Message, $this->_fleet['fleet_end_stay'], NULL, 1, $this->_fleet['fleet_universe']); $this->setState(FLEET_RETURN); $this->SaveFleet(); }
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); }
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><span class="textForBlind"> (' . $textForBlind . ')</span>'; return $FleetPopup; }
public static function sendFleet($fleetArray, $fleetMission, $fleetStartOwner, $fleetStartPlanetID, $fleetStartPlanetGalaxy, $fleetStartPlanetSystem, $fleetStartPlanetPlanet, $fleetStartPlanetType, $fleetTargetOwner, $fleetTargetPlanetID, $fleetTargetPlanetGalaxy, $fleetTargetPlanetSystem, $fleetTargetPlanetPlanet, $fleetTargetPlanetType, $fleetResource, $fleetStartTime, $fleetStayTime, $fleetEndTime, $fleetGroup = 0, $missileTarget = 0) { global $resource; $fleetShipCount = array_sum($fleetArray); $fleetData = array(); $db = Database::get(); $params = array(':planetId' => $fleetStartPlanetID); $planetQuery = ""; foreach ($fleetArray as $ShipID => $ShipCount) { $fleetData[] = $ShipID . ',' . floatToString($ShipCount); $planetQuery[] = $resource[$ShipID] . " = " . $resource[$ShipID] . " - :" . $resource[$ShipID]; $params[':' . $resource[$ShipID]] = floatToString($ShipCount); } $sql = 'UPDATE %%PLANETS%% SET ' . implode(', ', $planetQuery) . ' WHERE id = :planetId;'; $db->update($sql, $params); $sql = 'INSERT INTO %%FLEETS%% SET fleet_owner = :fleetStartOwner, fleet_target_owner = :fleetTargetOwner, fleet_mission = :fleetMission, fleet_amount = :fleetShipCount, fleet_array = :fleetData, fleet_universe = :universe, fleet_start_time = :fleetStartTime, fleet_end_stay = :fleetStayTime, fleet_end_time = :fleetEndTime, fleet_start_id = :fleetStartPlanetID, fleet_start_galaxy = :fleetStartPlanetGalaxy, fleet_start_system = :fleetStartPlanetSystem, fleet_start_planet = :fleetStartPlanetPlanet, fleet_start_type = :fleetStartPlanetType, fleet_end_id = :fleetTargetPlanetID, fleet_end_galaxy = :fleetTargetPlanetGalaxy, fleet_end_system = :fleetTargetPlanetSystem, fleet_end_planet = :fleetTargetPlanetPlanet, fleet_end_type = :fleetTargetPlanetType, fleet_resource_metal = :fleetResource901, fleet_resource_crystal = :fleetResource902, fleet_resource_deuterium = :fleetResource903, fleet_group = :fleetGroup, fleet_target_obj = :missileTarget, start_time = :timestamp;'; $db->insert($sql, array(':fleetStartOwner' => $fleetStartOwner, ':fleetTargetOwner' => $fleetTargetOwner, ':fleetMission' => $fleetMission, ':fleetShipCount' => $fleetShipCount, ':fleetData' => implode(';', $fleetData), ':fleetStartTime' => $fleetStartTime, ':fleetStayTime' => $fleetStayTime, ':fleetEndTime' => $fleetEndTime, ':fleetStartPlanetID' => $fleetStartPlanetID, ':fleetStartPlanetGalaxy' => $fleetStartPlanetGalaxy, ':fleetStartPlanetSystem' => $fleetStartPlanetSystem, ':fleetStartPlanetPlanet' => $fleetStartPlanetPlanet, ':fleetStartPlanetType' => $fleetStartPlanetType, ':fleetTargetPlanetID' => $fleetTargetPlanetID, ':fleetTargetPlanetGalaxy' => $fleetTargetPlanetGalaxy, ':fleetTargetPlanetSystem' => $fleetTargetPlanetSystem, ':fleetTargetPlanetPlanet' => $fleetTargetPlanetPlanet, ':fleetTargetPlanetType' => $fleetTargetPlanetType, ':fleetResource901' => $fleetResource[901], ':fleetResource902' => $fleetResource[902], ':fleetResource903' => $fleetResource[903], ':fleetGroup' => $fleetGroup, ':missileTarget' => $missileTarget, ':timestamp' => TIMESTAMP, ':universe' => Universe::current())); $fleetId = $db->lastInsertId(); $sql = 'INSERT INTO %%FLEETS_EVENT%% SET fleetID = :fleetId, `time` = :endTime;'; $db->insert($sql, array(':fleetId' => $fleetId, ':endTime' => $fleetStartTime)); $sql = 'INSERT INTO %%LOG_FLEETS%% SET fleet_id = :fleetId, fleet_owner = :fleetStartOwner, fleet_target_owner = :fleetTargetOwner, fleet_mission = :fleetMission, fleet_amount = :fleetShipCount, fleet_array = :fleetData, fleet_universe = :universe, fleet_start_time = :fleetStartTime, fleet_end_stay = :fleetStayTime, fleet_end_time = :fleetEndTime, fleet_start_id = :fleetStartPlanetID, fleet_start_galaxy = :fleetStartPlanetGalaxy, fleet_start_system = :fleetStartPlanetSystem, fleet_start_planet = :fleetStartPlanetPlanet, fleet_start_type = :fleetStartPlanetType, fleet_end_id = :fleetTargetPlanetID, fleet_end_galaxy = :fleetTargetPlanetGalaxy, fleet_end_system = :fleetTargetPlanetSystem, fleet_end_planet = :fleetTargetPlanetPlanet, fleet_end_type = :fleetTargetPlanetType, fleet_resource_metal = :fleetResource901, fleet_resource_crystal = :fleetResource902, fleet_resource_deuterium = :fleetResource903, fleet_group = :fleetGroup, fleet_target_obj = :missileTarget, start_time = :timestamp;'; $db->insert($sql, array(':fleetId' => $fleetId, ':fleetStartOwner' => $fleetStartOwner, ':fleetTargetOwner' => $fleetTargetOwner, ':fleetMission' => $fleetMission, ':fleetShipCount' => $fleetShipCount, ':fleetData' => implode(';', $fleetData), ':fleetStartTime' => $fleetStartTime, ':fleetStayTime' => $fleetStayTime, ':fleetEndTime' => $fleetEndTime, ':fleetStartPlanetID' => $fleetStartPlanetID, ':fleetStartPlanetGalaxy' => $fleetStartPlanetGalaxy, ':fleetStartPlanetSystem' => $fleetStartPlanetSystem, ':fleetStartPlanetPlanet' => $fleetStartPlanetPlanet, ':fleetStartPlanetType' => $fleetStartPlanetType, ':fleetTargetPlanetID' => $fleetTargetPlanetID, ':fleetTargetPlanetGalaxy' => $fleetTargetPlanetGalaxy, ':fleetTargetPlanetSystem' => $fleetTargetPlanetSystem, ':fleetTargetPlanetPlanet' => $fleetTargetPlanetPlanet, ':fleetTargetPlanetType' => $fleetTargetPlanetType, ':fleetResource901' => $fleetResource[901], ':fleetResource902' => $fleetResource[902], ':fleetResource903' => $fleetResource[903], ':fleetGroup' => $fleetGroup, ':missileTarget' => $missileTarget, ':timestamp' => TIMESTAMP, ':universe' => Universe::current())); }
public function show() { global $USER, $PLANET, $LNG, $resource, $reslist; if ($PLANET[$resource[21]] == 0) { $this->printMessage($LNG['bd_shipyard_required']); } $buildTodo = HTTP::_GP('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 && $NotBuilding == true) { if (!empty($buildTodo)) { $maxBuildQueue = Config::get()->max_elements_ships; if ($maxBuildQueue != 0 && $Count >= $maxBuildQueue) { $this->printMessage(sprintf($LNG['bd_max_builds'], $maxBuildQueue)); } $this->BuildAuftr($buildTodo); $ElementQueue = unserialize($PLANET['b_hangar_id']); } if ($action == "delete") { $this->CancelAuftr(); } } $elementInQueue = array(); $buildList = array(); $elementList = 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]); } $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') { $elementIDs = array_merge($reslist['defense'], $reslist['missile']); } else { $elementIDs = $reslist['fleet']; } $Missiles = array(); foreach ($reslist['missile'] as $elementID) { $Missiles[$elementID] = $PLANET[$resource[$elementID]]; } $MaxMissiles = BuildFunctions::getMaxConstructibleRockets($USER, $PLANET, $Missiles); foreach ($elementIDs as $Element) { if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element)) { continue; } $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element); $costOverflow = BuildFunctions::getRestPrice($USER, $PLANET, $Element, $costResources); $elementTime = BuildFunctions::getBuildingTime($USER, $PLANET, $Element, $costResources); $buyable = BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources); $maxBuildable = BuildFunctions::getMaxConstructibleElements($USER, $PLANET, $Element, $costResources); if (isset($MaxMissiles[$Element])) { $maxBuildable = min($maxBuildable, $MaxMissiles[$Element]); } $AlreadyBuild = in_array($Element, $reslist['one']) && (isset($elementInQueue[$Element]) || $PLANET[$resource[$Element]] != 0); $elementList[$Element] = array('id' => $Element, 'available' => $PLANET[$resource[$Element]], 'costResources' => $costResources, 'costOverflow' => $costOverflow, 'elementTime' => $elementTime, 'buyable' => $buyable, 'maxBuildable' => floatToString($maxBuildable), 'AlreadyBuild' => $AlreadyBuild); } $this->assign(array('elementList' => $elementList, 'NotBuilding' => $NotBuilding, 'BuildList' => $buildList, 'maxlength' => strlen(Config::get()->max_fleet_per_build), 'mode' => $mode)); $this->display('page.shipyard.default.tpl'); }
function TargetEvent() { global $resource, $reslist; $db = Database::get(); $config = Config::get($this->_fleet['fleet_universe']); $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> <span class="%s">%s: %s</span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span class="reportSteal element901">%s</span> </span><span>%s: <span class="reportSteal element902">%s</span> </span><span>%s: <span class="reportSteal element903">%s</span></span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span class="reportDebris element901">%s</span> </span><span>%s: <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->Fleet_Cdr; $defIntoDebris = $config->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 fleet.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 fleet.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]; } $debrisTotal = array_sum($debris); $moonFactor = $config->moon_factor; $maxMoonChance = $config->moon_chance; if ($targetPlanet['id_luna'] == 0 && $targetPlanet['planet_type'] == 1) { $chanceCreateMoon = round($debrisTotal / 100000 * $moonFactor); $chanceCreateMoon = min($chanceCreateMoon, $maxMoonChance); } else { $chanceCreateMoon = 0; } $reportInfo = 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) { $LNG = $this->getLanguage($targetUser['lang']); $reportInfo['moonName'] = $LNG['type_planet'][3]; PlayerUtil::createMoon($this->_fleet['fleet_universe'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $targetUser['id'], $reportInfo['moonName'], $chanceCreateMoon, $this->_fleet['fleet_start_time']); if (Config::get($this->_fleet['fleet_universe'])->debris_moon == 1) { foreach ($debrisResource as $elementID) { $planetDebris[$elementID] = 0; } } } require_once 'includes/classes/missions/functions/GenerateReport.php'; $reportData = GenerateReport($combatResult, $reportInfo); switch ($combatResult['won']) { case "a": // Win $attackStatus = 'wons'; $defendStatus = 'loos'; $class = array('raportWin', 'raportLose'); break; case "r": // Lose $attackStatus = 'loos'; $defendStatus = 'wons'; $class = array('raportLose', 'raportWin'); break; case "w": default: // Draw $attackStatus = 'draws'; $defendStatus = 'draws'; $class = array('raportDraw', 'raportDraw'); break; } $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' => $i + 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(); }
break; default: $price_string .= $units[$units_num - 1] . $key . 'ек '; //копеек } } else { ${$price_string} .= $key . 'ек '; } break; } } } return $price_string; } foreach ($price_float as $price_value) { echo floatToString($price_value); } // В) $x_deg_arr = array(65, 89, 45, 12, -41, -90); function tang($x_deg) { if ($x_deg != -90 && $x_deg != 90) { $x_rad = $x_deg * pi() / 180; $x_tang = $x_rad + 1 / 3 * pow($x_rad, 3) + 2 / 15 * pow($x_rad, 5) + 17 / 315 * pow($x_rad, 7) + 62 / 2835 * pow($x_rad, 9); } else { $x_tang = 'N/A'; } echo 'tg(' . $x_deg . ')=' . $x_tang; } foreach ($x_deg_arr as $x_value) { echo tang($x_value) . '<br />';