From 26cb03cdb6ac24ff6519469d01c9c192bc344e11 Mon Sep 17 00:00:00 2001 From: iopietro Date: Mon, 23 Apr 2018 20:28:38 +0200 Subject: [PATCH] Artifacts fixing part 1 +Added a new table in the database, called "artefacts_chrono" which stores the chronology of all artifacts +Added the support for the artifacts chronology in 27_show.tpl +Added the support for interacting with the artifacts chronology table in Database.php +Cleaned the code in 27_show.tpl +Some minor improovements and bug fixing --- GameEngine/Automation.php | 28 +++---- GameEngine/Database.php | 51 ++++++++++--- GameEngine/Lang/en.php | 1 + Templates/Build/27.tpl | 20 ++--- Templates/Build/27_show.tpl | 142 ++++++++++++++++++++++-------------- Templates/text.tpl | 33 ++++++++- sql_updates.txt | 11 +++ var/db/struct.sql | 19 +++++ 8 files changed, 212 insertions(+), 93 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index ce928f05..84a84e41 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -47,12 +47,12 @@ class Automation { if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time()-filemtime("GameEngine/Prevention/cleardeleting.txt")>50) { $this->clearDeleting(); } - if (! file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50) + if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50) { $this->buildComplete(); } $this->MasterBuilder(); - if (! file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50) + if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50) { $this->demolitionComplete(); } @@ -2475,8 +2475,8 @@ class Automation { //check for last village or capital if($user_cps >= $need_cps){ - if(count($varray)!='1' AND $to['capital']!='1' AND $villexp < $canconquer){ - if($to['owner']!=3 OR $to['name']!='WW Buildingplan'){ + if(count($varray) != 1 && $to['capital'] != 1 && $villexp < $canconquer){ + if($to['owner'] != 3 || $to['name'] != 'WW Buildingplan'){ // check for standing Palace or Residence // note: at this point, we can use cache, since we've cleared it above if ($database->getFieldLevelInVillage($data['to'], '25, 26')) { @@ -2518,7 +2518,7 @@ class Automation { $info_chief = "".$chief_pic.",Inhabitants of ".$villname." village decided to join your empire."; if ($artifact['vref'] == $data['to']){ - $database->claimArtefact($data['to'], $data['to'], $database->getVillageField($data['from'],"owner")); + $database->claimArtefact($data['to'], $data['to'], $database->getVillageField($data['from'], "owner")); } @@ -2648,8 +2648,8 @@ class Automation { $xp=""; $info_hero = $hero_pic.",Your hero had nothing to kill therefore gains no XP at all."; } else { - $xp=" and gained ".$heroxp." XP from the battle."; - $info_hero = $hero_pic.",Your hero gained ".$heroxp." XP."; + $xp=" and gained ".$heroxp." XP from the battle."; + $info_hero = $hero_pic.",Your hero gained ".$heroxp." XP."; } if ($isoasis != 0) { //oasis fix by ronix @@ -2679,14 +2679,14 @@ class Automation { if ($heroxp == 0) { $xp=" no XP from the battle."; } else { - $xp=" gained ".$heroxp." XP from the battle."; + $xp=" gained ".$heroxp." XP from the battle."; } $artifact = reset($database->getOwnArtefactInfo($data['to'])); if (!empty($artifact)) { - if ($type=='3') { - if ($database->canClaimArtifact($data['from'],$artifact['vref'],$artifact['size'],$artifact['type'])) { - $database->claimArtefact($data['from'],$data['to'],$database->getVillageField($data['from'],"owner")); - $info_hero = $hero_pic.",Your hero is carrying home an artefact".$xp; + if ($type == 3) { + if ($database->canClaimArtifact($data['from'], $artifact['vref'], $artifact['size'], $artifact['type'])) { + $database->claimArtefact($data['from'], $data['to'], $database->getVillageField($data['from'], "owner")); + $info_hero = $hero_pic.",Your hero is carrying home the artifact ".$artifact['name']." and".$xp; // if the defender pop is 0 with no artefact, then destroy the village if($database->getVillageField($data['to'], "pop") == 0){ @@ -2697,7 +2697,7 @@ class Automation { $info_hero = $hero_pic.",".$form->getError("error").$xp; } }else{ - $info_hero = $hero_pic.",Your hero could not claim the artefact during raid".$xp; + $info_hero = $hero_pic.",Your hero could not claim an artifact during raid".$xp; } } } @@ -2705,7 +2705,7 @@ class Automation { if ($heroxp == 0) { $xp=""; } else { - $xp=" but gained ".$heroxp." XP from the battle."; + $xp=" but gained ".$heroxp." XP from the battle."; } if ($traped11>0) { $info_hero = $hero_pic.",Your hero was trapped".$xp; diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 5e89d914..518843d1 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -2471,11 +2471,8 @@ class MYSQLi_DB implements IDbConnection { $q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "vdata where wref = '$wref'"; $result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC); - if ($result['Total']) { - return true; - } else { - return false; - } + + return $result['Total']; } // no need to cache this method @@ -6953,10 +6950,10 @@ References: User ID/Message ID, Mode } // no need to cache this method - function getOwnArtefactInfo($vref) { + function getOwnArtefactInfo($vref, $use_cache = true) { // load the data - type is irrelevant, since the method caches all data // then returns the one for our type - $this->getOwnArtefactInfoByType($vref, 1); + $this->getOwnArtefactInfoByType($vref, 1, $use_cache); // return what we've cached return (self::$artefactInfoByTypeCache[$vref]); @@ -7143,7 +7140,43 @@ References: User ID/Message ID, Mode $time = time(); $q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id, conquered = $time, active = 1 WHERE vref = $ovref"; - return mysqli_query($this->dblink,$q); + + if(mysqli_query($this->dblink, $q)) + { + $artifactID = reset($this->getOwnArtefactInfo($vref, false))['id']; + return $this->addArtifactsChronology($artifactID, $id, $vref, $time); + } + else return false; + } + + /** + * Retrieves the chronology of one specific artifact + * + * @param int $artefactid The id of the artifact + * @return array Returns the chronology for the passed artifact + */ + + function getArtifactsChronology($artifactID){ + list($artifactID) = $this->escape_input((int) $artifactID); + + $q = "SELECT * FROM " . TB_PREFIX . "artefacts_chrono WHERE artefactid = $artifactID ORDER BY conqueredtime ASC"; + $result = mysqli_query($this->dblink, $q); + return $this->mysqli_fetch_all($result); + } + + /** + * Stores when an artifact was conquered and who had conquered it + * + * @param int $artefactid The id of the artifact + * @param int $vref The vref of the village that has conquered the artifact + * @return bool Return true if the query was successful, false otherwise + */ + + function addArtifactsChronology($artifactID, $uid, $vref, $conqueredTime){ + list($artifactID, $uid, $vref, $conqueredTime) = $this->escape_input((int) $artifactID, (int) $uid, (int) $vref, (int) $conqueredTime); + + $q = "INSERT INTO " . TB_PREFIX . "artefacts_chrono (artefactid, uid, vref, conqueredtime) VALUES ('$artifactID', '$uid', '$vref', '$conqueredTime')"; + return mysqli_query($this->dblink, $q); } // no need to cache this method @@ -7224,7 +7257,7 @@ References: User ID/Message ID, Mode } } -// no need to cache this method + // no need to cache this method function getArtefactDetails($id) { list($id) = $this->escape_input((int) $id); diff --git a/GameEngine/Lang/en.php b/GameEngine/Lang/en.php index e0071b7f..8fc20783 100755 --- a/GameEngine/Lang/en.php +++ b/GameEngine/Lang/en.php @@ -1016,6 +1016,7 @@ define("TROOPS_MAKE_SLOWEST","troops make slowest with"); define("YOU_CONSTRUCT","you can construct "); define("CRANNY_INCREASED","cranny capacity is increased by"); define("CRANNY_DECRESE","cranny capacity is decrese by"); +define("NO_PREVIOUS_OWNERS","There are no previous owners."); define("TREASURY_DESC","The riches of your empire are kept in the treasury. The treasury has room for one treasure. After you have captured an artefact it takes 24 hours on a normal server or 12 hours on a thrice speed server to be effective."); define("TRADEOFFICE","Trade Office"); diff --git a/Templates/Build/27.tpl b/Templates/Build/27.tpl index 76cda9ed..46c5f71a 100644 --- a/Templates/Build/27.tpl +++ b/Templates/Build/27.tpl @@ -7,19 +7,15 @@

resarray['f'.$id]; ?>

- 0) include("27_show.tpl"); + else + { + if(!isset($_GET['t'])) include("27_1.tpl"); + elseif(isset($_GET['t']) && $_GET['t'] == 2) include("27_2.tpl"); + elseif(isset($_GET['t']) && $_GET['t'] == 3) include("27_3.tpl"); + } include("upgrade.tpl"); ?> \ No newline at end of file diff --git a/Templates/Build/27_show.tpl b/Templates/Build/27_show.tpl index 36f6052a..bec9e120 100644 --- a/Templates/Build/27_show.tpl +++ b/Templates/Build/27_show.tpl @@ -1,54 +1,56 @@ getArtefactDetails($_GET['show']); if($artefact['size'] == 1 && $artefact['type'] != 11){ - $reqlvl = 10; - $effect = VILLAGE; - }else{ - if($artefact['type'] != 11){ - $reqlvl = 20; - }else{ - $reqlvl = 10; - } -$effect = ACCOUNT; + $reqlvl = 10; + $effect = VILLAGE; +}else{ + $reqlvl = $artefact['type'] != 11 ? 20 : 10; + $effect = ACCOUNT; } -if ($artefact['conquered'] >= (time()-86400)){ - $active = date("Y-m-d H:i:s",$artefact['conquered']+86400); - }else{ - $active = ACTIVE; - } + +if($artefact['owner'] == 3) $active = "-"; +elseif (!$artefact['active']) $active = date("Y-m-d H:i:s",$artefact['conquered'] + 86400); +else $active = "".ACTIVE.""; + //// Added by brainiac - thank you -if ($artefact['type'] == 8){$kind=$artefact['kind']; $effecty=$artefact['effect2'];}else{$kind=$artefact['type']; $effecty=$artefact['effect'];} - switch($kind){ - case 1: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=BUILDING_WEAKER;}else{$betterorbadder=BUILDING_STRONGER;} - break; - case 2: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=TROOPS_SLOWEST;}else{$betterorbadder=TROOPS_FASTER;} - break; - case 3: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=SPIES_DECRESE;}else{$betterorbadder=SPIES_INCREASE;} - break; - case 4: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=CONSUME_HIGH;}else{$betterorbadder=CONSUME_LESS;} - break; - case 5: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=TROOPS_MAKE_SLOWEST;}else{$betterorbadder=TROOPS_MAKE_FASTER;} - break; - case 6: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=YOU_CONSTRUCT;}else{$betterorbadder=YOU_CONSTRUCT;} - break; - case 7: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=CRANNY_DECRESE;}else{$betterorbadder=CRANNY_INCREASED;} - break; - case 8: - if($artefact['type'] == 8 && $artefact['bad_effect']==1){$betterorbadder=SPIES_INCREASE;}else{$betterorbadder=SPIES_DECRESE;} - - break; - +if ($artefact['type'] == 8) +{ + $kind = $artefact['kind']; + $effecty = $artefact['effect2']; +}else{ + $kind = $artefact['type']; + $effecty = $artefact['effect']; } -$bonus=$betterorbadder." ".$effecty.""; +$artefactBadEffect = $artefact['type'] == 8 && $artefact['bad_effect'] == 1; +switch($kind){ + case 1: + $betterorbadder = $artefactBadEffect ? BUILDING_WEAKER : BUILDING_STRONGER; + break; + case 2: + $betterorbadder = $artefactBadEffect ? TROOPS_SLOWEST : TROOPS_FASTER; + break; + case 3: + $betterorbadder = $artefactBadEffect ? SPIES_DECRESE : SPIES_INCREASE; + break; + case 4: + $betterorbadder = $artefactBadEffect ? CONSUME_HIGH : CONSUME_LESS; + break; + case 5: + $betterorbadder = $artefactBadEffect ? TROOPS_MAKE_SLOWEST : TROOPS_MAKE_FASTER; + break; + case 6: + $betterorbadder = $artefactBadEffect ? YOU_CONSTRUCT : YOU_CONSTRUCT; + break; + case 7: + $betterorbadder = $artefactBadEffect ? CRANNY_DECRESE : CRANNY_INCREASED; + break; + case 8: + $betterorbadder = $artefactBadEffect ? SPIES_INCREASE : SPIES_DECRESE; + break; +} + +$bonus = $betterorbadder." ".$effecty; ?>
@@ -68,18 +70,28 @@ $bonus=$betterorbadder." ".$effecty.""; -getUserField($artefact['owner'],"username",0);?> +getUserField($artefact['owner'], "username", 0);?> +checkVilExist($artefact['vref'])){?> getVillageField($artefact['vref'], "name");?> + +[?] + -">getAllianceName($database->getUserField($artefact['owner'],"alliance",0)); ?> + +getUserField($artefact['owner'], "alliance", 0)) > 0){ ?> +getAllianceName($alliance); ?> + +- + + @@ -98,7 +110,7 @@ $bonus=$betterorbadder." ".$effecty.""; - + @@ -111,19 +123,37 @@ $bonus=$betterorbadder." ".$effecty.""; - + - - -getUserField($artefact['owner'],"username",0);?> -getVillageField($artefact['vref'], "name");?> - - +getArtifactsChronology($_GET['show']); +if(!empty($owners)){ +foreach($owners as $owner){ +?> + +getUserField($owner['uid'], "username", 0);?> + +checkVilExist($owner['vref'])){?> +getVillageField($owner['vref'], "name");?> + +[?] + + + - -
\ No newline at end of file + + + + + + \ No newline at end of file diff --git a/Templates/text.tpl b/Templates/text.tpl index 956f48d2..7fcae382 100644 --- a/Templates/text.tpl +++ b/Templates/text.tpl @@ -10,7 +10,36 @@ ################################################################################# -$txt=""; +$txt="Construction plans + + + +Countless days have passed since the first battles upon the walls of the cursed villages of the Dread Natars, many armies of both the free ones and the Natarian empire struggled and died before the walls of the many strongholds from which the Natars had once ruled all creation. Now with the dust settled and a relative calm having settled in, armies began to count their losses and collect their dead, the stench of combat still lingering in the night air, a smell of a slaughter unforgettable in its extent and brutality yet soon to be dwarfed by yet others. The largest armies of the free ones and the Dread Natars were marshalling for yet another renewed assault upon the coveted former strongholds of the Natarian Empire. + +Soon scouts arrived telling of a most awesome sight and a chilling reminder, a dread army of an unfathomable size had been spotted marshalling at the end of the world, the Natarian capital, a force so great and unstoppable that the dust from their march would choke off all light, a force so brutal and ruthless that it would crush all hope. The free people knew that they had to race now, race against time and the endless hordes of the Natarian Empire to raise a Wonder of the World to restore the world to peace and vanquish the Natarian threat. + +But to raise such a great Wonder would be no easy task, one would need construction plans created in the distant past, plans of such an arcane nature that even the very wisest of sages knew not their contents or locations. + +Tens of thousands of scouts roamed across all existence searching in vain for these mystical plans, looking in all places but the dreaded Natarian Capital, yet could not find them. Today however, they return bearing good news, they return baring the locations of the plans, hidden by the armies of the Natars inside secret strongholds constructed to be hidden from the eyes of man. + +Now begins the final stretch, when the greatest armies of the Free people and the Natars will clash across the world for the fate of all that lies under heaven. This is the war that will echo across the eons, this is your war, and here you shall etch your name across history, here you shall become legend. + + +Facts: +To steal one, the following things must happen: +You must attack the village (NO Raid!) +WIN the Attack +Destroy the treasury +An empty treasury lvl 10 MUST be in the village where that attack came from +Have a hero in an attack + +If not, the next attack on that village, winning with a hero and empty treasury will take the building plan. + +To build a WW, you must own a plan yourself (you = the WW village owner) from lvl 0 to 50, from 51 to 100 you need an additional plan in your alliance! Two plans in the WW village account would not work! + +The construction plans are conquerable immediately when they appear to the server. + +There will be a countdown in game, showing the exact time of the release, 5 days prior to the launch. "; //bbcode = html code $txt = preg_replace("/\[b\]/is",'', $txt); @@ -23,4 +52,4 @@ $txt = preg_replace("/\[\/u\]/is",'', $txt); //nl2br = enter echo nl2br($txt); -?> +?> \ No newline at end of file diff --git a/sql_updates.txt b/sql_updates.txt index 2653f925..61183197 100644 --- a/sql_updates.txt +++ b/sql_updates.txt @@ -1,3 +1,14 @@ +-- 23.04.2018 -> new table +CREATE TABLE IF NOT EXISTS `s1_artefacts_chrono` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `artefactid` int(11) NULL, + `uid` int(11) NULL, + `vref` int(11) NULL, + `conqueredtime` int(11) NULL, + PRIMARY KEY (`id`), + KEY `artefactid-conqueredtime` (`artefactid`,`conqueredtime`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; + -- 7.01.2018 -> new column ALTER TABLE s1_fdata ADD `ww_lastupdate` int(11) NULL DEFAULT NULL AFTER `wwname`; diff --git a/var/db/struct.sql b/var/db/struct.sql index 2e8d9f32..c7dbd466 100644 --- a/var/db/struct.sql +++ b/var/db/struct.sql @@ -212,6 +212,25 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%artefacts` ( -- -- -------------------------------------------------------- +-- +-- Table structure for `%PREFIX%artefacts_chrono` +-- + +CREATE TABLE IF NOT EXISTS `%PREFIX%artefacts_chrono` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `artefactid` int(11) NULL, + `uid` int(11) NULL, + `vref` int(11) NULL, + `conqueredtime` int(11) NULL, + PRIMARY KEY (`id`), + KEY `artefactid-conqueredtime` (`artefactid`,`conqueredtime`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; + +-- +-- Table structure for table `%PREFIX%artefacts_chrono` +-- +-- -------------------------------------------------------- + -- -- Table structure for table `%PREFIX%alidata` --