mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-09-03 00:47:19 +00:00
Fixed a catapult bug
+Fixed a bug that didn't recount building time for in waiting loop buildings +Fixed a bug that didn't remove a building from the waiting loop, if the previous was destroyed by catapults
This commit is contained in:
@@ -798,7 +798,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveCatapultsDestruction(&$bdo, &$battlepart, &$info_cat, &$data, $catapultTarget, $twoRowsCatapultSetup, $isSecondRow, $catp_pic, $can_destroy, $isoasis, &$village_destroyed) {
|
private function resolveCatapultsDestruction(&$bdo, &$battlepart, &$info_cat, &$data, $catapultTarget, $twoRowsCatapultSetup, $isSecondRow, $catp_pic, $can_destroy, $isoasis, &$village_destroyed, $tribe) {
|
||||||
global $battle, $database, $bid34;
|
global $battle, $database, $bid34;
|
||||||
|
|
||||||
if(isset($catapultTarget))
|
if(isset($catapultTarget))
|
||||||
@@ -813,7 +813,7 @@ class Automation {
|
|||||||
$newLevel = $battle->CalculateNewBuildingLevel($battlepart['catapults']['moral'], $battlepart['catapults']['updown'], $tblevel, $battlepart['catapults']['realAttackers'] / ($twoRowsCatapultSetup ? 2 : 1), $data['t8'] / ($twoRowsCatapultSetup ? 2 : 1));
|
$newLevel = $battle->CalculateNewBuildingLevel($battlepart['catapults']['moral'], $battlepart['catapults']['updown'], $tblevel, $battlepart['catapults']['realAttackers'] / ($twoRowsCatapultSetup ? 2 : 1), $data['t8'] / ($twoRowsCatapultSetup ? 2 : 1));
|
||||||
|
|
||||||
//If that building was present in the building queue, we have to modify his level or remove it
|
//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]);
|
$database->modifyBData($data['to'], $tbid, [$newLevel, $tblevel], $tribe);
|
||||||
|
|
||||||
// building/field destroyed
|
// building/field destroyed
|
||||||
if ($newLevel == 0)
|
if ($newLevel == 0)
|
||||||
@@ -1940,7 +1940,7 @@ class Automation {
|
|||||||
* resolve 1st row of catapults
|
* resolve 1st row of catapults
|
||||||
*/
|
*/
|
||||||
$village_destroyed = 0;
|
$village_destroyed = 0;
|
||||||
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget, !$catapults2WillNotShoot, false, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
|
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget, !$catapults2WillNotShoot, false, $catp_pic, $can_destroy, $isoasis, $village_destroyed, $targettribe);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECOND CATAPULTS ROW
|
* SECOND CATAPULTS ROW
|
||||||
@@ -1998,7 +1998,7 @@ class Automation {
|
|||||||
* resolve 2nd row of catapults
|
* resolve 2nd row of catapults
|
||||||
*/
|
*/
|
||||||
if (!$catapults2WillNotShoot) {
|
if (!$catapults2WillNotShoot) {
|
||||||
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget2, true, true, $catp_pic, $can_destroy, $isoasis, $village_destroyed);
|
$this->resolveCatapultsDestruction($bdo, $battlepart, $info_cat, $data, $catapultTarget2, true, true, $catp_pic, $can_destroy, $isoasis, $village_destroyed, $targettribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear resource levels cache, since we might have destroyed buildings/fields by now
|
// clear resource levels cache, since we might have destroyed buildings/fields by now
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Building {
|
|||||||
private $maxConcurrent;
|
private $maxConcurrent;
|
||||||
private $allocated;
|
private $allocated;
|
||||||
private $basic,$inner,$plus = 0;
|
private $basic,$inner,$plus = 0;
|
||||||
public $buildArray = array();
|
public $buildArray = [];
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
global $session;
|
global $session;
|
||||||
@@ -369,7 +369,7 @@ class Building {
|
|||||||
foreach($this->buildArray as $jobs) {
|
foreach($this->buildArray as $jobs) {
|
||||||
if($jobs['id'] == $d) {
|
if($jobs['id'] == $d) {
|
||||||
$uprequire = $this->resourceRequired($jobs['field'], $jobs['type']);
|
$uprequire = $this->resourceRequired($jobs['field'], $jobs['type']);
|
||||||
if($database->removeBuilding($d)) {
|
if($database->removeBuilding($d, $session->tribe, $village->wid, $village->resarray)) {
|
||||||
if($jobs['master'] == 0) $database->modifyResource($village->wid, $uprequire['wood'], $uprequire['clay'], $uprequire['iron'], $uprequire['crop'], 1);
|
if($jobs['master'] == 0) $database->modifyResource($village->wid, $uprequire['wood'], $uprequire['clay'], $uprequire['iron'], $uprequire['crop'], 1);
|
||||||
$this->redirect($jobs['field']);
|
$this->redirect($jobs['field']);
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-28
@@ -733,23 +733,18 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
list($username, $password, $email, $tribe, $act) = $this->escape_input($username, $password, $email, $tribe, $act);
|
list($username, $password, $email, $tribe, $act) = $this->escape_input($username, $password, $email, $tribe, $act);
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$stime = strtotime(START_DATE)-strtotime(date('m/d/Y'))+strtotime(START_TIME);
|
$stime = strtotime(START_DATE) - strtotime(date('m/d/Y')) + strtotime(START_TIME);
|
||||||
if($stime > time()){
|
if($stime > $time) $time = $stime;
|
||||||
$time = $stime;
|
|
||||||
}
|
|
||||||
$timep = $time + PROTECTION;
|
$timep = $time + PROTECTION;
|
||||||
$time = time();
|
$time = time();
|
||||||
$q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime,is_bcrypt) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time,1)";
|
$q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime,is_bcrypt) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time,1)";
|
||||||
if(mysqli_query($this->dblink,$q)) {
|
if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink);
|
||||||
return mysqli_insert_id($this->dblink);
|
else
|
||||||
} else {
|
{
|
||||||
// if an error has occured, we probably don't have DB converted to handle bcrypt passwords yet
|
// if an error has occured, we probably don't have DB converted to handle bcrypt passwords yet
|
||||||
$q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time)";
|
$q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time)";
|
||||||
if(mysqli_query($this->dblink,$q)) {
|
if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink);
|
||||||
return mysqli_insert_id($this->dblink);
|
else return false;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4384,32 +4379,43 @@ References: User ID/Message ID, Mode
|
|||||||
return mysqli_query($this->dblink,$q);
|
return mysqli_query($this->dblink,$q);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeBuilding($d) {
|
/**
|
||||||
list($d) = $this->escape_input((int) $d);
|
* Called when removing a queued building by a player or because destroyed by catapults
|
||||||
global $building, $village, $session;
|
*
|
||||||
|
* @param int $d The ID of the building which needs to be deleted
|
||||||
|
* @param int $tribe The tribe of the player
|
||||||
|
* @param int $wid The village ID of the player
|
||||||
|
* @param array $fieldsArray Optional, the array containing the village building/resource fields
|
||||||
|
* @return bool Returns true if the building was delete successfully, false otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
//Variables initialization
|
||||||
$jobToDelete = [];
|
$jobToDelete = [];
|
||||||
$canBeRemoved = true;
|
$canBeRemoved = true;
|
||||||
$time = time();
|
$time = time();
|
||||||
$newTime = $loopTime = 0;
|
$newTime = $loopTime = 0;
|
||||||
|
if(empty($fieldsArray)) $fieldsArray = $this->getResourceLevel($wid);
|
||||||
|
$jobs = $this->getJobs($wid);
|
||||||
|
|
||||||
//Search the job which needs to be deleted
|
//Search the job which needs to be deleted
|
||||||
$jobs = $building->buildArray;
|
|
||||||
foreach($jobs as $job){
|
foreach($jobs as $job){
|
||||||
//We need to modify waiting loop orders
|
//We need to modify waiting loop orders
|
||||||
if(!empty($jobToDelete) && $job['loopcon'] == 1 && ($session->tribe != 1 || $session->tribe == 1 && (($jobToDelete['field'] <= 18 && $job['field'] <= 18) || ($jobToDelete['field'] >= 19 && $job['field'] >= 19)))){
|
if(!empty($jobToDelete) && $job['loopcon'] == 1 && ($tribe != 1 || $tribe == 1 && (($jobToDelete['field'] <= 18 && $job['field'] <= 18) || ($jobToDelete['field'] >= 19 && $job['field'] >= 19)))){
|
||||||
|
|
||||||
//Does this job have the same field of the deleted one?
|
//Does this job have the same field of the deleted one?
|
||||||
$sameBuilding = $jobToDelete['field'] == $job['field'] ? 1 : 0;
|
$sameBuilding = $jobToDelete['field'] == $job['field'] ? 1 : 0;
|
||||||
|
|
||||||
//Can the building be completely removed from the village?
|
//Can the building be completely removed from the village?
|
||||||
if($sameBuilding && $canBeRemoved) $canBeRemoved = !$sameBuilding;
|
if($sameBuilding && $canBeRemoved) $canBeRemoved = !$sameBuilding;
|
||||||
|
|
||||||
//Get the time required to upgrade the building at the given level
|
//Get the time required to upgrade the building at the given level
|
||||||
$newTime = $building->resourceRequired($job['field'],
|
$newTime = $building->resourceRequired($job['field'],
|
||||||
$job['type'],
|
$job['type'],
|
||||||
$job['level'] - $village->resarray['f'.$job['field']] - $sameBuilding)['time'];
|
$job['level'] - $fieldsArray['f'.$job['field']] - $sameBuilding)['time'];
|
||||||
|
|
||||||
//Increase the looptime
|
//Increase the looptime
|
||||||
$loopTime += $newTime;
|
$loopTime += $newTime;
|
||||||
@@ -4432,7 +4438,7 @@ References: User ID/Message ID, Mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($canBeRemoved && $jobToDelete['field'] > 18 && $jobToDelete['type'] != 99 && $jobToDelete['level'] - 1 == 0){
|
if($canBeRemoved && $jobToDelete['field'] > 18 && $jobToDelete['type'] != 99 && $jobToDelete['level'] - 1 == 0){
|
||||||
$this->setVillageLevel($village->wid, ["f".$jobToDelete['field']."t"], [0]);
|
$this->setVillageLevel($wid, ["f".$jobToDelete['field']."t"], [0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d";
|
$q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d";
|
||||||
@@ -4899,16 +4905,18 @@ References: User ID/Message ID, Mode
|
|||||||
* @param int The village ID
|
* @param int The village ID
|
||||||
* @param int $field The field where the building is located
|
* @param int $field The field where the building is located
|
||||||
* @param array $levels The new level of the building and the old one
|
* @param array $levels The new level of the building and the old one
|
||||||
* @return bool Returns true if the query was successful, false otherwise
|
* @param int $tribe The player's tribe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function modifyBData($wid, $field, $levels){
|
function modifyBData($wid, $field, $levels, $tribe){
|
||||||
list($wid, $field, $levels) = $this->escape_input((int) $wid, (int) $field, $levels);
|
list($wid, $field, $levels, $tribe) = $this->escape_input((int) $wid, (int) $field, (int) $levels, (int) $tribe);
|
||||||
|
|
||||||
if($levels[0] == 0) $q = "DELETE FROM " .TB_PREFIX. "bdata WHERE wid = $wid AND field = $field";
|
if($levels[0] == 0){
|
||||||
else $q = "UPDATE " .TB_PREFIX. "bdata SET level = level - $levels[1] + $levels[0] WHERE wid = $wid AND field = $field";
|
$q = "SELECT id FROM " .TB_PREFIX. "bdata WHERE wid = $wid AND field = $field";
|
||||||
|
$orders = $this->mysqli_fetch_all(mysqli_query($this->dblink, $q));
|
||||||
return mysqli_query($this->dblink, $q);
|
foreach($orders as $order) $this->removeBuilding($order['id'], $tribe, $wid);
|
||||||
|
}
|
||||||
|
else mysqli_query($this->dblink, $q = "UPDATE " .TB_PREFIX. "bdata SET level = level - $levels[1] + $levels[0] WHERE wid = $wid AND field = $field");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBData($wid, $use_cache = true) {
|
private function getBData($wid, $use_cache = true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user