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), clay = IF(clay < 0, 0, clay),
iron = IF(iron < 0, 0, iron), iron = IF(iron < 0, 0, iron),
crop = IF(crop < 0, 0, crop), crop = IF(crop < 0, 0, crop),
maxstore = IF(maxstore < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxstore), maxstore = IF(maxstore < ".STORAGE_BASE.", ".STORAGE_BASE.", maxstore),
maxcrop = IF(maxcrop < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxcrop) maxcrop = IF(maxcrop < ".STORAGE_BASE.", ".STORAGE_BASE.", maxcrop)
WHERE WHERE
maxstore < (800 * ".STORAGE_MULTIPLIER.") OR maxstore < ".STORAGE_BASE." OR
maxcrop < (800 * ".STORAGE_MULTIPLIER.") OR maxcrop < ".STORAGE_BASE." OR
wood < 0 OR wood < 0 OR
clay < 0 OR clay < 0 OR
iron < 0 OR iron < 0 OR
@@ -518,11 +518,11 @@ class Automation {
clay = IF(clay < 0, 0, clay), clay = IF(clay < 0, 0, clay),
iron = IF(iron < 0, 0, iron), iron = IF(iron < 0, 0, iron),
crop = IF(crop < 0, 0, crop), crop = IF(crop < 0, 0, crop),
maxstore = IF(maxstore < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxstore), maxstore = IF(maxstore < ".STORAGE_BASE.", ".STORAGE_BASE.", maxstore),
maxcrop = IF(maxcrop < (800 * ".STORAGE_MULTIPLIER."), (800 * ".STORAGE_MULTIPLIER."), maxcrop) maxcrop = IF(maxcrop < ".STORAGE_BASE.", ".STORAGE_BASE.", maxcrop)
WHERE WHERE
maxstore < (800 * ".STORAGE_MULTIPLIER.") OR maxstore < ".STORAGE_BASE." OR
maxcrop < (800 * ".STORAGE_MULTIPLIER.") OR maxcrop < ".STORAGE_BASE." OR
wood < 0 OR wood < 0 OR
clay < 0 OR clay < 0 OR
iron < 0 OR iron < 0 OR
@@ -4238,13 +4238,13 @@ class Automation {
if ($type==10 || $type==38) { if ($type==10 || $type==38) {
$q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`=`maxstore`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref']; $q = "UPDATE ".TB_PREFIX."vdata SET `maxstore`=`maxstore`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref'];
$database->query($q); $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); $database->query($q);
} }
if ($type==11 || $type==39) { if ($type==11 || $type==39) {
$q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`=`maxcrop`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref']; $q = "UPDATE ".TB_PREFIX."vdata SET `maxcrop`=`maxcrop`-".$buildarray[$level]['attri']." WHERE wref=".(int) $vil['vref'];
$database->query($q); $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); $database->query($q);
} }
if ($level==1) { $clear=",f".$vil['buildnumber']."t=0"; } else { $clear=""; } if ($level==1) { $clear=",f".$vil['buildnumber']."t=0"; } else { $clear=""; }
@@ -4359,6 +4359,15 @@ class Automation {
continue; 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_query($GLOBALS['link'],'UPDATE `' . TB_PREFIX . 'vdata` SET `maxstore` = ' . (int) $ress . ', `maxcrop` = ' . (int) $crop . ' WHERE `wref` = ' . (int) $row['vref']);
} }
mysqli_commit($GLOBALS['link']); mysqli_commit($GLOBALS['link']);
@@ -4679,6 +4688,7 @@ class Automation {
} }
}else{ }else{
if($killunits < $maxcount){ if($killunits < $maxcount){
die('vvvv');
$database->modifyUnit($starv['wref'], array($maxtype), array($killunits), array(0)); $database->modifyUnit($starv['wref'], array($maxtype), array($killunits), array(0));
$database->setVillageField($starv['wref'], 'starv', $upkeep); $database->setVillageField($starv['wref'], 'starv', $upkeep);
$database->setVillageField($starv['wref'], 'starvupdate', $time); $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); list($vid, $wood, $clay, $iron, $crop, $mode) = $this->escape_input((int) $vid, (int) $wood, (int) $clay, (int) $iron, (int) $crop, $mode);
$shit = false; $shit = false;
$q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid.""; $q = "SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid;
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
$checkres= $this->mysqli_fetch_all($result); $checkres = $this->mysqli_fetch_all($result);
if(!$mode){
$nwood=$checkres[0]['wood']-$wood; if(!$mode){
$nclay=$checkres[0]['clay']-$clay; $nwood = $checkres[0]['wood'] - $wood;
$niron=$checkres[0]['iron']-$iron; $nclay = $checkres[0]['clay'] - $clay;
$ncrop=$checkres[0]['crop']-$crop; $niron = $checkres[0]['iron'] - $iron;
if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;} $ncrop = $checkres[0]['crop'] - $crop;
$dwood=($nwood<0)?0:$nwood; if ( $nwood < 0 or $nclay < 0 or $niron < 0 or $ncrop < 0 ) {
$dclay=($nclay<0)?0:$nclay; $shit = true;
$diron=($niron<0)?0:$niron; }
$dcrop=($ncrop<0)?0:$ncrop; $dwood = ( $nwood < 0 ) ? 0 : $nwood;
}else{ $dclay = ( $nclay < 0 ) ? 0 : $nclay;
$nwood=$checkres[0]['wood']+$wood; $diron = ( $niron < 0 ) ? 0 : $niron;
$nclay=$checkres[0]['clay']+$clay; $dcrop = ( $ncrop < 0 ) ? 0 : $ncrop;
$niron=$checkres[0]['iron']+$iron; } else {
$ncrop=$checkres[0]['crop']+$crop; $nwood=$checkres[0]['wood']+$wood;
$dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood; $nclay=$checkres[0]['clay']+$clay;
$dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay; $niron=$checkres[0]['iron']+$iron;
$diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron; $ncrop=$checkres[0]['crop']+$crop;
$dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop; $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; if ( ! $shit ) {
return mysqli_query($this->dblink,$q); }else{return false;} $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) { function setMaxStoreForVillage($vid, $maxLevel) {
$vid = (int) $vid; $vid = (int) $vid;
@@ -2621,7 +2628,7 @@ class MYSQLi_DB implements IDbConnection {
UPDATE UPDATE
".TB_PREFIX."vdata ".TB_PREFIX."vdata
SET SET
`maxstore` = IF( `maxstore` - $maxLevel < 800, 800, `maxstore` - $maxLevel ) `maxstore` = IF( `maxstore` - $maxLevel < ".STORAGE_BASE.", ".STORAGE_BASE.", `maxstore` - $maxLevel )
WHERE WHERE
wref=$vid"); wref=$vid");
} }
@@ -2634,7 +2641,7 @@ class MYSQLi_DB implements IDbConnection {
UPDATE UPDATE
".TB_PREFIX."vdata ".TB_PREFIX."vdata
SET SET
`maxcrop` = IF( `maxcrop` - $maxLevel < 800, 800, `maxcrop` - $maxLevel ) `maxcrop` = IF( `maxcrop` - $maxLevel < ".STORAGE_BASE.", ".STORAGE_BASE.", `maxcrop` - $maxLevel )
WHERE WHERE
wref=$vid"); wref=$vid");
} }