From 07e5f322e227c2933bad592ecb4d17bc00fff58a Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Sun, 19 Nov 2017 02:33:07 +0100 Subject: [PATCH] fix: reinforcements sent back do not hide the reinforcements table --- GameEngine/Database.php | 10 ++++++++++ GameEngine/Technology.php | 20 +++++++++++--------- GameEngine/Units.php | 23 +++++++++++++++++------ Templates/Build/16.tpl | 8 ++++++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 1b7105a7..0edae62d 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -766,6 +766,7 @@ class MYSQLi_DB implements IDbConnection { $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'"; mysqli_query($this->dblink,$q); + self::clearReinforcementsCache(); } function updateResource($vid, $what, $number) { @@ -5604,6 +5605,15 @@ class MYSQLi_DB implements IDbConnection { return self::$villageReinforcementsCache[$id.$mode]; } + public static function clearReinforcementsCache() { + self::$reinforcementsCache = []; + self::$villageReinforcementsCache = []; + self::$villageFromReinforcementsCache = []; + self::$oasisArrayReinforcementsCache = []; + self::$oasisReinforcementsCache = []; + self::$unitsCache = []; + } + // no need to cache this method function getVillageMovement($id) { list($id) = $this->escape_input($id); diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index 8e802ac3..ea7bd30e 100755 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -820,16 +820,18 @@ private function trainUnit($unit,$amt,$great=false) { return $generator->procMtime($reqtime); } - public function checkReinf($id) { + public function checkReinf($id, $use_cache = true) { global $database; - $enforce=$database->getEnforceArray($id,0); - $fail='0'; - for($i=1; $i<50; $i++){ - if($enforce['u'.$i.'']>0){ - $fail='1'; - } - } - if ($enforce['hero']>0) $fail='1'; + $enforce=$database->getEnforceArray($id, 0, $use_cache); + $fail=0; + + for ($i=1; $i<50; $i++) { + if($enforce['u'.$i.'']>0){ + $fail=1; + } + } + + if ($enforce['hero']>0) $fail=1; if($fail==0){ $database->deleteReinf($id); } diff --git a/GameEngine/Units.php b/GameEngine/Units.php index e6590d67..b64e64e7 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -320,7 +320,7 @@ class Units { } $reference = $database->addAttack($enforce['from'],$enforce['u'.$start],$enforce['u'.($start+1)],$enforce['u'.($start+2)],$enforce['u'.($start+3)],$enforce['u'.($start+4)],$enforce['u'.($start+5)],$enforce['u'.($start+6)],$enforce['u'.($start+7)],$enforce['u'.($start+8)],$enforce['u'.($start+9)],$enforce['hero'],2,0,0,0,0); $database->addMovement(4,$enforce['vref'],$enforce['from'],$reference,time(),($time+time())); - $database->deleteReinf($enforce['id']); + $database->deleteReinf($enforce['id']); } private function sendTroops($post) { @@ -620,12 +620,23 @@ class Units { $start = ( $database->getUserField( $to['owner'], 'tribe', 0 ) - 1 ) * 10 + 1; $end = ( $database->getUserField( $to['owner'], 'tribe', 0 ) * 10 ); - $j = '1'; + $units = []; + $amounts = []; + $modes = []; + + $j = 1; for ( $i = $start; $i <= $end; $i ++ ) { - $database->modifyEnforce( $post['ckey'], $i, $post[ 't' . $j . '' ], 0 ); + $units[] = $i; + $amounts[] = $post[ 't' . $j . '' ]; + $modes[] = 0; $j ++; } - $database->modifyEnforce( $post['ckey'], 'hero', $post['t11'], 0 ); + + $units[] = 'hero'; + $amounts[] = $post['t11']; + $modes[] = 0; + + $database->modifyEnforce( $post['ckey'], $units, $amounts, $modes ); $j ++; //get cord $from = $database->getVillage( $enforce['from'] ); @@ -688,9 +699,9 @@ class Units { } $reference = $database->addAttack( $enforce['from'], $post['t1'], $post['t2'], $post['t3'], $post['t4'], $post['t5'], $post['t6'], $post['t7'], $post['t8'], $post['t9'], $post['t10'], $post['t11'], 2, 0, 0, 0, 0 ); $database->addMovement( 4, $village->wid, $enforce['from'], $reference, time(), ( $time + time() ) ); - $technology->checkReinf( $post['ckey'] ); + $technology->checkReinf( $post['ckey'], false ); - header( "Location: build.php?id=39" ); + header( "Location: build.php?id=39&refresh=1" ); exit; } diff --git a/Templates/Build/16.tpl b/Templates/Build/16.tpl index fca1b544..89c790bd 100644 --- a/Templates/Build/16.tpl +++ b/Templates/Build/16.tpl @@ -1,4 +1,8 @@ -

resarray['f'.$id]; ?>

@@ -31,7 +35,7 @@ if($units_incoming > 0 or $settlers_incoming > 0 or $oasis_incoming > 0){ - +