PHP web game learning-Explanation of Xnova (ogame) source code (16th)

Source: Internet
Author: User
This article mainly introduces the code process of the Attack Task page interpreted by the PHP web game Xnova (ogame) Source Code. For more information, see

This article mainly introduces the code process of the Attack Task page interpreted by the PHP web game Xnova (ogame) Source Code. For more information, see

19th. Attack Task (MissionCaseAttack. php)

According to the number of the fleet task, the first attack task is the attack task. This code is very long and you have to be patient when you look at it.
Fortunately, there are not many references and detailed comments are provided, so readers will not be confused.

Function MissionCaseAttack ($ FleetRow) {global $ user, $ phpEx, $ xnova_root_path, $ pricelist, $ lang, $ resource, $ CombatCaps; // in the fleet record, fleet_start_time represents not the departure time, the arrival time // indicates the departure time. start_time // In addition, fleet_end_time indicates the return time. // fleet_end_stay indicates the end time of the stay (used by Joint Defense and expedition tasks) // Therefore, the following judgment indicates that "the ship has arrived at the destination", instead of "The ship has taken off" if ($ FleetRow ['fleet _ start_time '] <= time ()) {// fleet_mess is used to record the status of the fleet. It can be understood as whether it is on the way forward or on the way back. // However, it is difficult to use it, If there are only two States, you can use true and false to record the status. // so I set it to three States: 0, 1, and 2. for the task that needs to stay ,, if ($ FleetRow ['fleet _ mess '] = 0) {// determine whether the file storing combat data exists. // if the file does not exist, the operation is interrupted. A message is displayed, prompting the Administrator to contact if (! Isset ($ CombatCaps [202] ['sd']) {message ("". $ lang ['sys _ no_vars']. "", $ lang ['sys _ error'], "fleet. ". $ phpEx, 2);} // starting with zookeeper, it is a series of database queries, obtain the number and technology level of fleets on both sides of the defense team. // obtain the defender planet data based on the Fleet Information $ QryTargetPlanet = "SELECT * FROM {table}"; $ QryTargetPlanet. = "WHERE"; $ QryTargetPlanet. = "'galaxy '= '". $ FleetRow ['fleet _ end_galaxy ']. "'AND"; $ QryTargetPlanet. = "'system' = '". $ FleetRow ['fleet _ end_system ']. "'AND"; $ Q RyTargetPlanet. = "'Planet '= '". $ FleetRow ['fleet _ end_planet ']. "'AND"; $ QryTargetPlanet. = "'Planet _ type' = '". $ FleetRow ['fleet _ end_type ']. "';"; $ TargetPlanet = doquery ($ QryTargetPlanet, 'planets', true); $ TargetUserID = $ TargetPlanet ['id _ owner']; // obtain the attacker information based on the ship information $ QryCurrentUser = "SELECT * FROM {table}"; $ QryCurrentUser. = "WHERE"; $ QryCurrentUser. = "'id' = '". $ FleetRow ['fleet _ owner']. "';"; $ CurrentUser = doquery ($ QryCurrentUser, 'users', true); $ CurrentUserID = $ CurrentUser ['id']; // obtain the owner information of the target planet FROM the planet data $ QryTargetUser = "SELECT * FROM {table}"; $ QryTargetUser. = "WHERE"; $ QryTargetUser. = "'id' = '". $ TargetUserID. "';"; $ TargetUser = doquery ($ QryTargetUser, 'users', true ); // then obtain the technical information of both parties. // In fact, the following two can be combined with the preceding two queries. $ QryTargetTech = "SELECT"; $ QryTargetTech. = "'military _ tech ', 'd Efence_tech ', 'shield _ tech' "; $ QryTargetTech. = "FROM {table}"; $ QryTargetTech. = "WHERE"; $ QryTargetTech. = "'id' = '". $ TargetUserID. "';"; $ TargetTechno = doquery ($ QryTargetTech, 'users', true); $ QryCurrentTech = "SELECT"; $ QryCurrentTech. = "'military _ tech ', 'Defense _ tech', 'shield _ tech '"; $ QryCurrentTech. = "FROM {table}"; $ QryCurrentTech. = "WHERE"; $ QryCurrentTech. = "'id' = '". $ Curre NtUserID. "';"; $ CurrentTechno = doquery ($ QryCurrentTech, 'users', true); // zookeeper if there are other projects that can affect the three sides of the ship fleet (such as the Commander ), it should also be obtained here // generate the defender's fleet (Defense) // If joint defense is to be considered, we should also extract the fleet of joint defense on this planet // then calculate the quantity and technology level together ($ SetItem = 200; $ SetItem 0) {$ TargetSet [$ SetItem] ['Count'] = $ TargetPlanet [$ resource [$ SetItem] ;}// generates the attacker's fleet, which is also stored in arrays. 'Fleet _ array' cannot be used directly. // the structure of this field is number, quantity, number, and quantity ;...... // Use explode twice to scatter it and store it in the array $ TheFleet = explode (";", $ FleetRow ['fleet _ array']); foreach ($ TheFleet as $ a => B B) {if ($ B! = '') {$ A = explode (", ", $ B ); $ CurrentSet [$ a [0] ['Count'] = $ a [1] ;}// include it in the combat engine, ready to fight1_de_once ($ xnova_root_path. 'regiondes/ataki. '. $ phpEx); // collection time before Input $ mtime = microtime (); $ mtime = explode ("", $ mtime ); $ mtime = $ mtime [1] + $ mtime [0]; $ starttime = $ mtime; // enter the fleet and technology of both sides into the combat engine, use $ walka to record the output result $ walka = walka ($ CurrentSet, $ TargetSet, $ CurrentTechno, $ TargetTechno); // re-collect the time, get the time used in the Combat Process // that is, "Battle Report generated in x. xxxxxxxxxx seconds $ mtime = microtime (); $ mtime = explode ("", $ mtime); $ mtime = $ mtime [1] + $ mtime [0]; $ endtime = $ mtime; $ totaltime = ($ endtime-$ starttime ); // use a separate array to record the remaining fleet information of the attacker, $ CurrentSet = $ walka ["atakujacy"]; //…… Defender's Fleet Information, $ TargetSet = $ walka ["wrog"]; //... Result of the battle, $ FleetResult = $ walka ["wygrana"]; //... Details of each round, $ dane_do_rw = $ walka ["dane_do_rw"]; // loss and ruins of both parties $ zlom = $ walka ["zlom"]; // calculate the remaining units of the attacker. By the way, the loading volume is also calculated into $ FleetArray = ""; $ FleetAmount = 0; $ FleetStorage = 0; foreach ($ CurrentSet as $ Ship => $ Count) {$ FleetStorage + = $ pricelist [$ Ship] ["capacity"] * $ Count ['Count']; // use $ FleetArray to record the status of the fleet, convert it to the format of fields in the database, and prepare "warehouse receiving" $ FleetArray. = $ Ship. ",". $ Count ['Count']. ";"; $ FleetAmount + = $ Count ['Count'];} $ FleetS Torage-= $ 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. = "'". $ resource [$ Ship]. "'= '". $ Count ['Count']. "'," ;}}// if the combat result is an attacker's victory, the system begins to calculate the resource theft. php: update the resources of the target planet before the exploitation. $ Mining ['metal'] = 0; $ Mining ['crystal '] = 0; $ Mining ['deuter '] = 0; if ($ FleetResult = "a") {if ($ FleetStorage> 0) {$ metal = $ TargetPlanet ['metal']/2; $ crystal = $ TargetP Lanet ['clear']/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 '] ;}}// until the computing ends, if there are many metal giants on the planet, but there is almost no crystal or heavy hydrogen. // then there will be a metal with 1/3 warehouses, and the remaining 2/3 warehouses are all empty. // you can consider improving the method of exploitation by yourself, it is not difficult. $ Mining ['metal'] = Round ($ Mining ['metal']); $ Mining ['crystal '] = round ($ Mining ['crystal']); $ Mining ['deuter '] = round ($ Mining ['deuter']); // zookeeper updates the database $ QryUpdateTarget = "UPDATE {table} SET "; $ QryUpdateTarget. = $ TargetPlanetUpd; $ QryUpdateTarget. = "'metal' = 'metal '-'". $ Mining ['metal']. "',"; $ QryUpdateTarget. = "'crystal '= 'crystal '-'". $ Mining ['crystal ']. "',"; $ QryUpdateTarget. = "'deletery' = 'deleteriu M '-'". $ 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. = "LIMI T 1; "; doquery ($ QryUpdateTarget, 'planets '); $ qryupdategalworkflow =" UPDATE {table} SET "; $ qryupdategalworkflow. = "'metal' = 'metal' + '". $ zlom ['metal']. "',"; $ qryupdategal.pdf. = "'crystal '= 'crystal' + '". $ zlom ['crystal ']. "'"; $ qryupdategal.pdf. = "WHERE"; $ qryupdategalworkflow. = "'galaxy '= '". $ FleetRow ['fleet _ end_galaxy ']. "'AND"; $ qryupdategal.pdf. = "'system' = '". $ FleetRow ['fleet _ end_syste M']. "'AND"; $ qryupdategal.pdf. = "'Planet '= '". $ FleetRow ['fleet _ end_planet ']. "'"; $ qryupdategal.pdf. = "LIMIT 1;"; doquery ($ qryupdategal.pdf, 'galaxy '); // zookeeper calculates the ruins and losses $ FleetDebris = $ zlom ['metal'] + $ zlom ['crystal ']; $ StrAttackerUnits = sprintf ($ lang ['sys _ attacker_lostunits '], pretty_number ($ zlom ["atakujacy"]); $ StrDefenderUnits = sprintf ($ lang ['sys _ defender_lostunits '], pretty_number ($ zl Om ["wrog"]); $ StrRuins = sprintf ($ lang ['sys _ gcdrunits '], pretty_number ($ zlom ["metal"]), $ lang ['metal'], pretty_number ($ zlom ['crystal ']), $ lang ['crystal']); $ DebrisField = $ StrAttackerUnits. "". $ StrDefenderUnits. "". $ StrRuins; // ↓ $ MoonChance = $ FleetDebris/100000; if ($ FleetDebris> 2000000) {$ MoonChance = 20;} if ($ FleetDebris = 100000) {$ UserChance = maid (1,100); $ ChanceMoon = Sprintf ($ lang ['sys _ moonproba'], $ MoonChance);} // If RP is good enough, the moon will be generated. Of course, the premise is that there is no moon if ($ UserChance> 0) and ($ UserChance $ MoonChance) {……} on this coordinate ){......} // Battle report generation starts from here, which is 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; // Attack and Defense Information of both parties. If there are other elements that can affect the three sides of the ship, add them here. // Of course, the data here is only displayed in the War report, $ 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_pla Net ']); $ 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_gal Comment '], $ FleetRow ['fleet _ end_system'], $ FleetRow ['fleet _ end_planet ']); $ DefenderTech = sprintf ($ lang ['sys _ attack_techologies'], $ DefendTechon ['a'], $ DefendTechon ['B'], $ DefendTechon ['C']); // generates details of crossfire Based on the details of each round of battle, including the quantity of each round, attack and defense value, damage caused and absorbed, etc. // some key values may need to be viewed by the combat engine to understand what it represents, so it doesn't matter if you don't understand it. Just pull into foreach ($ dane_do_rw as $ a => $ B ){......} // The final switch ($ FleetResult) {……} is displayed based on the outcome ){......} // The combat report is generated on x. xxxxxxxxxxxx seconds $ SimMessage = sprintf ($ lang ['sys _ rapport_build_time '], $ totaltime); $ raport. = $ SimMessage. ""; // encode the combat report and save it to 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'); // This is the message sent to the player, there is an onclick link to the above war report // The following is sent to the attacker, according to different combat results, the title also has different colors $ raport = ""; $ raport. = ""; if ($ FleetResult = "a") {$ raport. = "";} elseif ($ FleetResult = "r") {$ raport. = "";} elseif ($ FleetResult = "w") {$ raport. = "";} $ raport. = ...... // The volume suddenly returns to the resource loading of the computing attack fleet, actually, you can move it to $ Mining ['metal'] = $ Mining ['metal'] + $ FleetRow ["fleet_resource_metal"]; $ Mining ['crystal '] = $ Mining ['crystal'] + $ FleetRow ["fleet_resource_crystal"]; $ Mining ['deuter '] = $ Mining ['deuter'] + $ FleetRow ["fleet_resource_deuterium"]; // UPDATE the Fleet Information $ QryUpdateFleet = "UPDATE {table} SET"; $ QryUpdateFleet. = "'fleet _ amount '= '". $ FleetAmount. "',"; $ QryUpdateFleet. = "'fle Et_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 combat message to the attacker SendSimpleMessage ($ CurrentUserID ,'', $ FleetRow ['fleet _ start_time '], 3, $ lang ['sys _ mess_tower'], $ lang ['sys _ mess_attack_report '], $ raport ); // The hacker suddenly inserted in and started to calculate combat experience and number of battles. // seriously suspect that the coder drank the file $ AddPoint = $ CurrentUser ['xpraid '] + 1 When writing the file; $ QryUpdateOfficier = "UPDATE {table} SET"; $ QryUpdateOfficier. = "'xpraid '= '". $ AddPoint. "'"; $ QryUpdat EOfficier. = "WHERE id = '". $ CurrentUserID. "'"; $ QryUpdateOfficier. = "LIMIT 1;"; doquery ($ QryUpdateOfficier, 'users'); $ RaidsTotal = $ CurrentUser ['rakids'] + 1; if ($ FleetResult = "") {$ RaidsWin = $ CurrentUser ['raid swin'] + 1; $ QryUpdateRaidsCompteur = "UPDATE {table} SET"; $ QryUpdateRaidsCompteur. = "'raid swin' = '". $ RaidsWin. "',"; $ QryUpdateRaidsCompteur. = "'rakids' = '". $ RaidsTotal." '"; $ QryUpdateRaidsCompteur. = "WHERE id = '". $ CurrentUserID. "'"; $ QryUpdateRaidsCompteur. = "LIMIT 1;"; doquery ($ QryUpdateRaidsCompteur, 'users');} elseif ($ FleetResult = "r" | $ FleetResult = "w ") {$ RaidsLoose = $ CurrentUser ['raid slose'] + 1; $ QryUpdateRaidsCompteur = "UPDATE {table} SET"; $ QryUpdateRaidsCompteur. = "'raid swin' = '". $ RaidsLoose. "',"; $ QryUpdateRaidsCompteur. = "'raid '= '". $ RaidsTotal. "'"; $ QryUpdateRaidsCompteur. = "WHERE id = '". $ CurrentUserID. "'"; $ QryUpdateRaidsCompteur. = "LIMIT 1;"; doquery ($ QryUpdateRaidsCompteur, 'users');} // Finally, Zookeeper came back and began to write the message sent to the defender $ raport2 = ""; $ raport2. = ""; if ($ FleetResult = "a") {$ raport2. = "";} elseif ($ FleetResult = "r") {$ raport2. = "";} elseif ($ FleetResult = "w") {$ raport2. = "";} $ raport2. = $ lang ['sys _ mess_attack_r Eport ']. "[". $ 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 '], $ raport2);} // if the ship returns to the departure location, unload the ship, and then the plane enters the database $ 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 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 occupy the channel all the time. The same is true for other fleet tasks. 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. = "'deleterium '= 'deleterium' + ". $ 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 ');}}}}

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.