Skip to content

Commit

Permalink
fix: construction of a palace and a residence in one village
Browse files Browse the repository at this point in the history
  • Loading branch information
martinambrus committed Nov 22, 2017
1 parent 6f7dff2 commit ddb8614
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 70 deletions.
182 changes: 117 additions & 65 deletions GameEngine/Building.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
## --------------------------------------------------------------------------- ##
## Project: TravianZ ##
## Version: 22.06.2015 ##
## Version: 22.06.2015 ##
## Filename Building.php ##
## Developed by: Mr.php , Advocaite , brainiacX , yi12345 , Shadow , ronix ##
## Developed by: Mr.php , Advocaite , brainiacX , yi12345 , Shadow , ronix ##
## Fixed by: Shadow - STARVATION , HERO FIXED COMPL., TPLinux ##
## Fixed by: InCube - double troops ##
## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2015. All rights reserved. ##
## URLs: http://travian.shadowss.ro ##
## Source code: https://github.com/Shadowss/TravianZ ##
## Source code: https://github.com/Shadowss/TravianZ ##
## ##
#################################################################################

Expand Down Expand Up @@ -41,27 +41,50 @@ public function __construct() {
}
}
}


public function residenceOfPalaceBuildInProgress($vid) {
global $database, $village;

$residenceOrPalaceInProgress = $database->getBuildingByType($village->wid, '25, 26');
$residenceBuildInProgress = false;
$palaceBuildInProgress = false;

if (count($residenceOrPalaceInProgress)) {
foreach ($residenceOrPalaceInProgress as $record) {
if ($record['type'] == 25) {
$residenceBuildInProgress = true;
} else {
$palaceBuildInProgress = true;
}
}
}

return [
'residence' => $residenceBuildInProgress,
'palace' => $palaceBuildInProgress
];
}

public function canProcess($id,$tid) {
//add fix by ronix
global $session;
if($session->access==BANNED){
header("Location: banned.php");
exit;
} else {
if ($this->checkResource($id,$tid)!=4) {
if($tid >= 19) {
header("Location: dorf2.php");
exit;
}
else {
header("Location: dorf1.php");
exit;
}
exit;
}
}
}
//add fix by ronix
global $session;
if($session->access==BANNED){
header("Location: banned.php");
exit;
} else {
if ($this->checkResource($id,$tid)!=4) {
if($tid >= 19) {
header("Location: dorf2.php");
exit;
}
else {
header("Location: dorf1.php");
exit;
}
exit;
}
}
}

