From fca22ac98b86cbe4610575e60303399fe9c8bd18 Mon Sep 17 00:00:00 2001 From: iopietro Date: Wed, 23 May 2018 17:36:16 +0200 Subject: [PATCH] General fixes +Fixed a bug that didn't permit to attack with catapults with the new automation system +Fixed a warning that could have been displayed in certain cases --- GameEngine/Automation.php | 1 + GameEngine/Building.php | 21 ++++++--------------- GameEngine/Database.php | 38 +++++++++++++++++++++++++++++++++++--- GameEngine/Message.php | 8 +++----- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 24ead1d6..aef2de5a 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -26,6 +26,7 @@ include_once("Ranking.php"); include_once("Generator.php"); include_once("Multisort.php"); +include_once("Building.php"); $autoprefix = ''; for ($i = 0; $i < 5; $i++) { diff --git a/GameEngine/Building.php b/GameEngine/Building.php index 35454150..66ccf99b 100755 --- a/GameEngine/Building.php +++ b/GameEngine/Building.php @@ -479,8 +479,8 @@ private function downgradeBuilding($id) { } } - private function constructBuilding($id,$tid) { - global $database,$village,$session,$logging; + private function constructBuilding($id, $tid) { + global $database, $village, $session, $logging; if($session->access == BANNED) { header("Location: banned.php"); @@ -890,7 +890,7 @@ public function finishAll($redirect_url = '') { public function resourceRequired($id, $tid, $plus = 1) { $name = "bid".$tid; - global $$name, $village, $bid15; + global $$name, $village, $bid15, $database; $dataarray = $$name; $wood = $dataarray[$village->resarray['f'.$id] + $plus]['wood']; @@ -898,19 +898,10 @@ public function resourceRequired($id, $tid, $plus = 1) { $iron = $dataarray[$village->resarray['f'.$id] + $plus]['iron']; $crop = $dataarray[$village->resarray['f'.$id] + $plus]['crop']; $pop = $dataarray[$village->resarray['f'.$id] + $plus]['pop']; - - if($tid == 15){ - if($this->getTypeLevel(15) == 0) $time = round($dataarray[$village->resarray['f'.$id] + $plus]['time'] / SPEED * 5); - else $time = round($dataarray[$village->resarray['f'.$id] + $plus]['time'] / SPEED); - }else{ - if($this->getTypeLevel(15) > 0) { - $time = round($dataarray[$village->resarray['f'.$id] + $plus]['time'] * ($bid15[$this->getTypeLevel(15)]['attri'] /100) / SPEED); - } - else $time = round($dataarray[$village->resarray['f'.$id] + $plus]['time'] * 5 / SPEED); - } - + $time = $database->getBuildingTime($id, $tid, $plus, $village->wid, $village->resarray); $cp = $dataarray[$village->resarray['f'.$id] + $plus]['cp']; - return ["wood" => $wood, "clay" => $clay, "iron" => $iron, "crop" => $crop, "pop" => $pop, "time" => $time,"cp" => $cp]; + + return ["wood" => $wood, "clay" => $clay, "iron" => $iron, "crop" => $crop, "pop" => $pop, "time" => $time, "cp" => $cp]; } public function getTypeField($type) { diff --git a/GameEngine/Database.php b/GameEngine/Database.php index ad29e03f..79b47550 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -4476,6 +4476,36 @@ function addBuilding($wid, $field, $type, $loop, $time, $master, $level) { return mysqli_query($this->dblink,$q); } + /** + * Get the time required to build a specified building + * + * @param int $id The ID where the building is located + * @param int $tid The type of the building + * @param int $plus The construction queue count + * @param int $wref The village ID + * @param array $buildingArray The array containing the buildings in the village + * @return int Returns the building time + */ + + function getBuildingTime($id, $tid, $plus, $wref, $buildingArray) { + list($id, $tid, $plus, $wref, $buildingArray) = $this->escape_input((int) $id, (int) $tid, (int) $plus, (int) $wref, $buildingArray); + global ${'bid'.$tid}, $bid15; + + $dataArray = ${'bid'.$tid}; + + //Check if we've the main building or not + $mainBuilding = $this->getFieldLevelInVillage($wref, 15); + if($tid == 15){ + if($mainBuilding == 0) return round($dataArray[$buildingArray['f'.$id] + $plus]['time'] / SPEED * 5); + else return round($dataArray[$buildingArray['f'.$id] + $plus]['time'] / SPEED); + }else{ + if($mainBuilding > 0) { + return round($dataArray[$buildingArray['f'.$id] + $plus]['time'] * ($bid15[$mainBuilding]['attri'] / 100) / SPEED); + } + else return round($dataArray[$buildingArray['f'.$id] + $plus]['time'] * 5 / SPEED); + } + } + /** * Called when removing a queued building by a player or because destroyed by catapults * @@ -4488,7 +4518,6 @@ function addBuilding($wid, $field, $type, $loop, $time, $master, $level) { function removeBuilding($d, $tribe, $wid, $fieldsArray = []) { list($d, $tribe, $wid, $fieldsArray) = $this->escape_input((int) $d, (int) $tribe, (int) $wid, $fieldsArray); - global $building; //Variables initialization $jobToDelete = []; @@ -4510,9 +4539,12 @@ function removeBuilding($d, $tribe, $wid, $fieldsArray = []) { if($sameBuilding && $canBeRemoved) $canBeRemoved = !$sameBuilding; //Get the time required to upgrade the building at the given level - $newTime = $building->resourceRequired($job['field'], + $newTime = $this->getBuildingTime( + $job['field'], $job['type'], - $job['level'] - $fieldsArray['f'.$job['field']] - $sameBuilding)['time']; + $job['level'] - $fieldsArray['f'.$job['field']] - $sameBuilding, + $wid, + $fieldsArray); //Increase the looptime $loopTime += $newTime; diff --git a/GameEngine/Message.php b/GameEngine/Message.php index 8ee17a59..a5b2887c 100755 --- a/GameEngine/Message.php +++ b/GameEngine/Message.php @@ -502,17 +502,15 @@ private function sendMessage($recieve, $topic, $text, $security_check = true) { $user = $database->getUserField($recieve, "id", 1); // Vulnerability closed by Shadow - if ($security_check) { $q = "SELECT Count(*) as Total FROM ".TB_PREFIX."mdata WHERE owner='".$session->uid."' AND time > ".(time() - 60); - $res = mysqli_fetch_array(mysqli_query($database->dblink,$q) or die(mysqli_error($database->dblink). " query ".$q), MYSQLI_ASSOC); + $res = mysqli_fetch_array(mysqli_query($database->dblink,$q), MYSQLI_ASSOC); $flood = $res['Total']; - if($flood > 5) - return; //flood + + if($flood > 5) return; //flood } // Vulnerability closed by Shadow - if(WORD_CENSOR) { $topic = $this->wordCensor($topic); $text = $this->wordCensor($text);