From 683b692a5524347ba5dea094819c612f65d91f5e Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Sat, 4 Nov 2017 09:36:55 +0100 Subject: [PATCH] fix: gold can go to negative values Master builder cannot be used if we only have 2 gold and we chose to insta-finish everything. In such case, master builder task will be deleted instead of completed. Fixes #264 --- GameEngine/Building.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/GameEngine/Building.php b/GameEngine/Building.php index 87abddff..f97baaa4 100755 --- a/GameEngine/Building.php +++ b/GameEngine/Building.php @@ -785,20 +785,29 @@ class Building { $q = "UPDATE ".TB_PREFIX."fdata set f".$jobs['field']." = ".$jobs['level'].", f".$jobs['field']."t = ".$jobs['type']." where vref = ".$jobs['wid']; $countPlus2Gold = true; } else { - $countMasterGold = true; - $villwood = $database->getVillageField($jobs['wid'],'wood'); - $villclay = $database->getVillageField($jobs['wid'],'clay'); - $villiron = $database->getVillageField($jobs['wid'],'iron'); - $villcrop = $database->getVillageField($jobs['wid'],'crop'); - $type = $jobs['type']; - $buildarray = $GLOBALS["bid".$type]; - $buildwood = $buildarray[$level]['wood']; - $buildclay = $buildarray[$level]['clay']; - $buildiron = $buildarray[$level]['iron']; - $buildcrop = $buildarray[$level]['crop']; - if($buildwood < $villwood && $buildclay < $villclay && $buildiron < $villiron && $buildcrop < $villcrop) { - $enought_res = 1; - $q = "UPDATE ".TB_PREFIX."fdata set f".$jobs['field']." = ".$jobs['level'].", f".$jobs['field']."t = ".(int) $jobs['type']." where vref = ".(int) $jobs['wid']; + // don't allow master builder to build anything + // if we only have 2 gold, since that would take us to -1 gold + if ($session->gold > 2) { + $countMasterGold = true; + $villwood = $database->getVillageField($jobs['wid'],'wood'); + $villclay = $database->getVillageField($jobs['wid'],'clay'); + $villiron = $database->getVillageField($jobs['wid'],'iron'); + $villcrop = $database->getVillageField($jobs['wid'],'crop'); + $type = $jobs['type']; + $buildarray = $GLOBALS["bid".$type]; + $buildwood = $buildarray[$level]['wood']; + $buildclay = $buildarray[$level]['clay']; + $buildiron = $buildarray[$level]['iron']; + $buildcrop = $buildarray[$level]['crop']; + if($buildwood < $villwood && $buildclay < $villclay && $buildiron < $villiron && $buildcrop < $villcrop) { + $enought_res = 1; + $q = "UPDATE ".TB_PREFIX."fdata set f".$jobs['field']." = ".$jobs['level'].", f".$jobs['field']."t = ".(int) $jobs['type']." where vref = ".(int) $jobs['wid']; + } + } else { + // if we only have 2 gold, we need to cancel this job, as there will never + // be enough gold now in our account to finish this up + $q = "DELETE FROM ".TB_PREFIX."bdata WHERE id = ".(int) $jobs['id']; + $database->query($q); } }