public function procBuild($get) {
global $session, $village, $database;
Expand All @@ -81,14 +104,28 @@ public function procBuild($get) {
if($session->access==BANNED){
header("Location: banned.php");
exit;
}
$level = $database->getResourceLevel($village->wid);
$database->addBuilding($village->wid, $get['id'], $get['master'], 1, $get['time'], 1, $level['f'.$get['id']] + 1 + count($database->getBuildingByField($village->wid,$get['id'])));
if($get['id'] > 18) {
header("Location: dorf2.php");
}

// check if we're not trying to hack-build residence and palace together
if (
($progresses = $this->residenceOfPalaceBuildInProgress($village->wid)) &&
(
!in_array($get['master'], [25, 26]) ||
(
($get['master'] == 25 && $progresses['palace'] === false) ||
($get['master'] == 26 && $progresses['residence'] === false)
)
)
) {
$level = $database->getResourceLevel( $village->wid );
$database->addBuilding( $village->wid, $get['id'], $get['master'], 1, $get['time'], 1, $level[ 'f' . $get['id'] ] + 1 + count( $database->getBuildingByField( $village->wid, $get['id'] ) ) );
}

if ( $get['id'] > 18 ) {
header( "Location: dorf2.php" );
exit;
} else {
header("Location: dorf1.php");
header( "Location: dorf1.php" );
exit;
}
}
Expand Down Expand Up @@ -434,37 +471,52 @@ private function constructBuilding($id,$tid) {
global $database,$village,$session,$logging;

if($this->allocated < $this->maxConcurrent) {
if($tid == 16) {
$id = 39;
}
else if($tid == 31 || $tid == 32 || $tid == 33) {
$id = 40;
}
$uprequire = $this->resourceRequired($id,$tid);
$time = time() + $uprequire['time'];
$bindicate = $this->canBuild($id,$village->resarray['f'.$id.'t']);
$loop = ($bindicate == 9 ? 1 : 0);
if($loop == 1) {
foreach($this->buildArray as $build) {
if($build['field'] >= 19 || ($session->tribe <> 1 && !ALLOW_ALL_TRIBE)) {
$time = $build['timestamp'] + ceil(60/SPEED) + $uprequire['time'];
}
}
}
if($this->meetRequirement($tid)) {
if($session->access!=BANNED){
$level = $database->getResourceLevel($village->wid);
if($database->addBuilding($village->wid,$id,$tid,$loop,$time,0,$level['f'.$id] + 1 + count($database->getBuildingByField($village->wid,$id)))) {
$logging->addBuildLog($village->wid,$this->procResType($tid),($village->resarray['f'.$id]+1),1);
$database->modifyResource($village->wid,$uprequire['wood'],$uprequire['clay'],$uprequire['iron'],$uprequire['crop'],0);
header("Location: dorf2.php");
exit;
}
}else{
header("Location: banned.php");
exit;
}
}
// check if we're not trying to hack-build residence and palace together
if (
($progresses = $this->residenceOfPalaceBuildInProgress($village->wid)) &&
(
!in_array($tid, [25, 26]) ||
(
($tid == 25 && $progresses['palace'] === false) ||
($tid == 26 && $progresses['residence'] === false)
)
)
) {

if ( $tid == 16 ) {
$id = 39;
} else if ( $tid == 31 || $tid == 32 || $tid == 33 ) {
$id = 40;
}
$uprequire = $this->resourceRequired( $id, $tid );
$time = time() + $uprequire['time'];
$bindicate = $this->canBuild( $id, $village->resarray[ 'f' . $id . 't' ] );
$loop = ( $bindicate == 9 ? 1 : 0 );
if ( $loop == 1 ) {
foreach ( $this->buildArray as $build ) {
if ( $build['field'] >= 19 || ( $session->tribe <> 1 && ! ALLOW_ALL_TRIBE ) ) {
$time = $build['timestamp'] + ceil( 60 / SPEED ) + $uprequire['time'];
}
}
}
if ( $this->meetRequirement( $tid ) ) {
if ( $session->access != BANNED ) {
$level = $database->getResourceLevel( $village->wid );
if ( $database->addBuilding( $village->wid, $id, $tid, $loop, $time, 0, $level[ 'f' . $id ] + 1 + count( $database->getBuildingByField( $village->wid, $id ) ) ) ) {
$logging->addBuildLog( $village->wid, $this->procResType( $tid ), ( $village->resarray[ 'f' . $id ] + 1 ), 1 );
$database->modifyResource( $village->wid, $uprequire['wood'], $uprequire['clay'], $uprequire['iron'], $uprequire['crop'], 0 );
header( "Location: dorf2.php" );
exit;
}
} else {
header( "Location: banned.php" );
exit;
}
}
} else {
header( "Location: dorf2.php" );
exit;
}
}
}

Expand Down Expand Up @@ -830,15 +882,15 @@ public function getTypeLevel($tid,$vid=0) {
if ($session->uid == 1) {
return 0;
}

$keyholder = array();

if($vid == 0) {
$resourcearray = $village->resarray;
} else {
$resourcearray = $database->getResourceLevel($vid);
}

foreach(array_keys($resourcearray,$tid) as $key) {
if(strpos($key,'t')) {
$key = preg_replace("/[^0-9]/", '', $key);
Expand All @@ -853,7 +905,7 @@ public function getTypeLevel($tid,$vid=0) {
// resource field
if($tid <= 4) {
$temparray = array();

for($i=0;$i<=$element-1;$i++) {
// collect current field level
array_push($temparray,$resourcearray['f'.$keyholder[$i]]);
Expand All @@ -870,7 +922,7 @@ public function getTypeLevel($tid,$vid=0) {
// village building
else {
$target = 0;

// find the highest level built for this building type
for($i=1;$i<=$element-1;$i++) {
if($resourcearray['f'.$keyholder[$i]] > $resourcearray['f'.$keyholder[$target]]) {
Expand Down Expand Up @@ -1024,7 +1076,7 @@ public function finishAll($redirect_url = '') {
$database->updateUserField($session->uid, "gold", $newgold, 1);
}

$stillbuildingarray = $database->getJobs($village->wid);
$stillbuildingarray = $database->getJobs($village->wid);
if (count($stillbuildingarray) == 1) {
if($stillbuildingarray[0]['loopcon'] == 1) {
//$q = "UPDATE ".TB_PREFIX."bdata SET loopcon=0,timestamp=".(time()+$stillbuildingarray[0]['timestamp']-$innertimestamp)." WHERE id=".$stillbuildingarray[0]['id'];
Expand Down
6 changes: 4 additions & 2 deletions GameEngine/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4971,9 +4971,11 @@ function getBuildingByField2($wid,$field) {

// no need to cache this method
function getBuildingByType($wid,$type) {
list($wid,$type) = $this->escape_input((int) $wid,(int) $type);
$wid = (int) $wid;

$type = (strpos($type, ',') === false ? (int) $type : $this->escape($type));

$q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = $type and master = 0";
$q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type IN($type) and master = 0";
$result = mysqli_query($this->dblink,$q);
return $this->mysqli_fetch_all($result);
}
Expand Down
9 changes: 6 additions & 3 deletions Templates/Build/avaliable.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ $greatwarehouse1 = getTypeCount(38);
$greatgranary1 = getTypeCount(39);
$greatworkshop1 = getTypeCount(42);

$residenceOrPalaceInProgress = $building->residenceOfPalaceBuildInProgress($village->wid);
$residenceBuildInProgress = $residenceOrPalaceInProgress['residence'];
$palaceBuildInProgress = $residenceOrPalaceInProgress['palace'];

?>
<div id="build" class="gid0"><h1<?php echo CONSTRUCT_NEW_BUILDING;?></h1>
<?php
Expand Down Expand Up @@ -163,7 +167,7 @@ include("avaliable/grainmill.tpl");
if($granary >= 1 && $warehouse >= 1 && $mainbuilding >= 3 && $market == 0 && $market1 == 0 && $id != 39 && $id != 40) {
include("avaliable/marketplace.tpl");
}
if($mainbuilding >= 5 && $residence == 0 && $residence1 == 0 && $id != 39 && $id != 40 && $palace == 0) {
if($mainbuilding >= 5 && $residence == 0 && $residence1 == 0 && $id != 39 && $id != 40 && $palace == 0 && !$palaceBuildInProgress) {
include("avaliable/residence.tpl");
}
if($academy == 0 && $academy1 == 0 && $mainbuilding >= 3 && $barrack >= 3 && $id != 39 && $id != 40) {
Expand Down Expand Up @@ -195,9 +199,8 @@ if ($test){

}


//if Castle no ready include palace.tpl
if (!$test){
if (!$test && !$residenceBuildInProgress){
include("avaliable/palace.tpl");
}

Expand Down

0 comments on commit ddb8614

Please sign in to comment.