fix: hero movements got screwed up while doing DB caching stuff...

#313
This commit is contained in:
Martin Ambrus
2017-11-17 23:46:01 +01:00
parent bfc7a2b28a
commit 2041ad750e
3 changed files with 8 additions and 12 deletions
+4 -8
View File
@@ -1697,8 +1697,7 @@ class Automation {
$alldead=array(); $alldead=array();
$heroAttackDead=$dead11; $heroAttackDead=$dead11;
//kill own defence //kill own defence
$q = "SELECT * FROM ".TB_PREFIX."units WHERE vref='".$data['to']."'"; $unitlist = $database->getUnit($data['to']);
$unitlist = $database->query_return($q);
$start = ($targettribe-1)*10+1; $start = ($targettribe-1)*10+1;
$end = ($targettribe*10); $end = ($targettribe*10);
@@ -1713,7 +1712,7 @@ class Automation {
} }
if($unitlist){ if($unitlist){
$owndead[$i]=round($battlepart[2]*$unitlist[0]['u'.$i]); $owndead[$i] = round($battlepart[2] * (isset($unitlist[0]) ? $unitlist[0]['u'.$i] : 0));
$unitModifications_units[] = $i; $unitModifications_units[] = $i;
$unitModifications_amounts[] = $owndead[$i]; $unitModifications_amounts[] = $owndead[$i];
$unitModifications_modes[] = 0; $unitModifications_modes[] = 0;
@@ -2136,10 +2135,7 @@ class Automation {
} }
} }
if ($herosend_att>0){ if ($herosend_att>0){
$qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $from['owner']." AND dead = 0"; $hero_unit = $database->getHeroField($from['owner'], 'unit');
$resulth = mysqli_query($GLOBALS['link'],$qh);
$hero_f=mysqli_fetch_array($resulth);
$hero_unit=$hero_f['unit'];
$speeds[] = $GLOBALS['u'.$hero_unit]['speed']; $speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
} }
@@ -3349,7 +3345,7 @@ class Automation {
) { ) {
//don't reinforce, addunit instead //don't reinforce, addunit instead
$database->modifyUnit($data['to'],array("hero"),array(1),array(1)); $database->modifyUnit($data['to'],array("hero"),array(1),array(1));
$heroid = $database->getHero($DefenderID,1); $heroid = $database->getHeroField($DefenderID, 'heroid');
$database->modifyHero("wref",$data['to'],$heroid,0); $database->modifyHero("wref",$data['to'],$heroid,0);
$HeroTransfer = 1; $HeroTransfer = 1;
} }
+2 -2
View File
@@ -5169,14 +5169,14 @@ class MYSQLi_DB implements IDbConnection {
// first of all, check if we should be using cache and whether the field // first of all, check if we should be using cache and whether the field
// required is already cached // required is already cached
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$heroFieldCache, $uid.$field)) && !is_null($cachedValue)) { if ($use_cache && ($cachedValue = self::returnCachedContent(self::$heroFieldCache, $uid.$field)) && !is_null($cachedValue)) {
return $cachedValue; return $cachedValue[$field];
} }
$q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = $uid AND dead = 0"; $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = $uid AND dead = 0";
$result = mysqli_query($this->dblink,$q); $result = mysqli_query($this->dblink,$q);
self::$heroFieldCache[$uid.$field] = $this->mysqli_fetch_all($result); self::$heroFieldCache[$uid.$field] = $this->mysqli_fetch_all($result);
return self::$heroFieldCache[$uid.$field]; return self::$heroFieldCache[$uid.$field][$field];
} }
function modifyHero($column,$value,$heroid,$mode=0) { function modifyHero($column,$value,$heroid,$mode=0) {
+2 -2
View File
@@ -287,7 +287,7 @@ class Units {
} }
} }
if( intval($enforce['hero']) > 0){ if( intval($enforce['hero']) > 0){
$hero_unit = $database->getHeroField($from['owner'], 'unit')['unit']; $hero_unit = $database->getHeroField($from['owner'], 'unit');
$speeds[] = $GLOBALS['u'.$hero_unit]['speed']; $speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
}else{ }else{
$enforce['hero']='0'; $enforce['hero']='0';
@@ -654,7 +654,7 @@ class Units {
} }
if ( isset( $post['t11'] ) ) { if ( isset( $post['t11'] ) ) {
if ( $post['t11'] != '' && $post['t11'] > 0 ) { if ( $post['t11'] != '' && $post['t11'] > 0 ) {
$hero_unit = $database->getHeroField($from['owner'], 'unit')['unit']; $hero_unit = $database->getHeroField($from['owner'], 'unit');
$speeds[] = $GLOBALS[ 'u' . $hero_unit ]['speed']; $speeds[] = $GLOBALS[ 'u' . $hero_unit ]['speed'];
} else { } else {
$post['t11'] = '0'; $post['t11'] = '0';