General fixes

+Fixed an exploit that permitted to starts other players' farm lists
+Fixed an exploit that permitted to save our raids to other players'
farm lists
+Fixed an exploit that permitted to edit other players' farm lists
+Fixed a rounding upkeep bug
+Moved the whole startRaid.tpl to a new method in Units.php
+A lot of clean-up
+Improoved indentation
+In the raid list, the "carry" image will now show to the left of an
attack
+Fixed a bug that displayed the wrong loot to returning troops released
by traps
+General minor bug fixing and improovements
-Deleted a lot of redundant code
This commit is contained in:
iopietro
2018-05-04 22:12:18 +02:00
parent 49bc3c5073
commit cf74514451
17 changed files with 762 additions and 1274 deletions
+6 -98
View File
@@ -648,10 +648,6 @@ class adm_DB {
} else {
$enforce['hero']='0';
}
$artefact = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,3,0));
$artefact1 = count($database->getOwnUniqueArtefactInfo2($enforce['from'],2,1,1));
$artefact2 = count($database->getOwnUniqueArtefactInfo2($from['owner'],2,2,0));
$troopsTime = $this->procDistanceTime($fromCor, $toCor, min($speeds), $enforce['from']);
$time = $database->getArtifactsValueInfluence($from['owner'], $enforce['from'], 2, $troopsTime);
@@ -663,27 +659,15 @@ class adm_DB {
}
public function calculateProduction($wid,$uid,$b1,$b2,$b3,$b4,$fdata,$ocounter,$pop) {
global $technology,$database;
$normalA = $database->getOwnArtefactInfoByType($wid,4);
$largeA = $database->getOwnUniqueArtefactInfo($uid,4,2);
$uniqueA = $database->getOwnUniqueArtefactInfo($uid,4,3);
$upkeep = $this->getUpkeep($this->getAllUnits($wid),0,$wid,$uid);
$production=array();
public function calculateProduction($wid, $uid, $b1, $b2, $b3, $b4, $fdata, $ocounter, $pop) {
global $technology, $database;
$upkeep = $technology->getUpkeep($this->getAllUnits($wid), 0, $wid);
$production = [];
$production['wood'] = $this->getWoodProd($fdata, $ocounter,$b1);
$production['clay'] = $this->getClayProd($fdata, $ocounter,$b2);
$production['iron'] = $this->getIronProd($fdata, $ocounter,$b3);
if ($uniqueA['size']==3 && $uniqueA['owner']==$uid){
$production['crop'] = $this->getCropProd($fdata, $ocounter,$b4)-$pop-(($upkeep)-round($upkeep*0.50));
}elseif ($normalA['type']==4 && $normalA['size']==1 && $normalA['owner']==$uid){
$production['crop'] = $this->getCropProd($fdata, $ocounter,$b4)-$pop-(($upkeep)-round($upkeep*0.25));
}else if ($largeA['size']==2 && $largeA['owner']==$uid){
$production['crop'] = $this->getCropProd($fdata, $ocounter,$b4)-$pop-(($upkeep)-round($upkeep*0.25));
}else{
$production['crop'] = $this->getCropProd($fdata, $ocounter,$b4)-$pop-$upkeep;
}
$production['crop'] = $this->getCropProd($fdata, $ocounter,$b4) - $pop - $upkeep;
return $production;
}
@@ -852,82 +836,6 @@ class adm_DB {
}
return $ownunit;
}
public function getUpkeep($array,$type,$vid,$uid,$prisoners=0) {
global $database;
$buildarray = array();
$buildarray = $database->getResourceLevel($vid);
$upkeep = 0;
switch($type) {
case 0:
$start = 1;
$end = 50;
break;
case 1:
$start = 1;
$end = 10;
break;
case 2:
$start = 11;
$end = 20;
break;
case 3:
$start = 21;
$end = 30;
break;
case 4:
$start = 31;
$end = 40;
break;
case 5:
$start = 41;
$end = 50;
break;
}
for($i=$start;$i<=$end;$i++) {
$k = $i-$start+1;
$unit = "u".$i;
$unit2 = "t".$k;
global $$unit;
$dataarray = $$unit;
for($j=19;$j<=38;$j++) {
if($buildarray['f'.$j.'t'] == 41) {
$horsedrinking = $j;
}
}
if($prisoners == 0){
if(isset($horsedrinking)){
if(($i==4 && $buildarray['f'.$horsedrinking] >= 10)
|| ($i==5 && $buildarray['f'.$horsedrinking] >= 15)
|| ($i==6 && $buildarray['f'.$horsedrinking] == 20)) {
$upkeep += ($dataarray['pop']-1) * $array[$unit];
} else {
$upkeep += $dataarray['pop'] * $array[$unit];
}}else{
$upkeep += $dataarray['pop'] * $array[$unit];
}
}else{
if(isset($horsedrinking)){
if(($i==4 && $buildarray['f'.$horsedrinking] >= 10)
|| ($i==5 && $buildarray['f'.$horsedrinking] >= 15)
|| ($i==6 && $buildarray['f'.$horsedrinking] == 20)) {
$upkeep += ($dataarray['pop']-1) * $array[$unit2];
} else {
$upkeep += $dataarray['pop'] * $array[$unit2];
}}else{
$upkeep += $dataarray['pop'] * $array[$unit2];
}
}
}
$unit = ($prisoners > 0) ? 't11' : 'hero';
if(!isset($array[$unit])) $array[$unit] = 0;
$upkeep += $array[$unit] * 6;
return $database->getArtifactsValueInfluence($uid, $vid, 4, $upkeep);
}
};
$admin = new adm_DB;
+145 -363
View File
@@ -18,17 +18,21 @@
class Automation {
private $bountyresarray = array();
private $bountyinfoarray = array();
private $bountyproduction = array();
private $bountyocounter = array();
private $bountyunitall = array();
private $bountyresarray = [];
private $bountyinfoarray = [];
private $bountyproduction = [];
private $bountyocounter = [];
private $bountyunitall = [];
private $bountypop;
private $bountyOresarray = array();
private $bountyOinfoarray = array();
private $bountyOproduction = array();
private $bountyOresarray = [];
private $bountyOinfoarray = [];
private $bountyOproduction = [];
private $bountyOpop = 1;
const bountyOWoodProd = 40 * SPEED;
const bountyOClayProd = 40 * SPEED;
const bountyOIronProd = 40 * SPEED;
const bountyOCropProd = 40 * SPEED;
public function __construct() {
$this->procNewClimbers();
@@ -38,55 +42,54 @@ class Automation {
$this->pruneResource();
$this->pruneOResource();
$this->checkWWAttacks();
if(!file_exists("GameEngine/Prevention/culturepoints.txt") or time()-filemtime("GameEngine/Prevention/culturepoints.txt")>50) {
if(!file_exists("GameEngine/Prevention/culturepoints.txt") or time() - filemtime("GameEngine/Prevention/culturepoints.txt") > 50) {
$this->culturePoints();
}
if(!file_exists("GameEngine/Prevention/updatehero.txt") or time()-filemtime("GameEngine/Prevention/updatehero.txt")>50) {
if(!file_exists("GameEngine/Prevention/updatehero.txt") or time() - filemtime("GameEngine/Prevention/updatehero.txt") > 50) {
$this->updateHero();
}
if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time()-filemtime("GameEngine/Prevention/cleardeleting.txt")>50) {
if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time() - filemtime("GameEngine/Prevention/cleardeleting.txt") > 50) {
$this->clearDeleting();
}
if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50)
if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt") > 50)
{
$this->buildComplete();
}
$this->MasterBuilder();
if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50)
if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt") > 50)
{
$this->demolitionComplete();
}
$this->delTradeRoute();
$this->TradeRoute();
if(!file_exists("GameEngine/Prevention/market.txt") or time()-filemtime("GameEngine/Prevention/market.txt")>50) {
if(!file_exists("GameEngine/Prevention/market.txt") or time() - filemtime("GameEngine/Prevention/market.txt") > 50) {
$this->marketComplete();
}
if(!file_exists("GameEngine/Prevention/research.txt") or time()-filemtime("GameEngine/Prevention/research.txt")>50) {
if(!file_exists("GameEngine/Prevention/research.txt") or time() - filemtime("GameEngine/Prevention/research.txt") > 50) {
$this->researchComplete();
}
if(!file_exists("GameEngine/Prevention/training.txt") or time()-filemtime("GameEngine/Prevention/training.txt")>50) {
if(!file_exists("GameEngine/Prevention/training.txt") or time() - filemtime("GameEngine/Prevention/training.txt") > 50) {
$this->trainingComplete();
}
if(!file_exists("GameEngine/Prevention/starvation.txt") or time()-filemtime("GameEngine/Prevention/starvation.txt")>50) {
if(!file_exists("GameEngine/Prevention/starvation.txt") or time() - filemtime("GameEngine/Prevention/starvation.txt") > 50) {
$this->starvation();
}
if(!file_exists("GameEngine/Prevention/celebration.txt") or time()-filemtime("GameEngine/Prevention/celebration.txt")>50) {
if(!file_exists("GameEngine/Prevention/celebration.txt") or time() - filemtime("GameEngine/Prevention/celebration.txt") > 50) {
$this->celebrationComplete();
}
if(!file_exists("GameEngine/Prevention/sendunits.txt") or time()-filemtime("GameEngine/Prevention/sendunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/sendunits.txt") or time() - filemtime("GameEngine/Prevention/sendunits.txt") > 50) {
$this->sendunitsComplete();
}
if(!file_exists("GameEngine/Prevention/loyalty.txt") or time()-filemtime("GameEngine/Prevention/loyalty.txt")>60) {
if(!file_exists("GameEngine/Prevention/loyalty.txt") or time() - filemtime("GameEngine/Prevention/loyalty.txt") > 60) {
$this->loyaltyRegeneration();
}
if(!file_exists("GameEngine/Prevention/sendreinfunits.txt") or time()-filemtime("GameEngine/Prevention/sendreinfunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/sendreinfunits.txt") or time() - filemtime("GameEngine/Prevention/sendreinfunits.txt") > 50) {
$this->sendreinfunitsComplete();
}
if(!file_exists("GameEngine/Prevention/returnunits.txt") or time()-filemtime("GameEngine/Prevention/returnunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/returnunits.txt") or time() - filemtime("GameEngine/Prevention/returnunits.txt") > 50) {
$this->returnunitsComplete();
}
if(!file_exists("GameEngine/Prevention/settlers.txt") or time()-filemtime("GameEngine/Prevention/settlers.txt")>50) {
if(!file_exists("GameEngine/Prevention/settlers.txt") or time() - filemtime("GameEngine/Prevention/settlers.txt") > 50) {
$this->sendSettlersComplete();
}
if(!file_exists("GameEngine/Prevention/artifacts.txt") or time() - filemtime("GameEngine/Prevention/artifacts.txt") > 60) {
@@ -261,7 +264,7 @@ class Automation {
$element = count($keyholder);
if($element >= 2) {
if($tid <= 4) {
$temparray = array();
$temparray = [];
for($i = 0; $i <= $element - 1; $i++) {
array_push($temparray,$resourcearray['f'.$keyholder[$i]]);
}
@@ -349,24 +352,28 @@ class Automation {
private function ClearUser() {
global $database;
if(AUTO_DEL_INACTIVE) {
$time = time()-UN_ACT_TIME;
$time = time() - UN_ACT_TIME;
$q = "INSERT INTO ".TB_PREFIX."deleting SELECT id, UNIX_TIMESTAMP() FROM ".TB_PREFIX."users WHERE timestamp < $time AND tribe IN(1,2,3)";
$q = "INSERT INTO ".TB_PREFIX."deleting SELECT id, UNIX_TIMESTAMP() FROM ".TB_PREFIX."users WHERE timestamp < $time AND tribe IN(1, 2, 3)";
$database->query($q);
}
}
private function ClearInactive() {
global $database;
if(TRACK_USR) {
$timeout = time()-USER_TIMEOUT*60;
$timeout = time()-USER_TIMEOUT * 60;
$q = "DELETE FROM ".TB_PREFIX."active WHERE timestamp < $timeout";
$database->query($q);
}
}
private function pruneOResource() {
global $database;
if(!ALLOW_BURST) {
$database->query("UPDATE
".TB_PREFIX."odata
@@ -388,6 +395,7 @@ class Automation {
}
private function pruneResource() {
global $database;
if(!ALLOW_BURST) {
$database->query("UPDATE
".TB_PREFIX."vdata
@@ -491,13 +499,9 @@ class Automation {
$fieldDbName = (in_array($indi['type'], [10, 38]) ? 'maxstore' : 'maxcrop');
$max = $villageData[$fieldDbName];
if($level == 1 && $max == STORAGE_BASE) {
$max=STORAGE_BASE;
}
if ($level != 1) {
$max -= ${'bid'.$indi['type']}[$level-1]['attri'] * STORAGE_MULTIPLIER;
}
if($level == 1 && $max == STORAGE_BASE) $max = STORAGE_BASE;
if ($level != 1) $max -= ${'bid'.$indi['type']}[$level-1]['attri'] * STORAGE_MULTIPLIER;
$max += ${'bid'.$indi['type']}[$level]['attri'] * STORAGE_MULTIPLIER;
@@ -583,141 +587,42 @@ class Automation {
// bad, but should work :D
// I took the data from my first ww (first .org world)
// todo: get the algo from the real travian with the 100 biggest
// offs and so on
$troops = array(
5 => array(
array(3412, 2814, 4156, 3553, 9, 0),
array(35, 0, 77, 33, 17, 10)
),
// TODO: get the algo from the real travian with the 100 biggest offs
10 => array(
array(4314, 3688, 5265, 4621, 13, 0),
array(65, 0, 175, 77, 28, 17)
),
15 => array(
array(4645, 4267, 5659, 5272, 15, 0),
array(99, 0, 305, 134, 40, 25)
),
20 => array(
array(6207, 5881, 7625, 7225, 22, 0),
array(144, 0, 456, 201, 56, 36)
),
25 => array(
array(6004, 5977, 7400, 7277, 23, 0),
array(152, 0, 499, 220, 58, 37)
),
30 => array(
array(7073, 7181, 8730, 8713, 27, 0),
array(183, 0, 607, 268, 69, 45)
),
35 => array(
array(7090, 7320, 8762, 8856, 28, 0),
array(186, 0, 620, 278, 70, 45)
),
40 => array(
array(7852, 6967, 9606, 8667, 25, 0),
array(146, 0, 431, 190, 60, 37)
),
45 => array(
array(8480, 8883, 10490, 10719, 35, 0),
array(223, 0, 750, 331, 83, 54)
),
50 => array(
array(8522, 9038, 10551, 10883, 35, 0),
array(224, 0, 757, 335, 83, 54)
),
55 => array(
array(8931, 8690, 10992, 10624, 32, 0),
array(219, 0, 707, 312, 84, 54)
),
60 => array(
array(12138, 13013, 15040, 15642, 51, 0),
array(318, 0, 1079, 477, 118, 76)
),
65 => array(
array(13397, 14619, 16622, 17521, 58, 0),
array(345, 0, 1182, 522, 127, 83)
),
70 => array(
array(16323, 17665, 20240, 21201, 70, 0),
array(424, 0, 1447, 640, 157, 102)
),
75 => array(
array(20739, 22796, 25746, 27288, 91, 0),
array(529, 0, 1816, 803, 194, 127)
),
80 => array(
array(21857, 24180, 27147, 28914, 97, 0),
array(551, 0, 1898, 839, 202, 132)
),
85 => array(
array(22476, 25007, 27928, 29876, 100, 0),
array(560, 0, 1933, 855, 205, 134)
),
90 => array(
array(31345, 35053, 38963, 41843, 141, 0),
array(771, 0, 2668, 1180, 281, 184)
),
95 => array(
array(31720, 35635, 39443, 42506, 144, 0),
array(771, 0, 2671, 1181, 281, 184)
),
96 => array(
array(32885, 37007, 40897, 44130, 150, 0),
array(795, 0, 2757, 1219, 289, 190)
),
97 => array(
array(32940, 37099, 40968, 44235, 150, 0),
array(794, 0, 2755, 1219, 289, 190)
),
98 => array(
array(33521, 37691, 41686, 44953, 152, 0),
array(812, 0, 2816, 1246, 296, 194)
),
99 => array(
array(36251, 40861, 45089, 48714, 165, 0),
array(872, 0, 3025, 1338, 317, 208)
)
);
$troops = [5 => [[3412, 2814, 4156, 3553, 9, 0], [35, 0, 77, 33, 17, 10]],
10 => [[4314, 3688, 5265, 4621, 13, 0], [65, 0, 175, 77, 28, 17]],
15 => [[4645, 4267, 5659, 5272, 15, 0], [99, 0, 305, 134, 40, 25]],
20 => [[6207, 5881, 7625, 7225, 22, 0], [144, 0, 456, 201, 56, 36]],
25 => [[6004, 5977, 7400, 7277, 23, 0], [152, 0, 499, 220, 58, 37]],
30 => [[7073, 7181, 8730, 8713, 27, 0], [183, 0, 607, 268, 69, 45]],
35 => [[7090, 7320, 8762, 8856, 28, 0], [186, 0, 620, 278, 70, 45]],
40 => [[7852, 6967, 9606, 8667, 25, 0], [146, 0, 431, 190, 60, 37]],
45 => [[8480, 8883, 10490, 10719, 35, 0], [223, 0, 750, 331, 83, 54]],
50 => [[8522, 9038, 10551, 10883, 35, 0], [224, 0, 757, 335, 83, 54]],
55 => [[8931, 8690, 10992, 10624, 32, 0], [219, 0, 707, 312, 84, 54]],
60 => [[12138, 13013, 15040, 15642, 51, 0], [318, 0, 1079, 477, 118, 76]],
65 => [[13397, 14619, 16622, 17521, 58, 0], [345, 0, 1182, 522, 127, 83]],
70 => [[16323, 17665, 20240, 21201, 70, 0], [424, 0, 1447, 640, 157, 102]],
75 => [[20739, 22796, 25746, 27288, 91, 0], [529, 0, 1816, 803, 194, 127]],
80 => [[21857, 24180, 27147, 28914, 97, 0], [551, 0, 1898, 839, 202, 132]],
85 => [[22476, 25007, 27928, 29876, 100, 0], [560, 0, 1933, 855, 205, 134]],
90 => [[31345, 35053, 38963, 41843, 141, 0], [771, 0, 2668, 1180, 281, 184]],
95 => [[31720, 35635, 39443, 42506, 144, 0], [771, 0, 2671, 1181, 281, 184]],
96 => [[32885, 37007, 40897, 44130, 150, 0], [795, 0, 2757, 1219, 289, 190]],
97 => [[32940, 37099, 40968, 44235, 150, 0], [794, 0, 2755, 1219, 289, 190]],
98 => [[33521, 37691, 41686, 44953, 152, 0], [812, 0, 2816, 1246, 296, 194]],
99 => [[36251, 40861, 45089, 48714, 165, 0], [872, 0, 3025, 1338, 317, 208]]];
// select the troops^^
if (isset($troops[$level]))
{
$units = $troops[$level];
}
else
{
return false;
}
if (isset($troops[$level])) $units = $troops[$level];
else return false;
// get the capital village from the natars
$query = mysqli_query($database->dblink,'SELECT `wref` FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = 3 and `capital` = 1 LIMIT 1') or die(mysqli_error($database->dblink));
$row = mysqli_fetch_assoc($query);
// start the attacks
$endtime = $time + round((60 * 60 * 24) / INCREASE_SPEED);
$endtime = $time + round(86400 / INCREASE_SPEED);
// -.-
$vid = (int) $vid;
@@ -729,7 +634,7 @@ class Automation {
$database->addMovement(3, $row['wref'], $vid, $ref, $time, $endtime);
// wave 2
$ref2 = $database->addAttack($row['wref'], 0, $units[1][0], $units[1][1], 0, $units[1][2], $units[1][3], $units[1][4], $units[1][5], 0, 0, 0, 3, 40, 0, 0, 0, 20, 20, 0, 20, 20, 20, 20, array('vid' => $vid, 'endtime' => ($endtime + 1)));
$ref2 = $database->addAttack($row['wref'], 0, $units[1][0], $units[1][1], 0, $units[1][2], $units[1][3], $units[1][4], $units[1][5], 0, 0, 0, 3, 40, 0, 0, 0, 20, 20, 0, 20, 20, 20, 20, ['vid' => $vid, 'endtime' => ($endtime + 1)]);
$database->addMovement(3, $row['wref'], $vid, $ref2, $time, $endtime + 1);
}
@@ -744,20 +649,20 @@ class Automation {
}
}
private function getPop($tid,$level) {
private function getPop($tid, $level) {
$name = "bid".$tid;
global $$name,$village;
global $$name;
$dataarray = $$name;
$pop = $dataarray[($level+1)]['pop'];
$cp = $dataarray[($level+1)]['cp'];
return array($pop,$cp);
$pop = $dataarray[($level + 1)]['pop'];
$cp = $dataarray[($level + 1)]['cp'];
return [$pop, $cp];
}
private function delTradeRoute() {
global $database;
$time = time();
$q = "DELETE from ".TB_PREFIX."route where timeleft < $time";
$database->query($q);
$database->delTradeRoute();
}
private function TradeRoute() {
@@ -868,17 +773,17 @@ class Automation {
$maxcarry2 *= $bid28[$this->getTypeLevel(28, $from)]['attri'] / 100;
}
$resource = array($wtrans,$ctrans,$itrans,$crtrans);
$reqMerc = ceil((array_sum($resource)-0.1)/$maxcarry2);
$resource = [$wtrans, $ctrans, $itrans, $crtrans];
$reqMerc = ceil((array_sum($resource) - 0.1) / $maxcarry2);
if($merchantAvail2 != 0 && $reqMerc <= $merchantAvail2) {
if($merchantAvail2 > 0 && $reqMerc <= $merchantAvail2) {
if($database->getVillageState($to)) {
$timetaken = $units->getWalkingTroopsTime($from, $to, 0, 0, [$tribe], 0);
$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
if($res!=0){
$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
$database->modifyResource($from,$resource[0],$resource[1],$resource[2],$resource[3],0);
$database->addMovement(0,$from,$to,$reference,microtime(true),microtime(true)+$timetaken,$send);
$res = $resource[0] + $resource[1] + $resource[2] + $resource[3];
if($res > 0){
$reference = $database->sendResource($resource[0], $resource[1], $resource[2], $resource[3], $reqMerc, 0);
$database->modifyResource($from, $resource[0], $resource[1], $resource[2], $resource[3], 0);
$database->addMovement(0, $from, $to, $reference, microtime(true), microtime(true) + $timetaken, $send);
}
}
}
@@ -931,11 +836,9 @@ class Automation {
}
// oasis cannot be destroyed
$pop=$this->recountPop($data['to'], false);
$pop = $this->recountPop($data['to'], false);
if ($isoasis == 0) {
if($pop==0 && $can_destroy==1){
$village_destroyed = 1;
}
if($pop == 0 && $can_destroy == 1) $village_destroyed = 1;
}
if ($isSecondRow) {
@@ -1000,9 +903,7 @@ class Automation {
// recalculate population and check if the village shouldn't be destroyed at this point
$pop = $this->recountPop($data['to'], false);
if ($isoasis == 0) {
if($pop==0 && $can_destroy==1) {
$village_destroyed = 1;
}
if($pop == 0 && $can_destroy == 1) $village_destroyed = 1;
}
if ($isSecondRow) {
@@ -1063,8 +964,7 @@ class Automation {
endtime < $time
ORDER BY endtime ASC";
$dataarray = $database->query_return($q);
$totalattackdead = 0;
$data_num = 0;
$totalattackdead = $data_num = 0;
if ($dataarray && count($dataarray)) {
// preload village data
@@ -1108,7 +1008,7 @@ class Automation {
$NatarCapital= ($toF['owner'] == 3 && $toF['capital']==1);
if(!isset($to['name']) || $to['name']=='') $to['name']="??";
$DefenderUnit = array();
$DefenderUnit = [];
$DefenderUnit = $database->getUnit($data['to']);
$evasion = $toF["evasion"];
$maxevasion = $DefenderUserData["maxevasion"];
@@ -1159,7 +1059,7 @@ class Automation {
$database->modifyUnit($data['to'], $evasionUnitModifications_units, $evasionUnitModifications_amounts, $evasionUnitModifications_modes);
}
//get defence units
$enforDefender = array();
$enforDefender = [];
$rom = $ger = $gal = $nat = $natar = 0;
$Defender = $database->getUnit($data['to'], false);
$enforcementarray = $database->getEnforceVillage($data['to'], 0);
@@ -1192,22 +1092,22 @@ class Automation {
}
//get attack units
$Attacker = array();
$start = ($owntribe-1)*10+1;
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catapult = array(8,18,28,48);
$ram = array(7,17,27,47);
$chief = array(9,19,29,49);
$spys = array(4,14,23,44);
$Attacker = [];
$start = ($owntribe - 1) * 10 + 1;
$end = $owntribe * 10;
$u = ($owntribe - 1) * 10;
$catapult = [8, 18, 28, 48];
$ram = [7, 17, 27, 47];
$chief = [9, 19, 29, 49];
$spys = [4, 14, 23, 44];
for($i = $start; $i <= $end; $i++) {
$y = $i - $u;
$Attacker['u'.$i] = $dataarray[$data_num]['t'.$y];
//there are catas
if(in_array($i,$catapult)) $catp_pic = $i;
if(in_array($i,$ram)) $ram_pic = $i;
if(in_array($i,$chief)) $chief_pic = $i;
if(in_array($i,$spys)) $spy_pic = $i;
if(in_array($i, $catapult)) $catp_pic = $i;
if(in_array($i, $ram)) $ram_pic = $i;
if(in_array($i, $chief)) $chief_pic = $i;
if(in_array($i, $spys)) $spy_pic = $i;
}
$Attacker['uhero'] = $dataarray[$data_num]['t11'];
$hero_pic = "hero";
@@ -1298,30 +1198,22 @@ class Automation {
}
//get attack units
$Attacker = array();
$start = ($owntribe-1)*10+1;
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catapult = array(8,18,28,38,48);
$ram = array(7,17,27,37,47);
$chief = array(9,19,29,39,49);
$spys = array(4,14,23,44);
for($i=$start;$i<=$end;$i++) {
$y = $i-$u;
$Attacker = [];
$start = ($owntribe - 1) * 10 + 1;
$end = $owntribe * 10;
$u = ($owntribe - 1) * 10;
$catapult = [8, 18, 28, 38, 48];
$ram = [7, 17, 27, 37, 47];
$chief = [9, 19, 29, 39, 49];
$spys = [4, 14, 23, 44];
for($i = $start; $i <= $end; $i++) {
$y = $i - $u;
$Attacker['u'.$i] = $dataarray[$data_num]['t'.$y];
//there are catas
if(in_array($i,$catapult)) {
$catp_pic = $i;
}
if(in_array($i,$ram)) {
$ram_pic = $i;
}
if(in_array($i,$chief)) {
$chief_pic = $i;
}
if(in_array($i,$spys)) {
$spy_pic = $i;
}
if(in_array($i, $catapult)) $catp_pic = $i;
if(in_array($i, $ram)) $ram_pic = $i;
if(in_array($i, $chief)) $chief_pic = $i;
if(in_array($i, $spys)) $spy_pic = $i;
}
$Attacker['uhero'] = $dataarray[$data_num]['t11'];
$hero_pic = "hero";
@@ -1993,8 +1885,8 @@ class Automation {
// we're manually targetting 1st and/or 2nd row of catapults
if (!$catapults1TargetRandom)
{
$_catapultsTarget1Levels=array();
$__catapultsTarget1AltTargets=array();
$_catapultsTarget1Levels = [];
$__catapultsTarget1AltTargets = [];
// calculate targets for 1st rows of catapults
$j = 0;
@@ -2030,7 +1922,7 @@ class Automation {
// 1st row of catapults set to target randomly
if ($catapults1TargetRandom)
{
$list=array();
$list = [];
for ($i = 1; $i <= 41; $i++)
{
if ($i == 41) $i = 99;
@@ -2052,8 +1944,8 @@ class Automation {
// we're manually targetting 2nd row of catapults
if (!$catapults2TargetRandom)
{
$_catapultsTarget2Levels=array();
$__catapultsTarget2AltTargets=array();
$_catapultsTarget2Levels = [];
$__catapultsTarget2AltTargets = [];
// calculate targets for 2nd rows of catapults
$j = 0;
@@ -3065,12 +2957,12 @@ class Automation {
if (!isset($wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']])) {
$tribe = $database->getUserField($database->getVillageField($data['to'],"owner"),"tribe",0);
if($tribe == 1){ $u = ""; } elseif($tribe == 2){ $u = "1"; } elseif($tribe == 3){ $u = "2"; } elseif($tribe == 4){ $u = "3"; } else{ $u = "4"; }
$u = $tribe == 1 ? "" : $tribe - 1;
$database->modifyUnit(
$data['to'],
array($u."1",$u."2",$u."3",$u."4",$u."5",$u."6",$u."7",$u."8",$u."9",$tribe."0","hero"),
array($data['t1'],$data['t2'],$data['t3'],$data['t4'],$data['t5'],$data['t6'],$data['t7'],$data['t8'],$data['t9'],$data['t10'],$data['t11']),
array(1,1,1,1,1,1,1,1,1,1,1)
[$u."1", $u."2", $u."3", $u."4", $u."5", $u."6", $u."7", $u."8", $u."9", $tribe."0", "hero"],
[$data['t1'], $data['t2'], $data['t3'], $data['t4'], $data['t5'], $data['t6'], $data['t7'], $data['t8'], $data['t9'], $data['t10'], $data['t11']],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
);
$movementProcIDs[] = $data['moveid'];
@@ -3080,12 +2972,9 @@ class Automation {
// make sure we don't process duplicate movements until the big bad bug which inserts them into DB is fixed
$wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']] = true;
} else {
// duplicate record, just mark it as processed
$movementProcIDs[] = $data['moveid'];
}
} // duplicate record, just mark it as processed
else $movementProcIDs[] = $data['moveid'];
}
$database->setMovementProc(implode(', ', $movementProcIDs));
}
@@ -3098,10 +2987,10 @@ class Automation {
foreach($dataarray as $data) {
if($data['wood'] >= $data['clay'] && $data['wood'] >= $data['iron'] && $data['wood'] >= $data['crop']){ $sort_type = "10"; }
elseif($data['clay'] >= $data['wood'] && $data['clay'] >= $data['iron'] && $data['clay'] >= $data['crop']){ $sort_type = "11"; }
elseif($data['iron'] >= $data['wood'] && $data['iron'] >= $data['clay'] && $data['iron'] >= $data['crop']){ $sort_type = "12"; }
elseif($data['crop'] >= $data['wood'] && $data['crop'] >= $data['clay'] && $data['crop'] >= $data['iron']){ $sort_type = "13"; }
if($data['wood'] >= $data['clay'] && $data['wood'] >= $data['iron'] && $data['wood'] >= $data['crop']) $sort_type = 10;
elseif($data['clay'] >= $data['wood'] && $data['clay'] >= $data['iron'] && $data['clay'] >= $data['crop']) $sort_type = 11;
elseif($data['iron'] >= $data['wood'] && $data['iron'] >= $data['clay'] && $data['iron'] >= $data['crop']) $sort_type = 12;
elseif($data['crop'] >= $data['wood'] && $data['crop'] >= $data['clay'] && $data['crop'] >= $data['iron']) $sort_type = 13;
$to = $database->getMInfo($data['to']);
$from = $database->getMInfo($data['from']);
@@ -3117,7 +3006,6 @@ class Automation {
$this->pruneResource();
// Settlers
$q = "SELECT `to`, moveid FROM ".TB_PREFIX."movement where ref = 0 and proc = '0' and sort_type = '4' and endtime < $time";
$dataarray = $database->query_return($q);
@@ -3129,7 +3017,6 @@ class Automation {
$database->modifyUnit($data['to'],array($tribe."0"),array(3),array(1));
$movementProcIDs[] = $data['moveid'];
}
$database->setMovementProc(implode(', ', $movementProcIDs));
}
@@ -3487,108 +3374,17 @@ class Automation {
return $ownunit;
}
public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
global $database, $session, $village;
if ( $vid == 0 ) {
$vid = $village->wid;
}
$buildarray = array();
if ( $vid != 0 ) {
$buildarray = $database->getResourceLevel( $vid );
}
$upkeep = 0;
switch ( $type ) {
case 0:
$start = 1;
$end = 50;
break;
case 1:
$start = 1;
$end = 10;
break;
case 2:
$start = 11;
$end = 20;
break;
case 3:
$start = 21;
$end = 30;
break;
case 4:
$start = 31;
$end = 40;
break;
case 5:
$start = 41;
$end = 50;
break;
}
for ( $i = $start; $i <= $end; $i ++ ) {
$k = $i - $start + 1;
$unit = "u" . $i;
$unit2 = "t" . $k;
global $$unit;
$dataarray = $$unit;
for ( $j = 19; $j <= 38; $j ++ ) {
if ( $buildarray[ 'f' . $j . 't' ] == 41 ) {
$horsedrinking = $j;
}
}
if ( $prisoners == 0 ) {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 ) ) {
$upkeep += ( $dataarray['pop'] - 1 ) * $array[ $unit ];
} else {
$upkeep += $dataarray['pop'] * $array[ $unit ];
}
} else {
$upkeep += $dataarray['pop'] * $array[ $unit ];
}
} else {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 ) ) {
$upkeep += ( $dataarray['pop'] - 1 ) * $array[ $unit2 ];
} else {
$upkeep += $dataarray['pop'] * $array[ $unit2 ];
}
} else {
$upkeep += $dataarray['pop'] * $array[ $unit2 ];
}
}
}
$unit = ($prisoners > 0) ? 't11' : 'hero';
if(!isset($array[$unit])) $array[$unit] = 0;
$upkeep += $array[$unit] * 6;
$who = $database->getVillageField($vid, "owner");
return $database->getArtifactsValueInfluence($who, $vid, 4, $upkeep);
}
private function bountycalculateOProduction($bountywid) {
$this->bountyOproduction['wood'] = $this->bountyGetOWoodProd();
$this->bountyOproduction['clay'] = $this->bountyGetOClayProd();
$this->bountyOproduction['iron'] = $this->bountyGetOIronProd();
$this->bountyOproduction['crop'] = $this->bountyGetOCropProd();
$this->bountyOproduction['wood'] = self::bountyOWoodProd;
$this->bountyOproduction['clay'] = self::bountyOClayProd;
$this->bountyOproduction['iron'] = self::bountyOIronProd;
$this->bountyOproduction['crop'] = self::bountyOCropProd;
}
private function bountycalculateProduction($bountywid, $uid) {
$upkeep = $this->getUpkeep($this->getAllUnits($bountywid), 0);
global $technology;
$upkeep = $technology->getUpkeep($this->getAllUnits($bountywid), 0, $bountywid);
$this->bountyproduction['wood'] = $this->bountyGetWoodProd();
$this->bountyproduction['clay'] = $this->bountyGetClayProd();
$this->bountyproduction['iron'] = $this->bountyGetIronProd();
@@ -3597,6 +3393,7 @@ class Automation {
private function bountyprocessProduction($bountywid) {
global $database;
$timepast = time() - $this->bountyinfoarray['lastupdate'];
$nwood = ($this->bountyproduction['wood'] / 3600) * $timepast;
$nclay = ($this->bountyproduction['clay'] / 3600) * $timepast;
@@ -3607,6 +3404,7 @@ class Automation {
}
private function bountyprocessOProduction($bountywid) {
global $database;
$timepast = time() - $this->bountyinfoarray['lastupdated'];
$nwood = ($this->bountyOproduction['wood'] / 3600) * $timepast;
$nclay = ($this->bountyOproduction['clay'] / 3600) * $timepast;
@@ -3616,22 +3414,6 @@ class Automation {
$database->updateOasis($bountywid);
}
private function bountyGetOWoodProd() {
return round(SPEED * 40);
}
private function bountyGetOClayProd() {
return round(SPEED * 40);
}
private function bountyGetOIronProd() {
return round(SPEED * 40);
}
private function bountyGetOCropProd() {
return round(SPEED * 40);
}
private function bountyGetWoodProd() {
global $bid1, $bid5;
@@ -3672,7 +3454,7 @@ class Automation {
global $bid3, $bid7;
$iron = $foundry = 0;
$ironholder = array();
$ironholder = [];
for($i = 1; $i <= 38; $i++) {
if($this->bountyresarray['f'.$i.'t'] == 3) array_push($ironholder,'f'.$i);
if($this->bountyresarray['f'.$i.'t'] == 7) $foundry = $this->bountyresarray['f'.$i];
@@ -4205,7 +3987,7 @@ class Automation {
*/
private function addStarvationData($wref){
global $database;
global $database, $technology;
$getVillage = $database->getVillage($wref);
@@ -4213,7 +3995,7 @@ class Automation {
if ($getVillage['owner'] > 5){
$crop = $database->getCropProdstarv($wref, false);
$unitArrays = $this->getAllUnits($wref, false);
$villageUpkeep = $getVillage['pop'] + $this->getUpkeep($unitArrays, 0);
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
$starv = $getVillage['starv'];
if ($crop < $villageUpkeep){
@@ -4233,7 +4015,7 @@ class Automation {
//TODO: This function needs to be splitted in many subfunctions (for TravianZ refactor)
private function starvation() {
global $database, $autoprefix;
global $database, $technology, $autoprefix;
if(file_exists($autoprefix."GameEngine/Prevention/starvation.txt")) {
unlink($autoprefix."GameEngine/Prevention/starvation.txt");
@@ -4269,7 +4051,7 @@ class Automation {
{
$unitarrays = $this->getAllUnits($starv['wref']);
$upkeep = $starv['pop'] + $this->getUpkeep($unitarrays, 0, $starv['wref']);
$upkeep = $starv['pop'] + $technology->getUpkeep($unitarrays, 0, $starv['wref']);
$enforceArrays = $prisonerArrays = $unitArrays = $attackArrays = $allTroopsArray = $starvingTroops = $killedUnits = [];
+3 -3
View File
@@ -253,9 +253,9 @@ class Battle {
$cap = $ap = $dp = $cdp = $rap = $rdp = 0;
//Get involved artifacts
$attacker_artefact = $database->getArtifactsValueInfluence($AttackerID, $AttackerWref, 3, 1);
$defender_artefact = $database->getArtifactsValueInfluence($DefenderID, $DefenderWref, 3, 1);
$strongerbuildings = $database->getArtifactsValueInfluence($DefenderID, $DefenderWref, 1, 1);
$attacker_artefact = $database->getArtifactsValueInfluence($AttackerID, $AttackerWref, 3, 1, false);
$defender_artefact = $database->getArtifactsValueInfluence($DefenderID, $DefenderWref, 3, 1, false);
$strongerbuildings = $database->getArtifactsValueInfluence($DefenderID, $DefenderWref, 1, 1, false);
if(isset($Attacker['uhero']) && $Attacker['uhero'] != 0){
$atkhero = $this->getBattleHero($AttackerID);
+20 -64
View File
@@ -224,11 +224,6 @@ class MYSQLi_DB implements IDbConnection {
*/
$artefactDataCache = [],
/**
* @var array Cache of fool artefacts.
*/
$foolArtefactCache = [],
/**
* @var array Cache of own artefact infos, from the simple SQL select.
*/
@@ -4307,6 +4302,17 @@ References: User ID/Message ID, Mode
return $this->mysqli_fetch_all($result);
}
/**
* Delete expired trade routes
*
*/
function delTradeRoute() {
$time = time();
$q = "DELETE from " . TB_PREFIX . "route where timeleft < $time";
return mysqli_query($this->dblink, $q);
}
function createTradeRoute($uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time) {
list($uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time) = $this->escape_input((int) $uid,(int) $wid,(int) $from,(int) $r1,(int) $r2,(int) $r3,(int) $r4,(int) $start,(int) $deliveries,(int) $merchant,(int) $time);
@@ -6917,8 +6923,8 @@ References: User ID/Message ID, Mode
* @return int Returns the new value, multiplied or divided by artifacts bonus or malus
*/
function getArtifactsValueInfluence($uid, $vid, $kind, $multiplicand){
list($uid, $vid, $kind, $multiplicand) = $this->escape_input((int) $uid,(int) $vid, $kind, $multiplicand);
function getArtifactsValueInfluence($uid, $vid, $kind, $multiplicand, $round = true){
list($uid, $vid, $kind, $multiplicand, $round) = $this->escape_input((int) $uid,(int) $vid, $kind, $multiplicand, $round);
$artefacts = $foolArefacts = [];
$multipliers = [1 => [4, 5, 3], 2 => [1/2, 1/3, 2/3], 3 => [5, 10, 3], 4 => [1/2, 1/2, 3/4], 5 => [1/2, 1/2, 3/4], 7 => [3, 6, 2]];
@@ -6951,7 +6957,7 @@ References: User ID/Message ID, Mode
if(in_array($kind, [2, 4, 5])) $foolEffect = 1 / $foolEffect;
return ($multiplicand == 1 ) ? $multiplicand * $multiplier * $foolEffect : round($multiplicand * $multiplier * $foolEffect);
return !$round ? $multiplicand * $multiplier * $foolEffect : round($multiplicand * $multiplier * $foolEffect);
}
/**
@@ -7100,56 +7106,6 @@ References: User ID/Message ID, Mode
return (isset(self::$artefactDataCache[$id.$mode][$size.$type]) ? self::$artefactDataCache[$id.$mode][$size.$type] : []);
}
function getFoolArtefactInfo($type, $vid, $uid, $use_cache = true) {
list($type, $vid, $uid) = $this->escape_input((int) $type, (int) $vid, (int) $uid);
// first of all, check if we should be using cache and whether the field
// required is already cached
if ($use_cache && isset(self::$foolArtefactCache[$vid]) && is_array(self::$foolArtefactCache[$vid]) && !count(self::$foolArtefactCache[$vid])) {
return [];
} else if ($use_cache && ($cachedValue = self::returnCachedContent(self::$foolArtefactCache, $vid)) && !is_null($cachedValue)) {
$data = [];
// prepare the data as requested
if (isset($cachedValue[$type.$uid])) {
foreach ($cachedValue[$type.$uid] as $row) {
if ($row['type'] == 8 && $row['kind'] == $type && $row['owner'] == $uid && $row['size'] > 1 && $row['active'] > 1) {
$data[] = $row;
}
}
}
return $data;
}
$q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid"; //" AND ((type = 8 AND kind = $type) OR (owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type))";
$result = $this->mysqli_fetch_all(mysqli_query($this->dblink,$q));
// cache all types and return the requested one
if (count($result)) {
foreach ($result as $arteInfo) {
if (!isset(self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']])) {
self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']] = [];
}
self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']][] = $arteInfo;
}
} else {
self::$foolArtefactCache[$vid] = [];
}
if (
isset(self::$foolArtefactCache[$vid][$type.$uid]) &&
self::$foolArtefactCache[$vid][$type.$uid]['type'] == 8 &&
self::$foolArtefactCache[$vid][$type.$uid]['kind'] == $type &&
self::$foolArtefactCache[$vid][$type.$uid]['owner'] == $uid &&
self::$foolArtefactCache[$vid][$type.$uid]['size'] > 1 &&
self::$foolArtefactCache[$vid][$type.$uid]['active'] > 1
) {
return self::$foolArtefactCache[$vid][$type.$uid];
} else {
return [];
}
}
function villageHasArtefact($vref) {
// this is a somewhat non-ideal, externally non-changeable way of caching
// but since we're only ever going to be calling this from a single point of Automation,
@@ -7425,17 +7381,17 @@ References: User ID/Message ID, Mode
return mysqli_query($this->dblink,$q);
}
function addSlotFarm($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
list($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
function addSlotFarm($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
list($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input($lid, $owner, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
$q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`, `t7`, `t8`, `t9`, `t10`) VALUES ('$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$t8', '$t9', '$t10')";
$q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`, `t7`, `t8`, `t9`, `t10`) SELECT '$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$t8', '$t9', '$t10' WHERE EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner)";
return mysqli_query($this->dblink,$q);
}
function editSlotFarm($eid, $lid, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
list($eid, $lid, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input((int) $eid, $lid, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
function editSlotFarm($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
list($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) = $this->escape_input((int) $eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10);
$q = "UPDATE " . TB_PREFIX . "raidlist set lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6', t7 = '$t7', t8 = '$t8', t9 = '$t9', t10 = '$t10' WHERE id = $eid";
$q = "UPDATE " . TB_PREFIX . "raidlist SET lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6', t7 = '$t7', t8 = '$t8', t9 = '$t9', t10 = '$t10' WHERE id = $eid AND lid = $oldLid AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner) AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $oldLid AND owner = $owner)";
return mysqli_query($this->dblink,$q);
}
+146 -195
View File
@@ -49,7 +49,7 @@ class Technology {
public function getABUpgrades($type='a') {
global $village;
$holder = array();
$holder = [];
foreach($village->researching as $research) {
if(substr($research['tech'],0,1) == $type){
array_push($holder,$research);
@@ -111,16 +111,17 @@ class Technology {
public function getTrainingList($type) {
global $database,$village;
$trainingarray = $database->getTraining($village->wid);
$listarray = array();
$barracks = array(1,2,3,11,12,13,14,21,22,31,32,33,34,35,36,37,38,39,40,41,42,43,44);
$listarray = [];
$barracks = [1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44];
// fix by brainiac - THANK YOU
$greatbarracks = array(61,62,63,71,72,73,74,81,82,91,92,93,94,95,96,97,98,99,100,101,102,103,104);
$stables = array(4,5,6,15,16,23,24,25,26,45,46);
$greatstables = array(64,65,66,75,76,83,84,85,86,105,106);
$workshop = array(7,8,17,18,27,28,47,48);
$greatworkshop = array(67,68,77,78,87,88,107,108);
$residence = array(9,10,19,20,29,30,49,50);
$trapper = array(99);
$greatbarracks = [61, 62, 63, 71, 72, 73, 74, 81, 82, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104];
$stables = [4, 5, 6, 15, 16, 23, 24, 25, 26, 45, 46];
$greatstables = [64, 65, 66, 75, 76, 83, 84, 85, 86, 105, 106];
$workshop = [7, 8, 17, 18, 27, 28, 47, 48];
$greatworkshop = [67, 68, 77, 78, 87, 88, 107, 108];
$residence = [9, 10, 19, 20, 29, 30, 49, 50];
$trapper = [99];
if(count($trainingarray) > 0) {
foreach($trainingarray as $train) {
if($type == 1 && in_array($train['unit'],$barracks)) {
@@ -165,11 +166,11 @@ class Technology {
public function getUnitList() {
global $database,$village;
$unitarray = func_num_args() == 1? $database->getUnit(func_get_arg(0)) : $village->unitall;
$listArray = array();
for($i=1;$i<count($this->unarray);$i++) {
$holder = array();
if(!empty($unitarray['u'.$i]) && $unitarray['u'.$i] != 0 && $unitarray['u'.$i] != "") {
$unitarray = func_num_args() == 1 ? $database->getUnit(func_get_arg(0)) : $village->unitall;
$listArray = [];
for($i = 1; $i < count($this->unarray); $i++) {
$holder = [];
if(!empty($unitarray['u'.$i]) && $unitarray['u'.$i] > 0 && !empty($unitarray['u'.$i])) {
$holder['id'] = $i;
$holder['name'] = $this->unarray[$i];
$holder['amt'] = $unitarray['u'.$i];
@@ -177,65 +178,62 @@ class Technology {
}
}
if($unitarray['hero'] != 0 && $unitarray['hero'] != "") {
if($unitarray['hero'] > 0 && !empty($unitarray['hero'])) {
$holder['id'] = "hero";
$holder['name'] = $this->unarray[$i];
$holder['amt'] = $unitarray['hero'];
array_push($listArray,$holder);
}
}
return $listArray;
}
public function maxUnit($unit,$great=false) {
$unit = "u".$unit;
global $village,$$unit,$database;
$unitarray = $$unit;
$unit = "u" . $unit;
global $village, $$unit, $database;
$unitarray = $$unit;
$res = $database->getVillage($village->wid, 0, false);
if ($res['wood'] > $res['maxstore']){$res['wood'] = $res['maxstore'];}
if ($res['clay'] > $res['maxstore']){$res['clay'] = $res['maxstore'];}
if ($res['iron'] > $res['maxstore']){$res['iron'] = $res['maxstore'];}
if ($res['crop'] > $res['maxcrop']){$res['crop'] = $res['maxcrop'];}
$woodcalc = floor($res['wood'] / ($unitarray['wood'] * ($great?3:1)));
$claycalc = floor($res['clay'] / ($unitarray['clay'] * ($great?3:1)));
$ironcalc = floor($res['iron'] / ($unitarray['iron'] * ($great?3:1)));
if($res['crop']>0){
$cropcalc = floor($res['crop'] / ($unitarray['crop'] * ($great?3:1)));
}else{
$cropcalc = 0;
}
if($unit != "u99"){
$popcalc = floor($village->getProd("crop")/$unitarray['pop']);
}else{
$popcalc = $village->getProd("crop");
}
return min($woodcalc,$claycalc,$ironcalc,$cropcalc);
if($res['wood'] > $res['maxstore']) $res['wood'] = $res['maxstore'];
if($res['clay'] > $res['maxstore']) $res['clay'] = $res['maxstore'];
if($res['iron'] > $res['maxstore']) $res['iron'] = $res['maxstore'];
if($res['crop'] > $res['maxcrop']) $res['crop'] = $res['maxcrop'];
$woodcalc = floor($res['wood'] / ($unitarray['wood'] * ($great ? 3 : 1)));
$claycalc = floor($res['clay'] / ($unitarray['clay'] * ($great ? 3 : 1)));
$ironcalc = floor($res['iron'] / ($unitarray['iron'] * ($great ? 3 : 1)));
if($res['crop'] > 0) $cropcalc = floor($res['crop'] / ($unitarray['crop'] * ($great ? 3 : 1)));
else $cropcalc = 0;
if($unit != "u99") $popcalc = floor($village->getProd("crop") / $unitarray['pop']);
else $popcalc = $village->getProd("crop");
return min($woodcalc, $claycalc, $ironcalc, $cropcalc);
}
public function maxUnitPlus($unit,$great=false) {
$unit = "u".$unit;
global $village,$$unit,$database;
$unit = "u" . $unit;
global $village, $$unit, $database;
$unitarray = $$unit;
$res = $database->getVillage($village->wid);
$totalres = $res['wood']+$res['clay']+$res['iron']+$res['crop'];
$totalresunit = ($unitarray['wood'] * ($great?3:1))+($unitarray['clay'] * ($great?3:1))+($unitarray['iron'] * ($great?3:1))+($unitarray['crop'] * ($great?3:1));
$max =round($totalres/$totalresunit);
$totalres = $res['wood'] + $res['clay'] + $res['iron'] + $res['crop'];
$totalresunit = ($unitarray['wood'] * ($great ? 3 : 1)) + ($unitarray['clay'] * ($great ? 3 : 1)) + ($unitarray['iron'] * ($great ? 3 : 1)) + ($unitarray['crop'] * ($great ? 3 : 1));
$max = round($totalres / $totalresunit);
return $max;
}
public function getUnits() {
global $database,$village;
if(func_num_args() == 1) {
$base = func_get_arg(0);
}
$ownunit = func_num_args() == 2? func_get_arg(0) : $database->getUnit($base);
$enforcementarray = func_num_args() == 2? func_get_arg(1) : $database->getEnforceVillage($base,0);
if(count($enforcementarray) > 0) {
foreach($enforcementarray as $enforce) {
for($i=1;$i<=50;$i++) {
$ownunit['u'.$i] += $enforce['u'.$i];
}
global $database, $village;
if(func_num_args() == 1) $base = func_get_arg(0);
$ownunit = func_num_args() == 2 ? func_get_arg(0) : $database->getUnit($base);
$enforcementarray = func_num_args() == 2 ? func_get_arg(1) : $database->getEnforceVillage($base, 0);
if(count($enforcementarray) > 0){
foreach($enforcementarray as $enforce){
for($i = 1; $i <= 50; $i++) $ownunit['u'.$i] += $enforce['u'.$i];
}
}
return $ownunit;
@@ -243,70 +241,71 @@ class Technology {
function getAllUnits($base,$InVillageOnly=False,$mode=0) {
global $database;
$ownunit = $database->getUnit($base);
$ownunit['u99'] -= $ownunit['u99'];
$ownunit['u99o'] -= $ownunit['u99o'];
$enforcementarray = $database->getEnforceVillage($base,0);
if(count($enforcementarray) > 0) {
foreach($enforcementarray as $enforce) {
for($i=1;$i<=50;$i++) {
$ownunit['u'.$i] += $enforce['u'.$i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
if ($mode==0) {
$enforceoasis=$database->getOasisEnforce($base,0);
if(count($enforceoasis) > 0) {
foreach($enforceoasis as $enforce) {
for($i=1;$i<=50;$i++) {
$ownunit['u'.$i] += $enforce['u'.$i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
$enforceoasis1=$database->getOasisEnforce($base,1);
if(count($enforceoasis1) > 0) {
foreach($enforceoasis1 as $enforce) {
for($i=1;$i<=50;$i++) {
$ownunit['u'.$i] += $enforce['u'.$i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
$prisoners = $database->getPrisoners($base,1);
if(!empty($prisoners)) {
foreach($prisoners as $prisoner){
$owner = $database->getVillageField($base,"owner");
$ownertribe = $database->getUserField($owner,"tribe",0);
$start = ($ownertribe-1)*10+1;
$end = ($ownertribe*10);
for($i=$start;$i<=$end;$i++) {
$j = $i-$start+1;
$ownunit['u'.$i] += $prisoner['t'.$j];
}
$ownunit['hero'] += $prisoner['t11'];
}
}
}
if(!$InVillageOnly) {
$movement = $database->getVillageMovement($base);
if(!empty($movement)) {
for($i=1;$i<=50;$i++) {
if (!isset($ownunit['u'.$i])) {
$ownunit['u'.$i] = 0;
}
$ownunit['u'.$i] += (isset($movement['u'.$i]) ? $movement['u'.$i] : 0);
}
if (!isset($ownunit['hero'])) {
$ownunit['hero'] = 0;
}
$ownunit['hero'] += (isset($movement['hero']) ? $movement['hero'] : 0);
}
}
return $ownunit;
$ownunit = $database->getUnit($base);
$ownunit['u99'] -= $ownunit['u99'];
$ownunit['u99o'] -= $ownunit['u99o'];
$enforcementarray = $database->getEnforceVillage($base, 0);
if(count($enforcementarray) > 0){
foreach($enforcementarray as $enforce){
for($i = 1; $i <= 50; $i++){
$ownunit['u' . $i] += $enforce['u' . $i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
if($mode == 0){
$enforceoasis = $database->getOasisEnforce($base, 0);
if(count($enforceoasis) > 0){
foreach($enforceoasis as $enforce){
for($i = 1; $i <= 50; $i++){
$ownunit['u' . $i] += $enforce['u' . $i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
$enforceoasis1 = $database->getOasisEnforce($base, 1);
if(count($enforceoasis1) > 0){
foreach($enforceoasis1 as $enforce){
for($i = 1; $i <= 50; $i++){
$ownunit['u' . $i] += $enforce['u' . $i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
$prisoners = $database->getPrisoners($base, 1);
if(!empty($prisoners)){
foreach($prisoners as $prisoner){
$owner = $database->getVillageField($base, "owner");
$ownertribe = $database->getUserField($owner, "tribe", 0);
$start = ($ownertribe - 1) * 10 + 1;
$end = ($ownertribe * 10);
for($i = $start; $i <= $end; $i++){
$j = $i - $start + 1;
$ownunit['u' . $i] += $prisoner['t' . $j];
}
$ownunit['hero'] += $prisoner['t11'];
}
}
}
if(!$InVillageOnly){
$movement = $database->getVillageMovement($base);
if(!empty($movement)){
for($i = 1; $i <= 50; $i++){
if(!isset($ownunit['u' . $i])){
$ownunit['u' . $i] = 0;
}
$ownunit['u' . $i] += (isset($movement['u' . $i]) ? $movement['u' . $i] : 0);
}
if(!isset($ownunit['hero'])){
$ownunit['hero'] = 0;
}
$ownunit['hero'] += (isset($movement['hero']) ? $movement['hero'] : 0);
}
}
return $ownunit;
}
public function meetTRequirement($unit) {
@@ -419,92 +418,44 @@ class Technology {
}
}
public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
global $database, $session, $village;
public function getUpkeep($array, $type, $vid = 0, $prisoners = 0) {
global $database, $village;
if ( $vid == 0 ) {
$vid = $village->wid;
if ($vid == 0) $vid = $village->wid;
$upkeep = 0;
$horsedrinking = $database->getFieldLevelInVillage($vid, 41);
if(!$type){
$start = 1;
$end = 50;
}else{
$start = ($type - 1) * 10 + 1;
$end = $type * 10;
}
$buildarray = array();
$buildarray = $database->getResourceLevel( $vid );
$upkeep = 0;
switch ( $type ) {
case 0:
$start = 1;
$end = 50;
break;
case 1:
$start = 1;
$end = 10;
break;
case 2:
$start = 11;
$end = 20;
break;
case 3:
$start = 21;
$end = 30;
break;
case 4:
$start = 31;
$end = 40;
break;
case 5:
$start = 41;
$end = 50;
break;
}
for ( $j = 19; $j <= 38; $j ++ ) {
if ( $buildarray[ 'f' . $j . 't' ] == 41 ) {
$horsedrinking = $j;
break;
}
}
for ( $i = $start; $i <= $end; $i ++ ) {
$k = $i - $start + 1;
$unit = "u" . $i;
$unit2 = "t" . $k;
global $$unit;
for ($i = $start; $i <= $end; $i ++) {
$k = $i - $start + 1;
$unit = $prisoners == 0 ? "u" . $i : "t" . $k;
global $$unit;
$dataarray = $$unit;
if ( $prisoners == 0 ) {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 )
) {
$upkeep += (( $dataarray['pop'] - 1 ) * $array[ $unit ]);
} else {
$upkeep += ($dataarray['pop'] * $array[ $unit ]);
}
} else {
$upkeep += ($dataarray['pop'] * $array[ $unit ]);
}
} else {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 )
) {
$upkeep += (( $dataarray['pop'] - 1 ) * $array[ $unit2 ]);
} else {
$upkeep += ($dataarray['pop'] * $array[ $unit2 ]);
}
} else {
$upkeep += ($dataarray['pop'] * $array[ $unit2 ]);
if($horsedrinking > 0) {
if (($i == 4 && $horsedrinking >= 10) || ($i == 5 && $horsedrinking >= 15) || ( $i == 6 && $horsedrinking == 20)) {
$upkeep += ($dataarray['pop'] - 1) * $array[$unit];
}
else $upkeep += ($dataarray['pop'] * $array[$unit]);
}
else $upkeep += ($dataarray['pop'] * $array[$unit]);
}
$unit = ($prisoners > 0) ? 't11' : 'hero';
if(!isset($array[$unit])) $array[$unit] = 0;
$upkeep += $array[$unit] * 6;
$who = $database->getVillageField($vid, "owner");
return $database->getArtifactsValueInfluence($session->uid, $vid, 4, $upkeep);
return ceil($database->getArtifactsValueInfluence($who, $vid, 4, $upkeep, false));
}
private function trainUnit($unit, $amt, $great = false) {
@@ -591,7 +542,7 @@ class Technology {
}
public function meetRRequirement($tech) {
global $session,$building;
global $session, $building;
switch($tech) {
case 2: return $building->getTypeLevel(22) >= 1 && $building->getTypeLevel(13) >= 1;
case 3: return $building->getTypeLevel(22) >= 5 && $building->getTypeLevel(12) >= 1;
@@ -735,7 +686,7 @@ class Technology {
return mysqli_affected_rows($database->dblink);
}
public function calculateAvaliable($id,$resarray=array()) {
public function calculateAvaliable($id, $resarray = []) {
global $village,$generator,${'r'.$id};
if(count($resarray)==0) {
$resarray['wood'] = ${'r'.$id}['wood'];
+100 -6
View File
@@ -40,11 +40,7 @@ class Units {
return $post;
}
break;
case "8":
$this->sendTroopsBack($post);
break;
case "3":
if (isset($post['a']) && $post['a'] == 533374 && empty($post['disabled'])) $this->sendTroops($post);
else{
@@ -67,6 +63,10 @@ class Units {
$post = $this->loadUnits($post);
return $post;
}
case "8":
$this->sendTroopsBack($post);
break;
}
}
}
@@ -77,7 +77,7 @@ class Units {
// Coordinates and look confirm name people
if(isset($post['x']) && isset($post['y']) && !empty($post['x']) && !empty($post['y'])) {
$vid = $database->getVilWref($post['x'], $post['y']);
unset($post['dname'], $_POST['dname']);
unset($post['dname'], $post['dname']);
}else if(isset($post['dname']) && !empty($post['dname'])){
$vid = $database->getVillageByName(stripslashes($post['dname']));
}
@@ -774,6 +774,100 @@ class Units {
return $generator->procDistanceTime($fromCor, $toCor, min($speeds), $mode);
}
public function startRaidList($post){
global $database, $generator, $session;
$slots = $post['slot'];
$lid = $post['lid'];
$tribe = $session->tribe;
$getFLData = $database->getFLData($lid);
if($getFLData['owner'] != $session->uid) {
header("Location: build.php?id=39&t=99");
exit();
}
$sql = "SELECT id, towref, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 FROM " . TB_PREFIX . "raidlist WHERE lid = ".$database->escape((int)$lid)." order by id asc";
$array = $database->query_return($sql);
foreach($array as $row){
$sql1 = mysqli_fetch_array(mysqli_query($database->dblink, "SELECT * FROM " . TB_PREFIX . "units WHERE vref = ".(int)$getFLData['wref']));
$sid = $row['id'];
$wref = $row['towref'];
for($i = 1; $i <= 10; $i++) ${'t'.$i} = $row['t'.$i];
$t11 = 0;
$villageOwner = $database->getVillageField($wref, 'owner');
$userAccess = $database->getUserField($villageOwner, 'access', 0);
$userID = $database->getUserField($villageOwner, 'id', 0);
if($userAccess != 0 && !($userAccess == MULTIHUNTER && $userID == 5) && ($userAccess != ADMIN || (ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN))){
if($tribe == 1){
$uname = "u";
$uname1 = "u1";
$uname2 = "";
}elseif($tribe == 2){
$uname = "u1";
$uname1 = "u2";
$uname2 = "1";
}elseif($tribe == 3){
$uname = "u2";
$uname1 = "u3";
$uname2 = "2";
}elseif($tribe == 4){
$uname = "u3";
$uname1 = "u4";
$uname2 = "3";
}else{
$uname = "u4";
$uname1 = "u5";
$uname2 = "4";
}
if($sql1[$uname.'1'] >= $t1 && $sql1[$uname.'2'] >= $t2 && $sql1[$uname.'3'] >= $t3 && $sql1[$uname.'4'] >= $t4 && $sql1[$uname.'5'] >= $t5 && $sql1[$uname.'6'] >= $t6 && $sql1[$uname.'7'] >= $t7 && $sql1[$uname.'8'] >= $t8 && $sql1[$uname.'9'] >= $t9 && $sql1[$uname1.'0'] >= $t10 && $sql1['hero'] >= $t11){
if($post['slot'.$sid] == 'on'){
$ckey = $generator->generateRandStr(6);
$time_now = time();
$id = $database->addA2b($ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, 4);
$data = $database->getA2b($ckey, $time_now);
$troopsTime = $this->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);
$ctar1 = $ctar2 = 0;
$abdata = $database->getABTech($getFLData['wref']);
$reference = $database->addAttack(($getFLData['wref']), $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], $data['u7'], $data['u8'], $data['u9'], $data['u10'], $data['u11'], $data['type'], $ctar1, $ctar2, 0, $abdata['b1'], $abdata['b2'], $abdata['b3'], $abdata['b4'], $abdata['b5'], $abdata['b6'], $abdata['b7'], $abdata['b8']);
$troops = [];
$amounts = [];
$modes = [];
for($u = 1; $u <= 10; $u++){
if($tribe == 1) $unitKey = $uname2 . $u;
else $unitKey = $uname2.($u < 10 ? $u : 0);
$troops[] = $unitKey;
$amounts[] = $data['u'.$u];
$modes[] = 0;
}
$troops[] = 'hero';
$amounts[] = $data['u11'];
$modes[] = 0;
$database->modifyUnit($getFLData['wref'], $troops, $amounts, $modes);
$database->addMovement(3, $getFLData['wref'], $data['to_vid'], $reference, time(), ($time + time()));
// prevent re-use of the same attack via re-POSTing the same data
$database->remA2b($id);
}
}
}
}
header("Location: build.php?id=39&t=99");
exit();
}
};
$units = new Units;