mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-15 15:51:01 +00:00
@@ -1219,7 +1219,9 @@ class Automation {
|
|||||||
$vilIDs[$data['from']] = true;
|
$vilIDs[$data['from']] = true;
|
||||||
$vilIDs[$data['to']] = true;
|
$vilIDs[$data['to']] = true;
|
||||||
}
|
}
|
||||||
$database->getProfileVillages(array_keys($vilIDs), 5);
|
$vilIDs = array_keys($vilIDs);
|
||||||
|
$database->getProfileVillages($vilIDs, 5);
|
||||||
|
$database->getUnit($vilIDs);
|
||||||
|
|
||||||
// calculate battles
|
// calculate battles
|
||||||
foreach($dataarray as $data) {
|
foreach($dataarray as $data) {
|
||||||
@@ -3376,7 +3378,9 @@ class Automation {
|
|||||||
$vilIDs[$data['from']] = true;
|
$vilIDs[$data['from']] = true;
|
||||||
$vilIDs[$data['to']] = true;
|
$vilIDs[$data['to']] = true;
|
||||||
}
|
}
|
||||||
$database->getProfileVillages(array_keys($vilIDs), 5);
|
$vilIDs = array_keys($vilIDs);
|
||||||
|
$database->getProfileVillages($vilIDs, 5);
|
||||||
|
$database->getUnit($vilIDs);
|
||||||
|
|
||||||
// calculate reinforcements data
|
// calculate reinforcements data
|
||||||
$movementProcIDs = [];
|
$movementProcIDs = [];
|
||||||
@@ -4263,12 +4267,15 @@ class Automation {
|
|||||||
$vilIDs = array_keys($vilIDs);
|
$vilIDs = array_keys($vilIDs);
|
||||||
$database->getProfileVillages($vilIDs, 5);
|
$database->getProfileVillages($vilIDs, 5);
|
||||||
$database->cacheResourceLevels($vilIDs);
|
$database->cacheResourceLevels($vilIDs);
|
||||||
|
$database->getUnit($vilIDs);
|
||||||
|
|
||||||
// calculate training updates
|
// calculate training updates
|
||||||
foreach($trainlist as $train){
|
foreach($trainlist as $train){
|
||||||
$timepast = $train['timestamp2'] - $time;
|
$timepast = $train['timestamp2'] - $time;
|
||||||
$pop = $train['pop'];
|
$pop = $train['pop'];
|
||||||
|
$valuesUpdated = false;
|
||||||
if($timepast <= 0 && $train['amt'] > 0) {
|
if($timepast <= 0 && $train['amt'] > 0) {
|
||||||
|
$valuesUpdated = true;
|
||||||
$timepast2 = $time - $train['timestamp2'];
|
$timepast2 = $time - $train['timestamp2'];
|
||||||
$trained = 1;
|
$trained = 1;
|
||||||
while($timepast2 >= $train['eachtime']){
|
while($timepast2 >= $train['eachtime']){
|
||||||
@@ -4285,11 +4292,16 @@ class Automation {
|
|||||||
}
|
}
|
||||||
$database->updateTraining($train['id'],$trained,$trained*$train['eachtime']);
|
$database->updateTraining($train['id'],$trained,$trained*$train['eachtime']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($valuesUpdated) {
|
||||||
|
call_user_func(get_class($database).'::clearUnitsCache');
|
||||||
|
}
|
||||||
|
|
||||||
if($train['amt'] == 0){
|
if($train['amt'] == 0){
|
||||||
$database->trainUnit($train['id'],0,0,0,0,1,1);
|
$database->trainUnit($train['id'],0,0,0,0,1,1);
|
||||||
}
|
}
|
||||||
$crop = $database->getCropProdstarv($train['vref']);
|
$crop = $database->getCropProdstarv($train['vref']);
|
||||||
$unitarrays = $this->getAllUnits($train['vref'], false);
|
$unitarrays = $this->getAllUnits($train['vref']);
|
||||||
$village = $database->getVillage($train['vref'], 0);
|
$village = $database->getVillage($train['vref'], 0);
|
||||||
$upkeep = $village['pop'] + $this->getUpkeep($unitarrays, 0);
|
$upkeep = $village['pop'] + $this->getUpkeep($unitarrays, 0);
|
||||||
$starv = $database->getVillageField($train['vref'],"starv");
|
$starv = $database->getVillageField($train['vref'],"starv");
|
||||||
|
|||||||
+34
-8
@@ -5472,22 +5472,44 @@ References: User ID/Message ID, Mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getUnit($vid, $use_cache = true) {
|
function getUnit($vid, $use_cache = true) {
|
||||||
$vid = (int) $vid;
|
$array_passed = is_array($vid);
|
||||||
|
|
||||||
|
if (!$array_passed) {
|
||||||
|
$singleVillage = true;
|
||||||
|
$vid = [$vid];
|
||||||
|
} else {
|
||||||
|
foreach ($vid as $index => $vidValue) {
|
||||||
|
$vid[$index] = (int) $vidValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$returnArray = [];
|
||||||
|
|
||||||
// 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::$unitsCache, $vid)) && !is_null($cachedValue)) {
|
if ($use_cache && !$array_passed && ($cachedValue = self::returnCachedContent(self::$unitsCache, (int) $vid[0])) && !is_null($cachedValue)) {
|
||||||
return $cachedValue;
|
return $cachedValue;
|
||||||
}
|
} else if ($use_cache && $array_passed) {
|
||||||
|
$newIDs = [];
|
||||||
|
foreach ($vid as $villageID) {
|
||||||
|
// don't cache what we don't need to cache
|
||||||
|
if (isset(self::$unitsCache[$villageID])) {
|
||||||
|
$returnArray[$villageID] = self::$unitsCache[$villageID];
|
||||||
|
} else {
|
||||||
|
// add the uncached ID, so we can select and cache it
|
||||||
|
$newIDs[] = $villageID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$vid = $newIDs;
|
||||||
|
|
||||||
if (!is_array($vid)) {
|
// nothing to cache? return what we have
|
||||||
$singleVillage = true;
|
if (!count($vid)) {
|
||||||
$vid = [$vid];
|
return $returnArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT * from " . TB_PREFIX . "units where vref IN(".implode(', ', $vid).")";
|
$q = "SELECT * from " . TB_PREFIX . "units where vref IN(".implode(', ', $vid).")";
|
||||||
$result = mysqli_query($this->dblink,$q);
|
$result = mysqli_query($this->dblink,$q);
|
||||||
$returnArray = [];
|
|
||||||
$resCount = 0;
|
$resCount = 0;
|
||||||
$vidCount = count($vid);
|
$vidCount = count($vid);
|
||||||
|
|
||||||
@@ -6048,7 +6070,11 @@ References: User ID/Message ID, Mode
|
|||||||
self::$villageFromReinforcementsCache = [];
|
self::$villageFromReinforcementsCache = [];
|
||||||
self::$oasisArrayReinforcementsCache = [];
|
self::$oasisArrayReinforcementsCache = [];
|
||||||
self::$oasisReinforcementsCache = [];
|
self::$oasisReinforcementsCache = [];
|
||||||
self::$unitsCache = [];
|
self::clearUnitsCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function clearUnitsCache() {
|
||||||
|
self::$unitsCache = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need to cache this method
|
// no need to cache this method
|
||||||
|
|||||||
Reference in New Issue
Block a user