mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +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;
|
||||
|
||||
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));
|
||||
|
||||
//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
|
||||
if ($newLevel == 0)
|
||||
@@ -1940,7 +1940,7 @@ class Automation {
|
||||
* resolve 1st row of catapults
|
||||
*/
|
||||
$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
|
||||
@@ -1998,7 +1998,7 @@ class Automation {
|
||||
* resolve 2nd row of catapults
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -23,7 +23,7 @@ class Building {
|
||||
private $maxConcurrent;
|
||||
private $allocated;
|
||||
private $basic,$inner,$plus = 0;
|
||||
public $buildArray = array();
|
||||
public $buildArray = [];
|
||||
|
||||
public function __construct() {
|
||||
global $session;
|
||||
@@ -369,7 +369,7 @@ class Building {
|
||||
foreach($this->buildArray as $jobs) {
|
||||
if($jobs['id'] == $d) {
|
||||
$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);
|
||||
$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);
|
||||
|
||||
$time = time();
|
||||
$stime = strtotime(START_DATE)-strtotime(date('m/d/Y'))+strtotime(START_TIME);
|
||||
if($stime > time()){
|
||||
$time = $stime;
|
||||
}
|
||||
$stime = strtotime(START_DATE) - strtotime(date('m/d/Y')) + strtotime(START_TIME);
|
||||
if($stime > $time) $time = $stime;
|
||||
$timep = $time + PROTECTION;
|
||||
$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)";
|
||||
if(mysqli_query($this->dblink,$q)) {
|
||||
return mysqli_insert_id($this->dblink);
|
||||
} else {
|
||||
if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink);
|
||||
else
|
||||
{
|
||||
// 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)";
|
||||
if(mysqli_query($this->dblink,$q)) {
|
||||
return mysqli_insert_id($this->dblink);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink);
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4384,32 +4379,43 @@ References: User ID/Message ID, Mode
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
function removeBuilding($d) {
|
||||
list($d) = $this->escape_input((int) $d);
|
||||
global $building, $village, $session;
|
||||
/**
|
||||
* Called when removing a queued building by a player or because destroyed by catapults
|
||||
*
|
||||
* @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
|
||||
$jobToDelete = [];
|
||||
$canBeRemoved = true;
|
||||
$time = time();
|
||||
$newTime = $loopTime = 0;
|
||||
if(empty($fieldsArray)) $fieldsArray = $this->getResourceLevel($wid);
|
||||
$jobs = $this->getJobs($wid);
|
||||
|
||||
//Search the job which needs to be deleted
|
||||
$jobs = $building->buildArray;
|
||||
//Search the job which needs to be deleted
|
||||
foreach($jobs as $job){
|
||||
//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?
|
||||
$sameBuilding = $jobToDelete['field'] == $job['field'] ? 1 : 0;
|
||||
|
||||
//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
|
||||
$newTime = $building->resourceRequired($job['field'],
|
||||
$job['type'],
|
||||
$job['level'] - $village->resarray['f'.$job['field']] - $sameBuilding)['time'];
|
||||
$job['level'] - $fieldsArray['f'.$job['field']] - $sameBuilding)['time'];
|
||||
|
||||
//Increase the looptime
|
||||
$loopTime += $newTime;
|
||||
@@ -4432,7 +4438,7 @@ References: User ID/Message ID, Mode
|
||||
}
|
||||
|
||||
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";
|
||||
@@ -4899,16 +4905,18 @@ References: User ID/Message ID, Mode
|
||||
* @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
|
||||
* @param int $tribe The player's tribe
|
||||
*/
|
||||
|
||||
function modifyBData($wid, $field, $levels){
|
||||
list($wid, $field, $levels) = $this->escape_input((int) $wid, (int) $field, $levels);
|
||||
function modifyBData($wid, $field, $levels, $tribe){
|
||||
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";
|
||||
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);
|
||||
if($levels[0] == 0){
|
||||
$q = "SELECT id FROM " .TB_PREFIX. "bdata WHERE wid = $wid AND field = $field";
|
||||
$orders = $this->mysqli_fetch_all(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) {
|
||||
|
||||
Reference in New Issue
Block a user