19. Attack Task (missioncaseattack.php)
According to the fleet task number, the first one is the attack mission. This code is long and you have to be patient when you look at it.
The good news is that there is not much to quote, and a detailed comment is not going to make the reader dizzy.
function Missioncaseattack ($FleetRow) {global $user, $phpEx, $xnova _root_path, $pricelist, $lang, $resource, $CombatC
APs In the fleet's record, Fleet_start_time represents not the departure time, but the arrival time///start_time//In addition to the Fleet_end_time this is the time to return home/fleet_en D_stay This is the time to end the stay (combined defense and expedition missions will be used)//So the following judgment means "the fleet has reached its destination" rather than "the fleet took off" if ($FleetRow [' fleet_start_time '] <= times ( ) {//fleet_mess is used to record the state of the fleet, which is generally understood to be on the way or return to the road//But the sense of use is not good, if only two states, you can use True and false to record//So I set it to 0,1,2 three-shape State, for the task that needs to stay, stay in the third State if ($FleetRow [' fleet_mess '] = = 0) {//↓↓ This judgment is to test the existence of the file that holds the battle data////If the file does not exist, break the operation, mentioning Contact Administrator if (!isset ($CombatCaps [202][' SD ']) {message ("<span style=" font-family: ">". $lang [' Sys_no_v Ars ']. "</span>", $lang [' Sys_error '], "fleet."
$phpEx, 2);
//↓↓ begins with a series of database queries, obtains the fleet number and technology level of both the attacking sides and/or obtains the defensive planet data according to the fleet information $QryTargetPlanet = "SELECT * FROM {table}}";
$QryTargetPlanet. = "WHERE"; $QryTargetPlanet. = "'Galaxy ' = '. $FleetRow [' Fleet_end_galaxy '].
"' and"; $QryTargetPlanet. = "' System ' = '". $FleetRow [' Fleet_end_system '].
"' and"; $QryTargetPlanet. = "' Planet ' = '". $FleetRow [' fleet_end_planet '].
"' and"; $QryTargetPlanet. = "' planet_type ' = '". $FleetRow [' Fleet_end_type '].
"';";
$TargetPlanet = Doquery ($QryTargetPlanet, ' planets ', true);
$TargetUserID = $TargetPlanet [' Id_owner '];
Obtaining the attacker's information from the fleet information $QryCurrentUser = "SELECT * FROM {table}}";
$QryCurrentUser. = "WHERE"; $QryCurrentUser. = "' id ' = '". $FleetRow [' Fleet_owner '].
"';";
$CurrentUser = Doquery ($QryCurrentUser, ' users ', true);
$CurrentUserID = $CurrentUser [' id '];
Information on the owner of the target planet obtained by the planet data $QryTargetUser = "Select * from {{table}}}";
$QryTargetUser. = "WHERE"; $QryTargetUser. = "' id ' = '". $TargetUserID.
"';";
$TargetUser = Doquery ($QryTargetUser, ' users ', true);
And then get the information on both sides of the science and technology in fact, the following two can be completely with the above two query whole together $QryTargetTech = "Select";
$QryTargetTech. = "' Military_tech ', ' Defence_tech ', ' Shield_tech '";
$QryTargetTech. = "From {{table}}";
$QryTargetTech. = "WHERE"; $QryTargetTech. = "' id ' = '". $TargetUserID.
"';";
$TargetTechno = Doquery ($QryTargetTech, ' users ', true);
$QryCurrentTech = "Select";
$QryCurrentTech. = "' Military_tech ', ' Defence_tech ', ' Shield_tech '";
$QryCurrentTech. = "From {{table}}";
$QryCurrentTech. = "WHERE"; $QryCurrentTech. = "' id ' = '". $CurrentUserID.
"';";
$CurrentTechno = Doquery ($QryCurrentTech, ' users ', true); ↑↑ If there are any other items that can affect the fleet measurements (such as commanders, etc.), they should also be taken out of the defensive side of the fleet (defense)//If the joint defense is considered, it should also be taken out of the United Defense fleet on the planet//and then together Calculate quantity and technical level for ($SetItem = $SetItem 0) {$TargetSet [$SetItem] [' count '] = $TargetPlanet [$resource [$Set
Item]]; }//Generate an attacker's fleet, which is also stored in an array. ' Fleet_array ' is not directly to use//the structure of this field is numbered, quantity, number, quantity; ...//So it is necessary to useExplode it with two times and then deposit it into an array $TheFleet = explode (";", $FleetRow [' Fleet_array ']);
foreach ($TheFleet as $a => $b) {if ($b!= ') {$a = explode (",", $b);
$CurrentSet [$a [0]][' count '] = $a [1]; }//included in the combat engine, ready to fight include_once ($xnova _root_path. ' Includes/ataki. '
$PHPEX);
Collect time before entering information $mtime = Microtime ();
$mtime = Explode ("", $mtime);
$mtime = $mtime [1] + $mtime [0];
$starttime = $mtime;
Import both fleets and technology into the combat engine and record the output with $walka $walka = Walka ($CurrentSet, $TargetSet, $CurrentTechno, $TargetTechno);
Collect time again, get the time of battle process//That is the origin of "combat report produced in x.xxxxxxxxxx second" $mtime = Microtime ();
$mtime = Explode ("", $mtime);
$mtime = $mtime [1] + $mtime [0];
$endtime = $mtime;
$totaltime = ($endtime-$starttime);
A separate array is used to record the remaining fleet information of the attacker, $CurrentSet = $walka ["Atakujacy"]; ......
The defensive side of the fleet information, $TargetSet = $walka ["Wrog"]; ...... FightThe outcome, $FleetResult = $walka ["Wygrana"]; ......
Details of each round, $dane _do_rw = $walka ["DANE_DO_RW"];
and the loss and ruin of both sides $zlom = $walka ["Zlom"];
Calculate the remaining units of the attacker, and also calculate the amount of load $FleetArray = "";
$FleetAmount = 0;
$FleetStorage = 0;
foreach ($CurrentSet as $Ship => $Count) {$FleetStorage + = $pricelist [$Ship] ["Capacity"] * $Count [' Count ']; Use $fleetarray to record the fleet situation, convert the format of the field in the database, prepare the "warehousing" $FleetArray. = $Ship. "," . $Count [' Count '].
";";
$FleetAmount + + $Count [' Count '];
} $FleetStorage-= $FleetRow ["Fleet_resource_metal"];
$FleetStorage-= $FleetRow ["Fleet_resource_crystal"];
$FleetStorage-= $FleetRow ["Fleet_resource_deuterium"];
Calculate the post-war situation of the defensive planet $TargetPlanetUpd = ""; if (!is_null ($TargetSet)) {foreach ($TargetSet as $Ship => $Count) {$TargetPlanetUpd. = "'". $resou rce[$Ship]. "` = '" . $Count [' Count '].
"', "; }///If the result of the battle is won by the attacking party,Start computing the plundering resources ↓↓//here you can include planetresourceupdate.php, update the resources of the target planet before plundering $Mining [' metal '] = 0;
$Mining [' crystal '] = 0;
$Mining [' deuter '] = 0;
if ($FleetResult = = "a") {if ($FleetStorage > 0) {$metal = $TargetPlanet [' Metal ']/2;
$crystal = $TargetPlanet [' Crystal ']/2;
$deuter = $TargetPlanet ["deuterium"]/2;
if (($metal) > $FleetStorage/3) {$Mining [' metal '] = $FleetStorage/3;
$FleetStorage = $FleetStorage-$Mining [' Metal '];
else {$Mining [' metal '] = $metal;
$FleetStorage = $FleetStorage-$Mining [' Metal '];
} if (($crystal) > $FleetStorage/2) {$Mining [' crystal '] = $FleetStorage/2;
$FleetStorage = $FleetStorage-$Mining [' Crystal '];
else {$Mining [' crystal '] = $crystal;
$FleetStorage = $FleetStorage-$Mining [' Crystal ']; } if ($deUter) > $FleetStorage) {$Mining [' deuter '] = $FleetStorage;
$FleetStorage = $FleetStorage-$Mining [' Deuter '];
else {$Mining [' deuter '] = $deuter;
$FleetStorage = $FleetStorage-$Mining [' Deuter ']; The calculation is over when//↑↑ is here, but if the planet has a huge metal, but crystals and heavy hydrogen are few and far between, there will be 1/3 warehouses of metal, and 2/3 are empty, so consider taking your own.
It is not difficult to perfect the method $Mining [' metal '] = round ($Mining [' Metal ']);
$Mining [' crystal '] = round ($Mining [' crystal ']);
$Mining [' deuter '] = round ($Mining [' Deuter ']);
↓↓ Update Database $QryUpdateTarget = "Update {{table}}} SET";
$QryUpdateTarget. = $TARGETPLANETUPD; $QryUpdateTarget. = "' Metal ' = ' metal '-'". $Mining [' Metal '].
"', "; $QryUpdateTarget. = "' crystal ' = ' crystal '-'". $Mining [' Crystal '].
"', "; $QryUpdateTarget. = "' deuterium ' = ' deuterium '-'". $Mining [' Deuter '].
"' ";
$QryUpdateTarget. = "WHERE"; $QryUpdateTarget. = "' Galaxy ' = '" . $FleetRow [' Fleet_end_galaxy '].
"' and"; $QryUpdateTarget. = "' System ' = '". $FleetRow [' Fleet_end_system '].
"' and"; $QryUpdateTarget. = "' Planet ' = '". $FleetRow [' fleet_end_planet '].
"' and"; $QryUpdateTarget. = "' planet_type ' = '". $FleetRow [' Fleet_end_type '].
"' ";
$QryUpdateTarget. = "LIMIT 1;";
Doquery ($QryUpdateTarget, ' planets ');
$QryUpdateGalaxy = "UPDATE {{table}}} SET"; $QryUpdateGalaxy. = "' Metal ' = ' metal ' + '". $zlom [' Metal '].
"', "; $QryUpdateGalaxy. = "' crystal ' = ' crystal ' + '". $zlom [' Crystal '].
"' ";
$QryUpdateGalaxy. = "WHERE"; $QryUpdateGalaxy. = "' Galaxy ' = '". $FleetRow [' Fleet_end_galaxy '].
"' and"; $QryUpdateGalaxy. = "' System ' = '". $FleetRow [' Fleet_end_system '].
"' and"; $QryUpdateGalaxy. = "' Planet ' = '". $FleetRow [' fleet_end_planet '].
"' ";
$QryUpdateGalaxy. = "LIMIT 1;";
Doquery ($QryUpdateGalaxy, ' galaxy '); ↓↓ calculates the ruin and loss $FleetDebris = $zlom [' metal '] + $zlom [' crystal '];
$StrAttackerUnits = sprintf ($lang [' sys_attacker_lostunits '], Pretty_number ($zlom ["atakujacy"]);
$StrDefenderUnits = sprintf ($lang [' sys_defender_lostunits '], Pretty_number ($zlom ["Wrog"]); $StrRuins = sprintf ($lang [' sys_gcdrunits '], Pretty_number ($zlom ["Metal"]), $lang [' Metal '], Pretty_number ($zlom ['
Crystal ']), $lang [' Crystal ']); $DebrisField = $StrAttackerUnits. "" . $StrDefenderUnits. "" .
$StrRuins;
↓↓ calculate the probability of producing a month $MoonChance = $FleetDebris/100000;
if ($FleetDebris > 2000000) {$MoonChance = 20;
} if ($FleetDebris = 100000) {$UserChance = Mt_rand (1, 100);
$ChanceMoon = sprintf ($lang [' Sys_moonproba '], $MoonChance); //If the RP is good enough, the moon will be produced.
Of course, the premise is that the coordinates do not have the moon if ($UserChance > 0) and ($UserChance $MoonChance) {...}
↓↓ from here begins to generate combat reports, very long, but not complex $AttackDate = Date ("R", $FleetRow ["Fleet_start_time"]); $title = SPrintf ($lang [' Sys_attack_title '], $AttackDate); $raport = "". $title.
"";
$zniszczony = false;
$a _zestrzelona = 0; ↓↓ Both sides attack and defense information. If there are any other factors that can affect the measurements of the fleet, add it here. Of course, the data here is only shown in dispatches, which is not going to affect the island's actual combat $AttackTechon [' A '] = $CurrentTechno ["Military_tech"]
* 10;
$AttackTechon [' B '] = $CurrentTechno ["Defence_tech"] * 10;
$AttackTechon [' C '] = $CurrentTechno ["Shield_tech"] * 10; $AttackerData = sprintf ($lang [' Sys_attack_attacker_pos '], $CurrentUser ["username"], $FleetRow [' Fleet_start_galaxy '
], $FleetRow [' Fleet_start_system '], $FleetRow [' fleet_start_planet ']); $AttackerTech = sprintf ($lang [' sys_attack_techologies '], $AttackTechon [' A '], $AttackTechon [' B '], $AttackTechon [' C ']
);
$DefendTechon [' A '] = $TargetTechno ["Military_tech"] * 10;
$DefendTechon [' B '] = $TargetTechno ["Defence_tech"] * 10;
$DefendTechon [' C '] = $TargetTechno ["Shield_tech"] * 10; $DefenderData = sprintf ($lang [' Sys_attack_defender_pos '], $TargetUser ["username"], $FleetRow [' Fleet_end_galaxy '], $FleetRow [' Fleet_end_system '], $FleetRow [' fleet_end_planet ']); $DefenderTech = sprintf ($lang [' sys_attack_techologies '], $DefendTechon [' A '], $DefendTechon [' B '], $DefendTechon [' C ']
); According to the details of each round in the battle, the details of the firefight, including the number of each round, attack and defense value, caused and absorbed how much damage, etc.//some key values may need to see the combat engine to understand what it represents, so it doesn't matter if you don't understand ↓↓foreach ($dane _do_
RW as $a => $b) {...}
↓↓ according to the result of the outcome show the corresponding end switch ($FleetResult) {...}
Combat reports are generated in x.xxxxxxxxxxxx seconds $SimMessage = sprintf ($lang [' Sys_rapport_build_time '], $totaltime); $raport. = $SimMessage.
""; ↓↓ the combat report into the database $dpath = (! $user ["Dpath"])?
Default_skinpath: $user ["Dpath"];
$rid = MD5 ($raport);
$QryInsertRapport = "INSERT into {{table}}} SET";
$QryInsertRapport. = "' Time ' = Unix_timestamp (),"; $QryInsertRapport. = "' id_owner1 ' = '". $FleetRow [' Fleet_owner '].
"', "; $QryInsertRapport. = "' id_owner2 ' = '". $TargetUserID. "', ";
$QryInsertRapport. = "' rid ' = '". $rid.
"', "; $QryInsertRapport. = "' A_zestrzelona ' = '". $a _zestrzelona.
"', "; $QryInsertRapport. = "' raport ' = '". Addslashes ($raport).
"';";
Doquery ($QryInsertRapport, ' RW ');
↓↓ here is the message to the player, which has an onclick link to the Dispatches//below this is to the attackers, according to the results of the battle, the title also has a different color $raport = "";
$raport. = "";
if ($FleetResult = = "a") {$raport. = "";
} elseif ($FleetResult = = "R") {$raport. = "";
} elseif ($FleetResult = = "W") {$raport. = ""; $raport. = ...//↓ here is a sudden return to calculating the amount of resource load on the attacking fleet, which can actually be moved to the top $Mining [' metal '] = $Mining [' metal '] + $FleetRow ["f
Leet_resource_metal "];
$Mining [' crystal '] = $Mining [' crystal '] + $FleetRow ["fleet_resource_crystal"];
$Mining [' deuter '] = $Mining [' deuter '] + $FleetRow ["Fleet_resource_deuterium"];
Update fleet Information $QryUpdateFleet = "Update {{table}}} SET"; $QryUpdateFleet. = "' fleet_amount ' = '". $FleetAmounT.
"', "; $QryUpdateFleet. = "' Fleet_array ' = '". $FleetArray.
"', ";
$QryUpdateFleet. = "' fleet_mess ' = ' 1 ',"; $QryUpdateFleet. = "' fleet_resource_metal ' = '". $Mining [' Metal '].
"', "; $QryUpdateFleet. = "' fleet_resource_crystal ' = '". $Mining [' Crystal '].
"', "; $QryUpdateFleet. = "' fleet_resource_deuterium ' = '". $Mining [' Deuter '].
"' "; $QryUpdateFleet. = "WHERE fleet_id = '". $FleetRow [' fleet_id '].
"' ";
$QryUpdateFleet. = "LIMIT 1;";
Doquery ($QryUpdateFleet, ' fleets '); Send a battle message to the attacker Sendsimplemessage ($CurrentUserID, ', $FleetRow [' Fleet_start_time '], 3, $lang [' Sys_mess_tower '], $la
ng[' Sys_mess_attack_report '], $raport);
↓ again suddenly inserted to start calculating combat experience and number of battles//serious doubt coder write this file is not drunk $AddPoint = $CurrentUser [' xpraid '] + 1;
$QryUpdateOfficier = "UPDATE {{table}}} SET"; $QryUpdateOfficier. = "' xpraid ' = '". $AddPoint.
"' "; $QryUpdateOfficier. = "WHERE id = '". $CurrentUserID. "' ";
$QryUpdateOfficier. = "LIMIT 1;";
Doquery ($QryUpdateOfficier, ' users ');
$RaidsTotal = $CurrentUser [' raids '] + 1;
if ($FleetResult = = "a") {$RaidsWin = $CurrentUser [' Raidswin '] + 1;
$QryUpdateRaidsCompteur = "UPDATE {{table}}} SET"; $QryUpdateRaidsCompteur. = "' Raidswin ' = '". $RaidsWin.
"', "; $QryUpdateRaidsCompteur. = "' raids ' = '". $RaidsTotal.
"' "; $QryUpdateRaidsCompteur. = "WHERE id = '". $CurrentUserID.
"' ";
$QryUpdateRaidsCompteur. = "LIMIT 1;";
Doquery ($QryUpdateRaidsCompteur, ' users ');
} elseif ($FleetResult = = "R" | | | $FleetResult = = "W") {$RaidsLoose = $CurrentUser [' raidsloose '] + 1;
$QryUpdateRaidsCompteur = "UPDATE {{table}}} SET"; $QryUpdateRaidsCompteur. = "' Raidswin ' = '". $RaidsLoose.
"', "; $QryUpdateRaidsCompteur. = "' raids ' = '". $RaidsTotal.
"' "; $QryUpdateRaidsCompteur. = "WHERE id = '". $CurrentUserID.
"' "; $QryUpDateraidscompteur. = "LIMIT 1;";
Doquery ($QryUpdateRaidsCompteur, ' users ');
//↓↓ finally came back, began to write to the defense side of the message $raport 2 = "";
$raport 2. = "";
if ($FleetResult = = "a") {$raport 2. = "";
} elseif ($FleetResult = = "R") {$raport 2. = "";
} elseif ($FleetResult = = "W") {$raport 2. = ""; $raport 2. = $lang [' Sys_mess_attack_report ']. " [" . $FleetRow [' Fleet_end_galaxy ']. ":" . $FleetRow [' Fleet_end_system ']. ":" . $FleetRow [' fleet_end_planet '].
"]"; Sendsimplemessage ($TargetUserID, ', $FleetRow [' Fleet_start_time '], 3, $lang [' Sys_mess_tower '], $lang [' Sys_mess_
Attack_report '], $raport 2);
//↓↓ if the fleet returns to the beginning, it starts unloading and then the aircraft is in storage $fquery = ""; if ($FleetRow [' fleet_end_time '] $Count) {$fquery. = "'. $resource [$Ship]. "` = `" . $resource [$Ship]. "` + '" . $Count [' Count '].
"', ";
} else {$fleet = explode (";", $FleetRow [' Fleet_array ']); foreach ($FLEET as $a => $b) {if ($b!= ') {$a = explode (",", $b);
$fquery. = "{$resource [$a [0]]}={$resource [$a [0]]} + {$a [1]}, \ n"; }}//→ to the end, don't forget to delete this fleet record, or you'll be taking the fairway. The same is true for other fleet missions. Doquery ("DELETE from {{table}}} WHERE ' fleet_id ' =".)
$FleetRow ["fleet_id"], ' fleets '); if (!) (
$FleetResult = = "W")) {$QryUpdatePlanet = ' UPDATE {{table}} ' SET ';
$QryUpdatePlanet. = $fquery; $QryUpdatePlanet. = "' Metal ' = ' metal ' +". $FleetRow [' Fleet_resource_metal '].
", "; $QryUpdatePlanet. = "' crystal ' = ' crystal ' +". $FleetRow [' Fleet_resource_crystal '].
", "; $QryUpdatePlanet. = "' deuterium ' = ' deuterium ' +". $FleetRow [' Fleet_resource_deuterium '].
" ";
$QryUpdatePlanet. = "WHERE"; $QryUpdatePlanet. = "' Galaxy ' =". $FleetRow [' Fleet_start_galaxy '].
"and"; $QryUpdatePlanet. = "' System ' =". $FleetRow [' Fleet_start_system '].
"and"; $QryUpdatePlanet. = "' Planet ' =". $FleetRow [' fleet_start_planet '].
"and"; $QryUpdatePlanet. = "' Planet_type ' =". $FleetRow [' Fleet_start_type '].
"LIMIT 1;";
Doquery ($QryUpdatePlanet, ' planets '); }
}
}
}