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"); }
function send() { global $reslist, $pricelist, $LNG; if (!isset($_REQUEST['battleinput'])) { $this->sendJSON(0); } $BattleArray = $_REQUEST['battleinput']; $elements = array(0, 0); foreach ($BattleArray as $BattleSlotID => $BattleSlot) { if (isset($BattleSlot[0]) && (array_sum($BattleSlot[0]) > 0 || $BattleSlotID == 0)) { $attacker = array(); $attacker['fleetDetail'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0); $attacker['player'] = array('id' => 1000 + $BattleSlotID + 1, 'username' => $LNG['bs_atter'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[0][109], 'defence_tech' => $BattleSlot[0][110], 'shield_tech' => $BattleSlot[0][111], 'dm_defensive' => 0, 'dm_attack' => 0); $attacker['player']['factor'] = getFactors($attacker['player'], 'attack'); foreach ($BattleSlot[0] as $ID => $Count) { if (!in_array($ID, $reslist['fleet']) || $BattleSlot[0][$ID] <= 0) { unset($BattleSlot[0][$ID]); } } $attacker['unit'] = $BattleSlot[0]; $attackers[] = $attacker; } if (isset($BattleSlot[1]) && (array_sum($BattleSlot[1]) > 0 || $BattleSlotID == 0)) { $defender = array(); $defender['fleetDetail'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0); $defender['player'] = array('id' => 2000 + $BattleSlotID + 1, 'username' => $LNG['bs_deffer'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[1][109], 'defence_tech' => $BattleSlot[1][110], 'shield_tech' => $BattleSlot[1][111], 'dm_attack' => 0, 'dm_defensive' => 0); $defender['player']['factor'] = getFactors($defender['player'], 'attack'); foreach ($BattleSlot[1] as $ID => $Count) { if (!in_array($ID, $reslist['fleet']) && !in_array($ID, $reslist['defense']) || $BattleSlot[1][$ID] <= 0) { unset($BattleSlot[1][$ID]); } } $defender['unit'] = $BattleSlot[1]; $defenders[] = $defender; } } $LNG->includeData(array('FLEET')); require_once 'includes/classes/missions/functions/calculateAttack.php'; require_once 'includes/classes/missions/functions/calculateSteal.php'; require_once 'includes/classes/missions/functions/GenerateReport.php'; $combatResult = calculateAttack($attackers, $defenders, Config::get()->Fleet_Cdr, Config::get()->Defs_Cdr); if ($combatResult['won'] == "a") { $stealResource = calculateSteal($attackers, array('metal' => $BattleArray[0][1][1], 'crystal' => $BattleArray[0][1][2], 'deuterium' => $BattleArray[0][1][3]), true); } else { $stealResource = array(901 => 0, 902 => 0, 903 => 0); } $debris = array(); foreach (array(901, 902) as $elementID) { $debris[$elementID] = $combatResult['debris']['attacker'][$elementID] + $combatResult['debris']['defender'][$elementID]; } $debrisTotal = array_sum($debris); $moonFactor = Config::get()->moon_factor; $maxMoonChance = Config::get()->moon_chance; $chanceCreateMoon = round($debrisTotal / 100000 * $moonFactor); $chanceCreateMoon = min($chanceCreateMoon, $maxMoonChance); $sumSteal = array_sum($stealResource); $stealResourceInformation = sprintf($LNG['bs_derbis_raport'], pretty_number(ceil($debrisTotal / $pricelist[219]['capacity'])), $LNG['tech'][219], pretty_number(ceil($debrisTotal / $pricelist[209]['capacity'])), $LNG['tech'][209]); $stealResourceInformation .= '<br>'; $stealResourceInformation .= sprintf($LNG['bs_steal_raport'], pretty_number(ceil($sumSteal / $pricelist[202]['capacity'])), $LNG['tech'][202], pretty_number(ceil($sumSteal / $pricelist[203]['capacity'])), $LNG['tech'][203], pretty_number(ceil($sumSteal / $pricelist[217]['capacity'])), $LNG['tech'][217]); $reportInfo = array('thisFleet' => array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_start_time' => TIMESTAMP), 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => $chanceCreateMoon, 'moonDestroy' => false, 'moonName' => NULL, 'moonDestroyChance' => NULL, 'moonDestroySuccess' => NULL, 'fleetDestroyChance' => NULL, 'fleetDestroySuccess' => NULL, 'additionalInfo' => $stealResourceInformation); $reportData = GenerateReport($combatResult, $reportInfo); $reportID = md5(uniqid('', true) . TIMESTAMP); $db = Database::get(); $sql = "INSERT INTO %%RW%% SET rid = :reportID, raport = :reportData, time = :time;"; $db->insert($sql, array(':reportID' => $reportID, ':reportData' => serialize($reportData), ':time' => TIMESTAMP)); $this->sendJSON($reportID); }
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> <span %s>%s: %s</span></td> </tr> <tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</span> </span><span>%s: <span style="color:#5ca6aa;">%s</span> </span><span>%s: <span style="color:#339966;">%s</span></span></td> \t\t</tr> <tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</font> </span><span>%s: <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(); }
function TargetEvent() { global $db, $pricelist, $LANG, $CONF, $UNI, $reslist; $UsedPlanet = $GLOBALS['DATABASE']->getFirstCell("SELECT COUNT(*) FROM " . PLANETS . " WHERE `id` = '" . $this->_fleet['fleet_end_id'] . "';"); $Target2 = $GLOBALS['DATABASE']->uniquequery("SELECT id_owner FROM " . PLANETS . " WHERE `id` = '" . $this->_fleet['fleet_end_id'] . "';"); $targetPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE id = '" . $this->_fleet['fleet_end_id'] . "';"); if (!$UsedPlanet) { $this->setState(FLEET_RETURN); $this->SaveFleet(); } elseif ($Target2['id_owner'] != 9998) { $this->setState(FLEET_RETURN); $this->SaveFleet(); } else { $expeditionPoints = array(); foreach ($reslist['fleet'] as $ID) { $expeditionPoints[$ID] = ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]) / 1000; } $expeditionPoints[202] = 12; $expeditionPoints[203] = 47; $expeditionPoints[204] = 12; $expeditionPoints[205] = 110; $expeditionPoints[206] = 47; $expeditionPoints[207] = 160; $fleetRaw = explode(";", $this->_fleet['fleet_array']); $fleetCapacity = 0; $fleetPoints = 0; $fleetArray = array(); $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter']; 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]]; } $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']); $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;"; } $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> <span %s>%s: %s</span></td> </tr> <tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</span> </span><span>%s: <span style="color:#5ca6aa;">%s</span> </span><span>%s: <span style="color:#339966;">%s</span></span></td> \t\t</tr> <tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</font> </span><span>%s: <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), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0, 'academy_1101' => 0, 'academy_1102' => 0, 'academy_1301' => 0, 'academy_1302' => 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 = 'raportDraw'; $defendClass = 'raportDraw'; 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_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' && $this->_fleet['fleet_end_type'] == 4) { $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " set `id_owner` = '" . $this->_fleet['fleet_owner'] . "' where `id` = '" . $this->_fleet['fleet_end_id'] . "';"); } SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $message); $this->setState(FLEET_RETURN); $this->SaveFleet(); } }
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(); }
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(); }
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> <span class="%s">%s: %s</span></td> \t\t</tr> \t\t<tr> \t\t\t<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>%s: <span class="raportSteal element904">%s</span></span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span class="raportDebris element901">%s</span> </span><span>%s: <span class="raportDebris element902">%s</span><span>%s: <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(); }
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> <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::get($this->_fleet['fleet_universe'])->Fleet_Cdr; $defIntoDebris = Config::get($this->_fleet['fleet_universe'])->Defs_Cdr; $combatResult = calculateAttack($fleetAttack, $fleetDefend, $fleetIntoDebris, $defIntoDebris); foreach ($fleetAttack as $fleetID => $fleetDetail) { $fleetArray = ''; $totalCount = 0; $fleetDetail['unit'] = array_filter($fleetDetail['unit']); foreach ($fleetDetail['unit'] as $elementID => $amount) { $fleetArray .= $elementID . ',' . floattostring($amount) . ';'; $totalCount += $amount; } if ($totalCount == 0) { if ($this->_fleet['fleet_id'] == $fleetID) { $this->KillFleet(); } else { $sql = 'DELETE %%FLEETS%%, %%FLEETS_EVENT%% FROM %%FLEETS%% INNER JOIN %%FLEETS_EVENT%% ON fleetID = fleet_id WHERE fleet_id = :fleetId;'; $db->delete($sql, array(':fleetId' => $fleetID)); } $sql = 'UPDATE %%LOG_FLEETS%% SET fleet_state = :fleetState WHERE fleet_id = :fleetId;'; $db->update($sql, array(':fleetId' => $fleetID, ':fleetState' => FLEET_HOLD)); unset($fleetAttack[$fleetID]); } elseif ($totalCount > 0) { $sql = "UPDATE %%FLEETS%% fleet, %%LOG_FLEETS%% log SET\n\t\t\t\tfleet.fleet_array\t= :fleetData,\n\t\t\t\tfleet.fleet_amount\t= :fleetCount,\n\t\t\t\tlog.fleet_array\t\t= :fleetData,\n\t\t\t\tlog.fleet_amount\t= :fleetCount\n\t\t\t\tWHERE log.fleet_id = :fleetId AND log.fleet_id = :fleetId;"; $db->update($sql, array(':fleetData' => substr($fleetArray, 0, -1), ':fleetCount' => $totalCount, ':fleetId' => $fleetID)); } else { throw new OutOfRangeException("Negative Fleet amount ...."); } } foreach ($fleetDefend as $fleetID => $fleetDetail) { if ($fleetID != 0) { // Stay fleet $fleetArray = ''; $totalCount = 0; $fleetDetail['unit'] = array_filter($fleetDetail['unit']); foreach ($fleetDetail['unit'] as $elementID => $amount) { $fleetArray .= $elementID . ',' . floattostring($amount) . ';'; $totalCount += $amount; } if ($totalCount == 0) { $sql = 'DELETE %%FLEETS%%, %%FLEETS_EVENT%% FROM %%FLEETS%% INNER JOIN %%FLEETS_EVENT%% ON fleetID = fleet_id WHERE fleet_id = :fleetId;'; $db->delete($sql, array(':fleetId' => $fleetID)); $sql = 'UPDATE %%LOG_FLEETS%% SET fleet_state = :fleetState WHERE fleet_id = :fleetId;'; $db->update($sql, array(':fleetId' => $fleetID, ':fleetState' => FLEET_HOLD)); unset($fleetAttack[$fleetID]); } elseif ($totalCount > 0) { $sql = "UPDATE %%FLEETS%% fleet, %%LOG_FLEETS%% log SET\n\t\t\t\t\tfleet.fleet_array\t= :fleetData,\n\t\t\t\t\tfleet.fleet_amount\t= :fleetCount,\n\t\t\t\t\tlog.fleet_array\t\t= :fleetData,\n\t\t\t\t\tlog.fleet_amount\t= :fleetCount\n\t\t\t\t\tWHERE log.fleet_id = :fleetId AND log.fleet_id = :fleetId;"; $db->update($sql, array(':fleetData' => substr($fleetArray, 0, -1), ':fleetCount' => $totalCount, ':fleetId' => $fleetID)); } else { throw new OutOfRangeException("Negative Fleet amount ...."); } } else { $params = array(':planetId' => $this->_fleet['fleet_end_id']); // Planet fleet $fleetArray = array(); foreach ($fleetDetail['unit'] as $elementID => $amount) { $fleetArray[] = '`' . $resource[$elementID] . '` = :' . $resource[$elementID]; $params[':' . $resource[$elementID]] = $amount; } if (!empty($fleetArray)) { $sql = 'UPDATE %%PLANETS%% SET ' . implode(', ', $fleetArray) . ' WHERE id = :planetId;'; $db->update($sql, $params); } } } if ($combatResult['won'] == "a") { require_once 'includes/classes/missions/functions/calculateSteal.php'; $stealResource = calculateSteal($fleetAttack, $targetPlanet); } if ($this->_fleet['fleet_end_type'] == 3) { // Use planet debris, if attack on moons $sql = "SELECT der_metal, der_crystal FROM %%PLANETS%% WHERE id_luna = :moonId;"; $targetDebris = $db->selectSingle($sql, array(':moonId' => $this->_fleet['fleet_end_id'])); $targetPlanet += $targetDebris; } foreach ($debrisResource as $elementID) { $debris[$elementID] = $combatResult['debris']['attacker'][$elementID] + $combatResult['debris']['defender'][$elementID]; $planetDebris[$elementID] = $targetPlanet['der_' . $resource[$elementID]] + $debris[$elementID]; } $reportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => NULL, 'moonDestroy' => true, 'moonName' => NULL, 'moonDestroyChance' => NULL, 'moonDestroySuccess' => NULL, 'fleetDestroyChance' => NULL, 'fleetDestroySuccess' => false); switch ($combatResult['won']) { case "a": $moonDestroyChance = round((100 - sqrt($targetPlanet['diameter'])) * sqrt($fleetAttack[$this->_fleet['fleet_id']]['unit'][214]), 1); // Max 100% | Min 0% $moonDestroyChance = min($moonDestroyChance, 100); $moonDestroyChance = max($moonDestroyChance, 0); $randChance = mt_rand(1, 100); if ($randChance <= $moonDestroyChance) { $sql = 'SELECT id FROM %%PLANETS%% WHERE id_luna = :moonId;'; $planetID = $db->selectSingle($sql, array(':moonId' => $targetPlanet['id']), 'id'); $sql = 'UPDATE %%FLEETS%% SET fleet_start_type = 1, fleet_start_id = :planetId WHERE fleet_start_id = :moonId;'; $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id'])); $sql = 'UPDATE %%FLEETS%% SET fleet_end_type = 1, fleet_end_id = :moonId, fleet_mission = IF(fleet_mission = 9, 1, fleet_mission) WHERE fleet_end_id = :planetId AND fleet_id != :fleetId;'; $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id'], ':fleetId' => $this->_fleet['fleet_id'])); $sql = "UPDATE %%AKS%% SET target = :planetId WHERE target = :moonId;"; $db->update($sql, array(':planetId' => $planetID, ':moonId' => $targetPlanet['id'])); PlayerUtil::deletePlanet($targetPlanet['id']); $reportInfo['moonDestroySuccess'] = 1; } else { $reportInfo['moonDestroySuccess'] = 0; } $fleetDestroyChance = round(sqrt($targetPlanet['diameter']) / 2); $randChance = mt_rand(1, 100); if ($randChance <= $fleetDestroyChance) { $this->KillFleet(); $reportInfo['fleetDestroySuccess'] = true; } else { $reportInfo['fleetDestroySuccess'] = false; } $reportInfo['moonDestroyChance'] = $moonDestroyChance; $reportInfo['fleetDestroyChance'] = $fleetDestroyChance; // Win $attackStatus = 'wons'; $defendStatus = 'loos'; $class = array('raportWin', 'raportLose'); break; case "r": // Lose $attackStatus = 'loos'; $defendStatus = 'wons'; $class = array('raportLose', 'raportWin'); $reportInfo['moonDestroySuccess'] = -1; break; default: // Draw $attackStatus = 'draws'; $defendStatus = 'draws'; $class = array('raportDraw', 'raportDraw'); $reportInfo['moonDestroySuccess'] = -1; break; } require_once 'includes/classes/missions/functions/GenerateReport.php'; $reportData = GenerateReport($combatResult, $reportInfo); $reportID = md5(uniqid('', true) . TIMESTAMP); $sql = 'INSERT INTO %%RW%% SET rid = :reportId, raport = :reportData, time = :time, attacker = :attackers, defender = :defenders;'; $db->insert($sql, array(':reportId' => $reportID, ':reportData' => serialize($reportData), ':time' => $this->_fleet['fleet_start_time'], ':attackers' => implode(',', array_keys($userAttack)), ':defenders' => implode(',', array_keys($userDefend)))); $i = 0; foreach (array($userAttack, $userDefend) as $data) { $thisClass = $class[$i]; foreach ($data as $userID => $userName) { $LNG = $this->getLanguage(NULL, $userID); $message = sprintf($messageHTML, $reportID, $thisClass[$i], $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $LNG['type_planet_short'][$this->_fleet['fleet_end_type']], $LNG['sys_lost'], $thisClass[0], $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $thisClass[1], $LNG['sys_attack_defender_pos'], pretty_number($combatResult['unitLost']['defender']), $LNG['sys_gain'], $LNG['tech'][901], pretty_number($stealResource[901]), $LNG['tech'][902], pretty_number($stealResource[902]), $LNG['tech'][903], pretty_number($stealResource[903]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902])); PlayerUtil::sendMessage($userID, 0, $LNG['sys_mess_tower'], 3, $LNG['sys_mess_attack_report'], $message, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']); $sql = "INSERT INTO %%TOPKB_USERS%% SET\n\t\t\t\trid\t\t\t= :reportId,\n\t\t\t\trole\t\t= :userRole,\n\t\t\t\tusername\t= :username,\n\t\t\t\tuid\t\t\t= :userId;"; $db->insert($sql, array(':reportId' => $reportID, ':userRole' => 1, ':username' => $userName, ':userId' => $userID)); } $i++; } if ($this->_fleet['fleet_end_type'] == 3) { $debrisType = 'id_luna'; } else { $debrisType = 'id'; } $sql = 'UPDATE %%PLANETS%% SET der_metal = :metal, der_crystal = :crystal WHERE ' . $debrisType . ' = :planetId;'; $db->update($sql, array(':metal' => $planetDebris[901], ':crystal' => $planetDebris[902], ':planetId' => $this->_fleet['fleet_end_id'])); $sql = 'UPDATE %%PLANETS%% SET metal = metal - :metal, crystal = crystal - :crystal, deuterium = deuterium - :deuterium WHERE id = :planetId;'; $db->update($sql, array(':metal' => $stealResource[901], ':crystal' => $stealResource[902], ':deuterium' => $stealResource[903], ':planetId' => $this->_fleet['fleet_end_id'])); $sql = 'INSERT INTO %%TOPKB%% SET units = :units, rid = :reportId, time = :time, universe = :universe, result = :result;'; $db->insert($sql, array(':units' => $combatResult['unitLost']['attacker'] + $combatResult['unitLost']['defender'], ':reportId' => $reportID, ':time' => $this->_fleet['fleet_start_time'], ':universe' => $this->_fleet['fleet_universe'], ':result' => $combatResult['won'])); $sql = 'UPDATE %%USERS%% SET `' . $attackStatus . '` = `' . $attackStatus . '` + 1, kbmetal = kbmetal + :debrisMetal, kbcrystal = kbcrystal + :debrisCrystal, lostunits = lostunits + :lostUnits, desunits = desunits + :destroyedUnits WHERE id IN (' . implode(',', array_keys($userAttack)) . ');'; $db->update($sql, array(':debrisMetal' => $debris[901], ':debrisCrystal' => $debris[902], ':lostUnits' => $combatResult['unitLost']['attacker'], ':destroyedUnits' => $combatResult['unitLost']['defender'])); $sql = 'UPDATE %%USERS%% SET `' . $defendStatus . '` = `' . $defendStatus . '` + 1, kbmetal = kbmetal + :debrisMetal, kbcrystal = kbcrystal + :debrisCrystal, lostunits = lostunits + :lostUnits, desunits = desunits + :destroyedUnits WHERE id IN (' . implode(',', array_keys($userDefend)) . ');'; $db->update($sql, array(':debrisMetal' => $debris[901], ':debrisCrystal' => $debris[902], ':lostUnits' => $combatResult['unitLost']['defender'], ':destroyedUnits' => $combatResult['unitLost']['attacker'])); $this->setState(FLEET_RETURN); $this->SaveFleet(); }
function TargetEvent() { global $pricelist, $resource, $reslist, $db, $LANG; $targetPlanet = $db->uniquequery("SELECT * FROM " . PLANETS . " WHERE `id` = '" . $this->_fleet['fleet_end_id'] . "';"); $targetUser = $db->uniquequery("SELECT * FROM " . USERS . " WHERE id = '" . $targetPlanet['id_owner'] . "';"); require_once ROOT_PATH . 'includes/classes/class.PlanetRessUpdate.php'; $PlanetRess = new ResourceUpdate(); list($targetUser, $targetPlanet) = $PlanetRess->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']); $TargetUserID = $targetUser['id']; $attackFleets = array(); $AttackerRow['id'] = array(); $AttackerRow['name'] = array(); $DefenderRow['id'] = array(); $DefenderRow['name'] = array(); if ($this->_fleet['fleet_group'] != 0) { $db->query("DELETE FROM " . AKS . " WHERE `id` = '" . $this->_fleet['fleet_group'] . "';"); $fleets = $db->query("SELECT * FROM " . FLEETS . " WHERE fleet_group = '" . $this->_fleet['fleet_group'] . "';"); while ($fleet = $db->fetch_array($fleets)) { $attackFleets[$fleet['fleet_id']]['fleet'] = $fleet; $attackFleets[$fleet['fleet_id']]['user'] = $db->uniquequery("SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM " . USERS . " WHERE `id` = '" . $fleet['fleet_owner'] . "';"); $attackFleets[$fleet['fleet_id']]['detail'] = array(); $temp = explode(';', $fleet['fleet_array']); foreach ($temp as $temp2) { $temp2 = explode(',', $temp2); if ($temp2[0] < 100) { continue; } if (!isset($attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]])) { $attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]] = 0; } $attackFleets[$fleet['fleet_id']]['detail'][$temp2[0]] += $temp2[1]; } $AttackerRow['id'][] = $attackFleets[$fleet['fleet_id']]['user']['id']; $AttackerRow['name'][] = $attackFleets[$fleet['fleet_id']]['user']['username']; } } else { $attackFleets[$this->_fleet['fleet_id']]['fleet'] = $this->_fleet; $attackFleets[$this->_fleet['fleet_id']]['user'] = $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'] . "';"); $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]; } $AttackerRow['id'][] = $attackFleets[$this->_fleet['fleet_id']]['user']['id']; $AttackerRow['name'][] = $attackFleets[$this->_fleet['fleet_id']]['user']['username']; } $defense = array(); $def = $db->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 ($defRow = $db->fetch_array($def)) { $defense[$defRow['fleet_id']]['user'] = $db->uniquequery("SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM " . USERS . " WHERE id = '" . $defRow['fleet_owner'] . "';"); $defRowDef = explode(';', $defRow['fleet_array']); foreach ($defRowDef as $Element) { $Element = explode(',', $Element); if ($Element[0] < 100) { continue; } if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]])) { $defense[$defRow['fleet_id']][$Element[0]] = 0; } $defense[$defRow['fleet_id']]['def'][$Element[0]] += $Element[1]; } $DefenderRow['id'][] = $defense[$defRow['fleet_id']]['user']['id']; $DefenderRow['name'][] = $defense[$defRow['fleet_id']]['user']['username']; } $defense[0]['def'] = array(); $defense[0]['user'] = $targetUser; $DefenderRow['id'][] = $defense[0]['user']['id']; $DefenderRow['name'][] = $defense[0]['user']['username']; foreach (array_merge($reslist['fleet'], $reslist['defense']) as $ID) { if ($ID >= 500) { continue; } $defense[0]['def'][$ID] = $targetPlanet[$resource[$ID]]; } $Attacker['id'] = array_unique($AttackerRow['id']); $Attacker['name'] = array_unique($AttackerRow['name']); $Defender['id'] = array_unique($DefenderRow['id']); $Defender['name'] = array_unique($DefenderRow['name']); $CONF = $db->uniquequery("SELECT `Fleet_Cdr`, `Defs_Cdr` FROM `" . CONFIG . "` WHERE `uni` = '" . $this->_fleet['fleet_universe'] . "';"); require_once 'calculateAttack.php'; $result = calculateAttack($attackFleets, $defense, $CONF['Fleet_Cdr'], $CONF['Defs_Cdr']); $SQL = ""; foreach ($attackFleets as $fleetID => $attacker) { $fleetArray = ''; $totalCount = 0; foreach ($attacker['detail'] as $element => $amount) { if ($amount) { $fleetArray .= $element . ',' . floattostring($amount) . ';'; } $totalCount += $amount; } $SQL .= $totalCount <= 0 ? "DELETE FROM " . FLEETS . " WHERE `fleet_id`= '" . $fleetID . "';" : "UPDATE " . FLEETS . " SET `fleet_mess` = '1', `fleet_array` = '" . substr($fleetArray, 0, -1) . "', `fleet_amount` = '" . $totalCount . "' WHERE `fleet_id` = '" . $fleetID . "';"; } if ($result['won'] == "a") { require_once 'calculateSteal.php'; $steal = calculateSteal($attackFleets, $targetPlanet); } foreach ($defense as $fleetID => $defender) { if ($fleetID != 0) { $fleetArray = ''; $totalCount = 0; foreach ($defender['def'] as $element => $amount) { if ($amount) { $fleetArray .= $element . ',' . floattostring($amount) . ';'; } $totalCount += $amount; } $SQL .= $totalCount <= 0 ? "DELETE FROM " . FLEETS . " WHERE `fleet_id`= '" . $fleetID . "';" : "UPDATE " . FLEETS . " SET `fleet_array` = '" . substr($fleetArray, 0, -1) . "', `fleet_amount` = '" . $totalCount . "' WHERE `fleet_id` = '" . $fleetID . "';"; } else { $fleetArray = ''; foreach ($defender['def'] as $element => $amount) { $fleetArray .= "`" . $resource[$element] . "` = '" . floattostring($amount) . "', "; } $SQL .= "UPDATE " . PLANETS . " SET "; $SQL .= $fleetArray; $SQL .= "`metal` = `metal` - '" . $steal['metal'] . "', "; $SQL .= "`crystal` = `crystal` - '" . $steal['crystal'] . "', "; $SQL .= "`deuterium` = `deuterium` - '" . $steal['deuterium'] . "' "; $SQL .= "WHERE "; $SQL .= "`id` = '" . $this->_fleet['fleet_end_id'] . "';"; } } $db->multi_query($SQL); if ($this->_fleet['fleet_end_type'] == 3) { $targetPlanet = array_merge($targetPlanet, $db->uniquequery("SELECT `der_metal`, `der_crystal` FROM " . PLANETS . " WHERE `id_luna` = '" . $this->_fleet['fleet_end_id'] . "';")); } $ShootMetal = $result['debree']['att'][0] + $result['debree']['def'][0]; $ShootCrystal = $result['debree']['att'][1] + $result['debree']['def'][1]; $FleetDebris = $ShootMetal + $ShootCrystal; $DerbisMetal = $targetPlanet['der_metal'] + $ShootMetal; $DerbisCrystal = $targetPlanet['der_crystal'] + $ShootCrystal; $MoonChance = min(round($FleetDebris / 100000 * MOON_CHANCE_FACTOR, 0), MAX_MOON_CHANCE); $UserChance = mt_rand(1, 100); if ($targetPlanet['planet_type'] == 1 && $targetPlanet['id_luna'] == 0 && $MoonChance > 0 && $UserChance <= $MoonChance) { require_once ROOT_PATH . 'includes/functions/CreateOneMoonRecord.php'; $INFO['moon']['name'] = CreateOneMoonRecord($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $this->_fleet['fleet_universe'], $TargetUserID, $this->_fleet['fleet_start_time'], '', $MoonChance); $INFO['end_galaxy'] = $this->_fleet['fleet_end_galaxy']; $INFO['end_system'] = $this->_fleet['fleet_end_system']; $INFO['end_planet'] = $this->_fleet['fleet_end_planet']; if (DESTROY_DERBIS_MOON_CREATE) { $DerbisMetal = 0; $DerbisCrystal = 0; } } $INFO['steal'] = $steal; $INFO['fleet_start_time'] = $this->_fleet['fleet_start_time']; $INFO['moon']['des'] = 0; $INFO['moon']['chance'] = $MoonChance; $INFO['attvsdef'] = implode(' & ', $Attacker['name']) . ' vs ' . implode(' & ', $Defender['name']); require_once 'GenerateReport.php'; $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" . '?>'); file_put_contents(ROOT_PATH . 'raports/topkb_' . $rid . '.php', '<?php' . "\n" . '$raport = ' . preg_replace("/\\[\\d+\\:\\d+\\:\\d+\\]/i", "[X:X:X]", $raport) . ';' . "\n" . '?>'); if (DEBUG_EXTRA) { file_put_contents(ROOT_PATH . 'includes/attack.log', date('[d-M-Y H:i:s]', $this->_fleet['fleet_start_time']) . '(FleetID: ' . $this->_fleet['fleet_id'] . ') Attacker: ' . $this->_fleet['fleet_owner'] . '/ Defender: ' . $this->_fleet['fleet_target_owner'] . ' | TF: ' . floattostring($DerbisMetal) . '/' . floattostring($DerbisCrystal)); } $WhereAtt = ""; $WhereDef = ""; foreach ($Attacker['id'] as $id) { $WhereAtt .= "`id` = '" . $id . "' OR "; } foreach ($Defender['id'] as $id) { $WhereDef .= "`id` = '" . $id . "' OR "; } $Won = 0; $Lose = 0; $Draw = 0; switch ($result['won']) { case "a": $Won = 1; break; case "w": $Draw = 1; break; case "r": $Lose = 1; break; } $SQL = "UPDATE " . PLANETS . " SET "; $SQL .= "`der_metal` = " . floattostring($DerbisMetal) . ", "; $SQL .= "`der_crystal` = " . floattostring($DerbisCrystal) . " "; $SQL .= "WHERE "; $SQL .= "`universe` = '" . $this->_fleet['fleet_universe'] . "' AND "; $SQL .= "`galaxy` = '" . $this->_fleet['fleet_end_galaxy'] . "' AND "; $SQL .= "`system` = '" . $this->_fleet['fleet_end_system'] . "' AND "; $SQL .= "`planet` = '" . $this->_fleet['fleet_end_planet'] . "' AND "; $SQL .= "`planet_type` = '1';"; $SQL .= "INSERT INTO " . RW . " SET "; $SQL .= "`time` = '" . $this->_fleet['fleet_start_time'] . "', "; $SQL .= "`owners` = '" . implode(',', array_merge($Attacker['id'], $Defender['id'])) . "', "; $SQL .= "`rid` = '" . $rid . "';"; $SQL .= "INSERT INTO " . TOPKB . " SET "; $SQL .= "`time` = '" . $this->_fleet['fleet_start_time'] . "', "; $SQL .= "`id_owner1` = '" . implode(',', $Attacker['id']) . "', "; $SQL .= "`angreifer` = '" . implode(' & ', $Attacker['name']) . "', "; $SQL .= "`id_owner2` = '" . implode(',', $Defender['id']) . "', "; $SQL .= "`defender` = '" . implode(' & ', $Defender['name']) . "', "; $SQL .= "`gesamtunits` = '" . floattostring($result['lost']['att'] + $result['lost']['def']) . "', "; $SQL .= "`rid` = '" . $rid . "', "; $SQL .= "`universe` = '" . $this->_fleet['fleet_universe'] . "', "; $SQL .= "`fleetresult` = '" . $result['won'] . "';"; $SQL .= "UPDATE " . USERS . " SET "; $SQL .= "`wons` = wons + " . $Won . ", "; $SQL .= "`loos` = loos + " . $Lose . ", "; $SQL .= "`draws` = draws + " . $Draw . ", "; $SQL .= "`kbmetal` = kbmetal + " . floattostring($ShootMetal) . ", "; $SQL .= "`kbcrystal` = kbcrystal + " . floattostring($ShootCrystal) . ", "; $SQL .= "`lostunits` = lostunits + " . floattostring($result['lost']['att']) . ", "; $SQL .= "`desunits` = desunits + " . floattostring($result['lost']['def']) . " "; $SQL .= "WHERE "; $SQL .= substr($WhereAtt, 0, -4) . ";"; $SQL .= "UPDATE " . USERS . " SET "; $SQL .= "`wons` = wons + " . $Lose . ", "; $SQL .= "`loos` = loos + " . $Won . ", "; $SQL .= "`draws` = draws + " . $Draw . ", "; $SQL .= "`kbmetal` = kbmetal + " . floattostring($ShootMetal) . ", "; $SQL .= "`kbcrystal` = kbcrystal + " . floattostring($ShootCrystal) . ", "; $SQL .= "`lostunits` = lostunits + " . floattostring($result['lost']['def']) . ", "; $SQL .= "`desunits` = desunits + " . floattostring($result['lost']['att']) . " "; $SQL .= "WHERE "; $SQL .= substr($WhereDef, 0, -4) . ";"; $db->multi_query($SQL); switch ($result['won']) { case "r": $ColorAtt = "red"; $ColorDef = "green"; break; case "w": $ColorAtt = "orange"; $ColorDef = "orange"; case "a": $ColorAtt = "green"; $ColorDef = "red"; break; } foreach ($Attacker['id'] as $AttackersID) { if (empty($AttackersID)) { continue; } $LNG = $LANG->GetUserLang($AttackersID); $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($AttackersID, '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageAtt); } foreach ($Defender['id'] as $DefenderID) { if (empty($DefenderID)) { continue; } $LNG = $LANG->GetUserLang($DefenderID); $MessageDef = 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, $ColorDef, $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']), $ColorDef, $LNG['sys_perte_attaquant'], pretty_number($result['lost']['att']), $ColorAtt, $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($DefenderID, '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageDef); } }
function send() { global $USER, $PLANET, $reslist, $pricelist, $LNG, $CONF; if (!isset($_REQUEST['battleinput'])) { $this->sendJSON(0); } $pid = HTTP::_GP('pid', 0); $targetUser = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $pid . ";"); $BattleArray = $_REQUEST['battleinput']; $elements = array(0, 0); foreach ($BattleArray as $BattleSlotID => $BattleSlot) { if (isset($BattleSlot[0]) && (array_sum($BattleSlot[0]) > 0 || $BattleSlotID == 0)) { $attacker = array(); $attacker['fleetDetail'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0); $attacker['player'] = array('id' => 1000 + $BattleSlotID + 1, 'username' => $LNG['bs_atter'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[0][109], 'defence_tech' => $BattleSlot[0][110], 'shield_tech' => $BattleSlot[0][111], 'laser_tech' => $BattleSlot[0][120], 'ion_tech' => $BattleSlot[0][121], 'plasma_tech' => $BattleSlot[0][122], 'gravity_tech' => $BattleSlot[0][199], 'rpg_amiral' => $BattleSlot[0][602], 'academy_1101' => $USER['academy_1101'], 'academy_1102' => $USER['academy_1102'], 'academy_1301' => $USER['academy_1301'], 'academy_1302' => $USER['academy_1302'], 'academy_1103' => $BattleSlot[0][1103], 'academy_1108' => $BattleSlot[0][1108], 'academy_1109' => $BattleSlot[0][1109], 'academy_1110' => $BattleSlot[0][1110], 'academy_1111' => $BattleSlot[0][1111], 'academy_1303' => $BattleSlot[0][1303], 'academy_1311' => $BattleSlot[0][1311], 'experience_combat_level' => $USER['experience_combat_level']); $attacker['player']['factor'] = getFactors($attacker['player'], 'attack'); foreach ($BattleSlot[0] as $ID => $Count) { if (!in_array($ID, $reslist['fleet']) || $BattleSlot[0][$ID] <= 0) { unset($BattleSlot[0][$ID]); } } $attacker['unit'] = $BattleSlot[0]; $attackers[] = $attacker; } if (isset($BattleSlot[1]) && (array_sum($BattleSlot[1]) > 0 || $BattleSlotID == 0)) { $defender = array(); $defender['fleetDetail'] = array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0); $defender['player'] = array('id' => 2000 + $BattleSlotID + 1, 'username' => $LNG['bs_deffer'] . ' Nr.' . ($BattleSlotID + 1), 'military_tech' => $BattleSlot[1][109], 'defence_tech' => $BattleSlot[1][110], 'shield_tech' => $BattleSlot[1][111], 'laser_tech' => $BattleSlot[1][120], 'ion_tech' => $BattleSlot[1][121], 'plasma_tech' => $BattleSlot[1][122], 'gravity_tech' => $BattleSlot[1][199], 'rpg_amiral' => $BattleSlot[1][602], 'academy_1101' => $targetUser['academy_1101'], 'academy_1102' => $targetUser['academy_1102'], 'academy_1301' => $targetUser['academy_1301'], 'academy_1302' => $targetUser['academy_1302'], 'academy_1103' => $BattleSlot[1][1103], 'academy_1108' => $BattleSlot[1][1108], 'academy_1109' => $BattleSlot[1][1109], 'academy_1110' => $BattleSlot[1][1110], 'academy_1111' => $BattleSlot[1][1111], 'academy_1303' => $BattleSlot[1][1303], 'academy_1311' => $BattleSlot[1][1311], 'experience_combat_level' => 0); $defender['player']['factor'] = getFactors($defender['player'], 'attack'); foreach ($BattleSlot[1] as $ID => $Count) { if (!in_array($ID, $reslist['fleet']) && !in_array($ID, $reslist['defense']) || $BattleSlot[1][$ID] <= 0) { unset($BattleSlot[1][$ID]); } } $defender['unit'] = $BattleSlot[1]; $defenders[] = $defender; } } $LNG->includeData(array('FLEET')); require_once 'includes/classes/missions/calculateAttack.php'; require_once 'includes/classes/missions/calculateSteal.php'; require_once 'includes/classes/missions/GenerateReport.php'; $combatResult = calculateAttack($attackers, $defenders, Config::get('Fleet_Cdr'), Config::get('Defs_Cdr')); if ($combatResult['won'] == "a") { $stealResource = calculateSteal($attackers, array('metal' => $BattleArray[0][1][1], 'crystal' => $BattleArray[0][1][2], 'deuterium' => $BattleArray[0][1][3]), true); } else { $stealResource = array(901 => 0, 902 => 0, 903 => 0); } $debris = array(); foreach (array(901, 902) as $elementID) { $debris[$elementID] = $combatResult['debris']['attacker'][$elementID] + $combatResult['debris']['defender'][$elementID]; } $debrisTotal = array_sum($debris); $moonFactor = Config::get('moon_factor'); $maxMoonChance = Config::get('moon_chance'); $chanceCreateMoon = round($debrisTotal / 1000000 * $moonFactor); $chanceCreateMoon = min($chanceCreateMoon, $maxMoonChance); $raportInfo = array('thisFleet' => array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_start_time' => TIMESTAMP), 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => $chanceCreateMoon, 'moonDestroy' => false, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => null); $sumSteal = array_sum($stealResource); $stealResourceInformations = sprintf($LNG['bs_derbis_raport'], pretty_number(ceil($debrisTotal / $pricelist[219]['capacity'])), $LNG['tech'][219], pretty_number(ceil($debrisTotal / $pricelist[209]['capacity'])), $LNG['tech'][209]); $stealResourceInformations .= '<br>'; $stealResourceInformations .= sprintf($LNG['bs_steal_raport'], pretty_number(ceil($sumSteal / $pricelist[202]['capacity'])), $LNG['tech'][202], pretty_number(ceil($sumSteal / $pricelist[203]['capacity'])), $LNG['tech'][203], pretty_number(ceil($sumSteal / $pricelist[217]['capacity'])), $LNG['tech'][217]); $raportInfo = array('thisFleet' => array('fleet_start_galaxy' => 1, 'fleet_start_system' => 33, 'fleet_start_planet' => 7, 'fleet_start_type' => 1, 'fleet_end_galaxy' => 1, 'fleet_end_system' => 33, 'fleet_end_planet' => 7, 'fleet_end_type' => 1, 'fleet_start_time' => TIMESTAMP), 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => $chanceCreateMoon, 'moonDestroy' => false, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => null, 'additionalInfo' => $stealResourceInformations); $raportData = GenerateReport($combatResult, $raportInfo); $raportID = md5(uniqid('', true) . TIMESTAMP); $sqlQuery = "INSERT INTO " . RW . " SET rid = '" . $raportID . "', raport = '" . $GLOBALS['DATABASE']->sql_escape(serialize($raportData)) . "', time = " . TIMESTAMP . ";"; $GLOBALS['DATABASE']->query($sqlQuery); $this->sendJSON($raportID); }
function TargetEvent() { global $resource, $reslist; $fleetAttack = array(); $fleetDefend = array(); $userAttack = array(); $userDefend = array(); $stealResource = array(901 => 0, 902 => 0, 903 => 0); $debris = array(); $planetDebris = array(); $raportInfo = array(); $debrisRessource = array(901, 902); $messageHTML = <<<HTML \t\t<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 %s>%s: %s</span> <span %s>%s: %s</span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</span> </span><span>%s: <span style="color:#5ca6aa;">%s</span> </span><span>%s: <span style="color:#339966;">%s</span></span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</font> </span><span>%s: <span style="color:#5ca6aa;">%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']); $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(); 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 '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 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); $raportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => null, 'moonDestroy' => true, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => false); $destext = ""; switch ($combatResult['won']) { case "a": $moonDestroyChance = round((100 - sqrt($targetPlanet['diameter'])) * sqrt($fleetAttack[$this->_fleet['fleet_id']]['unit'][214]), 1); /* $moonDestroyChance = round((100 - sqrt($targetPlanet['diameter'])) * sqrt($fleetAttack[$this->_fleet['fleet_id']]['unit'][214] - ($fleetAttack[$this->_fleet['fleet_id']]['unit'][214] / 100 * $targetUser['premium_reward_moon']) - ($fleetAttack[$this->_fleet['fleet_id']]['unit'][214] / 100 * round(3*$targetPlanet['mondbasis']/2))), 1); */ // Max 100% | Min 0% $moonDestroyChance = min($moonDestroyChance, 100); $moonDestroyChance = max($moonDestroyChance, 0); $randChance = mt_rand(1, 100); if ($randChance <= $moonDestroyChance) { $planetID = $GLOBALS['DATABASE']->getFirstCell("SELECT id FROM " . PLANETS . " WHERE id_luna = " . $targetPlanet['id'] . ";"); $GLOBALS['DATABASE']->multi_query("\n\t\t\t\t\tUPDATE " . FLEETS . " SET \n\t\t\t\t\tfleet_start_type = 1, \n\t\t\t\t\tfleet_start_id = " . $planetID . "\n\t\t\t\t\tWHERE fleet_start_id = " . $targetPlanet['id'] . ";\n\t\t\t\t\tUPDATE " . FLEETS . " SET \n\t\t\t\t\tfleet_end_type = 1, \n\t\t\t\t\tfleet_end_id = " . $planetID . ",\n\t\t\t\t\tfleet_mission = IF(fleet_mission = 9, 1, fleet_mission) \n\t\t\t\t\tWHERE fleet_end_id = " . $this->_fleet['fleet_end_id'] . "\n\t\t\t\t\tAND fleet_id != " . $this->_fleet['fleet_id'] . ";\n\t\t\t\t\tUPDATE " . PLANETS . " \n\t\t\t\t\tSET id_luna = 0\n\t\t\t\t\tWHERE id_luna = " . $targetPlanet['id'] . ";\n\t\t\t\t\tDELETE FROM " . PLANETS . " \n\t\t\t\t\tWHERE id = " . $targetPlanet['id'] . ";"); $raportInfo['moonDestroySuccess'] = 1; $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET moon_destruction = moon_destruction + '1' 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['moon_destruction']; $ACTUAL = 3 * $xkf['achievements_misc_destructor'] + 3; $destructor_lvl = $xkf['achievements_misc_destructor'] + 1; $destructor_reward_points = 60; $destructor_reward_am = 60; $destructor_reward_points = $destructor_reward_points + $xkf['achievements_misc_destructor'] * $destructor_reward_points; $destructor_reward_am = $destructor_reward_am + $xkf['achievements_misc_destructor'] * $destructor_reward_am; } if ($ACTUA == $ACTUAL) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET achievements_misc_destructor = achievements_misc_destructor + '1', antimatter = antimatter + " . $destructor_reward_am . " WHERE id = " . $this->_fleet['fleet_owner'] . ";"); $msg = '<img alt="" style="float:left; width:60px; margin-right:6px;" src="styles/images/achiev/ach_destroyer_moons.png">reached: <span class="achiev_mes_head">destructor lvl. ' . $destructor_lvl . '</span><br> received:<br> ' . $destructor_reward_am . ' antimatter <br> ' . $destructor_reward_points . ' achievement points'; SendSimpleMessage($this->_fleet['fleet_owner'], '', TIMESTAMP, 4, 'System', 'Achievements', $msg); } } } else { $raportInfo['moonDestroySuccess'] = 0; } $fleetDestroyChance = round(sqrt($targetPlanet['diameter']) / 2); $randChance = mt_rand(1, 100); if ($randChance <= $fleetDestroyChance) { $this->KillFleet(); $raportInfo['fleetDestroySuccess'] = true; } else { $raportInfo['fleetDestroySuccess'] = false; } $raportInfo['moonDestroyChance'] = $moonDestroyChance; $raportInfo['fleetDestroyChance'] = $fleetDestroyChance; $attackStatus = 'wons'; $defendStatus = 'loos'; $attackClass = 'style="color:green;"'; $defendClass = 'style=color:red;"'; break; case "w": $attackStatus = 'draws'; $defendStatus = 'draws'; $attackClass = 'raportDraw'; $defendClass = 'raportDraw'; $raportInfo['moonDestroySuccess'] = -1; break; case "r": $attackStatus = 'loos'; $defendStatus = 'wons'; $attackClass = 'style="color:red;"'; $defendClass = 'style="color:green;"'; $raportInfo['moonDestroySuccess'] = -1; break; } require_once 'GenerateReport.php'; $raportData = GenerateReport($combatResult, $raportInfo); $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) { $LNG = $this->getLanguage(NULL, $userID); $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])); SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $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) { $LNG = $this->getLanguage(NULL, $userID); $message = sprintf($messageHTML, $raportID, $defendClass, $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'], $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['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902])); SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $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\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\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\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\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(); }
function TargetEvent() { global $resource, $reslist; $fleetAttack = array(); $fleetDefend = array(); $userAttack = array(); $userDefend = array(); $stealResource = array(901 => 0, 902 => 0, 903 => 0); $debris = array(); $planetDebris = array(); $raportInfo = array(); $debrisRessource = array(901, 902); $messageHTML = <<<HTML \t\t<div class="raportMessage"> \t<table> \t\t<tr> \t\t\t<td colspan="2"><a href="CombatReport.php?raport=%s" onclick="starttraining20()" target="_blank"><span %s>%s %s (%s)</span></a></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span %s>%s: %s</span> <span %s>%s: %s</span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</span> </span><span>%s: <span style="color:#5ca6aa;">%s</span> </span><span>%s: <span style="color:#339966;">%s</span></span></td> \t\t</tr> \t\t<tr> \t\t\t<td>%s</td><td><span>%s: <span style="color:#a47d7a;">%s</font> </span><span>%s: <span style="color:#5ca6aa;">%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']); $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(); 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 '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); /*ob_start(); print_r($fleetAttack); print_r($fleetDefend); print_r($fleetIntoDebris); print_r($defIntoDebris); $content = ob_get_contents(); ob_end_clean(); $f = fopen("file.txt", "w"); fwrite($f, $content); fclose($f);*/ $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 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 / 1000000 * $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 + $chanceCreateMoon / 100 * 35) { 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; } } $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET moon_creation = moon_creation + '1' 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['moon_creation']; $ACTUAL = 3 * $xkf['achievements_misc_moons'] + 3; $moons_lvl = $xkf['achievements_misc_moons'] + 1; $moons_reward_points = 50; $moons_reward_am = 50; $moons_reward_points = $moons_reward_points + $xkf['achievements_misc_moons'] * $moons_reward_points; $moons_reward_am = $moons_reward_am + $xkf['achievements_misc_moons'] * $moons_reward_am; } if ($ACTUA == $ACTUAL) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET achievements_misc_moons = achievements_misc_moons + '1', antimatter = antimatter + " . $moons_reward_am . " WHERE id = " . $this->_fleet['fleet_owner'] . ";"); $msg = '<img alt="" style="float:left; width:60px; margin-right:6px;" src="styles/images/achiev/ach_creation_moons.png">reached: <span class="achiev_mes_head">moons lvl. ' . $moons_lvl . '</span><br> received:<br> ' . $moons_reward_am . ' antimatter <br> ' . $moons_reward_points . ' achievement points'; SendSimpleMessage($this->_fleet['fleet_owner'], '', TIMESTAMP, 4, 'System', 'Achievements', $msg); } } } require_once 'GenerateReport.php'; $raportData = GenerateReport($combatResult, $raportInfo); $who_won = 0; if ($combatResult['won'] == 'a') { $who_won = $this->_fleet['fleet_owner']; } elseif ($combatResult['won'] == 'r') { $who_won = $this->_fleet['fleet_target_owner']; } elseif ($combatResult['won'] == 'w') { $who_won = 1; } $search_hit = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_topkb` ORDER by units DESC LIMIT 1 ;"); if ($GLOBALS['DATABASE']->numRows($search_hit) > 0) { $hit = $GLOBALS['DATABASE']->fetch_array($search_hit); $units = $hit['units']; $total_hit = $combatResult['unitLost']['attacker'] + $combatResult['unitLost']['defender']; if ($units < $total_hit) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `antimatter` = `antimatter` + '1000' where `id` = '" . $who_won . "';"); $msg = 'Congratulations, you are rewarded with 1.000 antimatter for the new top 1 hit.'; SendSimpleMessage($who_won, '', TIMESTAMP, 4, 'System', 'Top hof', $msg); } } // $allyInfo = $GLOBALS['DATABASE']->query("SELECT CombatExp FROM `uni1_alliance` WHERE id = ".$fleetAttack[$fleetID]['player']['ally_id'].";"); // $allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo); // $xx = $allyInfo['CombatExp']; // if($GLOBALS['DATABASE']->numRows($allyInfo==0){ // $xx = 0; // } $search_b = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_users` where `id` = " . $this->_fleet['fleet_owner'] . " ;"); $f = $GLOBALS['DATABASE']->fetch_array($search_b); $premium_combate = 0; if ($f['prem_batle_leveling'] > 0 && $f['prem_batle_leveling_days'] > TIMESTAMP) { $premium_combate = $f['prem_batle_leveling']; } if ($GLOBALS['DATABASE']->numRows($search_b) > 0) { $combat_points = round(($debris[901] + $debris[902]) / (100000000 * $f['experience_combat_level'] + 100000000)); $maximum_points = 0; if ($combat_points + $combat_points / 100 * $premium_combate >= 50000) { $maximum_points = 50000; } else { $maximum_points = $combat_points + $combat_points / 100 * $premium_combate; //$maximum_points = $maximum_points + ($maximum_points / 100 * $xx); } if ($maximum_points >= 1) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `experience_combat` = `experience_combat` + " . $maximum_points . " where `id` = '" . $this->_fleet['fleet_owner'] . "';\n\t\t"); } } $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['experience_combat']; $ally = $xkf['ally_id']; $ACTUAL = $xkf['experience_combat_max']; $NEWEP = $xkf['experience_combat'] - $xkf['experience_combat_max']; $NEWEPMAX = $xkf['experience_combat_max'] + $xkf['experience_combat_max'] / 5 * $xkf['experience_combat_level']; } if ($ACTUA >= $ACTUAL) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET experience_combat = " . $NEWEP . ", experience_combat_max = " . $NEWEPMAX . ", experience_combat_level = experience_combat_level + 1 WHERE id = " . $this->_fleet['fleet_owner'] . ";"); } if ($ally != 0 && $targetUser['ally_id'] != 0 && $ally != $targetUser['ally_id']) { $alliance_points = round(($debris[901] + $debris[902]) / 100000000); //$allyInfo = $GLOBALS['DATABASE']->query("SELECT GetAlliancePoints FROM `uni1_alliance` WHERE id = ".$fleetAttack[$fleetID]['player']['ally_id'].";"); //$allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo); $maximum_points = 0; if ($alliance_points >= 40) { $maximum_points = 40; } else { $maximum_points = $alliance_points; } $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET alliance_points = alliance_points + '" . $maximum_points . "' WHERE id = " . $ally . ";"); } } switch ($combatResult['won']) { case "a": $attackStatus = 'wons'; $defendStatus = 'loos'; $attackClass = 'style="color:green;"'; $defendClass = 'style="color:red;"'; break; case "w": $attackStatus = 'draws'; $defendStatus = 'draws'; $attackClass = 'style="color:orange;"'; $defendClass = 'style="color:orange;"'; break; case "r": $attackStatus = 'loos'; $defendStatus = 'wons'; $attackClass = 'style="color:red;"'; $defendClass = 'style="color:green;"'; 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) { $LNG = $this->getLanguage(NULL, $userID); $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])); SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $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) { $LNG = $this->getLanguage(NULL, $userID); $message = sprintf($messageHTML, $raportID, $defendClass, $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'], $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['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902])); SendSimpleMessage($userID, 0, $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $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\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\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\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\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); if ($attackStatus == 'wons') { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_attack` = `achievements_attack` + '1' 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['wons']; $ACTUAL = 50 * $xkf['achievements_misc_fighter'] + 50; $fighter_lvl = $xkf['achievements_misc_fighter'] + 1; $fighter_reward_points = 15; $fighter_reward_am = 15; $fighter_reward_points = $fighter_reward_points + $xkf['achievements_misc_fighter'] * $fighter_reward_points; $fighter_reward_am = $fighter_reward_am + $xkf['achievements_misc_fighter'] * $fighter_reward_am; } if ($ACTUA == $ACTUAL) { $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET achievements_misc_fighter = achievements_misc_fighter + '1', antimatter = antimatter + " . $fighter_reward_am . " WHERE id = " . $this->_fleet['fleet_owner'] . ";"); $msg = '<img alt="" style="float:left; width:60px; margin-right:6px;" src="styles/images/achiev/ach_wons.png">reached: <span class="achiev_mes_head">fighter lvl. ' . $fighter_lvl . '</span><br> received:<br> ' . $fighter_reward_am . ' antimatter <br> ' . $fighter_reward_points . ' achievement points'; SendSimpleMessage($this->_fleet['fleet_owner'], '', TIMESTAMP, 4, 'System', 'Achievements', $msg); } } $this->setState(FLEET_RETURN); $this->SaveFleet(); }
function TargetEvent() { global $pricelist, $resource, $reslist, $db; $targetPlanet = $db->uniquequery("SELECT * FROM " . PLANETS . " WHERE `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'] . "' ;"); $targetUser = $db->uniquequery("SELECT * FROM " . USERS . " WHERE `id` = '" . $targetPlanet['id_owner'] . "';"); $TargetUserID = $targetUser['id']; $attackFleets = array(); require_once ROOT_PATH . 'includes/classes/class.PlanetRessUpdate.' . PHP_EXT; $PlanetRess = new ResourceUpdate(); list($TargetUser, $targetPlanet) = $PlanetRess->CalcResource($TargetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']); $attackFleets[$this->_fleet['fleet_id']]['fleet'] = $this->_fleet; $attackFleets[$this->_fleet['fleet_id']]['user'] = $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'] . "';"); $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]; $AttackerRow['id'][] = $attackFleets[$this->_fleet['fleet_id']]['user']['id']; $AttackerRow['name'][] = $attackFleets[$this->_fleet['fleet_id']]['user']['username']; } $defense = array(); $def = $db->query('SELECT * FROM ' . FLEETS . ' WHERE `fleet_end_galaxy` = ' . $this->_fleet['fleet_end_galaxy'] . ' AND `fleet_end_system` = ' . $this->_fleet['fleet_end_system'] . ' AND `fleet_end_type` = ' . $this->_fleet['fleet_end_type'] . ' AND `fleet_end_planet` = ' . $this->_fleet['fleet_end_planet'] . ' AND fleet_start_time<' . TIMESTAMP . ' AND fleet_end_stay>=' . TIMESTAMP . ';'); while ($defRow = $db->fetch_array($def)) { $defRowDef = explode(';', $defRow['fleet_array']); foreach ($defRowDef as $Element) { $Element = explode(',', $Element); if ($Element[0] < 100) { continue; } if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]])) { $defense[$defRow['fleet_id']][$Element[0]] = 0; } $defense[$defRow['fleet_id']]['def'][$Element[0]] += $Element[1]; $defense[$defRow['fleet_id']]['user'] = $db->uniquequery("SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM " . USERS . " WHERE id = '" . $defRow['fleet_owner'] . "';"); } $DefenderRow['id'][] = $defense[$defRow['fleet_id']]['user']['id']; $DefenderRow['name'][] = $defense[$defRow['fleet_id']]['user']['username']; } $defense[0]['def'] = array(); $defense[0]['user'] = $targetUser; $DefenderRow['id'][] = $defense[0]['user']['id']; $DefenderRow['name'][] = $defense[0]['user']['username']; for ($i = 200; $i < 500; $i++) { if (isset($resource[$i]) && isset($targetPlanet[$resource[$i]])) { $defense[0]['def'][$i] = $targetPlanet[$resource[$i]]; } } $Attacker['id'] = array_unique($AttackerRow['id']); $Attacker['name'] = array_unique($AttackerRow['name']); $Defender['id'] = array_unique($DefenderRow['id']); $Defender['name'] = array_unique($DefenderRow['name']); require_once 'calculateAttack.' . PHP_EXT; $result = calculateAttack($attackFleets, $defense); $SQL = ""; foreach ($attackFleets as $fleetID => $attacker) { $fleetArray = ''; $totalCount = 0; foreach ($attacker['detail'] as $element => $amount) { if ($amount) { $fleetArray .= $element . ',' . floattostring($amount) . ';'; } $totalCount += $amount; } if ($totalCount <= 0) { $SQL .= "DELETE FROM " . FLEETS . " WHERE `fleet_id`= '" . $fleetID . "';"; } else { $SQL .= "UPDATE " . FLEETS . " SET `fleet_mess` = '1', `fleet_array` = '" . substr($fleetArray, 0, -1) . "', `fleet_amount` = '" . floattostring($totalCount) . "' WHERE `fleet_id` = '" . $fleetID . "';"; } } $db->multi_query($SQL); $SQL = ""; if ($result['won'] == "a") { require_once 'calculateSteal.' . PHP_EXT; $steal = calculateSteal($attackFleets, $targetPlanet); } foreach ($defense as $fleetID => $defender) { if ($fleetID != 0) { $fleetArray = ''; $totalCount = 0; foreach ($defender['def'] as $element => $amount) { if ($amount) { $fleetArray .= $element . ',' . floattostring($amount) . ';'; } $totalCount += $amount; } if ($totalCount <= 0) { $SQL .= "DELETE FROM " . FLEETS . " WHERE `fleet_id`= '" . $fleetID . "';"; } else { $SQL .= "UPDATE " . FLEETS . " SET `fleet_array` = '" . substr($fleetArray, 0, -1) . "', `fleet_amount` = '" . floattostring($totalCount) . "' WHERE `fleet_id` = '" . $fleetID . "';"; } } else { $fleetArray = ''; $totalCount = 0; foreach ($defender['def'] as $element => $amount) { $fleetArray .= "`" . $resource[$element] . "` = '" . floattostring($amount) . "', "; } $SQL .= "UPDATE " . PLANETS . " SET "; $SQL .= $fleetArray; $SQL .= "`metal` = `metal` - '" . floattostring($steal['metal']) . "', `crystal` = `crystal` - '" . floattostring($steal['crystal']) . "', `deuterium` = `deuterium` - '" . floattostring($steal['deuterium']) . "' WHERE `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'] . "';"; } } $db->multi_query($SQL); switch ($result['won']) { case "a": $chance = max(min(round((100 - sqrt($targetPlanet['diameter'])) * sqrt($attackFleets[$this->_fleet['fleet_id']]['detail'][214]), 1), 100), 0); $chance2 = round(sqrt($TargetPlanet['diameter']) / 2); $tirage = rand(0, 100); $tirage2 = rand(0, 100); $INFO['moon']['chance'] = $chance; $INFO['moon']['chance2'] = $chance2; if ($tirage <= $chance) { $db->multi_query("DELETE FROM " . PLANETS . " WHERE `id` = '" . $targetPlanet['id'] . "';UPDATE " . PLANETS . " SET `id_luna` = '0' WHERE `id_luna` = '" . $targetPlanet['id'] . "';UPDATE " . FLEETS . " SET `fleet_start_type` = '1' WHERE `fleet_start_galaxy` = '" . $this->_fleet['fleet_end_galaxy'] . "' AND `fleet_start_system` = '" . $this->_fleet['fleet_end_system'] . "' AND `fleet_start_planet` = '" . $this->_fleet['fleet_end_planet'] . "' AND `fleet_start_type` = '" . $this->_fleet['fleet_end_type'] . "';UPDATE " . FLEETS . " SET `fleet_end_type` = '1' WHERE `fleet_end_galaxy` = '" . $this->_fleet['fleet_end_galaxy'] . "' AND `fleet_end_system` = '" . $this->_fleet['fleet_end_system'] . "' AND `fleet_end_planet` = '" . $this->_fleet['fleet_end_planet'] . "' AND `fleet_end_type` = '" . $this->_fleet['fleet_end_type'] . "' AND `fleet_id` != '" . $this->_fleet['fleet_id'] . "';"); $INFO['moon']['desfail'] = 0; } else { $INFO['moon']['desfail'] = 2; } if ($tirage2 <= $chance2) { $INFO['moon']['fleetfail'] = 1; $db->query("DELETE FROM " . FLEETS . " WHERE `fleet_id` = '" . $this->_fleet["fleet_id"] . "';"); } else { $INFO['moon']['fleetfail'] = 0; } break; case "r": $INFO['moon']['desfail'] = 1; $destext .= sprintf($LNG['sys_destruc_mess'], $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']) . "<br>"; $destext .= $LNG['sys_destruc_stop'] . "<br>"; break; case "w": $INFO['moon']['desfail'] = 1; $destext .= sprintf($LNG['sys_destruc_mess'], $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']) . "<br>"; $destext .= $LNG['sys_destruc_stop'] . "<br>"; break; } $INFO['steal'] = $steal; $INFO['moon']['des'] = 1; $INFO['fleet_start_time'] = $this->_fleet['fleet_start_time']; $INFO['start_galaxy'] = $this->_fleet['fleet_start_galaxy']; $INFO['start_system'] = $this->_fleet['fleet_start_system']; $INFO['start_planet'] = $this->_fleet['fleet_start_planet']; $INFO['end_galaxy'] = $this->_fleet['fleet_end_galaxy']; $INFO['end_system'] = $this->_fleet['fleet_end_system']; $INFO['end_planet'] = $this->_fleet['fleet_end_planet']; 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" . '?>'); file_put_contents(ROOT_PATH . 'raports/topkb_' . $rid . '.php', '<?php' . "\n" . '$raport = ' . preg_replace("/\\[\\d+\\:\\d+\\:\\d+\\]/i", "[X:X:X]", $raport) . ';' . "\n" . '?>'); $WhereAtt = ""; $WhereDef = ""; foreach ($Attacker['id'] as $id) { $WhereAtt .= "`id` = '" . $id . "' OR "; } foreach ($Defender['id'] as $id) { $WhereDef .= "`id` = '" . $id . "' OR "; } $Won = 0; $Lose = 0; $Draw = 0; switch ($result['won']) { case "a": $Won = 1; break; case "w": $Draw = 1; break; case "r": $Lose = 1; break; } $DerbisMetal = bcadd($targetPlanet['der_metal'], bcadd($result['debree']['att'][0], $result['debree']['def'][0])); $DerbisCrystal = bcadd($targetPlanet['der_crystal'], bcadd($result['debree']['att'][1], $result['debree']['def'][1])); $SQLQuery = "UPDATE " . PLANETS . " SET "; $SQLQuery .= "`der_metal` = '" . $DerbisMetal . "', "; $SQLQuery .= "`der_crystal` = '" . $DerbisCrystal . "' "; $SQLQuery .= "WHERE "; $SQLQuery .= "`galaxy` = '" . $this->_fleet['fleet_end_galaxy'] . "' AND "; $SQLQuery .= "`system` = '" . $this->_fleet['fleet_end_system'] . "' AND "; $SQLQuery .= "`planet` = '" . $this->_fleet['fleet_end_planet'] . "' AND "; $SQLQuery .= "`planet_type` = '1' "; $SQLQuery .= "LIMIT 1;"; $SQLQuery .= "INSERT INTO " . RW . " SET "; $SQLQuery .= "`time` = '" . $this->_fleet['fleet_start_time'] . "', "; $SQLQuery .= "`owners` = '" . implode(',', array_merge($Attacker['id'], $Defender['id'])) . "', "; $SQLQuery .= "`rid` = '" . $rid . "', "; $SQLQuery .= "`raport` = '';"; $SQLQuery .= "INSERT INTO " . TOPKB . " SET "; $SQLQuery .= "`time` = '" . $this->_fleet['fleet_start_time'] . "', "; $SQLQuery .= "`id_owner1` = '" . implode(',', $Attacker['id']) . "', "; $SQLQuery .= "`angreifer` = '" . implode(' & ', $Attacker['name']) . "', "; $SQLQuery .= "`id_owner2` = '" . implode(',', $Defender['id']) . "', "; $SQLQuery .= "`defender` = '" . implode(' & ', $Defender['name']) . "', "; $SQLQuery .= "`gesamtunits` = '" . floattostring($result['lost']['att'] + $result['lost']['def']) . "', "; $SQLQuery .= "`rid` = '" . $rid . "', "; $SQLQuery .= "`raport` = '',"; $SQLQuery .= "`fleetresult` = '" . $result['won'] . "';"; $SQLQuery .= "UPDATE " . USERS . " SET "; $SQLQuery .= "`wons` = wons + " . $Won . ", "; $SQLQuery .= "`loos` = loos + " . $Lose . ", "; $SQLQuery .= "`draws` = draws + " . $Draw . ", "; $SQLQuery .= "`kbmetal` = kbmetal + " . floattostring($result['debree']['att'][0] + $result['debree']['def'][0]) . ", "; $SQLQuery .= "`kbcrystal` = kbcrystal + " . floattostring($result['debree']['att'][1] + $result['debree']['def'][1]) . ", "; $SQLQuery .= "`lostunits` = lostunits + " . floattostring($result['lost']['att']) . ", "; $SQLQuery .= "`desunits` = desunits + " . floattostring($result['lost']['def']) . " "; $SQLQuery .= "WHERE "; $SQLQuery .= substr($WhereAtt, 0, -4) . ";"; $SQLQuery .= "UPDATE " . USERS . " SET "; $SQLQuery .= "`wons` = wons + " . $Lose . ", "; $SQLQuery .= "`loos` = loos + " . $Won . ", "; $SQLQuery .= "`draws` = draws + " . $Draw . ", "; $SQLQuery .= "`kbmetal` = kbmetal + " . floattostring($result['debree']['att'][0] + $result['debree']['def'][0]) . ", "; $SQLQuery .= "`kbcrystal` = kbcrystal + " . floattostring($result['debree']['att'][1] + $result['debree']['def'][1]) . ", "; $SQLQuery .= "`lostunits` = lostunits + " . floattostring($result['lost']['def']) . ", "; $SQLQuery .= "`desunits` = desunits + " . floattostring($result['lost']['att']) . " "; $SQLQuery .= "WHERE "; $SQLQuery .= substr($WhereDef, 0, -4) . ";"; $db->multi_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; } foreach ($Attacker['id'] as $AttackersID) { if (empty($AttackersID)) { continue; } $LNG = $this->GetUserLang($AttackersID); $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($AttackersID, '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageAtt); } foreach ($Defender['id'] as $DefenderID) { if (empty($DefenderID)) { continue; } $LNG = $this->GetUserLang($DefenderID); $MessageDef = 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, $ColorDef, $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']), $ColorDef, $LNG['sys_perte_attaquant'], pretty_number($result['lost']['att']), $ColorAtt, $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($DefenderID, '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageDef); } }