function TargetEvent() { global $pricelist, $resource; $resourceIDs = array(901, 902, 903, 921); $debrisIDs = array(901, 902); $resQuery = array(); $collectQuery = array(); $collectedGoods = array(); foreach ($debrisIDs as $debrisID) { $collectedGoods[$debrisID] = 0; $resQuery[] = 'der_' . $resource[$debrisID]; } $sql = 'SELECT ' . implode(',', $resQuery) . ', (' . implode(' + ', $resQuery) . ') as total FROM %%PLANETS%% WHERE id = :planetId'; $targetData = Database::get()->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id'])); if (!empty($targetData['total'])) { $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;'; $targetUser = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner'])); $targetUserFactors = getFactors($targetUser); $shipStorageFactor = 1 + $targetUserFactors['ShipStorage']; // Get fleet capacity $fleetData = FleetFunctions::unserialize($this->_fleet['fleet_array']); $recyclerStorage = 0; $otherFleetStorage = 0; foreach ($fleetData as $shipId => $shipAmount) { if ($shipId == 209 || $shipId == 219) { $recyclerStorage += $pricelist[$shipId]['capacity'] * $shipAmount; } else { $otherFleetStorage += $pricelist[$shipId]['capacity'] * $shipAmount; } } $recyclerStorage *= $shipStorageFactor; $otherFleetStorage *= $shipStorageFactor; $incomingGoods = 0; foreach ($resourceIDs as $resourceID) { $incomingGoods += $this->_fleet['fleet_resource_' . $resource[$resourceID]]; } $totalStorage = $recyclerStorage + min(0, $otherFleetStorage - $incomingGoods); $param = array(':planetId' => $this->_fleet['fleet_end_id']); // fast way $collectFactor = min(1, $totalStorage / $targetData['total']); foreach ($debrisIDs as $debrisID) { $fleetColName = 'fleet_resource_' . $resource[$debrisID]; $debrisColName = 'der_' . $resource[$debrisID]; $collectedGoods[$debrisID] = ceil($targetData[$debrisColName] * $collectFactor); $collectQuery[] = $debrisColName . ' = GREATEST(0, ' . $debrisColName . ' - :' . $resource[$debrisID] . ')'; $param[':' . $resource[$debrisID]] = $collectedGoods[$debrisID]; $this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $collectedGoods[$debrisID]); } $sql = 'UPDATE %%PLANETS%% SET ' . implode(',', $collectQuery) . ' WHERE id = :planetId;'; Database::get()->update($sql, $param); } $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']); $Message = sprintf($LNG['sys_recy_gotten'], pretty_number($collectedGoods[901]), $LNG['tech'][901], pretty_number($collectedGoods[902]), $LNG['tech'][902]); PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 5, $LNG['sys_recy_report'], $Message, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']); $this->setState(FLEET_RETURN); $this->SaveFleet(); }
function TargetEvent() { $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;'; $senderUser = Database::get()->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner'])); $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']); $fleetArray = FleetFunctions::unserialize($this->_fleet['fleet_array']); $duration = $this->_fleet['fleet_start_time'] - $this->_fleet['start_time']; $SpeedFactor = FleetFunctions::GetGameSpeedFactor(); $distance = FleetFunctions::GetTargetDistance(array($this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet']), array($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'])); $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $senderUser, $SpeedFactor); $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $consumption / 2); $LNG = $this->getLanguage($senderUser['lang']); $TargetUserID = $this->_fleet['fleet_target_owner']; $TargetMessage = sprintf($LNG['sys_stat_mess'], GetTargetAddressLink($this->_fleet, ''), pretty_number($this->_fleet['fleet_resource_metal']), $LNG['tech'][901], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['tech'][902], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['tech'][903]); PlayerUtil::sendMessage($TargetUserID, 0, $LNG['sys_mess_tower'], 5, $LNG['sys_stat_mess_stay'], $TargetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']); $this->RestoreFleet(false); }
function RestoreFleet($onStart = true) { global $resource; $fleetData = FleetFunctions::unserialize($this->_fleet['fleet_array']); $updateQuery = array(); $param = array(':metal' => $this->_fleet['fleet_resource_metal'], ':crystal' => $this->_fleet['fleet_resource_crystal'], ':deuterium' => $this->_fleet['fleet_resource_deuterium'], ':darkmatter' => $this->_fleet['fleet_resource_darkmatter'], ':planetId' => $onStart == true ? $this->_fleet['fleet_start_id'] : $this->_fleet['fleet_end_id']); foreach ($fleetData as $shipId => $shipAmount) { $updateQuery[] = "p.`" . $resource[$shipId] . "` = p.`" . $resource[$shipId] . "` + :" . $resource[$shipId]; $param[':' . $resource[$shipId]] = $shipAmount; } $sql = 'UPDATE %%PLANETS%% as p, %%USERS%% as u SET ' . implode(', ', $updateQuery) . ', p.`metal` = p.`metal` + :metal, p.`crystal` = p.`crystal` + :crystal, p.`deuterium` = p.`deuterium` + :deuterium, u.`darkmatter` = u.`darkmatter` + :darkmatter WHERE p.`id` = :planetId AND u.id = p.id_owner;'; Database::get()->update($sql, $param); $this->KillFleet(); }
public function show() { global $USER, $PLANET, $reslist, $resource, $LNG; $acsData = array(); $FleetID = HTTP::_GP('fleetID', 0); $GetAction = HTTP::_GP('action', ""); $db = Database::get(); $this->tplObj->loadscript('flotten.js'); if (!empty($FleetID) && !IsVacationMode($USER)) { switch ($GetAction) { case "sendfleetback": FleetFunctions::SendFleetBack($USER, $FleetID); break; case "acs": $acsData = $this->getACSPageData($FleetID); break; } } $techExpedition = $USER[$resource[124]]; if ($techExpedition >= 1) { $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15, true); $maxExpedition = floor(sqrt($techExpedition)); } else { $activeExpedition = 0; $maxExpedition = 0; } $maxFleetSlots = FleetFunctions::GetMaxFleetSlots($USER); $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']); $targetSystem = HTTP::_GP('system', (int) $PLANET['system']); $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']); $targetType = HTTP::_GP('planettype', (int) $PLANET['planet_type']); $targetMission = HTTP::_GP('target_mission', 0); $sql = "SELECT * FROM %%FLEETS%% WHERE fleet_owner = :userID AND fleet_mission <> 10 ORDER BY fleet_end_time ASC;"; $fleetResult = $db->select($sql, array(':userID' => $USER['id'])); $activeFleetSlots = $db->rowCount(); $FlyingFleetList = array(); foreach ($fleetResult as $fleetsRow) { $FleetList[$fleetsRow['fleet_id']] = FleetFunctions::unserialize($fleetsRow['fleet_array']); if ($fleetsRow['fleet_mission'] == 4 && $fleetsRow['fleet_mess'] == FLEET_OUTWARD) { $returnTime = $fleetsRow['fleet_start_time']; } else { $returnTime = $fleetsRow['fleet_end_time']; } $FlyingFleetList[] = array('id' => $fleetsRow['fleet_id'], 'mission' => $fleetsRow['fleet_mission'], 'state' => $fleetsRow['fleet_mess'], 'startGalaxy' => $fleetsRow['fleet_start_galaxy'], 'startSystem' => $fleetsRow['fleet_start_system'], 'startPlanet' => $fleetsRow['fleet_start_planet'], 'startTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_start_time'], $USER['timezone']), 'endGalaxy' => $fleetsRow['fleet_end_galaxy'], 'endSystem' => $fleetsRow['fleet_end_system'], 'endPlanet' => $fleetsRow['fleet_end_planet'], 'endTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_end_time'], $USER['timezone']), 'amount' => pretty_number($fleetsRow['fleet_amount']), 'returntime' => $returnTime, 'resttime' => $returnTime - TIMESTAMP, 'FleetList' => $FleetList[$fleetsRow['fleet_id']]); } $FleetsOnPlanet = array(); foreach ($reslist['fleet'] as $FleetID) { if ($PLANET[$resource[$FleetID]] == 0) { continue; } $FleetsOnPlanet[] = array('id' => $FleetID, 'speed' => FleetFunctions::GetFleetMaxSpeed($FleetID, $USER), 'count' => $PLANET[$resource[$FleetID]]); } $this->assign(array('FleetsOnPlanet' => $FleetsOnPlanet, 'FlyingFleetList' => $FlyingFleetList, 'activeExpedition' => $activeExpedition, 'maxExpedition' => $maxExpedition, 'activeFleetSlots' => $activeFleetSlots, 'maxFleetSlots' => $maxFleetSlots, 'targetGalaxy' => $targetGalaxy, 'targetSystem' => $targetSystem, 'targetPlanet' => $targetPlanet, 'targetType' => $targetType, 'targetMission' => $targetMission, 'acsData' => $acsData, 'isVacation' => IsVacationMode($USER), 'bonusAttack' => $USER[$resource[109]] * 10 + (1 + abs($USER['factor']['Attack'])) * 100, 'bonusDefensive' => $USER[$resource[110]] * 10 + (1 + abs($USER['factor']['Defensive'])) * 100, 'bonusShield' => $USER[$resource[111]] * 10 + (1 + abs($USER['factor']['Shield'])) * 100, 'bonusCombustion' => $USER[$resource[115]] * 10, 'bonusImpulse' => $USER[$resource[117]] * 20, 'bonusHyperspace' => $USER[$resource[118]] * 30)); $this->display('page.fleetTable.default.tpl'); }
function EndStayEvent() { global $pricelist, $reslist, $resource; $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']); $config = Config::get($this->_fleet['fleet_universe']); $expeditionPoints = array(); foreach ($reslist['fleet'] as $shipId) { $expeditionPoints[$shipId] = ($pricelist[$shipId]['cost'][901] + $pricelist[$shipId]['cost'][902]) * 5 / 1000; } $fleetArray = FleetFunctions::unserialize($this->_fleet['fleet_array']); $fleetPoints = 0; $fleetCapacity = 0; foreach ($fleetArray as $shipId => $shipAmount) { $fleetCapacity += $shipAmount * $pricelist[$shipId]['capacity']; $fleetPoints += $shipAmount * $expeditionPoints[$shipId]; } $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter']; $GetEvent = mt_rand(1, 9); $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)]; switch ($GetEvent) { case 1: $eventSize = mt_rand(0, 100); $factor = 0; if (10 < $eventSize) { $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)]; $factor = mt_rand(10, 50); } elseif (0 < $eventSize && 10 >= $eventSize) { $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)]; $factor = mt_rand(50, 100); } elseif (0 == $eventSize) { $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)]; $factor = mt_rand(100, 200); } $chanceToFound = mt_rand(1, 6); if ($chanceToFound > 3) { $resourceId = 901; } elseif ($chanceToFound > 1) { $resourceId = 902; $factor = $factor / 2; } else { $resourceId = 903; $factor = $factor / 3; } $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;"; $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total'); if ($topPoints > 5000000) { $maxFactor = 12000; } elseif ($topPoints > 1000000) { $maxFactor = 9000; } elseif ($topPoints > 100000) { $maxFactor = 6000; } else { $maxFactor = 2400; } $founded = round(min($maxFactor, max(200, $factor)) * $fleetPoints); $fleetColName = 'fleet_resource_' . $resource[$resourceId]; $this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $founded); break; case 2: $eventSize = mt_rand(0, 100); $Size = 0; if (10 < $eventSize) { $Size = mt_rand(100, 300); $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)]; } elseif (0 < $eventSize && 10 >= $eventSize) { $Size = mt_rand(301, 600); $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 3)]; } elseif (0 == $eventSize) { $Size = mt_rand(601, 3000); $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)]; } $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size); break; case 3: $eventSize = mt_rand(0, 100); $Size = 0; $Message = ""; if (10 < $eventSize) { $Size = mt_rand(10, 50); $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)]; } elseif (0 < $eventSize && 10 >= $eventSize) { $Size = mt_rand(52, 100); $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)]; } elseif (0 == $eventSize) { $Size = mt_rand(102, 200); $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)]; } $sql = "SELECT MAX(total_points) as total FROM %%STATPOINTS%%\n\t\t\t\tWHERE `stat_type` = :type AND `universe` = :universe;"; $topPoints = Database::get()->selectSingle($sql, array(':type' => 1, ':universe' => $this->_fleet['fleet_universe']), 'total'); $MaxPoints = $topPoints < 5000000 ? 4500 : 6000; $FoundShips = max(round($Size * min($fleetPoints, $MaxPoints)), 10000); $FoundShipMess = ""; $NewFleetArray = ""; $Found = array(); foreach ($reslist['fleet'] as $ID) { if (!isset($fleetArray[$ID]) || $ID == 208 || $ID == 209 || $ID == 214) { continue; } $MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902])); if ($MaxFound <= 0) { continue; } $Count = mt_rand(0, $MaxFound); if ($Count <= 0) { continue; } $Found[$ID] = $Count; $FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]); $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count); if ($FoundShips <= 0) { break; } } if (empty($Found)) { $FoundShipMess .= '<br><br>' . $LNG['sys_expe_found_ships_nothing']; } foreach ($fleetArray as $ID => $Count) { if (!empty($Found[$ID])) { $Count += $Found[$ID]; } $NewFleetArray .= $ID . "," . floatToString($Count) . ';'; } $Message .= $FoundShipMess; $this->UpdateFleet('fleet_array', $NewFleetArray); $this->UpdateFleet('fleet_amount', array_sum($fleetArray)); break; case 4: $messageHTML = <<<HTML <div class="raportMessage"> <table> <tr> <td colspan="2"><a href="CombatReport.php?raport=%s" target="_blank"><span class="%s">%s %s (%s)</span></a></td> </tr> <tr> <td>%s</td><td><span class="%s">%s: %s</span> <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 $pricelist, $reslist, $resource; $db = Database::get(); $sql = 'SELECT * FROM %%USERS%% WHERE id = :userId;'; $senderUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner'])); $targetUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_target_owner'])); $sql = 'SELECT * FROM %%PLANETS%% WHERE id = :planetId;'; $targetPlanet = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_end_id'])); $sql = 'SELECT name FROM %%PLANETS%% WHERE id = :planetId;'; $senderPlanetName = $db->selectSingle($sql, array(':planetId' => $this->_fleet['fleet_start_id']), 'name'); $LNG = $this->getLanguage($senderUser['lang']); $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']); $targetUser['factor'] = getFactors($targetUser, 'basic', $this->_fleet['fleet_start_time']); $planetUpdater = new ResourceUpdate(); list($targetUser, $targetPlanet) = $planetUpdater->CalcResource($targetUser, $targetPlanet, true, $this->_fleet['fleet_start_time']); $sql = 'SELECT * FROM %%FLEETS%% WHERE fleet_end_id = :planetId AND fleet_mission = 5 AND fleet_end_stay > :time;'; $targetStayFleets = $db->select($sql, array(':planetId' => $this->_fleet['fleet_end_id'], ':time' => $this->_fleet['fleet_start_time'])); foreach ($targetStayFleets as $fleetRow) { $fleetData = FleetFunctions::unserialize($fleetRow['fleet_array']); foreach ($fleetData as $shipId => $shipAmount) { $targetPlanet[$resource[$shipId]] += $shipAmount; } } $fleetAmount = $this->_fleet['fleet_amount'] * (1 + $senderUser['factor']['SpyPower']); $senderSpyTech = max($senderUser['spy_tech'], 1); $targetSpyTech = max($targetUser['spy_tech'], 1); $techDifference = abs($senderSpyTech - $targetSpyTech); $MinAmount = ($senderSpyTech > $targetSpyTech ? -1 : 1) * pow($techDifference * SPY_DIFFENCE_FACTOR, 2); $SpyFleet = $fleetAmount >= $MinAmount; $SpyDef = $fleetAmount >= $MinAmount + 1 * SPY_VIEW_FACTOR; $SpyBuild = $fleetAmount >= $MinAmount + 3 * SPY_VIEW_FACTOR; $SpyTechno = $fleetAmount >= $MinAmount + 5 * SPY_VIEW_FACTOR; $classIDs[900] = array_merge($reslist['resstype'][1], $reslist['resstype'][2]); if ($SpyFleet) { $classIDs[200] = $reslist['fleet']; } if ($SpyDef) { $classIDs[400] = array_merge($reslist['defense'], $reslist['missile']); } if ($SpyBuild) { $classIDs[0] = $reslist['build']; } if ($SpyTechno) { $classIDs[100] = $reslist['tech']; } $targetChance = mt_rand(0, min($fleetAmount / 4 * ($targetSpyTech / $senderSpyTech), 100)); $spyChance = mt_rand(0, 100); $spyData = array(); foreach ($classIDs as $classID => $elementIDs) { foreach ($elementIDs as $elementID) { if (isset($targetUser[$resource[$elementID]])) { $spyData[$classID][$elementID] = $targetUser[$resource[$elementID]]; } else { $spyData[$classID][$elementID] = $targetPlanet[$resource[$elementID]]; } } if ($senderUser['spyMessagesMode'] == 1) { $spyData[$classID] = array_filter($spyData[$classID]); } } // I'm use template class here, because i want to exclude HTML in PHP. require_once 'includes/classes/class.template.php'; $template = new template(); $template->caching = true; $template->compile_id = $senderUser['lang']; $template->loadFilter('output', 'trimwhitespace'); list($tplDir) = $template->getTemplateDir(); $template->setTemplateDir($tplDir . 'game/'); $template->assign_vars(array('spyData' => $spyData, 'targetPlanet' => $targetPlanet, 'targetChance' => $targetChance, 'spyChance' => $spyChance, 'isBattleSim' => ENABLE_SIMULATOR_LINK == true && isModuleAvailable(MODULE_SIMULATOR), 'title' => sprintf($LNG['sys_mess_head'], $targetPlanet['name'], $targetPlanet['galaxy'], $targetPlanet['system'], $targetPlanet['planet'], _date($LNG['php_tdformat'], $this->_fleet['fleet_end_time'], $targetUser['timezone'], $LNG)))); $template->assign_vars(array('LNG' => $LNG), false); $spyReport = $template->fetch('shared.mission.spyReport.tpl'); PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_qg'], 0, $LNG['sys_mess_spy_report'], $spyReport, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']); $LNG = $this->getLanguage($targetUser['lang']); $targetMessage = $LNG['sys_mess_spy_ennemyfleet'] . " " . $senderPlanetName; if ($this->_fleet['fleet_start_type'] == 3) { $targetMessage .= $LNG['sys_mess_spy_report_moon'] . ' '; } $text = '<a href="game.php?page=galaxy&galaxy=%1$s&system=%2$s">[%1$s:%2$s:%3$s]</a> %7$s %8$s <a href="game.php?page=galaxy&galaxy=%4$s&system=%5$s">[%4$s:%5$s:%6$s]</a> %9$s'; $targetMessage .= sprintf($text, $this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $LNG['sys_mess_spy_seen_at'], $targetPlanet['name'], $LNG['sys_mess_spy_seen_at2']); PlayerUtil::sendMessage($this->_fleet['fleet_target_owner'], 0, $LNG['sys_mess_spy_control'], 0, $LNG['sys_mess_spy_activity'], $targetMessage, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']); if ($targetChance >= $spyChance) { $config = Config::get($this->_fleet['fleet_universe']); $whereCol = $this->_fleet['fleet_end_type'] == 3 ? "id_luna" : "id"; $sql = 'UPDATE %%PLANETS%% SET der_metal = der_metal + :metal, der_crystal = der_crystal + :crystal WHERE ' . $whereCol . ' = :planetId;'; $db->update($sql, array(':metal' => $fleetAmount * $pricelist[210]['cost'][901] * $config->Fleet_Cdr / 100, ':crystal' => $fleetAmount * $pricelist[210]['cost'][902] * $config->Fleet_Cdr / 100, ':planetId' => $this->_fleet['fleet_end_id'])); $this->KillFleet(); } else { $this->setState(FLEET_RETURN); $this->SaveFleet(); } }
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(); }