PHP Web Game Learning Xnova (Ogame) source Interpretation (16) _php Tutorial

Source: Internet
Author: User
Tags sprintf
19. Attack Mission (missioncaseattack.php)

According to the fleet task number, the first one is the attack mission. This code is very long and you have to be patient when you look at it.
Fortunately, the quoted content is not many, and gives a detailed comment, the reader will not be disoriented.

function Missioncaseattack ($FleetRow) {global $user, $phpEx, $xnova _root_path, $pricelist, $lang, $resource, $CombatCap   S In the fleet's record, Fleet_start_time represents not the departure time, but the time of arrival at the destination//representing the departure time is start_time//and also fleet_end_time this is the time to return home//fleet_end_s    Tay This is the time to end the stay (combined defense and expedition missions will be used)///So the following judgment means "the fleet has arrived at the destination", not "the fleet took off" if ($FleetRow [' Fleet_start_time ' <= Time ()) { Fleet_mess is used to record the status of the fleet, basically can be understood to be in the forward or return journey//But the feeling is not good use, if there are only two states, you can use True and false to record//So I set it to 0,1,2 three states, for the need to stay       Task, stay on the third State if ($FleetRow [' fleet_mess '] = = 0) {//↓↓ This judgment is to test whether the file holding the battle data exists//If the file does not exist, interrupt the operation, prompt to contact the administrator if (!isset ($CombatCaps [202][' SD '])) {Message ("" . $lang [' Sys_no_vars ']. "", $lang [' Sys_error ']," fleet. "      $phpEx, 2);      }//↓↓ started as a series of database queries to obtain the fleet number and technology level of both sides of the attack and/or to obtain 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 '];      The attacker information is obtained according to the fleet information $QryCurrentUser = "SELECT * FROM {table}}";      $QryCurrentUser. = "WHERE"; $QryCurrentUser. = "' id ' = '". $FleetRow [' Fleet_owner '].      "';";      $CurrentUser = Doquery ($QryCurrentUser, ' users ', true);      $CurrentUserID = $CurrentUser [' id ']; Information about 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 obtain both the scientific and technical information//In fact, the following two can be completely with the above two queries 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 other projects that can affect the measurements of the fleet (such as commanders, etc.), it should be taken out here as well//Generate defensive Fleet (defense)//If you consider joint defense, you should also pick up the fleet of Allied defenses on the planet//and then count them together.  Volume and technology level for ($SetItem = $; $SetItem 0) {        $TargetSet [$SetItem] [' count '] = $TargetPlanet [$resource [$SetItem]]; }}//Generate an attacker's fleet, which is also stored in an array. ' Fleet_array ' is not directly used//The structure of this field is numbered, quantity, number, number;      ...//So it takes two explode to break it up and deposit it into the array $TheFleet = explode (";", $FleetRow [' Fleet_array ']);          foreach ($TheFleet as $a = + $b) {if ($b! = ") {$a = explode (", ", $b);        $CurrentSet [$a [0]][' count '] = $a [1]; }}//contains into the combat engine, ready to fight include_once ($xnova _root_path. ' Includes/ataki. '      $PHPEX);      Acquisition time before entering information $mtime = Microtime ();      $mtime = Explode ("", $mtime);      $mtime = $mtime [1] + $mtime [0];      $starttime = $mtime;      Enter both fleets and technology into the combat engine and use $walka to record the output $walka = Walka ($CurrentSet, $TargetSet, $CurrentTechno, $TargetTechno);      The time taken to acquire the battle process, or the origin of the battle report from x.xxxxxxxxxx seconds $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"]; ......      Defensive fleet information, $TargetSet = $walka ["Wrog"]; ......      The outcome of the battle, $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"];      Calculates the remaining units of the attacker and, by the way, calculates the amount of the load $FleetArray = "";      $FleetAmount = 0;      $FleetStorage = 0;        foreach ($CurrentSet as $Ship + $Count) {$FleetStorage + = $pricelist [$Ship] ["Capacity"] * $Count [' Count ']; Use $fleetarray to record fleet situation, convert to the format of the field in the database, prepare "storage" $FleetArray. = $Ship. "," . $Count [' Count '].        ";";      $FleetAmount + = $Count [' Count '];      } $FleetStorage-= $FleetRow ["Fleet_resource_metal"];      $FleetStorage-= $FleetRow ["Fleet_resource_crystal"];      $FleetStorage-= $FleetRow ["Fleet_resource_deuterium"];  Calculate defensive planet after the post-war situation $TARGETPLANETUPD = ""; if (!is_null ($TargetSet)) {foreach ($TargetSet as $Ship =&Gt $Count) {$TargetPlanetUpd. = "'". $resource [$Ship]. "` = '" . $Count [' Count '].        "', "; }}//If the battle result is the winner of the attack, start calculating the plundering of the resource ↓↓//here can include into planetresourceupdate.php, update the target planet's resources before plundering $Mining [' meta      L '] = 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 ']; }}}//↑↑ to the end of the calculation, but if the planet metal is huge, but the crystal and the heavy hydrogen almost no//that will appear loaded with 1/3 positions of metal, the remaining 2/3 are all empty//So you can consider the plunder method to perfect      , it is not difficult to $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 situation of 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;      ↓↓ calculating the probability of monthly production $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, it will produce the moon.      Of course, if there is no moon on this coordinate (($UserChance > 0) and ($UserChance $MoonChance) {...} ↓↓ from here to generate battle reports, very long, but not complicated $AttackDate = datE ("R", $FleetRow ["Fleet_start_time"]);      $title = sprintf ($lang [' Sys_attack_title '], $AttackDate); $raport = "". $title.      "";      $zniszczony = false;      $a _zestrzelona = 0; ↓↓ both offensive and defensive information.  If there are other factors that can affect the measurements of the fleet, add it here//The data here is only shown in the battle, and it will not affect the actual combat of the island $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 ']      );  The details of the firefight are generated according to the details of each round in the battle, including the number of rounds, attack and defense values, how much damage is caused and absorbed, 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) {...}       ↓↓ displays the corresponding end switch ($FleetResult) {...} according to the outcome.      Battle reports generated in x.xxxxxxxxxxxx seconds $SimMessage = sprintf ($lang [' Sys_rapport_build_time '], $totaltime); $raport. = $SimMessage.      ""; ↓↓ to encode the battle 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 sent to the player, which has an onclick link to the above the battle reports//below this is sent to the attackers, depending on the outcome of the fight, the title has different colors $raport = "";      $raport. = "";      if ($FleetResult = = "a") {$raport. = "";      } elseif ($FleetResult = = "R") {$raport. = "";      } elseif ($FleetResult = = "W") {$raport. = ""; } $raport. = ...//↓ here suddenly went back to calculating the amount of resources loaded by the attacking fleet, which could actually be moved to the top $Mining [' metal '] = $Mining [' metal '] + $FleetRow ["Flee      T_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 '], $lan      g[' Sys_mess_attack_report '], $raport);      ↓ also suddenly inserted to start calculating combat experience and number of battles//serious suspicion coder writing this file is not drinking high $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 and began writing messages to the defender $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 departure point, it starts unloading and 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"; }}}//→ do not forget to delete this fleet record at the end, otherwise it will always occupy the fairway. Same 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 '); }    }  }}

http://www.bkjia.com/PHPjc/824738.html www.bkjia.com true http://www.bkjia.com/PHPjc/824738.html techarticle 19, the attack mission (missioncaseattack.php) according to the fleet task number, the first one is the attack mission. This code is very long and you have to be patient when you look at it. Fortunately, the quoted ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.