From bdd896573cddb4d171e80c96d6b3eca5c9e46023 Mon Sep 17 00:00:00 2001 From: iopietro Date: Sun, 13 May 2018 15:50:45 +0200 Subject: [PATCH] General fixes +Added WW building plans to the "Small artifacts" section of the treasury +Fixed a bug that permitted to maintain a building in queue when destroyed by catapults +Fixed a bug that didn't count the catapult destruction of a building in building queue --- GameEngine/Automation.php | 26 ++++++++++----------- GameEngine/Database.php | 31 ++++++++++++++++++------- Templates/Build/27_2.tpl | 49 ++++++++++++++------------------------- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 2727a0bb..8cab0e7a 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -812,9 +812,12 @@ class Automation { $newLevel = $battle->CalculateNewBuildingLevel($battlepart['catapults']['moral'], $battlepart['catapults']['updown'], $tblevel, $battlepart['catapults']['realAttackers'], $data['t8']); + //If that building was present in the building queue, we have to modify his level or remove it + $database->modifyBData($data['to'], $tbid, [$newLevel, $tblevel]); + // building/field destroyed if ($newLevel == 0) - { + { // prepare data to be updated $fieldsToSet = ["f".$tbid]; $fieldValuesToSet = [0]; @@ -834,20 +837,18 @@ class Automation { $buildarray = $GLOBALS["bid".$tbgid]; // (great) warehouse level was changed - if ($tbgid==10 || $tbgid==38) { + if ($tbgid == 10 || $tbgid == 38) { $database->setMaxStoreForVillage($data['to'], $buildarray[$newLevel]['attri']); } // (great) granary level was changed - if ($tbgid==11 || $tbgid==39) { + if ($tbgid == 11 || $tbgid == 39) { $database->setMaxCropForVillage($data['to'], $buildarray[$newLevel]['attri']); } // oasis cannot be destroyed $pop = $this->recountPop($data['to'], false); - if ($isoasis == 0) { - if($pop == 0 && $can_destroy == 1) $village_destroyed = 1; - } + if ($isoasis == 0 && $pop == 0 && $can_destroy == 1) $village_destroyed = 1; if ($isSecondRow) { if ($tbid > 0) { @@ -856,7 +857,7 @@ class Automation { } // embassy level was changed - if ($tbgid==18){ + if ($tbgid == 18){ $info_cat .= $database->checkEmbassiesAfterBattle($data['to'], $bdo['f'.$catapultTarget], false); } @@ -865,15 +866,14 @@ class Automation { $info_cat = "".$catp_pic.", ".$this->procResType($tbgid, $can_destroy)." destroyed."; // embassy level was changed - if ($tbgid==18){ + if ($tbgid == 18){ $info_cat .= $database->checkEmbassiesAfterBattle($data['to'], $bdo['f'.$catapultTarget], false); } } } // building/field not damaged - elseif ($newLevel == $tblevel) - { - if ($isSecondRow) { + elseif($newLevel == $tblevel){ + if($isSecondRow) { if ($tbid > 0) { $info_cat .= "Information \"Catapult\" ".$this->procResType($tbgid, $can_destroy)." was not damaged."; @@ -882,9 +882,9 @@ class Automation { $info_cat = "".$catp_pic.",".$this->procResType($tbgid, $can_destroy)." was not damaged."; } } - else // building/field was damaged, let's calculate the actual damage - { + else + { // update $bdo, so we don't have to reselect later $bdo['f'.$catapultTarget] = $newLevel; diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 1e977d0b..1cbd5c58 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -4941,7 +4941,7 @@ References: User ID/Message ID, Mode } function checkEmbassiesAfterBattle($vid, $current_level, $use_cache = true) { - $userData = $this->getUserArray($this->getVillageField($vid,"owner"), 1); + $userData = $this->getUserArray($this->getVillageField($vid, "owner"), 1); Automation::updateMax($this->getVillageField($vid,"owner")); $allianceStatus = $this->checkAllianceEmbassiesStatus([ @@ -4951,16 +4951,29 @@ References: User ID/Message ID, Mode 'lvl' => $current_level ], false, $use_cache); - if ($allianceStatus === false) { - return ' This player\'s alliance has been dispersed.'; - } else if ($allianceStatus === 0) { - return ' Player was forced to leave their alliance.'; - } else { - // all is good, no need to append additional alliance-related text - return ''; - } + if ($allianceStatus === false) return ' This player\'s alliance has been dispersed.'; + else if ($allianceStatus === 0) return ' Player was forced to leave their alliance.'; + else return ''; // all is good, no need to append additional alliance-related text } + /** + * Modify or delete a building being constructed/in queue + * + * @param int The village ID + * @param int $field The field where the building is located + * @param array $levels The new level of the building and the old one + * @return bool Returns true if the query was successful, false otherwise + */ + + function modifyBData($wid, $field, $levels){ + list($wid, $field, $levels) = $this->escape_input((int) $wid, (int) $field, $levels); + + if($levels[0] == 0) $q = "DELETE FROM " .TB_PREFIX. "bdata WHERE wid = $wid AND field = $field"; + else $q = "UPDATE " .TB_PREFIX. "bdata SET level = level - $levels[1] + $levels[0] WHERE wid = $wid AND field = $field"; + + return mysqli_query($this->dblink, $q); + } + private function getBData($wid, $use_cache = true) { $wid = (int) $wid; diff --git a/Templates/Build/27_2.tpl b/Templates/Build/27_2.tpl index 8a8ed4cc..a8641757 100644 --- a/Templates/Build/27_2.tpl +++ b/Templates/Build/27_2.tpl @@ -33,10 +33,9 @@ $count = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "artefacts"), MYSQLI_ASSOC); $count = $count['Total']; - if($count == 0) { - echo ''.NO_ARTIFACTS.''; - } else { - + if($count == 0) echo ''.NO_ARTIFACTS.''; + else + { $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 1"); while($row = mysqli_fetch_array($artefact)) { @@ -56,8 +55,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 2"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -76,8 +73,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 3"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -96,8 +91,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 4"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -115,8 +108,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 5"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -134,8 +125,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 6"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -153,8 +142,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 7"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -172,22 +159,6 @@ dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 8"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
Treasury 10, Effect Account
'; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 8"); while($row = mysqli_fetch_array($artefact)) { echo ''; @@ -199,6 +170,20 @@ echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; echo ''; } + ?> + + dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE type = 11"); + while($row = mysqli_fetch_array($artefact)) { + echo ''; + echo ''; + echo ''; + echo '' . $row['name'] . ' ' . $row['effect'] . '
'.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
'; + echo ''; + echo '' . $database->getUserField($row['owner'], "username", 0) . ''; + echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; + echo ''; + } } ?>