Skip to content

Commit

Permalink
General fixes
Browse files Browse the repository at this point in the history
+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
  • Loading branch information
iopietro committed May 23, 2018
1 parent e70d0ff commit fca22ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions GameEngine/Automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
21 changes: 6 additions & 15 deletions GameEngine/Building.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -890,27 +890,18 @@ 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'];
$clay = $dataarray[$village->resarray['f'.$id] + $plus]['clay'];
$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) {
Expand Down
38 changes: 35 additions & 3 deletions GameEngine/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 = [];
Expand All @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions GameEngine/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fca22ac

Please sign in to comment.