mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-09-23 10:26:42 +08:00
@@ -924,6 +924,15 @@ class Automation {
|
|||||||
$time = time();
|
$time = time();
|
||||||
$q = "SELECT `from`, wood, clay, iron, crop, wid, deliveries, id FROM ".TB_PREFIX."route where timestamp < $time";
|
$q = "SELECT `from`, wood, clay, iron, crop, wid, deliveries, id FROM ".TB_PREFIX."route where timestamp < $time";
|
||||||
$dataarray = $database->query_return($q);
|
$dataarray = $database->query_return($q);
|
||||||
|
|
||||||
|
$vilIDs = [];
|
||||||
|
foreach($dataarray as $data) {
|
||||||
|
$vilIDs[$data['to']] = true;
|
||||||
|
$vilIDs[$data['from']] = true;
|
||||||
|
}
|
||||||
|
$vilIDs = array_keys($vilIDs);
|
||||||
|
$database->getVillageByWorldID($vilIDs);
|
||||||
|
|
||||||
foreach($dataarray as $data) {
|
foreach($dataarray as $data) {
|
||||||
$targettribe = $database->getUserField($database->getVillageField($data['from'],"owner"),"tribe",0);
|
$targettribe = $database->getUserField($database->getVillageField($data['from'],"owner"),"tribe",0);
|
||||||
$this->sendResource2($data['wood'],$data['clay'],$data['iron'],$data['crop'],$data['from'],$data['wid'],$targettribe,$data['deliveries']);
|
$this->sendResource2($data['wood'],$data['clay'],$data['iron'],$data['crop'],$data['from'],$data['wid'],$targettribe,$data['deliveries']);
|
||||||
@@ -972,6 +981,15 @@ class Automation {
|
|||||||
|
|
||||||
$q1 = "SELECT send, moveid, `to`, wood, clay, iron, crop, `from` FROM ".TB_PREFIX."movement WHERE proc = 0 and sort_type = 2 and endtime < $time";
|
$q1 = "SELECT send, moveid, `to`, wood, clay, iron, crop, `from` FROM ".TB_PREFIX."movement WHERE proc = 0 and sort_type = 2 and endtime < $time";
|
||||||
$dataarray1 = $database->query_return($q1);
|
$dataarray1 = $database->query_return($q1);
|
||||||
|
|
||||||
|
$vilIDs = [];
|
||||||
|
foreach($dataarray1 as $data1) {
|
||||||
|
$vilIDs[$data1['to']] = true;
|
||||||
|
$vilIDs[$data1['from']] = true;
|
||||||
|
}
|
||||||
|
$vilIDs = array_keys($vilIDs);
|
||||||
|
$database->getVillageByWorldID($vilIDs);
|
||||||
|
|
||||||
foreach($dataarray1 as $data1) {
|
foreach($dataarray1 as $data1) {
|
||||||
$database->setMovementProc($data1['moveid']);
|
$database->setMovementProc($data1['moveid']);
|
||||||
if($data1['send'] > 1){
|
if($data1['send'] > 1){
|
||||||
@@ -3396,6 +3414,7 @@ class Automation {
|
|||||||
$database->getProfileVillages($vilIDs, 5);
|
$database->getProfileVillages($vilIDs, 5);
|
||||||
$database->getUnit($vilIDs);
|
$database->getUnit($vilIDs);
|
||||||
$database->getEnforce(array_keys($tos), array_keys($froms));
|
$database->getEnforce(array_keys($tos), array_keys($froms));
|
||||||
|
$database->getVillageByWorldID($vilIDs);
|
||||||
|
|
||||||
// calculate reinforcements data
|
// calculate reinforcements data
|
||||||
$movementProcIDs = [];
|
$movementProcIDs = [];
|
||||||
@@ -3713,7 +3732,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->getVillageByWorldID($vilIDs);
|
||||||
|
|
||||||
foreach($dataarray as $data) {
|
foreach($dataarray as $data) {
|
||||||
$ownerID = $database->getUserField($database->getVillageField($data['from'],"owner"),"id",0);
|
$ownerID = $database->getUserField($database->getVillageField($data['from'],"owner"),"id",0);
|
||||||
|
|||||||
+54
-6
@@ -1861,19 +1861,67 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getVillageByWorldID($vid, $use_cache = true) {
|
function getVillageByWorldID($vid, $use_cache = true) {
|
||||||
$vid = (int) $vid;
|
$array_passed = is_array($vid);
|
||||||
|
|
||||||
|
if (!$array_passed) {
|
||||||
|
$vid = [(int) $vid];
|
||||||
|
} else {
|
||||||
|
foreach ($vid as $index => $ivdValue) {
|
||||||
|
$vid[$index] = (int) $ivdValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!count($vid)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// 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::$villageFieldsCacheByWorldID, $vid)) && !is_null($cachedValue)) {
|
if ($use_cache && !$array_passed && isset(self::$villageFieldsCacheByWorldID[$vid[0]]) && is_array(self::$villageFieldsCacheByWorldID[$vid[0]]) && !count(self::$villageFieldsCacheByWorldID[$vid[0]])) {
|
||||||
|
return self::$villageFieldsCacheByWorldID[$vid[0]];
|
||||||
|
} else if ($use_cache && $array_passed) {
|
||||||
|
// check what we can return from cache
|
||||||
|
$newVIDs = [];
|
||||||
|
foreach ($vid as $key) {
|
||||||
|
if (!isset(self::$villageFieldsCacheByWorldID[$key])) {
|
||||||
|
$newVIDs [] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// everything's cached, just return the cache
|
||||||
|
if (!count($newVIDs)) {
|
||||||
|
return self::$villageFieldsCacheByWorldID;
|
||||||
|
} else {
|
||||||
|
// update remaining IDs to select and cache
|
||||||
|
$vid = $newVIDs;
|
||||||
|
}
|
||||||
|
} else if ($use_cache && !$array_passed && ($cachedValue = self::returnCachedContent(self::$villageFieldsCacheByWorldID, $vid[0])) && !is_null($cachedValue)) {
|
||||||
return $cachedValue;
|
return $cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $vid LIMIT 1";
|
$q = "SELECT * FROM " . TB_PREFIX . "wdata where id IN(".implode(', ', $vid).")";
|
||||||
$result = mysqli_query($this->dblink,$q);
|
$result = $this->mysqli_fetch_all(mysqli_query($this->dblink,$q));
|
||||||
|
|
||||||
self::$villageFieldsCacheByWorldID[$vid] = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
// return a single value
|
||||||
return self::$villageFieldsCacheByWorldID[$vid];
|
if (!$array_passed) {
|
||||||
|
self::$villageFieldsCacheByWorldID[$vid[0]] = $result[0];
|
||||||
|
} else {
|
||||||
|
if ($result && count($result)) {
|
||||||
|
foreach ( $result as $record ) {
|
||||||
|
self::$villageFieldsCacheByWorldID[$record['id']] = $record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for any missing IDs and fill them in with blanks,
|
||||||
|
// since no reinforcements were found for these villages
|
||||||
|
foreach ($vid as $key) {
|
||||||
|
if (!isset(self::$villageFieldsCacheByWorldID[$key])) {
|
||||||
|
self::$villageFieldsCacheByWorldID[$key] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($array_passed ? self::$villageFieldsCacheByWorldID : self::$villageFieldsCacheByWorldID[$vid[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVillageBattleData($vid, $use_cache = true) {
|
public function getVillageBattleData($vid, $use_cache = true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user