mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
refactor: village-related methods now all optimized
This commit is contained in:
+11
-2
@@ -511,10 +511,19 @@ class MYSQLi_DB implements IDbConnection {
|
||||
mysqli_query($this->dblink,$q);
|
||||
}
|
||||
function updateResource($vid, $what, $number) {
|
||||
list($vid, $what, $number) = $this->escape_input((int) $vid, $what, (int) $number);
|
||||
$vid = (int) $vid;
|
||||
|
||||
if (!is_array($what)) {
|
||||
$what = [$what];
|
||||
$number = [$number];
|
||||
}
|
||||
|
||||
$q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid";
|
||||
$pairs = [];
|
||||
foreach ($what as $index => $whatValue) {
|
||||
$pairs[] = $this->escape($whatValue) . ' = ' . (Math::isInt($number[$index]) ? $number[$index] : '"'.$this->escape($number[$index]).'"');
|
||||
}
|
||||
|
||||
$q = "UPDATE " . TB_PREFIX . "vdata SET ".implode(', ', $pairs)." WHERE wref = $vid";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
@@ -96,11 +96,16 @@ class Village {
|
||||
$this->loyalty = $this->infoarray['loyalty'];
|
||||
$this->master = count($database->getMasterJobs($this->wid));
|
||||
//de gs in town, zetten op max pakhuisinhoud
|
||||
if($this->awood>$this->maxstore){ $this->awood=$this->maxstore; $database->updateResource($this->wid,'wood',$this->maxstore); }
|
||||
if($this->aclay>$this->maxstore){ $this->aclay=$this->maxstore; $database->updateResource($this->wid,'clay',$this->maxstore); }
|
||||
if($this->airon>$this->maxstore){ $this->airon=$this->maxstore; $database->updateResource($this->wid,'iron',$this->maxstore); }
|
||||
if($this->acrop>$this->maxcrop){ $this->acrop=$this->maxcrop; $database->updateResource($this->wid,'crop',$this->maxcrop); }
|
||||
$resourceUpdates = [];
|
||||
if($this->awood>$this->maxstore){ $this->awood=$this->maxstore; $resourceUpdates['wood'] = $this->maxstore; }
|
||||
if($this->aclay>$this->maxstore){ $this->aclay=$this->maxstore; $resourceUpdates['clay'] = $this->maxstore; }
|
||||
if($this->airon>$this->maxstore){ $this->airon=$this->maxstore; $resourceUpdates['iron'] = $this->maxstore; }
|
||||
if($this->acrop>$this->maxcrop){ $this->acrop=$this->maxcrop; $resourceUpdates['crop'] = $this->maxcrop; }
|
||||
|
||||
// update DB values
|
||||
if (count($resourceUpdates)) {
|
||||
$database->updateResource( $this->wid, array_keys( $resourceUpdates ), array_values($resourceUpdates) );
|
||||
}
|
||||
}
|
||||
|
||||
private function calculateProduction() {
|
||||
|
||||
Reference in New Issue
Block a user