From cf745144514ee71d9e3c280196d93359a32155f0 Mon Sep 17 00:00:00 2001 From: iopietro Date: Fri, 4 May 2018 22:12:18 +0200 Subject: [PATCH] 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 --- GameEngine/Admin/database.php | 104 +---- GameEngine/Automation.php | 508 ++++++-------------- GameEngine/Battle.php | 6 +- GameEngine/Database.php | 84 +--- GameEngine/Technology.php | 341 ++++++-------- GameEngine/Units.php | 106 ++++- Templates/Build/16_incomming.tpl | 541 +++++++++++----------- Templates/Build/upgrade.tpl | 2 +- Templates/a2b/startRaid.tpl | 102 ---- Templates/goldClub/farmlist.tpl | 150 ++---- Templates/goldClub/farmlist_add.tpl | 13 +- Templates/goldClub/farmlist_addraid.tpl | 10 +- Templates/goldClub/farmlist_editraid.tpl | 56 ++- Templates/menu.tpl | 2 +- build.php | 4 +- gpack/travian_default/lang/en/compact.css | 5 + todo.txt | 2 +- 17 files changed, 762 insertions(+), 1274 deletions(-) delete mode 100644 Templates/a2b/startRaid.tpl diff --git a/GameEngine/Admin/database.php b/GameEngine/Admin/database.php index 09832938..3d6c3cfd 100755 --- a/GameEngine/Admin/database.php +++ b/GameEngine/Admin/database.php @@ -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; diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 28598f37..5b199306 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -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 = []; diff --git a/GameEngine/Battle.php b/GameEngine/Battle.php index 5a31d8be..a8974b44 100755 --- a/GameEngine/Battle.php +++ b/GameEngine/Battle.php @@ -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); diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 447a9e65..2bd471e7 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -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); } diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index 3ba34a36..a2fe6086 100755 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -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;$iunarray);$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']; diff --git a/GameEngine/Units.php b/GameEngine/Units.php index 8b4130b9..cd3b5cff 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -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; diff --git a/Templates/Build/16_incomming.tpl b/Templates/Build/16_incomming.tpl index 8b33bb35..f831ce7d 100644 --- a/Templates/Build/16_incomming.tpl +++ b/Templates/Build/16_incomming.tpl @@ -1,364 +1,339 @@ getMovement("34",$village->wid,1); +$units = $database->getMovement(34, $village->wid, 1); $total_for = count($units); -$send = $database->getMovement("1",$village->wid,1); +$send = $database->getMovement(1, $village->wid, 1); $total_for2 = count($send); $artifactsSum = $database->getArtifactsSumByKind($session->uid, $village->wid, 3); -for($y=0;$y < $total_for;$y++){ -for($i=0;$i < $total_for2;$i++){ -if($units[$y]['ref'] == $send[$i]['ref2']){ -$res1 = mysqli_query($database->dblink,"SELECT wood, clay, iron, crop FROM " . TB_PREFIX . "send where id = ".(int) $send[$i]['ref'].""); -$res = mysqli_fetch_array($res1); -} -} -$session->timer++; -if ($units[$y]['sort_type']==3){ - if ($units[$y]['attack_type']==3){ - $actionType = ATTACK_ON; - } else if ($units[$y]['attack_type']==4){ - $actionType = RAID_ON; - } else if ($units[$y]['attack_type']==2){ - $actionType = REINFORCEMENTFOR; +for($y = 0; $y < $total_for; $y++){ + for($i = 0; $i < $total_for2; $i++){ + if($units[$y]['ref'] == $send[$i]['ref2']){ + $res1 = mysqli_query($database->dblink, "SELECT wood, clay, iron, crop FROM ".TB_PREFIX."send where id = ".(int)$send[$i]['ref'].""); + $res = mysqli_fetch_array($res1); + } } - $reinfowner = $database->getVillageField($units[$y]['from'],"owner"); - if($units[$y]['attack_type'] != 1){ - if($units[$y]['from'] != 0){ - if($units[$y]['t11'] > 0 && $reinfowner == $session->uid) { - $colspan = 11; - }else{ - $colspan = 10; - } - echo " + $session->timer++; + if($units[$y]['sort_type'] == 3){ + if($units[$y]['attack_type'] == 2) $actionType = REINFORCEMENTFOR; + elseif($units[$y]['attack_type'] == 3) $actionType = ATTACK_ON; + elseif($units[$y]['attack_type'] == 4) $actionType = RAID_ON; + + $reinfowner = $database->getVillageField($units[$y]['from'], "owner"); + if($units[$y]['attack_type'] != 1){ + if($units[$y]['from'] != 0){ + if($units[$y]['t11'] > 0 && $reinfowner == $session->uid) $colspan = 11; + else $colspan = 10; + + echo "
- getMapCheck($units[$y]['from'])."\">".$database->getVillageField($units[$y]['from'],"name")."
"; - $tribe = $database->getUserField($database->getVillageField($units[$y]['from'],"owner"),"tribe",0); - $start = ($tribe-1)*10+1; - $end = ($tribe*10); - echo ""; - for($i=$start;$i<=($end);$i++) { - echo ""; - } - if($units[$y]['t11'] != 0 && $reinfowner == $session->uid) { - echo ""; - } - echo ""; - for($i=1;$i<=$colspan;$i++) { - $totalunits = $units[$y]['t1']+$units[$y]['t2']+$units[$y]['t3']+$units[$y]['t4']+$units[$y]['t5']+$units[$y]['t6']+$units[$y]['t7']+$units[$y]['t8']+$units[$y]['t9']+$units[$y]['t10']+$units[$y]['t11']; - if($units[$y]['attack_type'] == 2){ - if($reinfowner != $session->uid){ - echo ""; - }else{ - - - if($units[$y]['t'.$i] == 0) { - echo ""; - } - else { - echo ""; + echo "getMapCheck($units[$y]['to'])."\">".$actionType." ".$database->getVillageField($units[$y]['to'], "name").""; + echo ""; + $tribe = $database->getUserField($database->getVillageField($units[$y]['from'], "owner"), "tribe", 0); + $start = ($tribe - 1) * 10 + 1; + $end = ($tribe * 10); + echo ""; + for($i = $start; $i <= ($end); $i++){ + echo ""; } - }}else{ - if($artifactsSum['totals'] == 0){ - echo ""; - }else{ - if($units[$y]['t'.$i] == 0) { - echo ""; - }else{ - echo ""; - } - } - } - } - echo ""; - echo ' + if($units[$y]['t11'] != 0 && $reinfowner == $session->uid){ + echo ""; + } + echo ""; + for($i = 1; $i <= $colspan; $i++){ + $totalunits = $units[$y]['t1'] + $units[$y]['t2'] + $units[$y]['t3'] + $units[$y]['t4'] + $units[$y]['t5'] + $units[$y]['t6'] + $units[$y]['t7'] + $units[$y]['t8'] + $units[$y]['t9'] + $units[$y]['t10'] + $units[$y]['t11']; + if($units[$y]['attack_type'] == 2){ + if($reinfowner != $session->uid) echo ""; + else + { + if($units[$y]['t'.$i] == 0) echo ""; + else + { + echo ""; + } + } + }else{ + if($artifactsSum['totals'] == 0) echo ""; + else + { + if($units[$y]['t'.$i] == 0) echo ""; + else echo ""; + } + } + } + echo ""; + echo ' "; - echo "
+ getMapCheck($units[$y]['from'])."\">".$database->getVillageField($units[$y]['from'], "name")." "; - echo "getMapCheck($units[$y]['to'])."\">".$actionType." ".$database->getVillageField($units[$y]['to'],"name").""; - echo "
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />\"Hero\"
".TROOPS."?0"; - echo $units[$y]['t'.$i]."
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />?0?
\"Hero\"
".TROOPS."?0"; + echo $units[$y]['t'.$i]."?0?
'.ARRIVAL.' -
timer.'>'.$generator->getTimeFormat($units[$y]['endtime']-time()).' h
'; - $datetime = $generator->procMtime($units[$y]['endtime']); - echo "
"; - if($datetime[0] != "today") { - echo "".ON." ".$datetime[0]." "; - } - echo "".AT." ".$datetime[1]." ".HRS."
+
timer.'>'.$generator->getTimeFormat($units[$y]['endtime'] - time()).' h
'; + $datetime = $generator->procMtime($units[$y]['endtime']); + echo "
"; + if($datetime[0] != "today") echo "".ON." ".$datetime[0]." "; + echo "".AT." ".$datetime[1]." ".HRS."
"; - }else{ - echo "
+ echo "
"; + }else{ + echo ""; - $tribe = 4; - $start = ($tribe-1)*10+1; - $end = ($tribe*10); - echo ""; - for($i=$start;$i<=($end);$i++) { - echo ""; - } - echo ""; - for($i=1;$i<=10;$i++) { - echo ""; - } - echo ""; - echo ' + echo "".VILLAGE_OF_THE_ELDERS_TROOPS.""; + echo ""; + $tribe = 4; + $start = ($tribe - 1) * 10 + 1; + $end = ($tribe * 10); + echo ""; + for($i = $start; $i <= ($end); $i++){ + echo ""; + } + echo ""; + for($i = 1; $i <= 10; $i++){ + echo ""; + } + echo ""; + echo ' "; - echo "
village of the elders "; - echo "".VILLAGE_OF_THE_ELDERS_TROOPS.""; - echo "
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />
".TROOPS."?
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />
".TROOPS."?
'.ARRIVAL.' -
timer.'>'.$generator->getTimeFormat($units[$y]['endtime']-time()).' h
'; - $datetime = $generator->procMtime($units[$y]['endtime']); - echo "
"; - if($datetime[0] != "today") { - echo "".ON." ".$datetime[0]." "; - } - echo "".AT." ".$datetime[1]."
+
timer.'>'.$generator->getTimeFormat($units[$y]['endtime'] - time()).' h
'; + $datetime = $generator->procMtime($units[$y]['endtime']); + echo "
"; + if($datetime[0] != "today") echo "".ON." ".$datetime[0]." "; + echo "".AT." ".$datetime[1]."
"; + echo ""; + } } - } -}else if ($units[$y]['sort_type']==4){ - if ($units[$y]['attack_type']==1){ + }else if($units[$y]['sort_type'] == 4){ $actionType = RETURNFROM; - } else if ($units[$y]['attack_type']==2){ - $actionType = RETURNFROM; - } else if ($units[$y]['attack_type']==3){ - $actionType = RETURNFROM; - } else if ($units[$y]['attack_type']==4){ - $actionType = RETURNFROM; - } -$isoasis = $database->isVillageOases($units[$y]['from']); -if ($isoasis ==0){ -$from = $database->getMInfo($units[$y]['from']); -} else { -$from = $database->getOMInfo($units[$y]['from']);} - -$to = $database->getMInfo($units[$y]['vref']); -?> - + + $isoasis = $database->isVillageOases($units[$y]['from']); + if($isoasis == 0) $from = $database->getMInfo($units[$y]['from']); + else $from = $database->getOMInfo($units[$y]['from']); + + $to = $database->getMInfo($units[$y]['vref']); + ?> +
- - + + - + + tribe; - $start = ($tribe-1)*10+1; - $end = ($tribe*10); - echo ""; - for($i=$start;$i<=($end);$i++) { - echo ""; - } - if($units[$y]['t11'] != 0) { - echo ""; - } - ?> + $tribe = $session->tribe; + $start = ($tribe - 1) * 10 + 1; + $end = ($tribe * 10); + echo ""; + for($i = $start; $i <= ($end); $i++){ + echo ""; + } + if($units[$y]['t11'] != 0){ + echo ""; + } + ?> - + + 0"; - } - else { - echo ""; - } + for($i = 1; $i < ($units[$y]['t11'] != 0 ? 12 : 11); $i++){ + if($units[$y]['t'.$i] == 0) echo ""; + else + { + echo ""; } - ?> - + } + ?> + + - + if(isset($res)) $totalres = $res['wood'] + $res['clay'] + $res['iron'] + $res['crop']; + else $totalres = 0; + + if($units[$y]['attack_type'] != 2 && $units[$y]['attack_type'] != 1 && !empty($totalres)){ + ?> + + + + + + + - - - + + - - + + +
vname; ?>vname; ?>
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />\"Hero\" getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />\"Hero\"
"; - echo $units[$y]['t'.$i]."0"; + echo $units[$y]['t'.$i]."
\"Lumber\"".$res['wood']." | \"Clay\"".$res['clay']." | \"Iron\"".$res['iron']." | \"Crop\"".$res['crop'].""; echo "
\"carry\"".$totalres."/".$totalcarry."
"; ?> -
+
timer.">".$generator->getTimeFormat($units[$y]['endtime']-time())." h"; - $datetime = $generator->procMtime($units[$y]['endtime']); - echo "
"; - if($datetime[0] != "today") { - echo "".ON." ".$datetime[0]." "; - } - echo "".AT." ".$datetime[1]."
"; - ?> + echo "
timer.">".$generator->getTimeFormat($units[$y]['endtime'] - time())." h
"; + $datetime = $generator->procMtime($units[$y]['endtime']); + echo "
"; + if($datetime[0] != "today") echo "".ON." ".$datetime[0]." "; + echo "".AT." ".$datetime[1]."
"; + ?> -
getOasis($village->wid); foreach($array as $conqured){ -$oasis = $database->getMovement("6",$conqured['wref'],0); -$total_for = count($oasis); -for($y=0;$y < $total_for;$y++){ - $session->timer++; -$to = $database->getOMInfo($oasis[$y]['to']); - if ($oasis[$y]['attack_type']==2){ - $actionType = REINFORCEMENTFOR; - } else if ($oasis[$y]['attack_type']==3){ - $actionType = ATTACK_ON; - } else if ($oasis[$y]['attack_type']==4){ - $actionType = RAID_ON; - } - $reinfowner = $database->getVillageField($oasis[$y]['from'],"owner"); - if($oasis[$y]['t11'] != 0 && $reinfowner == $session->uid) { - $colspan = 11; - }else{ - $colspan = 10; - } + $oasis = $database->getMovement("6", $conqured['wref'], 0); + $total_for = count($oasis); + for($y = 0; $y < $total_for; $y++){ + $session->timer++; + $to = $database->getOMInfo($oasis[$y]['to']); + if($oasis[$y]['attack_type'] == 2) $actionType = REINFORCEMENTFOR; + else if($oasis[$y]['attack_type'] == 3) $actionType = ATTACK_ON; + else if($oasis[$y]['attack_type'] == 4) $actionType = RAID_ON; + + $reinfowner = $database->getVillageField($oasis[$y]['from'], "owner"); + if($oasis[$y]['t11'] != 0 && $reinfowner == $session->uid) $colspan = 11; + else $colspan = 10; + echo " + getMapCheck($oasis[$y]['from'])."\">".$database->getVillageField($oasis[$y]['from'], "name").""; - $tribe = $database->getUserField($reinfowner,"tribe",0); - $start = ($tribe-1)*10+1; - $end = ($tribe*10); - echo ""; - for($i=$start;$i<=($end);$i++) { - echo ""; - } - if($oasis[$y]['t11'] != 0 && $reinfowner == $session->uid) { - echo ""; - } - echo ""; - for($i=1;$i<=$colspan;$i++) { - $totalunits = $oasis[$y]['t1']+$oasis[$y]['t2']+$oasis[$y]['t3']+$oasis[$y]['t4']+$oasis[$y]['t5']+$oasis[$y]['t6']+$oasis[$y]['t7']+$oasis[$y]['t8']+$oasis[$y]['t9']+$oasis[$y]['t10']+$oasis[$y]['t11']; - if($oasis[$y]['attack_type'] == 2){ - if($reinfowner != $session->uid){ - echo ""; - }else{ - - - if($oasis[$y]['t'.$i] == 0) { - echo ""; - } - else { - echo ""; + echo "getMapCheck($oasis[$y]['to'])."\">".$actionType." ".$to['name'].""; + echo ""; + $tribe = $database->getUserField($reinfowner, "tribe", 0); + $start = ($tribe - 1) * 10 + 1; + $end = ($tribe * 10); + echo ""; + for($i = $start; $i <= ($end); $i++){ + echo ""; + } + if($oasis[$y]['t11'] != 0 && $reinfowner == $session->uid){ + echo ""; + } + echo ""; + for($i = 1; $i <= $colspan; $i++){ + $totalunits = $oasis[$y]['t1'] + $oasis[$y]['t2'] + $oasis[$y]['t3'] + $oasis[$y]['t4'] + $oasis[$y]['t5'] + $oasis[$y]['t6'] + $oasis[$y]['t7'] + $oasis[$y]['t8'] + $oasis[$y]['t9'] + $oasis[$y]['t10'] + $oasis[$y]['t11']; + if($oasis[$y]['attack_type'] == 2){ + if($reinfowner != $session->uid) echo ""; + else + { + if($oasis[$y]['t'.$i] == 0) echo ""; + else + { + echo ""; + } } - }}else{ - if($artifactsSum['totals'] == 0){ - echo ""; - }else{ - if($oasis[$y]['t'.$i] == 0) { - echo ""; - }else{ - echo ""; - } - } - } - } - echo ""; - echo ' + }else{ + if($artifactsSum['totals'] == 0) echo ""; + else + { + if($oasis[$y]['t'.$i] == 0) echo ""; + else echo ""; + } + } + } + echo ""; + echo ' "; echo "
- getMapCheck($oasis[$y]['from'])."\">".$database->getVillageField($oasis[$y]['from'],"name")." "; - echo "getMapCheck($oasis[$y]['to'])."\">".$actionType." ".$to['name'].""; - echo "
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />\"Hero\"
".TROOPS."?0"; - echo $oasis[$y]['t'.$i]."
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />\"Hero\"
".TROOPS."?0"; + echo $oasis[$y]['t'.$i]."?0?
?0?
'.ARRIVAL.' -
timer.'>'.$generator->getTimeFormat($oasis[$y]['endtime']-time()).' h
'; - $datetime = $generator->procMtime($oasis[$y]['endtime']); - echo "
"; - if($datetime[0] != "today") { - echo "".ON." ".$datetime[0]." "; - } - echo "".AT." ".$datetime[1]." ".HRS."
+
timer.'>'.$generator->getTimeFormat($oasis[$y]['endtime'] - time()).' h
'; + $datetime = $generator->procMtime($oasis[$y]['endtime']); + echo "
"; + if($datetime[0] != "today") echo "".ON." ".$datetime[0]." "; + echo "".AT." ".$datetime[1]." ".HRS."
"; -} + } } -$settlers = $database->getMovement("7",$village->wid,1); +$settlers = $database->getMovement(7, $village->wid, 1); $total_for3 = count($settlers); -for($x=0;$x < $total_for3;$x++){ - $session->timer++; -$to = $database->getMInfo($settlers[$x]['to']); -?> - +for($x = 0; $x < $total_for3; $x++){ + $session->timer++; + $to = $database->getMInfo($settlers[$x]['to']); + ?> +
- - + + tribe; - $start = ($tribe-1)*10+1; - $end = ($tribe*10); - echo ""; - for($i=$start;$i<=($end);$i++) { - echo ""; - } - ?> + $tribe = $session->tribe; + $start = ($tribe - 1) * 10 + 1; + $end = ($tribe * 10); + echo ""; + for($i = $start; $i <= ($end); $i++){ + echo ""; + } + ?> - + + 0"; - } - else { - echo ""; - } - } - ?> + for($z = 1; $z <= 9; $z++) $settlers[$x]['t'.$z] = 0; + $settlers[$x]['t10'] = 3; + + for($i = 1; $i < 11; $i++){ + if($settlers[$x]['t'.$i] == 0) echo ""; + else + { + echo ""; + } + } + ?> - - - - - + + + - - + + +
vname; ?>vname; ?>
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />
"; - echo $settlers[$x]['t'.$i]."0"; + echo $settlers[$x]['t'.$i]."
+ + +
timer.">".$generator->getTimeFormat($settlers[$x]['endtime']-time())." h"; - $datetime = $generator->procMtime($settlers[$x]['endtime']); - echo "
"; - if($datetime[0] != "today") { - echo "".ON." ".$datetime[0]." "; - } - echo "".AT." ".$datetime[1]."
"; - ?> + echo "
timer.">".$generator->getTimeFormat($settlers[$x]['endtime'] - time())." h
"; + $datetime = $generator->procMtime($settlers[$x]['endtime']); + echo "
"; + if($datetime[0] != "today") echo "".ON." ".$datetime[0]." "; + echo "".AT." ".$datetime[1]."
"; + ?> -
\ No newline at end of file diff --git a/Templates/Build/upgrade.tpl b/Templates/Build/upgrade.tpl index f0e9fe43..17994c72 100644 --- a/Templates/Build/upgrade.tpl +++ b/Templates/Build/upgrade.tpl @@ -89,7 +89,7 @@ if($session->userinfo['gold'] >= 3 && $building->getTypeLevel(17) >= 1 && $villa echo "".UPGRADE_GRANARY."."; } else if($bindicate == 7) { - if($village->allcrop - $village->pop - $automation->getUpkeep($village->unitall, 0) > 0){ + if($village->allcrop - $village->pop - $technology->getUpkeep($village->unitall, 0) > 0){ $neededtime = $building->calculateAvaliable($id,$village->resarray['f'.$id.'t'],1+$loopsame+$doublebuild+$master); echo "".ENOUGH_RESOURCES." ".$neededtime[0]." at ".$neededtime[1].""; }else{ diff --git a/Templates/a2b/startRaid.tpl b/Templates/a2b/startRaid.tpl deleted file mode 100644 index 776c9fa0..00000000 --- a/Templates/a2b/startRaid.tpl +++ /dev/null @@ -1,102 +0,0 @@ -getFLData($lid); - $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 = $units->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'] ); - $totalunits = $data['u1'] + $data['u2'] + $data['u3'] + $data['u4'] + $data['u5'] + $data['u6'] + $data['u7'] + $data['u8'] + $data['u9'] + $data['u10'] + $data['u11']; - - $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; -?> \ No newline at end of file diff --git a/Templates/goldClub/farmlist.tpl b/Templates/goldClub/farmlist.tpl index c84f4a1e..2a9a86c8 100644 --- a/Templates/goldClub/farmlist.tpl +++ b/Templates/goldClub/farmlist.tpl @@ -2,7 +2,7 @@ if(isset($_GET['t']) == 99 && isset($_GET['action']) == 0) { -if(isset($_GET['t']) == 99 && isset($_POST['action']) == 'addList' && !empty($_POST['did']) && !empty($_POST['name'])){ +if(isset($_GET['t']) == 99 && isset($_POST['action']) == 'addList' && !empty($_POST['did']) && !empty($_POST['name']) && $database->getVillageField($_POST['did'], 'owner') == $session->uid){ $database->createFarmList($_POST['did'], $session->uid, $_POST['name']); }else if(isset($_GET['t']) == 99 && isset($_POST['action']) == 'addList'){ header("Location: build.php?gid=16&t=99&action=addList"); @@ -23,7 +23,6 @@ while($row = mysqli_fetch_array($sql)){ -
@@ -53,19 +52,21 @@ while($row = mysqli_fetch_array($sql)){ dblink,"SELECT * FROM ".TB_PREFIX."raidlist WHERE lid = ".(int) $lid." ORDER BY distance ASC"); $query2 = mysqli_num_rows($sql2); -if($query2 == 0) { +if(!$query2) { echo 'There are no village.'; }else{ while($row = mysqli_fetch_array($sql2)){ -$id= $row['id'];$lid = $row['lid'];$towref = $row['towref'];$x = $row['x'];$y = $row['y']; -if($village->wid == $towref){ - $distance = '0'; -}else{ - $distance = $row['distance']; -} +$id = $row['id']; +$lid = $row['lid']; +$towref = $row['towref']; +$x = $row['x']; +$y = $row['y']; + +if($village->wid == $towref) $distance = '0'; +else $distance = $row['distance']; + +for($i = 1; $i <= 10; $i++) ${'t'.$i} = $row['t'.$i]; -$t1 = $row['t1'];$t2 = $row['t2'];$t3 = $row['t3'];$t4 = $row['t4'];$t5 = $row['t5'];$t6 = $row['t6'];$t7 = $row['t7']; -$t8 = $row['t8'];$t9 = $row['t9'];$t10 = $row['t10']; $vdata = $database->getVillage($towref); ?> @@ -80,29 +81,21 @@ $vdata = $database->getVillage($towref); getMovement(3,$towref,1); - $att = ''; - - if (count($incoming_attacks) > 0) { - $inc_atts = count($incoming_attacks); - if($incoming_attacks[$i]['attack_type'] == 2) { - $inc_atts -= 1; - } - if($inc_atts > 0) { - echo ''; + $incoming_attacks = $database->getMovement(3, $towref, 1); + if (($inc_atts = count($incoming_attacks)) > 0) { + foreach($incoming_attacks as $attack){ + if($attack['attack_type'] != 4) $inc_atts -= 1; + } + if($inc_atts > 0) echo ''; } - } ?>