fix: maxcrop & maxstore cannot be 0, nor it should be < lowest threshold

This commit is contained in:
Martin Ambrus
2017-11-16 21:49:22 +01:00
parent d3ec209ad8
commit d0a882f136
3 changed files with 58 additions and 41 deletions
+20 -10
View File
@@ -497,11 +497,11 @@ class Automation {
clay = IF(clay < 0, 0, clay),
iron = IF(iron < 0, 0, iron),
crop = IF(crop < 0, 0, crop),
maxstore = IF(maxstore < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxstore),
maxcrop = IF(maxcrop < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxcrop)
maxstore = IF(maxstore < ".STORAGE_BASE.", ".STORAGE_BASE.", maxstore),
maxcrop = IF(maxcrop < ".STORAGE_BASE.", ".STORAGE_BASE.", maxcrop)
WHERE
maxstore < (800 * ".STORAGE_MULTIPLIER.") OR
maxcrop < (800 * ".STORAGE_MULTIPLIER.") OR
maxstore < ".STORAGE_BASE." OR
maxcrop < ".STORAGE_BASE." OR
wood < 0 OR
clay < 0 OR
iron < 0 OR
@@ -518,11 +518,11 @@ class Automation {
clay = IF(clay < 0, 0, clay),
iron = IF(iron < 0, 0, iron),
crop = IF(crop < 0, 0, crop),
maxstore = IF(maxstore < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxstore),
maxcrop = IF(maxcrop < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxcrop)
maxstore = IF(maxstore < ".STORAGE_BASE.", ".STORAGE_BASE.", maxstore),
maxcrop = IF(maxcrop < ".STORAGE_BASE.", ".STORAGE_BASE.", maxcrop)
WHERE
maxstore < (800 * ".STORAGE_MULTIPLIER.") OR
maxcrop < (800 * ".STORAGE_MULTIPLIER.") OR
maxstore < ".STORAGE_BASE." OR
maxcrop < ".STORAGE_BASE." OR
wood < 0 OR
clay < 0 OR
iron < 0 OR
@@ -4238,13 +4238,13 @@ class Automation {
if ($type==10 || $type==38) {
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`=`maxstore`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref'];
$database->query($q);
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`=800 WHERE `maxstore`<= 800 AND wref=".(int) $vil['vref'];
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`= ".STORAGE_BASE." WHERE `maxstore`<= ".STORAGE_BASE." AND wref=".(int) $vil['vref'];
$database->query($q);
}
if ($type==11 || $type==39) {
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`=`maxcrop`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref'];
$database->query($q);
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`=800 WHERE `maxcrop`<=800 AND wref=".(int) $vil['vref'];
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`= ".STORAGE_BASE." WHERE `maxcrop`<=800 AND wref=".(int) $vil['vref'];
$database->query($q);
}
if ($level==1) { $clear=",f".$vil['buildnumber']."t=0"; } else { $clear=""; }
@@ -4359,6 +4359,15 @@ class Automation {
continue;
}
// maxstore nor maxcrop can go below the minimum threshold
if ($ress < STORAGE_BASE) {
$ress = STORAGE_BASE;
}
if ($crop < STORAGE_BASE) {
$crop = STORAGE_BASE;
}
mysqli_query($GLOBALS['link'],'UPDATE `' . TB_PREFIX . 'vdata` SET `maxstore` = ' . (int) $ress . ', `maxcrop` = ' . (int) $crop . ' WHERE `wref` = ' . (int) $row['vref']);
}
mysqli_commit($GLOBALS['link']);
@@ -4679,6 +4688,7 @@ class Automation {
}
}else{
if($killunits < $maxcount){
die('vvvv');
$database->modifyUnit($starv['wref'], array($maxtype), array($killunits), array(0));
$database->setVillageField($starv['wref'], 'starv', $upkeep);
$database->setVillageField($starv['wref'], 'starvupdate', $time);
+35 -28
View File
@@ -2585,33 +2585,40 @@ class MYSQLi_DB implements IDbConnection {
list($vid, $wood, $clay, $iron, $crop, $mode) = $this->escape_input((int) $vid, (int) $wood, (int) $clay, (int) $iron, (int) $crop, $mode);
$shit = false;
$q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid."";
$result = mysqli_query($this->dblink,$q);
$checkres= $this->mysqli_fetch_all($result);
if(!$mode){
$nwood=$checkres[0]['wood']-$wood;
$nclay=$checkres[0]['clay']-$clay;
$niron=$checkres[0]['iron']-$iron;
$ncrop=$checkres[0]['crop']-$crop;
if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;}
$dwood=($nwood<0)?0:$nwood;
$dclay=($nclay<0)?0:$nclay;
$diron=($niron<0)?0:$niron;
$dcrop=($ncrop<0)?0:$ncrop;
}else{
$nwood=$checkres[0]['wood']+$wood;
$nclay=$checkres[0]['clay']+$clay;
$niron=$checkres[0]['iron']+$iron;
$ncrop=$checkres[0]['crop']+$crop;
$dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood;
$dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay;
$diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron;
$dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop;
$q = "SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid;
$result = mysqli_query($this->dblink,$q);
$checkres = $this->mysqli_fetch_all($result);
if(!$mode){
$nwood = $checkres[0]['wood'] - $wood;
$nclay = $checkres[0]['clay'] - $clay;
$niron = $checkres[0]['iron'] - $iron;
$ncrop = $checkres[0]['crop'] - $crop;
if ( $nwood < 0 or $nclay < 0 or $niron < 0 or $ncrop < 0 ) {
$shit = true;
}
$dwood = ( $nwood < 0 ) ? 0 : $nwood;
$dclay = ( $nclay < 0 ) ? 0 : $nclay;
$diron = ( $niron < 0 ) ? 0 : $niron;
$dcrop = ( $ncrop < 0 ) ? 0 : $ncrop;
} else {
$nwood=$checkres[0]['wood']+$wood;
$nclay=$checkres[0]['clay']+$clay;
$niron=$checkres[0]['iron']+$iron;
$ncrop=$checkres[0]['crop']+$crop;
$dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood;
$dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay;
$diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron;
$dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop;
}
if(!$shit){
$q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid;
return mysqli_query($this->dblink,$q); }else{return false;}
}
if ( ! $shit ) {
$q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = " . $vid;
return mysqli_query( $this->dblink, $q );
} else {
return false;
}
}
function setMaxStoreForVillage($vid, $maxLevel) {
$vid = (int) $vid;
@@ -2621,7 +2628,7 @@ class MYSQLi_DB implements IDbConnection {
UPDATE
".TB_PREFIX."vdata
SET
`maxstore` = IF( `maxstore` - $maxLevel < 800, 800, `maxstore` - $maxLevel )
`maxstore` = IF( `maxstore` - $maxLevel < ".STORAGE_BASE.", ".STORAGE_BASE.", `maxstore` - $maxLevel )
WHERE
wref=$vid");
}
@@ -2634,7 +2641,7 @@ class MYSQLi_DB implements IDbConnection {
UPDATE
".TB_PREFIX."vdata
SET
`maxcrop` = IF( `maxcrop` - $maxLevel < 800, 800, `maxcrop` - $maxLevel )
`maxcrop` = IF( `maxcrop` - $maxLevel < ".STORAGE_BASE.", ".STORAGE_BASE.", `maxcrop` - $maxLevel )
WHERE
wref=$vid");
}
+3 -3
View File
@@ -126,7 +126,7 @@ class Market
$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
if($res!=0)
{
$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
$database->modifyResource($village->wid,$resource[0],$resource[1],$resource[2],$resource[3],0);
$database->addMovement(0,$village->wid,$id,$reference,time(),time()+$timetaken,$post['send3']);
$logging->addMarketLog($village->wid,1,array($resource[0],$resource[1],$resource[2],$resource[3],$id));
@@ -201,7 +201,7 @@ class Market
}
}
if($this->merchantAvail() != 0 && $reqMerc <= $this->merchantAvail())
{
{
if($database->modifyResource($village->wid,$wood,$clay,$iron,$crop,0))
{
$time = 0;
@@ -265,7 +265,7 @@ class Market
[$mytime + $timestamp, $histime + $timestamp]
);
$resource = array(1=>0,0,0,0);
$resource[$infoarray['wtype']] = $infoarray['wamt'];
$resource[$infoarray['wtype']] = $infoarray['wamt'];
$database->modifyResource($village->wid,$resource[1],$resource[2],$resource[3],$resource[4],0);
$database->setMarketAcc($get['g']);
$database->removeAcceptedOffer($get['g']);