From 77136a97841afc7697db21e2c2606db86510bbab Mon Sep 17 00:00:00 2001 From: iopietro Date: Tue, 24 Jul 2018 03:04:25 +0200 Subject: [PATCH] Artifacts update and optimizations +Added the "Artifacts" section in the Admin Panel, which contains two options: return a deleted artifact to the Natars and create new Artifacts, assigned to a specified player +Return to Natars coded, in the village section of the Admin Panel +Moved a lot of functions and costants from Automation.php to the "new" class Artifacts.php +Optimized a lot the whole Natars creation process, decreased the number of query of about 600 +Optimized a lot the function which deletes a player's account, it's now executed almost instantly, even with players with a lot of villages +Redesigned the map spawn system, using a more Travian-like village distribution +Fixed a bug that did show a broken village in the artifact chronology, if that village was destroyed +Reduced the amount of redundant code (about 230 lines) for 27_1.tpl/27_2.tpl and 27_3.tpl +Fixed a bug that permitted to build the Great Granary and the Great Warehouse in the whole account, with only a village effect artifact +Fixed a bug in the Admin Panel map that didn't permit to show village informations, if that village contained single quotes in its name --- Admin/Templates/artifact.tpl | 4 +- Admin/Templates/artifacts.tpl | 129 +++++ Admin/Templates/map.tpl | 19 +- Admin/admin.php | 16 +- GameEngine/Account.php | 65 +-- GameEngine/Admin/Mods/addUsers.php | 10 +- GameEngine/Admin/admin.php | 36 +- GameEngine/Admin/function.php | 65 ++- GameEngine/Artifacts.php | 436 +++++++++++++- GameEngine/Automation.php | 266 +-------- GameEngine/Building.php | 4 +- GameEngine/Database.php | 886 ++++++++++++++++------------- Templates/Build/27_1.tpl | 97 ++-- Templates/Build/27_2.tpl | 174 +----- Templates/Build/27_3.tpl | 273 +-------- Templates/Build/27_show.tpl | 16 +- Templates/Build/avaliable.tpl | 12 +- img/admin/acc.gif | Bin 0 -> 77 bytes 18 files changed, 1313 insertions(+), 1195 deletions(-) create mode 100644 Admin/Templates/artifacts.tpl create mode 100644 img/admin/acc.gif diff --git a/Admin/Templates/artifact.tpl b/Admin/Templates/artifact.tpl index f4c1aa44..907018b2 100644 --- a/Admin/Templates/artifact.tpl +++ b/Admin/Templates/artifact.tpl @@ -32,7 +32,7 @@ $artifactInfo = Artifacts::getArtifactInfo($artifact); - +
@@ -48,6 +48,6 @@ $artifactInfo = Artifacts::getArtifactInfo($artifact); Return to Natars'; + if($village['owner'] != 3 && !empty($artifact)) echo 'Return to Natars'; ?> \ No newline at end of file diff --git a/Admin/Templates/artifacts.tpl b/Admin/Templates/artifacts.tpl new file mode 100644 index 00000000..1275e2fe --- /dev/null +++ b/Admin/Templates/artifacts.tpl @@ -0,0 +1,129 @@ +getDeletedArtifacts(); +?> + + + + +

Artifacts

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Add artifact(s)
TypeQuantityPlayer id
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Deleted artifact(s)
NameBonusArea of effectTime of conquerOld ownerOld village
+ +
+ getUserField($artifact['owner'], "username", 0); + if($oldOwnerName != "[?]"){ + ?> + + + + +
+ getVillageField($artifact['vref'], "name"); + if($oldVillageName != "[?]"){ + ?> + + + + +
+ + + \ No newline at end of file diff --git a/Admin/Templates/map.tpl b/Admin/Templates/map.tpl index 9f87bbce..d320c8ac 100644 --- a/Admin/Templates/map.tpl +++ b/Admin/Templates/map.tpl @@ -96,21 +96,22 @@ if ($check1 == "" && $check2 == "" && $check3 == "") $criteria = ""; $player_info = $database->query_return($q); foreach($player_info as $p_array) { - $p_name = $p_array['username']; - $p_village = mysqli_real_escape_string($database->dblink, $p_array['name']); + $p_name = htmlspecialchars(mysqli_escape_string($database->dblink, $p_array['username'])); + $p_village = htmlspecialchars(mysqli_escape_string($database->dblink, $p_array['name'])); $p_coor = "(".$p_array['x']."|".$p_array['y'].")"; $p_pop = $p_array['pop']; $p_tribe = $array_tribe[$p_array['tribe']]; $p_info ="
  • Player name: $p_name
  • Village name : $p_village
  • Coordinate: $p_coor
  • Population: $p_pop
  • Tribe: $p_tribe
  • ".($check3 != "" && isset($p_array['size']) ? "
  • Artifact effect: ".$artifactsEffect[$p_array['size']]."
  • " : "")."')\">
    "; - //250px = 0 - $xdiv = 250 / WORLD_MAX; - if($p_array['x'] < 0) $p_x = 250 - intval(abs($p_array['x']) * $xdiv); //- - elseif($p_array['x'] > 0) $p_x = 250 + intval(abs($p_array['x']) * $xdiv); //+ - if($p_array['y'] < 0) $p_y = 250 + intval(abs($p_array['y']) * $xdiv); //- - elseif($p_array['y'] > 0) $p_y = 250 - intval(abs($p_array['y']) * $xdiv); //+ - if($p_array['x'] == 0 && $p_array['y'] == 0) $p_x = $p_y = 250; //multihunter + //245px = 0 + $pixelDiv = 245; + $xdiv = $pixelDiv / WORLD_MAX; + if($p_array['x'] <= 0) $p_x = $pixelDiv - intval(abs($p_array['x']) * $xdiv); //-x + elseif($p_array['x'] >= 0) $p_x = $pixelDiv + intval(abs($p_array['x']) * $xdiv); //+x + + if($p_array['y'] <= 0) $p_y = $pixelDiv + intval(abs($p_array['y']) * $xdiv); //-y + elseif($p_array['y'] >= 0) $p_y = $pixelDiv - intval(abs($p_array['y']) * $xdiv); //+y echo '
    '.$p_info.'
    '; } diff --git a/Admin/admin.php b/Admin/admin.php index 97e198c4..2fbe6e0f 100644 --- a/Admin/admin.php +++ b/Admin/admin.php @@ -23,6 +23,7 @@ include_once("../GameEngine/Database.php"); include_once ("../GameEngine/Lang/" . LANG . ".php"); include_once("../GameEngine/Admin/database.php"); include_once("../GameEngine/Data/buidata.php"); +include_once("../GameEngine/Artifacts.php"); include('Templates/ver.tpl'); include('Templates/update_latest.tpl'); @@ -59,6 +60,10 @@ if (!empty($_GET['p'])) { case 'map': $subpage = 'Map'; break; + + case 'artifacts': + $subpage = 'Artifacts'; + break; case 'search': $subpage = 'General Search'; @@ -120,14 +125,6 @@ if (!empty($_GET['p'])) { $subpage = 'Create Users'; break; - case 'natarend': - $subpage = 'Add WW Villages'; - break; - - case 'natarbuildingplan': - $subpage = 'Add WW Building Plan Villages'; - break; - case 'admin_log': $subpage = 'Admin Log'; break; @@ -498,7 +495,7 @@ if (!empty($_GET['p'])) {
  • Server Homepage
  • Control Panel Home
  • Return to the server
  • -
  • Server Update ()
  • +
  • Server Update ()
  • Logout
  • Server Info
  • Search diff --git a/GameEngine/Account.php b/GameEngine/Account.php index 45c9548e..3e66f78b 100755 --- a/GameEngine/Account.php +++ b/GameEngine/Account.php @@ -134,10 +134,10 @@ class Account { } } else { - $uid = $database->register($_POST['name'],password_hash($_POST['pw'], PASSWORD_BCRYPT,['cost' => 12]),$_POST['email'],$_POST['vid'],$act); + $uid = $database->register($_POST['name'], password_hash($_POST['pw'], PASSWORD_BCRYPT, ['cost' => 12]), $_POST['email'], $_POST['vid'], $act); if($uid) { - setcookie("COOKUSR",$_POST['name'],time()+COOKIE_EXPIRE,COOKIE_PATH); - setcookie("COOKEMAIL",$_POST['email'],time()+COOKIE_EXPIRE,COOKIE_PATH); + setcookie("COOKUSR" , $_POST['name'], time() + COOKIE_EXPIRE,COOKIE_PATH); + setcookie("COOKEMAIL" , $_POST['email'], time() + COOKIE_EXPIRE,COOKIE_PATH); $database->updateUserField( $uid, ["act", "invited"], @@ -145,7 +145,7 @@ class Account { 1 ); - $this->generateBase($_POST['kid'],$uid,$_POST['name']); + $this->generateBase($_POST['kid'], $uid, $_POST['name']); header("Location: login.php"); exit; } @@ -154,37 +154,38 @@ class Account { } private function Activate() { - if(START_DATE < date('d.m.Y') or START_DATE == date('d.m.Y') && START_TIME <= date('H:i')) - { - global $database; - $q = "SELECT act, username, password, email, tribe, location FROM ".TB_PREFIX."activate where act = '".$database->escape($_POST['id'])."'"; - $result = mysqli_query($database->dblink,$q); - $dbarray = mysqli_fetch_array($result); - if($dbarray['act'] == $_POST['id']) { - $uid = $database->register($dbarray['username'],$dbarray['password'],$dbarray['email'],$dbarray['tribe'],""); - if($uid) { - $database->unreg($dbarray['username']); - $this->generateBase($dbarray['location'],$uid,$dbarray['username']); - header("Location: activate.php?e=2"); - exit; - } - } - else - { - header("Location: activate.php?e=3"); - exit; - } - } - else - { - header("Location: activate.php"); - exit; - } - + global $database; + + if(START_DATE < date('d.m.Y') or START_DATE == date('d.m.Y') && START_TIME <= date('H:i')) + { + $q = "SELECT act, username, password, email, tribe, location FROM ".TB_PREFIX."activate where act = '".$database->escape($_POST['id'])."'"; + $result = mysqli_query($database->dblink,$q); + $dbarray = mysqli_fetch_array($result); + if($dbarray['act'] == $_POST['id']) { + $uid = $database->register($dbarray['username'], $dbarray['password'], $dbarray['email'], $dbarray['tribe'], ""); + if($uid) { + $database->unreg($dbarray['username']); + $this->generateBase($dbarray['location'],$uid,$dbarray['username']); + header("Location: activate.php?e=2"); + exit; + } + } + else + { + header("Location: activate.php?e=3"); + exit; + } + } + else + { + header("Location: activate.php"); + exit; + } } private function Unreg() { global $database; + $q = "SELECT password, username FROM ".TB_PREFIX."activate where id = ".(int) $_POST['id']; $result = mysqli_query($database->dblink,$q); $dbarray = mysqli_fetch_array($result); @@ -271,7 +272,7 @@ class Account { if($kid == 0) $kid = rand(1,4); else $kid = $_POST['kid']; - $database->generateVillages([['wid' => 0, 'kid' => $kid, 'capital' => 1]], $uid, $username); + $database->generateVillages([['wid' => 0, 'mode' => 0, 'type' => 3, 'kid' => $kid, 'capital' => 1, 'pop' => 2, 'name' => null, 'natar' => 0]], $uid, $username); $message->sendWelcome($uid, $username); } }; diff --git a/GameEngine/Admin/Mods/addUsers.php b/GameEngine/Admin/Mods/addUsers.php index 32382fd3..f53f6d10 100755 --- a/GameEngine/Admin/Mods/addUsers.php +++ b/GameEngine/Admin/Mods/addUsers.php @@ -100,11 +100,11 @@ else else { // Register them and build the village - $uid = $database->register($userName, password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]), $email, $tribe ,$act); + $uid = $database->register($userName, password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]), $email, $tribe, $act); if($uid) { /* -* [MENTION=6887]Tod[/MENTION]O +* [MENTION=6887]Todo[/MENTION] * * Allow option to create (random) bigger villages, * upgrade fields, granary, warehouse, wall etc @@ -130,12 +130,12 @@ else // already exists $protection = time(); mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET -protect = '".$protection."' -WHERE id = ".(int) $uid) or die(mysqli_error($database->dblink)); + protect = '".$protection."' + WHERE id = ".(int) $uid) or die(mysqli_error($database->dblink)); } $database->updateUserField($uid,"act","",1); - $wid = $database->generateBase($kid); + $wid = $database->generateBase($kid, 1); $database->setFieldTaken($wid); //calculate random generate value and level building diff --git a/GameEngine/Admin/admin.php b/GameEngine/Admin/admin.php index aee51c6d..d2b0db05 100755 --- a/GameEngine/Admin/admin.php +++ b/GameEngine/Admin/admin.php @@ -42,10 +42,10 @@ function aktiv() {this.srcElement.className='fl1'; } function inaktiv() {event.srcElement.className='fl2'; } function del(e,id){ -if(e == 'did'){ var conf = confirm('Dou you really want delete village id '+id+'?'); } -if(e == 'arti'){ var conf = confirm('Dou you really want delete artifact id '+id+'?'); } -if(e == 'unban'){ var conf = confirm('Dou you really want unban player '+id+'?'); } -if(e == 'stopDel'){ var conf = confirm('Dou you really want stop deleting user '+id+'?'); } +if(e == 'did'){ var conf = confirm('Do you really want to delete village id '+id+'?'); } +if(e == 'arti'){ var conf = confirm('Do you really want to delete artifact id '+id+'?'); } +if(e == 'unban'){ var conf = confirm('Do you really want to unban player '+id+'?'); } +if(e == 'stopDel'){ var conf = confirm('Do you really want to stop deleting user '+id+'?'); } return conf; } @@ -86,30 +86,22 @@ return conf; if($funct->CheckLogin()){ if($_POST or $_GET){ - if($_GET['p'] and $_GET['p']!="search"){ + if($_GET['p'] && $_GET['p'] != "search"){ $filename = '../Templates/Admin/'.$_GET['p'].'.tpl'; - if(file_exists($filename)){ - include($filename); - }else{ - include('../Templates/Admin/404.tpl'); - } - }else{ - include('../Templates/Admin/search.tpl'); + if(file_exists($filename)) include($filename); + else include('../Templates/Admin/404.tpl'); } - if($_POST['p'] and $_POST['s']){ + else include('../Templates/Admin/search.tpl'); + + if($_POST['p'] && $_POST['s']){ $filename = '../Templates/Admin/results_'.$_POST['p'].'.tpl'; - if(file_exists($filename)){ - include($filename); - }else{ - include('../Templates/Admin/404.tpl'); - } + if(file_exists($filename)) include($filename); + else include('../Templates/Admin/404.tpl'); } - }else{ - include('../Templates/Admin/home.tpl'); } - }else{ - include('../Templates/Admin/login.tpl'); + else include('../Templates/Admin/home.tpl'); } + else include('../Templates/Admin/login.tpl'); ?> diff --git a/GameEngine/Admin/function.php b/GameEngine/Admin/function.php index c95426be..7137a5c5 100755 --- a/GameEngine/Admin/function.php +++ b/GameEngine/Admin/function.php @@ -17,6 +17,7 @@ // # Source code: https://github.com/Shadowss/TravianZ ## // # ## // ################################################################################ +include_once("../GameEngine/Artifacts.php"); class funct { @@ -29,6 +30,8 @@ class funct { global $admin, $database; + $artifact = new Artifacts(); + switch ($get['action']) { case "recountPop": $admin->recountPop($get['did']); @@ -74,12 +77,66 @@ class funct case "logout": $this->LogOut(); break; - case "delArtifact": - if(isset($_GET['artid']) && is_numeric($_GET['artid'])) $database->deleteArtifact($_GET['artid']); - break; - case "returnArtifact": + case "delArtifact": + if(isset($_GET['artid']) && is_numeric($_GET['artid'])) $database->updateArtifactDetails($_GET['artid'], ['del' => 1]); break; + + case "returnArtifact": + //Check if the artifact id is valid + if(!isset($_GET['artid']) || !is_numeric($_GET['artid'])){ + header("location: admin.php"); + exit; + } + + //Get the informations of the artifact + $artifactInfo = $database->getArtefactDetails($_GET['artid'], $_GET['del']); + + //Check if the artifact exists + if(empty($artifactInfo) || $artifactInfo['owner'] == Artifacts::NATARS_UID) { + header("location: admin.php"); + exit; + } + + $artifact->returnArtifactToNatars($artifactInfo); + break; + + case "addArtifacts": + + $selectedArtifact = $_POST['selectedArtifact']; + $artifactQuantity = $_POST['artifactQuantity']; + $playerId = $_POST['playerId']; + + //Check if the inputs are valid + if(!isset($selectedArtifact) || !isset($artifactQuantity) || !isset($playerId) || empty($selectedArtifact) || + !is_numeric($artifactQuantity) || !is_numeric($playerId) || strpos($selectedArtifact, ':') === false || + $database->getUserField($playerId, "username", 0) == "[?]"){ + header("location: admin.php"); + exit; + } + + //The first element [0] is the type of the artifact, the second one [1] is the size of it + //and the third one, is the artifact description + $selectedArtifact = explode(":", $selectedArtifact); + + //Add the chosen artifact(s) + $artifactsArray = array_merge(Artifacts::NATARS_ARTIFACTS, Artifacts::NATARS_WW_BUILDING_PLANS); + $chosenArtifact = $artifactsArray[$selectedArtifact[2]][$selectedArtifact[1] - 1]; + + //Check if the artifact has been found or if doesn't exist + if(empty($chosenArtifact)){ + header("location: admin.php"); + exit; + } + + //Create the artifacts array + $chosenArtifact['quantity'] = $artifactQuantity; + $artifactArrays[$selectedArtifact[2]][] = $chosenArtifact; + + //Add the artifacts + $artifact->addArtifactVillages($artifactArrays, $playerId); + break; + case "killHero": $varray = $database->getProfileVillages($get['uid']); $killhero = false; diff --git a/GameEngine/Artifacts.php b/GameEngine/Artifacts.php index ae7b46fc..d078a4cf 100644 --- a/GameEngine/Artifacts.php +++ b/GameEngine/Artifacts.php @@ -1,5 +1,439 @@ [["type" => 1, "size" => 1, "name" => ARCHITECTS_SMALL, "vname" => ARCHITECTS_SMALLVILLAGE, "effect" => "(4x)", "quantity" => 6, "img" => 2], + ["type" => 1, "size" => 2, "name" => ARCHITECTS_LARGE, "vname" => ARCHITECTS_LARGEVILLAGE, "effect" => "(3x)", "quantity" => 4, "img" => 2], + ["type" => 1, "size" => 3, "name" => ARCHITECTS_UNIQUE,"vname" => ARCHITECTS_UNIQUEVILLAGE, "effect" => "(5x)", "quantity" => 1, "img" => 2]], + + HASTE_DESC => [["type" => 2, "size" => 1, "name" => HASTE_SMALL, "vname" => HASTE_SMALLVILLAGE, "effect" => "(2x)", "quantity" => 6, "img" => 4], + ["type" => 2, "size" => 2, "name" => HASTE_LARGE, "vname" => HASTE_LARGEVILLAGE, "effect" => "(1.5x)", "quantity" => 4, "img" => 4], + ["type" => 2, "size" => 3, "name" => HASTE_UNIQUE, "vname" => HASTE_UNIQUEVILLAGE, "effect" => "(3x)", "quantity" => 1, "img" => 4]], + + EYESIGHT_DESC => [["type" => 3, "size" => 1, "name" => EYESIGHT_SMALL, "vname" => EYESIGHT_SMALLVILLAGE, "effect" => "(5x)", "quantity" => 6, "img" => 5], + ["type" => 3, "size" => 2, "name" => EYESIGHT_LARGE, "vname" => EYESIGHT_LARGEVILLAGE, "effect" => "(3x)", "quantity" => 4, "img" => 5], + ["type" => 3, "size" => 3, "name" => EYESIGHT_UNIQUE, "vname" => EYESIGHT_UNIQUEVILLAGE, "effect" => "(10x)", "quantity" => 1, "img" => 5]], + + DIET_DESC => [["type" => 4, "size" => 1, "name" => DIET_SMALL, "vname" => DIET_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 6], + ["type" => 4, "size" => 2, "name" => DIET_LARGE, "vname" => DIET_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 6], + ["type" => 4, "size" => 3, "name" => DIET_UNIQUE, "vname" => DIET_UNIQUEVILLAGE, "effect" => "(50%)", "quantity" => 1, "img" => 6]], + + ACADEMIC_DESC => [["type" => 5, "size" => 1, "name" => ACADEMIC_SMALL, "vname" => ACADEMIC_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 8], + ["type" => 5, "size" => 2, "name" => ACADEMIC_LARGE, "vname" => ACADEMIC_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 8], + ["type" => 5, "size" => 3, "name" => ACADEMIC_UNIQUE, "vname" => ACADEMIC_UNIQUEVILLAGE, "effect" => "(50%)", "quantity" => 1, "img" => 8]], + + STORAGE_DESC => [["type" => 6, "size" => 1, "name" => STORAGE_SMALL, "vname" => STORAGE_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 9], + ["type" => 6, "size" => 2, "name" => STORAGE_LARGE, "vname" => STORAGE_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 9]], + + CONFUSION_DESC => [["type" => 7, "size" => 1, "name" => CONFUSION_SMALL, "vname" => CONFUSION_SMALLVILLAGE, "effect" => "(200)", "quantity" => 6, "img" => 10], + ["type" => 7, "size" => 2, "name" => CONFUSION_LARGE, "vname" => CONFUSION_LARGEVILLAGE, "effect" => "(100)", "quantity" => 4, "img" => 10], + ["type" => 7, "size" => 3, "name" => CONFUSION_UNIQUE, "vname" => CONFUSION_UNIQUEVILLAGE, "effect" => "(500)", "quantity" => 1, "img" => 10]], + + FOOL_DESC => [["type" => 8, "size" => 1, "name" => FOOL_SMALL, "vname" => FOOL_SMALLVILLAGE, "effect" => "", "quantity" => 10, "img" => "fool"], + 2 => ["type" => 8, "size" => 3, "name" => FOOL_UNIQUE, "vname" => FOOL_UNIQUEVILLAGE, "effect" => "", "quantity" => 1, "img" => "fool"]]], + + /** + * @var array WW building plans Natars' artifacts + */ + + NATARS_WW_BUILDING_PLANS = [PLAN_DESC => [["type" => 11, "size" => 1, "name" => PLAN,"vname" => PLANVILLAGE, "effect" => "", "quantity" => 13, "img" => 1]]], + + /** + * @var array Natars' normal artifacts buildings + */ + + NATARS_ARTIFACTS_BUILDINGS = [ + //Treasury of the 20th level, Residence of the 10th level, Rally Point of the 1th level + "f22t" => 27, "f22" => 20, "f28t" => 25, "f28" => 10, "f39t" => 16, "f39" => 1, + //18 Cranny of the 10th level + "f19t" => 23, "f19" => 10, "f20t" => 23, "f20" => 10, "f21t" => 23, "f21" => 10, + "f23t" => 23, "f23" => 10, "f24t" => 23, "f24" => 10, "f25t" => 23, "f25" => 10, + "f26t" => 23, "f26" => 10, "f27t" => 23, "f27" => 10, "f29t" => 23, "f29" => 10, + "f30t" => 23, "f30" => 10, "f31t" => 23, "f31" => 10, "f32t" => 23, "f32" => 10, + "f33t" => 23, "f33" => 10, "f34t" => 23, "f34" => 10, "f35t" => 23, "f35" => 10, + "f36t" => 23, "f36" => 10, "f37t" => 23, "f37" => 10, "f38t" => 23, "f38" => 10], + + + /** + * @var array Natars' WW villages buildings + */ + + NATARS_WW_VILLAGES_BUILDINGS = [ + //WW of the 0th level, Main Building of the 10th level, Marketplace of the 1th level + "f99t" => 40, "f99" => 0, "f22t" => 15, "f22" => 10, "f34t" => 17, "f34" => 1, + //Warehouse of the 20th & 10th level, Granary of the 20th & 10th level + "f20t" => 10, "f20" => 20, "f19t" => 10, "f19" => 10, "f23t" => 11, "f23" => 20, "f27t" => 11, "f27" => 10, + //All Woodcutter of the 5th level + "f1" => 5, "f3" => 5, "f14" => 5, "f17" => 5, + //All Clay Pit of the 5th level + "f5" => 5, "f6" => 5, "f16" => 5, "f18" => 5, + //All Iron Mine of the 5th level + "f4" => 5, "f7" => 5, "f10" => 5, "f11" => 5, + //All Cropland of the 6th level + "f2" => 6, "f8" => 6, "f9" => 6, "f12" => 6, "f13" => 6, "f15" => 6], + + /** + * @var integer The base amount of Natars' spying units, used when Natars account is created + */ + + NATARS_BASE_SPY = 1500; + + public + + /** + * @var funct Natars' troops for normal artifact + */ + + $natarsArtifactsUnits, + + /** + * @var funct WW villages Natars' troops + */ + + $natarsWWVillagesUnits; + + public function __construct(){ + + $this->natarsArtifactsUnits = function($multiplier){ + return [41 => rand(1000 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, + 42 => rand(1500 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, + 43 => rand(2300 * $multiplier, 2800 * $multiplier) * NATARS_UNITS, + 44 => rand(25 * $multiplier, 75 * $multiplier) * NATARS_UNITS, + 45 => rand(1200 * $multiplier, 1900 * $multiplier) * NATARS_UNITS, + 46 => rand(1500 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, + 47 => rand(500 * $multiplier, 900 * $multiplier) * NATARS_UNITS, + 48 => rand(100 * $multiplier, 300 * $multiplier) * NATARS_UNITS, + 49 => rand(1 * $multiplier, 5 * $multiplier) * NATARS_UNITS, + 50 => rand(1 * $multiplier, 5 * $multiplier) * NATARS_UNITS]; + }; + + $this->natarsWWVillagesUnits = function(){ + return [41 => rand(500, 12000) * NATARS_UNITS, + 42 => rand(1000 , 14000) * NATARS_UNITS, + 43 => rand(2000, 16000) * NATARS_UNITS, + 44 => rand(100, 500) * NATARS_UNITS, + 45 => rand(480, 17000) * NATARS_UNITS, + 46 => rand(600, 18000) * NATARS_UNITS, + 47 => rand(2000, 16000) * NATARS_UNITS, + 48 => rand(400, 2000) * NATARS_UNITS, + 49 => rand(40, 200) * NATARS_UNITS, + 50 => rand(50, 250) * NATARS_UNITS]; + }; + + } + + /** + * Called when Natars account need to be created, creates his account and capital village + * + */ + + public function createNatars(){ + global $database; + + //Register the Natars account, the Natars' password is the same as the MH's one + $password = $database->getUserField(5, 'password', 0); + $database->register(TRIBE5, $password, self::NATARS_EMAIL, self::NATARS_TRIBE, null, self::NATARS_UID, self::NATARS_DESC); + + //Convert from coordinates to village IDs + $possibleWids = $database->getVilWrefs(self::NATARS_CAPITAL_COORDINATES); + + //Check if the villages aren't already taken + $wid = $database->getFreeVillage($possibleWids); + + //Generate the Natars' capital + $wid = $database->generateVillages([['wid' => $wid, 'mode' => 2, 'type' => 3, 'kid' => 0, 'capital' => 1, 'pop' => 834, 'name' => null, 'natar' => 0]], self::NATARS_UID, TRIBE5); + + //Scouts all players + $this->scoutAllPlayers($wid); + + //Add artifacts + $this->addArtifactVillages(self::NATARS_ARTIFACTS); + } + + /** + * Called when Natars account has been created + * + * @param int $wid The village ID of the Natars' capital + */ + + public function scoutAllPlayers($wid){ + global $database; + + $array = $database->getProfileVillages(0, 1); + $refs = []; + $vils = []; + + foreach($array as $vill){ + $refs[] = $database->addAttack($wid, 0, 0, 0, self::NATARS_BASE_SPY * NATARS_UNITS, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 0); + $vils[] = $vill['wref']; + } + + $type = []; + $from = []; + $to = []; + $ref = []; + $time = []; + $timeValue = time(); + $endtime = []; + $endtimeValue = $timeValue + round(10000 / SPEED); + $counter = 0; + + foreach ($refs as $index => $refID) { + $type[] = 3; + $from[] = $wid; + $to[] = $vils[$index]; + $ref[] = $refID; + $time[] = $timeValue; + $endtime[] = $endtimeValue; + + // limit the insert, so it can push through any reasonable network limits imposed + if (++$counter > 25) { + $database->addMovement($type, $from, $to, $ref, $time, $endtime); + + $type = []; + $from = []; + $to = []; + $ref = []; + $time = []; + $endtime = []; + $counter = 0; + } + } + + if ($counter > 0) $database->addMovement($type, $from, $to, $ref, $time, $endtime); + } + + /** + * Creates villages and puts the desired artifacts in it + * + * @param array $artifactArrays The array containing the artifacts to insert + * @param int $uid The owner's user ID (Natars) + */ + + public function addArtifactVillages($artifactArrays, $uid = self::NATARS_UID) { + global $database; + + //Variables initialization + $artifactNumber = 0; + $artifactVillages = $artifactTroops = $artifactBuildings = $artifactsToAdd = $wids = []; + + //Create the artifact villages array + foreach($artifactArrays as $desc => $artifactType){ + foreach($artifactType as $artifact){ + for($i = 0; $i < $artifact['quantity']; $i++){ + //Generate the villages array + $artifactVillages[] = ['wid' => 0, 'mode' => $artifact['size'] + 1, 'type' => 3, 'kid' => rand(1, 4), 'capital' => 0, 'pop' => 163, 'name' => $artifact['vname'], 'natar' => 0]; + + //Set the unit arrays (1, 2 or 4) + $multiplier = $artifact['size'] == 3 ? 4 : $artifact['size']; + $unitArrays = ($this->natarsArtifactsUnits)($multiplier); + + //Generate the unit arrays + $artifactTroops[1][] = array_values($unitArrays); + $artifactBuildings[1][] = array_values(self::NATARS_ARTIFACTS_BUILDINGS); + + //Generate the artifacts array + $artifactsToAdd[] = ['owner' => $uid, 'type' => $artifact['type'], 'size' => $artifact['size'], + 'name' => $artifact['name'], 'desc' => $desc, 'effect' => $artifact['effect'], + 'img' => "type".$artifact['img'].".gif"]; + } + } + } + + //Set the unit types by using the last $unitArrays + $artifactTroops[0] = array_keys($unitArrays); + $artifactBuildings[0] = array_keys(self::NATARS_ARTIFACTS_BUILDINGS); + + //Generate the wids + $wids = array_merge($wids, (array)$database->generateVillages($artifactVillages, $uid, TRIBE5, $artifactTroops, $artifactBuildings)); + + //Create the artifacts for the generated wids + $database->addArtefacts($wids, $artifactsToAdd); + } + + /** + * Called when WW villages need to be created + * + */ + + public function createWWVillages(){ + global $database; + + $villageArrays = $troopArrays = $buildingArrays = $wids = []; + for($i = 1; $i <= 13; $i++){ + $villageArrays[] = ['wid' => 0, 'mode' => 5, 'type' => 3, 'kid' => ($i == 13 ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0, 'pop' => 233, 'name' => WWVILLAGE, 'natar' => 1]; + $troopArrays[1][] = array_values(($this->natarsWWVillagesUnits)()); + $buildingArrays[1][] = array_values(self::NATARS_WW_VILLAGES_BUILDINGS); + } + + $troopArrays[0] = array_keys(($this->natarsWWVillagesUnits)()); + $buildingArrays[0] = array_keys(self::NATARS_WW_VILLAGES_BUILDINGS); + + $wids = $database->generateVillages($villageArrays, self::NATARS_UID, TRIBE5, $troopArrays, $buildingArrays); + } + + /** + * Called when WW building plans need to be created + * + */ + + public function createWWBuildingPlans(){ + + //Add the artifacts and villages + $this->addArtifactVillages(self::NATARS_WW_BUILDING_PLANS); + } + + /** + * Automatically activate all artifacts that need to be activated + * + */ + + public function activateArtifacts(){ + global $database; + + //Get all inactive artifacts that have to be activated --> (24 hours / Speed of the server) + $time = time(); + $artifacts = $database->getInactiveArtifacts(round($time - (86400 / (SPEED == 2 ? 1.5 : (SPEED == 3 ? 2 : SPEED))))); + + if(!empty($artifacts)){ + + //Cache inactive artifacts by owner + $inactiveArtifactsCache = []; + foreach($artifacts as $artifact) $inactiveArtifactsCache[$artifact['owner']][] = $artifact; + + foreach($inactiveArtifactsCache as $owner => $inactiveArtifacts){ + + //Initialize the array + $activeArtifacts = []; + + //Get cached active artifacts + $ownArtifacts = $database->getOwnArtifactsSum($owner, true); + + //Activate activable artifacts + foreach($inactiveArtifacts as $artifact){ + if($ownArtifacts['totals'] < 3){ + if($artifact['size'] == 1){ //Village effect + $database->activateArtifact($artifact['id']); + $ownArtifacts['totals']++; + $ownArtifacts['small']++; + }elseif($artifact['size'] == 2 && !$ownArtifacts['unique'] && !$ownArtifacts['great']){ //Account effect + $database->activateArtifact($artifact['id']); + $ownArtifacts['totals']++; + $ownArtifacts['great']++; + }elseif($artifact['size'] == 3 && !$ownArtifacts['unique'] && !$ownArtifacts['great']){ //Unique effect + $database->activateArtifact($artifact['id']); + $ownArtifacts['totals']++; + $ownArtifacts['unique']++; + } + }elseif($ownArtifacts['small'] == 3 && $artifact['size'] > 1){ + //If we've 3 village effect artifacts activated and at least one account/unique effect not activated + //then we need to deactivate the most recent village effect artifact and activate the oldest account + //or unique effect artifact + + //Deactivate the most recent village effect artifact + $database->activateArtifact($database->getNewestArtifactBySize($owner, 1)['id'], 0); + + //Activate the great/unique artifact + $database->activateArtifact($artifact['id']); + + $ownArtifacts['small']--; + $ownArtifacts['totals']++; + if($artifact['size'] == 2) $ownArtifacts['great']++; + else $ownArtifacts['unique']++; + } + } + } + } + } + /** + * Return the selected artifact, to the Natars account, by creating a new village and + * by moving the artifact into it + * + * @param array $artifact The artifact array + */ + + public function returnArtifactToNatars($artifactArray){ + global $database; + + //Set the village arrays + $villageArrays = [['wid' => 0, 'mode' => $artifactArray['size'] + 1, 'type' => 3, + 'kid' => rand(1, 4), 'capital' => 0, 'pop' => 163, + 'name' => self::NATARS_ARTIFACTS[$artifactArray['desc']][$artifactArray['size'] - 1]['vname'], + 'natar' => $artifactArray['type'] != 11 ? 0 : 1]]; + + //Set the unit arrays + $multiplier = $artifactArray['size'] == 3 ? 4 : $artifactArray['size']; + $unitsArray = ($this->natarsArtifactsUnits)($multiplier); + + //Set the unit types + $artifactTroops[1][] = array_values($unitsArray); + $artifactTroops[0] = array_keys($unitsArray); + + //Set the buildings array + $artifactBuildings[1][] = array_values(self::NATARS_ARTIFACTS_BUILDINGS); + $artifactBuildings[0] = array_keys(self::NATARS_ARTIFACTS_BUILDINGS); + + //Generate the village + $wid = $database->generateVillages($villageArrays, self::NATARS_UID, TRIBE5, $artifactTroops, $artifactBuildings); + + //Update the artifact with the new village id and owner + $database->updateArtifactDetails($artifactArray['id'], ['vref' => $wid, 'owner' => self::NATARS_UID, 'active' => 0, 'del' => 0]); + } /** * Gets the artifact informations in plain text diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index e773e725..6c8d1e09 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -27,11 +27,21 @@ include_once("Ranking.php"); include_once("Generator.php"); include_once("Multisort.php"); include_once("Building.php"); +include_once("Artifacts.php"); class Automation { + /** + * @var object The artifacts class, used to create Natars, artifacts and obtaining info about them + */ + + private $artifacts; + public function __construct() { + //Classes initialization + $this->artifacts = new Artifacts(); + $autoprefix = ""; for ($i = 0; $i < 5; $i++) { $autoprefix = str_repeat('../', $i); @@ -238,13 +248,16 @@ class Automation { @set_time_limit(0); foreach($needDelete as $need) { - $needVillage = $database->getVillagesID($need['uid']); + $need['uid'] = (int) $need['uid']; + + //Get the villages which have to be deleted + $needVillages = $database->getVillagesID($need['uid']); //Delete all villages - foreach($needVillage as $village) $this->DelVillage((int) $village); + $database->DelVillage($needVillages); for($i = 0;$i < 20; $i++){ - $q = "SELECT id FROM ".TB_PREFIX."users where friend".$i." = ".(int) $need['uid']." or friend".$i."wait = ".(int) $need['uid'].""; + $q = "SELECT id FROM ".TB_PREFIX."users where friend".$i." = ".$need['uid']." or friend".$i."wait = ".$need['uid'].""; $array = $database->query_return($q); foreach($array as $friend){ $database->deleteFriend($friend['id'],"friend".$i); @@ -264,25 +277,21 @@ class Automation { Automation::updateMax($newleader); } - if (isset($alliance)) { - $database->deleteAlliance($alliance); - } - $q = "UPDATE ".TB_PREFIX."artefacts where owner = ".(int) $need['uid']." SET del = 1"; - $database->query($q); + if (isset($alliance)) $database->deleteAlliance($alliance); - $q = "DELETE FROM ".TB_PREFIX."hero where uid = ".(int) $need['uid']; + $q = "DELETE FROM ".TB_PREFIX."hero where uid = ".$need['uid']; $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."mdata where target = ".(int) $need['uid']." or owner = ".(int) $need['uid']; + $q = "DELETE FROM ".TB_PREFIX."mdata where target = ".$need['uid']." or owner = ".$need['uid']; $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."ndata where uid = ".(int) $need['uid']; + $q = "DELETE FROM ".TB_PREFIX."ndata where uid = ".$need['uid']; $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."users where id = ".(int) $need['uid']; + $q = "DELETE FROM ".TB_PREFIX."users where id = ".$need['uid']; $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."deleting where uid = ".(int) $need['uid']; + $q = "DELETE FROM ".TB_PREFIX."deleting where uid = ".$need['uid']; $database->query($q); } } @@ -2454,7 +2463,7 @@ class Automation { } //Delete the village - $this->DelVillage($data['to']); + $database->DelVillage($data['to']); //Reassign the hero, if dead and assigned to the deleted village $database->reassignHero($data['to']); @@ -2569,96 +2578,6 @@ class Automation { } } - function DelVillage($wref){ - global $database, $units; - - $database->clearExpansionSlot($wref); - $wref = (int) $wref; - $q = "DELETE FROM ".TB_PREFIX."abdata where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."bdata where wid = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."market where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."research where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."tdata where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."fdata where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."training where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."units where vref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."farmlist where wref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."raidlist where towref = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."route where wid = $wref OR `from` = $wref"; - $database->query($q); - $q = "DELETE FROM ".TB_PREFIX."movement where proc = 0 AND ((`to` = $wref AND sort_type=4) OR (`from` = $wref AND sort_type=3))"; - $database->query($q); - $database->removeOases($wref, 1); - - $getmovement = $database->getMovement(3, $wref, 1); - - $moveIDs = []; - $time = microtime(true); - $types = []; - $froms = []; - $tos = []; - $refs = []; - $times = []; - $endtimes = []; - - foreach($getmovement as $movedata) { - $time2 = $time - $movedata['starttime']; - $moveIDs[] = $movedata['moveid']; - $types[] = 4; - $froms[] = $movedata['to']; - $tos[] = $movedata['from']; - $refs[] = $movedata['ref']; - $times[] = $time; - $endtimes[] = $time+$time2; - } - - $database->setMovementProc(implode(', ', $moveIDs)); - $database->addMovement($types, $froms, $tos, $refs, $times, $endtimes); - - $q = "DELETE FROM ".TB_PREFIX."enforcement WHERE `from` = $wref"; - $database->query($q); - - //check return enforcement from del village - $units->returnTroops($wref); - - $q = "DELETE FROM ".TB_PREFIX."vdata WHERE `wref` = $wref"; - $database->query($q); - - if (mysqli_affected_rows($database->dblink) > 0) { - $q = "UPDATE ".TB_PREFIX."wdata set occupied = 0 where id = $wref"; - $database->query($q); - - // clear expansion slots, if this village is an expansion of any other village - $database->clearExpansionSlot($wref, 1); - - $getprisoners = $database->getPrisoners($wref); - foreach($getprisoners as $pris) { - $troops = 0; - for($i = 1; $i < 12; $i++) $troops += $pris['t'.$i]; - $database->modifyUnit($pris['wref'], ["99o"], [$troops], [0]); - $database->deletePrisoners($pris['id']); - } - - $getprisoners = $database->getPrisoners3($wref); - foreach($getprisoners as $pris) { - $troops = 0; - for($i = 1;$i < 12; $i++) $troops += $pris['t'.$i]; - $database->modifyUnit($pris['wref'], ["99o"], [$troops], [0]); - $database->deletePrisoners($pris['id']); - } - } - } - private function sendreinfunitsComplete() { global $bid23, $database, $battle; @@ -2983,41 +2902,7 @@ class Automation { if($database->areArtifactsSpawned() || strtotime(START_DATE) + (NATARS_SPAWN_TIME * 86400) > time()) return; //Create the Natars account and his capital - $database->createNatars(); - - //Artifacts constants - $artifactArrays = [ARCHITECTS_DESC => [["type" => 1, "size" => 1, "name" => ARCHITECTS_SMALL, "vname" => ARCHITECTS_SMALLVILLAGE, "effect" => "(4x)", "quantity" => 6, "img" => 2], - ["type" => 1, "size" => 2, "name" => ARCHITECTS_LARGE, "vname" => ARCHITECTS_LARGEVILLAGE, "effect" => "(3x)", "quantity" => 4, "img" => 2], - ["type" => 1, "size" => 3, "name" => ARCHITECTS_UNIQUE,"vname" => ARCHITECTS_UNIQUEVILLAGE, "effect" => "(5x)", "quantity" => 1, "img" => 2]], - - HASTE_DESC => [["type" => 2, "size" => 1, "name" => HASTE_SMALL, "vname" => HASTE_SMALLVILLAGE, "effect" => "(2x)", "quantity" => 6, "img" => 4], - ["type" => 2, "size" => 2, "name" => HASTE_LARGE, "vname" => HASTE_LARGEVILLAGE, "effect" => "(1.5x)", "quantity" => 4, "img" => 4], - ["type" => 2, "size" => 3, "name" => HASTE_UNIQUE, "vname" => HASTE_UNIQUEVILLAGE, "effect" => "(3x)", "quantity" => 1, "img" => 4]], - - EYESIGHT_DESC => [["type" => 3, "size" => 1, "name" => EYESIGHT_SMALL, "vname" => EYESIGHT_SMALLVILLAGE, "effect" => "(5x)", "quantity" => 6, "img" => 5], - ["type" => 3, "size" => 2, "name" => EYESIGHT_LARGE, "vname" => EYESIGHT_LARGEVILLAGE, "effect" => "(3x)", "quantity" => 4, "img" => 5], - ["type" => 3, "size" => 3, "name" => EYESIGHT_UNIQUE, "vname" => EYESIGHT_UNIQUEVILLAGE, "effect" => "(10x)", "quantity" => 1, "img" => 5]], - - DIET_DESC => [["type" => 4, "size" => 1, "name" => DIET_SMALL, "vname" => DIET_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 6], - ["type" => 4, "size" => 2, "name" => DIET_LARGE, "vname" => DIET_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 6], - ["type" => 4, "size" => 3, "name" => DIET_UNIQUE, "vname" => DIET_UNIQUEVILLAGE, "effect" => "(50%)", "quantity" => 1, "img" => 6]], - - ACADEMIC_DESC => [["type" => 5, "size" => 1, "name" => ACADEMIC_SMALL, "vname" => ACADEMIC_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 8], - ["type" => 5, "size" => 2, "name" => ACADEMIC_LARGE, "vname" => ACADEMIC_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 8], - ["type" => 5, "size" => 3, "name" => ACADEMIC_UNIQUE, "vname" => ACADEMIC_UNIQUEVILLAGE, "effect" => "(50%)", "quantity" => 1, "img" => 8]], - - STORAGE_DESC => [["type" => 6, "size" => 1, "name" => STORAGE_SMALL, "vname" => STORAGE_SMALLVILLAGE, "effect" => "(50%)", "quantity" => 6, "img" => 9], - ["type" => 6, "size" => 2, "name" => STORAGE_LARGE, "vname" => STORAGE_LARGEVILLAGE, "effect" => "(25%)", "quantity" => 4, "img" => 9]], - - CONFUSION_DESC => [["type" => 7, "size" => 1, "name" => CONFUSION_SMALL, "vname" => CONFUSION_SMALLVILLAGE, "effect" => "(200)", "quantity" => 6, "img" => 10], - ["type" => 7, "size" => 2, "name" => CONFUSION_LARGE, "vname" => CONFUSION_LARGEVILLAGE, "effect" => "(100)", "quantity" => 4, "img" => 10], - ["type" => 7, "size" => 3, "name" => CONFUSION_UNIQUE, "vname" => CONFUSION_UNIQUEVILLAGE, "effect" => "(500)", "quantity" => 1, "img" => 10]], - - FOOL_DESC => [["type" => 8, "size" => 1, "name" => FOOL_SMALL, "vname" => FOOL_SMALLVILLAGE, "effect" => "", "quantity" => 10, "img" => "fool"], - ["type" => 8, "size" => 3, "name" => FOOL_UNIQUE, "vname" => FOOL_UNIQUEVILLAGE, "effect" => "", "quantity" => 1, "img" => "fool"]]]; - - //Add artifacts and their villages - $database->addArtifactVillages($artifactArrays); + $this->artifacts->createNatars(); //Write the system message $database->displaySystemMessage(ARTEFACT); @@ -3035,44 +2920,8 @@ class Automation { //and if it's the time to spawn them or not if(!$database->areArtifactsSpawned() || $database->areWWVillagesSpawned() || strtotime(START_DATE) + (NATARS_WW_SPAWN_TIME * 86400) > time()) return; - //WW village Natars' troops - $unitArrays = [41 => rand(500, 12000) * NATARS_UNITS, - 42 => rand(1000 , 14000) * NATARS_UNITS, - 43 => rand(2000, 16000) * NATARS_UNITS, - 44 => rand(100, 500) * NATARS_UNITS, - 45 => rand(480, 17000) * NATARS_UNITS, - 46 => rand(600, 18000) * NATARS_UNITS, - 47 => rand(2000, 16000) * NATARS_UNITS, - 48 => rand(400, 2000) * NATARS_UNITS, - 49 => rand(40, 200) * NATARS_UNITS, - 50 => rand(50, 250) * NATARS_UNITS]; - - //WW village buildings - $buildingArrays = [ - //WW of the 0th level, Main Building of the 10th level, Marketplace of the 1th level, Delete Main Building of the 1th level - "f99t" => 40, "f99" => 0, "f22t" => 15, "f22" => 10, "f34t" => 17, "f34" => 1, "f26t" => 0, "f26" => 0, - //Warehouse of the 20th & 10th level, Granary of the 20th & 10th level - "f20t" => 10, "f20" => 20, "f19t" => 10, "f19" => 10, "f23t" => 11, "f23" => 20, "f27t" => 11, "f27" => 10, - //All Woodcutter of the 5th level - "f1t" => 1, "f1" => 5, "f3t" => 1, "f3" => 5, "f14t" => 1, "f14" => 5, "f17t" => 1, "f17" => 5, - //All Clay Pit of the 5th level - "f5t" => 2, "f5" => 5, "f6t" => 2, "f6" => 5, "f16t" => 2, "f16" => 5, "f18t" => 2, "f18" => 5, - //All Iron Mine of the 5th level - "f4t" => 3, "f4" => 5, "f7t" => 3, "f7" => 5, "f10t" => 3, "f10" => 5, "f11t" => 3, "f11" => 5, - //All Cropland of the 6th level - "f2t" => 4, "f2" => 6, "f8t" => 4, "f8" => 6, "f9t" => 4, "f9" => 6, "f12t" => 4, "f12" => 6, "f13t" => 4, "f13" => 6, "f15t" => 4, "f15" => 6]; - - $villageArrays = $wids = []; - for($i = 1; $i <= 13; $i++) $villageArrays[] = ['wid' => 0, 'kid' => ($i == 13 ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0]; - - $wids = $database->generateVillages($villageArrays, 3, "Natars"); - - foreach($wids as $wid){ - $database->modifyUnit($wid, array_keys($unitArrays), array_values($unitArrays), [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - $database->setVillageLevel($wid, array_keys($buildingArrays), array_values($buildingArrays)); - $database->setVillageFields($wid, ['natar', 'pop', 'name'], [1, 233, WWVILLAGE]); - // $this->recountPop($wid); //it is necessary to comment out otherwise the population will be 198 - } + //Create WW villages + $this->artifacts->createWWVillages(); //Write the system message $database->displaySystemMessage(WWVILLAGEMSG); @@ -3090,10 +2939,8 @@ class Automation { //and if it's the time to spawn them or not if(!$database->areArtifactsSpawned() || $database->areArtifactsSpawned(true) || strtotime(START_DATE) + (NATARS_WW_BUILDING_PLAN_SPAWN_TIME * 86400) > time()) return; - $artifactArrays = [PLAN_DESC => [["type" => 11, "size" => 1, "name" => PLAN,"vname" => PLANVILLAGE, "effect" => "", "quantity" => 13, "img" => 1]]]; - - //Add the artifacts and villages - $database->addArtifactVillages($artifactArrays); + //Create WW building plans + $this->artifacts->createWWBuildingPlans(); //Set the system message to contain the infos of the WW building plans $database->displaySystemMessage(PLAN_INFO); @@ -3110,59 +2957,8 @@ class Automation { //Check if there's at least one artifact, if not, return if(!$database->areArtifactsSpawned()) return; - //Get all inactive artifacts that have to be activated --> (24 hours / Speed of the server) - $time = time(); - $artifacts = $database->getInactiveArtifacts(round($time - (86400 / (SPEED == 2 ? 1.5 : (SPEED == 3 ? 2 : SPEED))))); - - if(!empty($artifacts)){ - - //Cache inactive artifacts by owner - $inactiveArtifactsCache = []; - foreach($artifacts as $artifact) $inactiveArtifactsCache[$artifact['owner']][] = $artifact; - - foreach($inactiveArtifactsCache as $owner => $inactiveArtifacts){ - - //Initialize the array - $activeArtifacts = []; - - //Get cached active artifacts - $ownArtifacts = $database->getOwnArtifactsSum($owner, true); - - //Activate activable artifacts - foreach($inactiveArtifacts as $artifact){ - if($ownArtifacts['totals'] < 3){ - if($artifact['size'] == 1){ //Village effect - $database->activateArtifact($artifact['id']); - $ownArtifacts['totals']++; - $ownArtifacts['small']++; - }elseif($artifact['size'] == 2 && !$ownArtifacts['unique'] && !$ownArtifacts['great']){ //Account effect - $database->activateArtifact($artifact['id']); - $ownArtifacts['totals']++; - $ownArtifacts['great']++; - }elseif($artifact['size'] == 3 && !$ownArtifacts['unique'] && !$ownArtifacts['great']){ //Unique effect - $database->activateArtifact($artifact['id']); - $ownArtifacts['totals']++; - $ownArtifacts['unique']++; - } - }elseif($ownArtifacts['small'] == 3 && $artifact['size'] > 1){ - //If we've 3 village effect artifacts activated and at least one account/unique effect not activated - //then we need to deactivate the most recent village effect artifact and activate the oldest account - //or unique effect artifact - - //Deactivate the most recent village effect artifact - $database->activateArtifact($database->getNewestArtifactBySize($owner, 1)['id'], 0); - - //Activate the great/unique artifact - $database->activateArtifact($artifact['id']); - - $ownArtifacts['small']--; - $ownArtifacts['totals']++; - if($artifact['size'] == 2) $ownArtifacts['great']++; - else $ownArtifacts['unique']++; - } - } - } - } + //Activate the artifacts that need to be activated + $this->artifacts->activateArtifacts(); } private function researchComplete() { @@ -4837,7 +4633,7 @@ class Automation { global $database; $time = time(); - $q = "SELECT id, size FROM " . TB_PREFIX . "artefacts where type = 8 AND active = 1 AND lastupdate <= ".($time - (86400 / (SPEED == 2 ? 1.5 : (SPEED == 3 ? 2 : SPEED)))); + $q = "SELECT id, size FROM " . TB_PREFIX . "artefacts where type = 8 AND active = 1 AND del = 0 AND lastupdate <= ".($time - (86400 / (SPEED == 2 ? 1.5 : (SPEED == 3 ? 2 : SPEED)))); $array = $database->query_return($q); if ($array) { foreach($array as $artefact) { diff --git a/GameEngine/Building.php b/GameEngine/Building.php index ac51f3e1..46c345b9 100755 --- a/GameEngine/Building.php +++ b/GameEngine/Building.php @@ -537,10 +537,10 @@ class Building { case 37: return $this->getTypeLevel(15) >= 3 && $this->getTypeLevel(16) >= 1 && !$isBuilt; // great warehouse can only be built with artefact or in Natar villages - case 38: return $this->getTypeLevel(15) >= 10 && (!$isBuilt || $this->getTypeLevel($id) == 20) && ($village->natar == 1 || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 1, 0)) || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 2, 0))); + case 38: return $this->getTypeLevel(15) >= 10 && (!$isBuilt || $this->getTypeLevel($id) == 20) && ($village->natar == 1 || count($database->getOwnUniqueArtefactInfo2($village->wid, 6, 1, 0)) || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 2, 0))); // great granary can only be built with artefact or in Natar villages - case 39: return $this->getTypeLevel(15) >= 10 && (!$isBuilt || $this->getTypeLevel($id) == 20) && ($village->natar == 1 || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 1, 0)) || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 2, 0))); + case 39: return $this->getTypeLevel(15) >= 10 && (!$isBuilt || $this->getTypeLevel($id) == 20) && ($village->natar == 1 || count($database->getOwnUniqueArtefactInfo2($village->wid, 6, 1, 0)) || count($database->getOwnUniqueArtefactInfo2($session->uid, 6, 2, 0))); case 40: return $this->allowWwUpgrade(); case 41: return $this->getTypeLevel(16) >= 10 && $this->getTypeLevel(20) == 20 && $session->tribe == 1 && !$isBuilt; diff --git a/GameEngine/Database.php b/GameEngine/Database.php index e80f3aa0..5c92bb1c 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -224,11 +224,6 @@ class MYSQLi_DB implements IDbConnection { */ $artefactDataCache = [], - /** - * @var array Cache of own artefact infos, from the simple SQL select. - */ - $artefactInfoSimpleCache = [], - /** * @var array Cache of own artefact infos by type. */ @@ -428,9 +423,7 @@ class MYSQLi_DB implements IDbConnection { $this->dbname = $dbname; // connect to the DB - if (!$this->connect()) { - die(mysqli_error($this->dblink)); - } + if (!$this->connect()) die(mysqli_error($this->dblink)); // we will operate in UTF8 mysqli_query($this->dblink,"SET NAMES 'UTF8'"); @@ -670,9 +663,8 @@ class MYSQLi_DB implements IDbConnection { if (isset($arrayVariable[$arrayStructure]) && !empty($arrayVariable[$arrayStructure])) { return $arrayVariable[$arrayStructure]; - } else { - return null; - } + } + else return null; } /** @@ -729,21 +721,23 @@ class MYSQLi_DB implements IDbConnection { return $this->dblink; } - function register($username, $password, $email, $tribe, $act) { - list($username, $password, $email, $tribe, $act) = $this->escape_input($username, $password, $email, $tribe, $act); + function register($username, $password, $email, $tribe, $act, $uid = 0, $desc = null) { + list($username, $password, $email, $tribe, $act, $uid, $desc) = $this->escape_input($username, $password, $email, (int) $tribe, $act, (int) $uid, $desc); $time = time(); - $stime = strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME); - if($stime > $time) $time = $stime; - $timep = $time + PROTECTION; - $time = time(); - $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime,is_bcrypt) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time,1)"; - if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink); + $startTime = strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME); + + //If we're registering the Natars tribe, the protection must be 0 + $protectionTime = $uid != 3 ? (($startTime > $time) ? $stime : $time) + PROTECTION : 0; + + $q = "INSERT INTO " . TB_PREFIX . "users (id, username, password, access, email, timestamp, tribe, act, protect, lastupdate, regtime, desc2, is_bcrypt) VALUES ($uid, '$username', '$password', " . USER . ", '$email', $time, $tribe, '$act', $protectionTime, $time, $time, '$desc', 1)"; + + if(mysqli_query($this->dblink, $q)) return mysqli_insert_id($this->dblink); else { // if an error has occured, we probably don't have DB converted to handle bcrypt passwords yet - $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, " . (int) $tribe . ", '$act', $timep, $time, $time)"; - if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink); + $q = "INSERT INTO " . TB_PREFIX . "users (id, username, password, access, email, timestamp, tribe, act, protect, lastupdate, regtime, desc2) VALUES ($uid, '$username', '$password', " . USER . ", '$email', $time, $tribe, '$act', $protectionTime, $time, $time, '$desc')"; + if(mysqli_query($this->dblink, $q)) return mysqli_insert_id($this->dblink); else return false; } } @@ -753,11 +747,8 @@ class MYSQLi_DB implements IDbConnection { $time = time(); $q = "INSERT INTO " . TB_PREFIX . "activate (username,password,access,email,tribe,timestamp,location,act,act2) VALUES ('$username', '$password', " . USER . ", '$email', " . (int) $tribe .", $time, $locate, '$act', '$act2')"; - if(mysqli_query($this->dblink,$q)) { - return mysqli_insert_id($this->dblink); - } else { - return false; - } + if(mysqli_query($this->dblink,$q)) return mysqli_insert_id($this->dblink); + else return false; } function unreg($username) { @@ -842,7 +833,8 @@ class MYSQLi_DB implements IDbConnection { $result = mysqli_query($this->dblink,$q); return $this->mysqli_fetch_all($result); } - + + //TODO: Remove this function to use the more general one // no need to cache this method function getVilWref($x, $y) { list($x, $y) = $this->escape_input((int) $x, (int) $y); @@ -852,6 +844,28 @@ class MYSQLi_DB implements IDbConnection { $dbarray = mysqli_fetch_array($result); return $dbarray['id']; } + + /** + * Converts from coordinates to village IDs + * + * @param array $coordinatesArray The coordinates array, containing the coordinates which need to be converted + * @return array Returns the converted coordinates + */ + + function getVilWrefs($coordinatesArray) { + list($coordinatesArray) = $this->escape_input($coordinatesArray); + + if(!is_array($coordinatesArray[0])) $coordinatesArray = [$coordinatesArray]; + + $conditions = []; + foreach($coordinatesArray as $coordinate) $conditions[] = "(x = ".$coordinate[0]." AND y = ".$coordinate[1].")"; + + $q = "SELECT id FROM " . TB_PREFIX . "wdata WHERE ".implode(" OR ", $conditions); + $result = mysqli_query($this->dblink, $q); + + while($row = mysqli_fetch_assoc($result)) $wids[] = $row['id']; + return $wids; + } function removeMeSit($uid, $uid2) { list($uid, $uid2) = $this->escape_input((int) $uid, (int) $uid2); @@ -1250,66 +1264,94 @@ class MYSQLi_DB implements IDbConnection { } } - // if $respect_gametime is false, we generate user base really anywhere - // and that means we can generate farms closer to the middle of the map as well - // ... otherwise we'd only generate farms at corner edges in late game, which - // sucks for people in the middle who registered too soon - function generateBase($sector, $mode=1, $respect_gametime = true) { - list($sector, $mode) = $this->escape_input($sector, $mode); + /** + * Generates a list of "free to take" villages + * + * @param int $sector The map sector, + | -, - | + , + | +, - | - (0 and > 3, 1, 2, 3) + * @param int $mode 0 if villages need be generated under certain filters, 1 if not + * @param bool $respect_gametime If is false, we generate user base really anywhere + * and that means we can generate farms closer to the middle of the map as well. + * Otherwise we'd only generate farms at corner edges in late game, which + * sucks for people in the middle who registered too soon + * @param int $numberOfVillages Number of villages which need to be generated + * @return array Return the generated villages + */ + + function generateBase($sector, $mode = 0, $numberOfVillages = 1) { + list($sector, $mode, $numberOfVillages) = $this->escape_input((int) $sector, (int) $mode, (int)$numberOfVillages); // don't let SQL time out when 30-500 seconds (depending on php.ini) is not enough @set_time_limit(0); - $num_rows = 0; - $count_while = 0; + $num_rows = $count = 0; + $villages = []; + $time = time(); + + while ($numberOfVillages > 0) { + switch($mode){ + case 0: + $daysPassedFromStart = ($time - strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME)) / 86400; - // random position on the map - used when generating farms via Admin - if (!$respect_gametime) $rand = rand(1,4); + $radiusMin = min(round(pow(2 * ($daysPassedFromStart / 5 * SPEED), 2)), round(pow(WORLD_MAX * 0.8, 2)) + round(pow(WORLD_MAX * 0.8, 2))); + $radiusMax = min(round(pow(4 * ($daysPassedFromStart / 5 * SPEED), 2)), pow(WORLD_MAX, 2) + pow(WORLD_MAX, 2)); + break; + + case 1: + default: + $radiusMin = 1; + $radiusMax = pow(WORLD_MAX, 2); + break; + + case 2: //Small artifacts & WW building plans + $radiusMin = round(pow(WORLD_MAX * 0.50, 2)); + $radiusMax = round(pow(WORLD_MAX * 0.75, 2)); + break; + + case 3: //Large artifacts + $radiusMin = round(pow(WORLD_MAX * 0.35, 2)); + $radiusMax = round(pow(WORLD_MAX * 0.55, 2)); + break; + + case 4: //Unique artifacts + $radiusMin = round(pow(WORLD_MAX * 0.05, 2)); + $radiusMax = round(pow(WORLD_MAX * 0.25, 2)); + break; - while (!$num_rows) { - if (!$mode) { - $gamesday = time() - COMMENCE; - // TODO: scale these with game speed? - if((!$respect_gametime && $rand === 1) || ($respect_gametime && $gamesday < 3600 * 24 * 10 && $count_while == 0)){ // 10 day - $wide1 = 1; - $wide2 = 20; - }elseif((!$respect_gametime && $rand === 2) || ($respect_gametime && $gamesday < 3600 * 24 * 20 && $count_while == 1)){ // 20 day - $wide1 = 20; - $wide2 = 40; - }elseif((!$respect_gametime && $rand === 3) || ($respect_gametime && $gamesday < 3600 * 24 * 30 && $count_while == 2)){ // 30 day - $wide1 = 40; - $wide2 = 80; - }else{ // over 30 day - $wide1 = 80; - $wide2 = WORLD_MAX; - } - }else { - $wide1 = 1; - $wide2 = WORLD_MAX; + case 5: //WW villages + $radiusMin = round(pow(WORLD_MAX * 0.8, 2)); + $radiusMax = round(pow(WORLD_MAX, 2)); + break; } switch($sector){ - case 1: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x- y+ - break; - case 2: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x+ y+ - break; - case 3: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x- y- - break; - default: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x+ y- + case 1: $sector = "x <= 0 AND y >= 0"; break; // - | + + case 2: $sector = "x >= 0 AND y >= 0"; break; // + | + + case 3: $sector = "x <= 0 AND y <= 0"; break; // - | - + default: $sector = "x >= 0 AND y <= 0"; // + | - } + + //Choose villages beetween two circumferences, by using their formula (x^2 + y^2 = r^2) + $q = "SELECT id FROM ".TB_PREFIX."wdata WHERE fieldtype = 3 AND ($sector) AND (POWER(x, 2) + POWER(y, 2) >= $radiusMin AND POWER(x, 2) + POWER(y, 2) <= $radiusMax) AND occupied = 0 ORDER BY RAND() LIMIT $numberOfVillages"; + $result = mysqli_query($this->dblink, $q); - $result = mysqli_query($this->dblink,$q); - $num_rows = mysqli_num_rows($result); - $count_while++; + //Prevent an infinite loop + $resultedRows = mysqli_num_rows($result); + if($resultedRows == 0 && $count >= 20) break; + + //Fill the villages array + $villages = array_merge($villages, $this->mysqli_fetch_all($result)); + + $num_rows += $resultedRows; + $numberOfVillages -= $resultedRows; + $count++; + + //If there are no more free cells in that sector, it have to be changed + //This instruction will be used only (in the next cicle(s)) if not all wids have been generated yet + $sector = rand(1, 4); } - $result = $this->mysqli_fetch_all($result); - $base = rand(0, ($num_rows - 1)); + foreach($villages as $village) $wids[] = $village['id']; - return $result[$base]['id']; + return $num_rows == 1 ? $wids[0] : $wids; } function setFieldTaken($id) { @@ -1331,83 +1373,129 @@ class MYSQLi_DB implements IDbConnection { * @param array $villageArrays The array of the villages which have to be created * @param int $uid The user ID * @param string $username The username of the future owner + * @param array $troopsArray The troops that need to be added in the village(s) + * @param array $buildingsArray The buildings that need to be created in the village(s) * @return array Returns the created villages ID */ - function generateVillages($villageArrays, $uid, $username){ - list($villageArrays, $uid, $username) = $this->escape_input($villageArrays, (int) $uid, $username); + function generateVillages($villageArrays, $uid, $username, $troopsArray = null, $buildingsArray = null){ + list($villageArrays, $uid, $username, $troopsArray, $buildingsArray) = $this->escape_input($villageArrays, (int) $uid, $username, $troopsArray, $buildingsArray); - $wids = []; + $wids = $takenWids = $countedWids = $generatedWids = $i = []; + + //Count each kid in its own array, to check how many villages must be created + foreach($villageArrays as $village){ + if($village['wid'] == 0) $countedWids[$village['mode']][$village['kid']]++; + } + + //Generate the number of desired village for each kid + //and merge them with the more general "wids" array + foreach($countedWids as $mode => $totalCount){ + foreach($totalCount as $sector => $count){ + $generatedWids = $this->generateBase($sector, $mode, $count); + $wids[$mode] = array_merge((array)$wids[$mode], !is_array($generatedWids) ? [$generatedWids] : $generatedWids); + if(empty($i[$mode])) $i[$mode] = 0; + } + } + + //Create the villages foreach($villageArrays as $village){ - if($village['wid'] == 0) $village['wid'] = $this->generateBase($village['kid'], 0); - $this->addVillage($village['wid'], $uid, $username, $village['capital']); - $this->addResourceFields($village['wid'], $this->getVillageType($village['wid'])); - $wids[] = $village['wid']; + + //Check if the village wid isn't already set and assing one among the generated ones + if($village['wid'] == 0) $village['wid'] = $wids[$village['mode']][$i[$village['mode']]++]; + + //Merge the wids into an unique array + $takenWids[] = $village['wid']; + $villageTypes[] = $village['type']; + + //Add the village and its buildings + $this->addVillage($village['wid'], $uid, $username, $village['capital'], $village['pop'], $village['name'], $village['natar']); } - $this->setFieldTaken($wids); - $this->addUnits($wids); - $this->addTech($wids); - $this->addABTech($wids); - - return count($wids) > 1 ? $wids : $wids[0]; + //Create tables for the just generated villages + $this->addResourceFields($takenWids, $villageTypes, $buildingsArray); + $this->setFieldTaken($takenWids); + $this->addUnits($takenWids, $troopsArray); + $this->addTech($takenWids); + $this->addABTech($takenWids); + + return count($takenWids) > 1 ? $takenWids : $takenWids[0]; } - function addVillage($wid, $uid, $username, $capital) { - list($wid, $uid, $username, $capital) = $this->escape_input((int) $wid, (int) $uid, $username, (int) $capital); + /** + * + * Create a village + * + * @param int $wid The village ID + * @param int $uid The User ID, the village's owner + * @param string $username The username + * @param int $capital 1 if it's a capital village, 0 otherwise + * @param int $pop The default village population + * @param string $villageName The default village name + * @return bool Returns true if the query was successful, false otherwise + */ + + function addVillage($wid, $uid, $username, $capital, $pop = 2, $villageName = null, $isNatar = 0) { + list($wid, $uid, $username, $capital, $pop, $villageName, $isNatar) = $this->escape_input((int) $wid, (int) $uid, $username, (int) $capital, (int) $pop, $villageName, (int) $isNatar); $total = count($this->getVillagesID($uid)); - if($total >= 1) $vname = $username . "\'s village " . ($total + 1); - else $vname = $username . "\'s village"; - + if($villageName == null) $villageName = $username."\'s village ".($total >= 1 ? $total + 1 : ""); + $time = time(); - $q = "INSERT into " . TB_PREFIX . "vdata (wref, owner, name, capital, pop, cp, celebration, wood, clay, iron, maxstore, crop, maxcrop, lastupdate, created) values ($wid, $uid, '$vname', $capital, 2, 1, 0, 750, 750, 750, ".STORAGE_BASE.", 750, ".STORAGE_BASE.", $time, $time)"; + $q = "INSERT into " . TB_PREFIX . "vdata (wref, owner, name, capital, pop, cp, celebration, wood, clay, iron, maxstore, crop, maxcrop, lastupdate, created, natar) values ($wid, $uid, '$villageName', $capital, $pop, 1, 0, 750, 750, 750, ".STORAGE_BASE.", 750, ".STORAGE_BASE.", $time, $time, $isNatar)"; return mysqli_query($this->dblink,$q); } - function addResourceFields($vid, $type) { - list($vid, $type) = $this->escape_input((int) $vid, $type); + /** + * + * Add the buildings tables to a specified village(s), and its relative buildings + * + * @param mixed $vid The village ID(s) + * @param mixed $type int if there's only one village, array if there are multiple villages + * @param array $buildingsArray divided in two portion, which contains the types (unidimensional array) and the values of the + * buildings that need to be added (bidimensional array) + * @return bool Return true if the query was successful, false otherwise + */ + + function addResourceFields($vids, $types, $buildingsArray = null) { + list($vids, $types, $buildingsArray) = $this->escape_input($vids, $types, $buildingsArray); - switch($type) { - case 1: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 2: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 3: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 4: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 5: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,3,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 6: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,4,4,1,3,4,4,4,4,4,4,4,4,4,4,4,2,4,4,1,15)"; - break; - case 7: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 8: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 9: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,4,1,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 10: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 11: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,1,1,3,1,4,4,3,3,2,2,3,1,4,4,2,4,4,1,15)"; - break; - case 12: - $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - default: $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - } - return mysqli_query($this->dblink,$q); + if(!is_array($vids)){ + $vids = [$vids]; + $types = [$types]; + } + + //Set the default villages structure (resources fields and main building) + $defaultVillage = "vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t" + .($buildingsArray != null ? ",".implode(",",$buildingsArray[0]) : ",f26,f26t"); + $defaultValues = []; + + //Select the village type and assemble the building values + foreach($vids as $index => $vid){ + $stringValues = ""; + $stringValues .= "(".$vid.","; + switch($types[$index]) { + case 1: $stringValues .= "4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 2: $stringValues .= "3,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 3: $stringValues .= "1,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 4: $stringValues .= "1,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 5: $stringValues .= "1,4,1,3,1,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 6: $stringValues .= "4,4,1,3,4,4,4,4,4,4,4,4,4,4,4,2,4,4"; break; + case 7: $stringValues .= "1,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 8: $stringValues .= "3,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 9: $stringValues .= "3,4,4,1,1,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 10: $stringValues .= "3,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + case 11: $stringValues .= "3,1,1,3,1,4,4,3,3,2,2,3,1,4,4,2,4,4"; break; + case 12: $stringValues .= "1,4,1,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2"; break; + default: $stringValues .= "4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2"; + } + + $stringValues .= $buildingsArray != null ? ",".implode(",",$buildingsArray[1][$index]).")" : ",1,15)"; + $defaultValues[] = $stringValues; + } + + $q = "INSERT INTO " . TB_PREFIX . "fdata ($defaultVillage) values".implode(",",$defaultValues); + return mysqli_query($this->dblink, $q); } function isVillageOases($wref, $use_cache = true) { @@ -1581,14 +1669,17 @@ class MYSQLi_DB implements IDbConnection { /** * Remove all oasis of a specified village if the mode is 1, if it's 0, then it'll remove only the selected oasis * - * @param int $vid The village ID (mode = 1)/oasis ID (mode = 0) of the oasis owner + * @param mixed $wref The village ID(s) (mode = 1)/oasis ID (mode = 0) of the oasis owner * @return bool Returns true if the query was successful, false otherwise */ function removeOases($wref, $mode = 0) { list($wref) = $this->escape_input((int) $wref); - $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, owner = 2, name = 'Unoccupied Oasis' WHERE ".(!$mode ? "wref = $wref" : "conqured = $wref"); + if(!is_array($wref)) $wref = [$wref]; + $wrefs = implode(",", $wref); + + $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, owner = 2, name = 'Unoccupied Oasis' WHERE ".(!$mode ? "wref IN($wrefs)" : "conqured IN($wrefs)"); return mysqli_query($this->dblink,$q); } @@ -1614,6 +1705,23 @@ class MYSQLi_DB implements IDbConnection { return ($vil['occupied'] != 0 || $vil['oasistype'] != 0); } } + + /** + * Get the first free village, if there's one + * + * @param array $wids The village IDs + * @return int Returns the wid of the first free village, if they're all taken, returns 0 + */ + + function getFreeVillage($wids){ + list($wids) = $this->escape_input($wids); + + if(!is_array($wids)) $wids = [$wids]; + + $q = "SELECT id FROM ".TB_PREFIX."wdata WHERE id IN(".implode(",", $wids).") AND occupied = 0 AND oasistype = 0 LIMIT 1"; + $result = mysqli_query($this->dblink, $q); + return mysqli_num_rows($result) > 0 ? mysqli_fetch_array($result)[0] : 0; + } // no need to refactor this method function getProfileMedal($uid) { @@ -4038,28 +4146,141 @@ class MYSQLi_DB implements IDbConnection { return mysqli_query($this->dblink,$q); } + /** + * Delete a single village or multiple ones + * + * @param mixed $wref The Village ID(s) + */ + + function DelVillage($wref){ + list($wref) = $this->escape_input($wref); + global $units; + + //Check if we've to delete a single village or multiple ones + if(!is_array($wref)) $wref = [$wref]; + + //Create the list of village IDs + $wrefs = implode(", ", $wref); + + $this->clearExpansionSlot($wref); + $q = "DELETE FROM ".TB_PREFIX."abdata where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."bdata where wid IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."market where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."research where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."tdata where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."fdata where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."training where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."units where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."farmlist where wref IN($wrefs)"; + $this->query($q); + $q = "UPDATE ".TB_PREFIX."artefacts SET del = 1 where vref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."raidlist where towref IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."route where wid IN($wrefs) OR `from` IN($wrefs)"; + $this->query($q); + $q = "DELETE FROM ".TB_PREFIX."movement where proc = 0 AND ((`to` IN($wrefs) AND sort_type = 4) OR (`from` IN($wrefs) AND sort_type = 3))"; + $this->query($q); + $this->removeOases($wref, 1); + + $getmovement = $this->getMovement(3, $wref, 1); + + $moveIDs = []; + $time = microtime(true); + $types = []; + $froms = []; + $tos = []; + $refs = []; + $times = []; + $endtimes = []; + + foreach($getmovement as $movedata) { + $time2 = $time - $movedata['starttime']; + $moveIDs[] = $movedata['moveid']; + $types[] = 4; + $froms[] = $movedata['to']; + $tos[] = $movedata['from']; + $refs[] = $movedata['ref']; + $times[] = $time; + $endtimes[] = $time+$time2; + } + + $this->setMovementProc(implode(', ', $moveIDs)); + $this->addMovement($types, $froms, $tos, $refs, $times, $endtimes); + + $q = "DELETE FROM ".TB_PREFIX."enforcement WHERE `from` IN($wrefs)"; + $this->query($q); + + //check return enforcement from del village + foreach($wref as $w) $units->returnTroops($w); + + $q = "DELETE FROM ".TB_PREFIX."vdata WHERE `wref` IN($wrefs)"; + $this->query($q); + + if (mysqli_affected_rows($this->dblink) > 0) { + $q = "UPDATE ".TB_PREFIX."wdata set occupied = 0 where id IN($wrefs)"; + $this->query($q); + + // clear expansion slots, if this village is an expansion of any other village + $this->clearExpansionSlot($wref, 1); + + $getprisoners = $this->getPrisoners($wref); + foreach($getprisoners as $pris) { + $troops = 0; + for($i = 1; $i < 12; $i++) $troops += $pris['t'.$i]; + $this->modifyUnit($pris['wref'], ["99o"], [$troops], [0]); + $this->deletePrisoners($pris['id']); + } + + $getprisoners = $this->getPrisoners($wref, 1); + foreach($getprisoners as $pris) { + $troops = 0; + for($i = 1; $i < 12; $i++) $troops += $pris['t'.$i]; + $this->modifyUnit($pris['wref'], ["99o"], [$troops], [0]); + $this->deletePrisoners($pris['id']); + } + } + } + + /** + * Clear the expansion slots of a specified village(s) + * + * @param mixed $id The village ID(s) + * @param number $mode 0 If there's the need to clear all expansion slots of a village, + * 1 if there's the need to clear a single expansion slot of a village + */ + function clearExpansionSlot($id, $mode = 0) { list($id) = $this->escape_input((int) $id); - if(!$mode){ + if(!is_array($id)) $id = [$id]; + $ids = implode(",", $id); + + if(!$mode){ $pairs = []; - for($i = 1; $i <= 3; $i++) { - $pairs[] = 'exp'.$i.' = 0'; - } + for($i = 1; $i <= 3; $i++) $pairs[] = 'exp'.$i.' = 0'; - $q = "UPDATE " . TB_PREFIX . "vdata SET ".implode(',', $pairs)." WHERE wref = " . $id; + $q = "UPDATE " . TB_PREFIX . "vdata SET ".implode(',', $pairs)." WHERE wref IN($ids)"; }else{ $q = " UPDATE ".TB_PREFIX."vdata SET - exp1 = IF(exp1 = $id, 0, exp1), - exp2 = IF(exp2 = $id, 0, exp2), - exp3 = IF(exp3 = $id, 0, exp3) + exp1 = IF(exp1 IN($ids), 0, exp1), + exp2 = IF(exp2 IN($ids), 0, exp2), + exp3 = IF(exp3 IN($ids), 0, exp3) WHERE - exp1 = $id OR - exp2 = $id OR - exp3 = $id"; + exp1 IN($ids) OR + exp2 IN($ids) OR + exp3 IN($ids)"; } mysqli_query($this->dblink, $q); } @@ -5774,16 +5995,31 @@ References: User ID/Message ID, Mode return $this->getAllMember($aid, 1); } - function addUnits($vid) { - if (!is_array($vid)) { - $vid = [$vid]; - } + /** + * Add the unit table(s) and troops if presents + * + * @param mixed $vid The villaged ID(s) + * @param array $troopsArray divided in two portion, which contains the types (unidimensional array) and the values of the + * troops that need to be added (bidimensional array) + * @return bool Returns true if the query was successful, false otherwise + */ + + function addUnits($vid, $troopsArray = null) { + list($vid, $type, $values) = $this->escape_input($vid, $type, $values); + + if (!is_array($vid)) $vid = [$vid]; + $types = $values = ""; + + if($troopsArray != null){ + $types = $troopsArray[0]; + $values = $troopsArray[1]; + + $types = ",u".implode(",u", $types); + } + + foreach ($vid as $index => $vidValue) $vid[$index] = (int) $vidValue.($troopsArray != null ? ",".implode(",", $values[$index]) : ""); - foreach ($vid as $index => $vidValue) { - $vid[$index] = (int) $vidValue; - } - - $q = "INSERT into " . TB_PREFIX . "units (vref) values (".implode('),(', $vid).")"; + $q = "INSERT into " . TB_PREFIX . "units (vref$types) values (".implode('),(', $vid).")"; return mysqli_query($this->dblink,$q); } @@ -7039,64 +7275,6 @@ References: User ID/Message ID, Mode return $this->mysqli_fetch_all($result)[0]; } - /** - * Creates villages and puts the desired artifacts in it - * - * @param array $artifactArrays The array containing the artifacts to insert - * @param int $uid The owner's user ID (Natars) - */ - - function addArtifactVillages($artifactArrays, $uid = 3) { - list($artifactArrays, $uid) = $this->escape_input($artifactArrays, (int) $uid); - - foreach($artifactArrays as $desc => $artifactType){ - foreach($artifactType as $artifact){ - for($i = 0; $i < $artifact['quantity']; $i++){ - $kid = rand(1, 4); - $wid = $this->generateBase($kid, 1); - $this->addArtefact($wid, $uid, $artifact['type'], $artifact['size'], $artifact['name'], $desc, $artifact['effect'], "type".$artifact['img'].".gif"); - $this->setFieldTaken($wid); - $this->addVillage($wid, $uid, $artifact['vname'], 0); - $this->addResourceFields($wid, $this->getVillageType($wid)); - $this->addUnits($wid); - $this->addTech($wid); - $this->addABTech($wid); - - //Set the population to 163 and the name of the village - $this->setVillageFields($wid, ['pop', 'name'], [163, $artifact['vname']]); - - //Set the unit arrays (1, 2 or 4) - $multiplier = $artifact['size'] == 3 ? 4 : $artifact['size']; - $unitArrays = [41 => rand(1000 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, - 42 => rand(1500 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, - 43 => rand(2300 * $multiplier, 2800 * $multiplier) * NATARS_UNITS, - 44 => rand(25 * $multiplier, 75 * $multiplier) * NATARS_UNITS, - 45 => rand(1200 * $multiplier, 1900 * $multiplier) * NATARS_UNITS, - 46 => rand(1500 * $multiplier, 2000 * $multiplier) * NATARS_UNITS, - 47 => rand(500 * $multiplier, 900 * $multiplier) * NATARS_UNITS, - 48 => rand(100 * $multiplier, 300 * $multiplier) * NATARS_UNITS, - 49 => rand(1 * $multiplier, 5 * $multiplier) * NATARS_UNITS, - 50 => rand(1 * $multiplier, 5 * $multiplier) * NATARS_UNITS]; - - //Set the buildings and their levels - $buildingArrays = [ - //Treasury of the 20th level, Residence of the 10th level, Rally Point of the 1th level - "f22t" => 27, "f22" => 20, "f28t" => 25, "f28" => 10, "f39t" => 16, "f39" => 1, - //18 Cranny of the 10th level - "f19t" => 23, "f19" => 10, "f20t" => 23, "f20" => 10, "f21t" => 23, "f21" => 10, - "f23t" => 23, "f23" => 10, "f24t" => 23, "f24" => 10, "f25t" => 23, "f25" => 10, - "f26t" => 23, "f26" => 10, "f27t" => 23, "f27" => 10, "f29t" => 23, "f29" => 10, - "f30t" => 23, "f30" => 10, "f31t" => 23, "f31" => 10, "f32t" => 23, "f32" => 10, - "f33t" => 23, "f33" => 10, "f34t" => 23, "f34" => 10, "f35t" => 23, "f35" => 10, - "f36t" => 23, "f36" => 10, "f37t" => 23, "f37" => 10, "f38t" => 23, "f38" => 10]; - - $this->modifyUnit($wid, array_keys($unitArrays), array_values($unitArrays), [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - $this->setVillageLevel($wid, array_keys($buildingArrays), array_values($buildingArrays)); - } - } - } - } - /** * Display a system message to all players * @@ -7117,120 +7295,6 @@ References: User ID/Message ID, Mode $this->setUsersOk(); } - /** - * Called when Natars account has been created - * - * @param int $wid The village ID of the Natars' capital - */ - - function scoutAllPlayers($wid){ - list($wid) = $this->escape_input((int) $wid); - - $array = $this->getProfileVillages(0, 1); - $refs = []; - $vils = []; - - foreach($array as $vill){ - $refs[] = $this->addAttack($wid, 0, 0, 0, 1500 * NATARS_UNITS, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 0); - $vils[] = $vill['wref']; - } - - $type = []; - $from = []; - $to = []; - $ref = []; - $time = []; - $timeValue = time(); - $endtime = []; - $endtimeValue = $timeValue + round(10000 / SPEED); - $counter = 0; - - foreach ($refs as $index => $refID) { - $type[] = 3; - $from[] = $wid; - $to[] = $vils[$index]; - $ref[] = $refID; - $time[] = $timeValue; - $endtime[] = $endtimeValue; - - // limit the insert, so it can push through any reasonable network limits imposed - if (++$counter > 25) { - $this->addMovement($type, $from, $to, $ref, $time, $endtime); - - $type = []; - $from = []; - $to = []; - $ref = []; - $time = []; - $endtime = []; - $counter = 0; - } - } - - if ($counter > 0) $this->addMovement($type, $from, $to, $ref, $time, $endtime); - } - - /** - * Called when Natars account have to be created, creates his account and capital village - * - */ - - function createNatars(){ - - //Create the Natars account - $username = "Natars"; - $password = $this->getUserField(5, 'password', 0); - $email = "natars@noreply.com"; - $uid = 3; - $tribe = 5; - $desc = "************************** - [#natars] - **************************"; - - $q = "INSERT INTO ".TB_PREFIX."users (id, username, password, access, email, timestamp, tribe, protect, desc2) VALUES ('$uid', '$username', '$password', ".USER.", '$email', ".time().", $tribe, 0, '$desc')"; - mysqli_query($this->dblink, $q); - - //Coordinate arrays of possible villages - $arrayXY = [[WORLD_MAX, WORLD_MAX], - [WORLD_MAX, -WORLD_MAX], - [-WORLD_MAX, -WORLD_MAX], - [WORLD_MAX - 1, WORLD_MAX], - [WORLD_MAX, WORLD_MAX - 1], - [-WORLD_MAX, WORLD_MAX - 1], - [WORLD_MAX - 1, -WORLD_MAX], - [WORLD_MAX - 1, WORLD_MAX - 1], - [WORLD_MAX, -WORLD_MAX + 1], - [WORLD_MAX - 1, -WORLD_MAX + 1], - [-WORLD_MAX + 1, -WORLD_MAX + 1], - [WORLD_MAX - 2, WORLD_MAX], - [WORLD_MAX - 2, -WORLD_MAX], - [WORLD_MAX - 2, WORLD_MAX - 1], - [WORLD_MAX - 1, WORLD_MAX - 2], - [-WORLD_MAX + 2, WORLD_MAX], - [-WORLD_MAX + 2, WORLD_MAX - 1], - [-WORLD_MAX + 2, -WORLD_MAX + 2]]; - - //Search if there's one spot left - for($i = 0; $i <= 17; $i++){ - $wid = $this->getVilWref($arrayXY[$i][0], $arrayXY[$i][1]); - $status = $this->getVillageState($wid); - if($status == 0){ - //The village isn't taken, let's occupy it - $this->generateVillages([['wid' => $wid, 'kid' => 0, 'capital' => 1]], $uid, $username); - break; - } - } - - //All villages are taken, then select a random village - if($status > 0) $wid = $this->generateVillages([['wid' => 0, 'kid' => 0, 'capital' => 1]], $uid, $username); - - //Set the capital pop to 834 - $this->setVillageField($wid, 'pop', 834); - - //Scouts all players - $this->scoutAllPlayers($wid); - } - /** * Called when a system message is sent or Natars/Artifacts have been spawned * @@ -7245,10 +7309,18 @@ References: User ID/Message ID, Mode return mysqli_query($this->dblink, $q); } - function addArtefact($vref, $owner, $type, $size, $name, $desc, $effect, $img) { - list($vref, $owner, $type, $size, $name, $desc, $effect, $img) = $this->escape_input($vref, $owner, $type, $size, $name, $desc, $effect, $img); + function addArtefacts($wids, $artifactsArray) { + list($wids, $artifactsArray) = $this->escape_input($wids, $artifactsArray); - $q = "INSERT INTO `" . TB_PREFIX . "artefacts` (`vref`, `owner`, `type`, `size`, `conquered`, `name`, `desc`, `effect`, `img`, `active`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img', '0')"; + if(!is_array($wids)) $wids = [$wids]; + + $time = time(); + + foreach($artifactsArray as $index => $artifact){ + $values[] = "(".$wids[$index].",".$artifact['owner'].",".$artifact['type'].",".$artifact['size'].",".$time.",'".$artifact['name']."','".$artifact['desc']."','".$artifact['effect']."','".$artifact['img']."', 0)"; + } + + $q = "INSERT INTO `" . TB_PREFIX . "artefacts` (`vref`, `owner`, `type`, `size`, `conquered`, `name`, `desc`, `effect`, `img`, `active`) VALUES ".implode(",", $values); return mysqli_query($this->dblink, $q); } @@ -7287,16 +7359,20 @@ References: User ID/Message ID, Mode return (self::$artefactInfoByTypeCache[$vref]); } - // no need to cache this method - function getOwnArtefactInfo3($uid) { - // load the data - type and size are irrelevant, since the method caches all data - // then returns the one for our type and size - $this->getOwnUniqueArtefactInfo($uid, 1, 1); + // no need to cache this method since its called one time only + function getOwnArtefactsInfo($uid) { + list($uid) = $this->escape_input((int) $uid); + + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $uid AND del = 0"; + $result = mysqli_query($this->dblink, $q); - // return what we've cached - return (self::$artefactInfoSimpleCache[$uid]); + return $this->mysqli_fetch_all($result); } + function getOwnArtefactInfoByType2($vref, $type, $use_cache = true) { + return $this->getOwnArtefactInfoByType($vref, $type, $use_cache); + } + function getOwnArtefactInfoByType($vref, $type, $use_cache = true) { $vref = (int) $vref; $type = (int) $type; @@ -7331,40 +7407,6 @@ References: User ID/Message ID, Mode return (isset(self::$artefactInfoByTypeCache[$vref][$type]) ? self::$artefactInfoByTypeCache[$vref][$type] : []); } - function getOwnArtefactInfoByType2($vref, $type, $use_cache = true) { - return $this->getOwnArtefactInfoByType($vref, $type, $use_cache); - } - - function getOwnUniqueArtefactInfo($id, $type, $size, $use_cache = true) { - list($id, $type, $size) = $this->escape_input((int) $id, (int) $type, (int) $size); - - // first of all, check if we should be using cache and whether the field - // required is already cached - if ($use_cache && isset(self::$artefactInfoSimpleCache[$id]) && is_array(self::$artefactInfoSimpleCache[$id]) && !count(self::$artefactInfoSimpleCache[$id])) { - return []; - } else if ($use_cache && ($cachedValue = self::returnCachedContent(self::$artefactInfoSimpleCache, $id)) && !is_null($cachedValue)) { - return (isset($cachedValue[$type.$size]) ? $cachedValue[$type.$size] : []); - } - - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND del = 0"; - $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::$artefactInfoSimpleCache[$arteInfo['owner']])) { - self::$artefactInfoSimpleCache[$arteInfo['owner']] = []; - } - - self::$artefactInfoSimpleCache[$arteInfo['owner']][$arteInfo['type'].$arteInfo['size']] = $arteInfo; - } - } else { - self::$artefactInfoSimpleCache[$id] = []; - } - - return (isset(self::$artefactInfoSimpleCache[$id][$type.$size]) ? self::$artefactInfoSimpleCache[$id][$type.$size] : []); - } - function getOwnUniqueArtefactInfo2($id, $type, $size, $mode, $use_cache = true) { list($id, $type, $size, $mode) = $this->escape_input((int) $id, (int) $type, (int) $size, $mode); @@ -7396,18 +7438,15 @@ References: User ID/Message ID, Mode } /** - * Delete an artifact - * - * @param int $id The artifact ID - * @return bool Return true if the query was successful, false otherwise + * Get deleted artifacts + * + * @return array Returns the deleted artifacts */ - function deleteArtifact($id){ - list($id) = $this->escape_input((int) $id); - - $q = "UPDATE " . TB_PREFIX . "artefacts SET del = 1 WHERE id = $id"; - - return mysqli_query($this->dblink, $q); + function getDeletedArtifacts(){ + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE del = 1"; + $result = mysqli_query($this->dblink, $q); + return $this->mysqli_fetch_all($result); } function villageHasArtefact($vref) { @@ -7472,6 +7511,21 @@ References: User ID/Message ID, Mode return mysqli_query($this->dblink, $q); } + /** + * @param mixed $size The integer/array which contains the artifacts size(s) + * @return int Returns if there are at least one not deleted artifact + */ + + function getArtifactsBysize($size){ + list($size) = $this->escape_input($size); + + if(!is_array($size)) $size = [$size]; + + $q = "SELECT * FROM ".TB_PREFIX."artefacts WHERE size IN(".implode(',', $size).") AND del = 0 ORDER BY id ASC"; + $result = mysqli_query($this->dblink, $q); + return $this->mysqli_fetch_all($result); + } + /** * @param bool $mode true: check if WW Building plans are already out, false: check if artifacts are already out * @return int Returns if artifacts are already out or not @@ -7612,14 +7666,40 @@ References: User ID/Message ID, Mode else return "Max num. of artefacts. Your hero could not claim the artefact"; } - // no need to cache this method - function getArtefactDetails($id) { - list($id) = $this->escape_input((int) $id); + /** + * Get the informations of a single artifact + * + * @param int $id The artifact id + * @param int $del If 0, it will search not-deleted artifacts, and vice versa with 1 + * @return array Returns the artefact informations + */ + + function getArtefactDetails($id, $del = 0) { + list($id, $del) = $this->escape_input((int) $id, (int) $del); - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = ".$id." AND del = 0 LIMIT 1"; + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = ".$id." AND del = ".$del." LIMIT 1"; $result = mysqli_query($this->dblink,$q); return mysqli_fetch_array($result); } + + /** + * Update an artifact with a specified fields => values array + * + * @param int $id The artifact ID + * @param array $detailsArray Contains the fields to update and the relative values + * @return bool Returns true if the query was successful, false otherwise + */ + + function updateArtifactDetails($id, $detailsArray){ + list($id, $detailsArray) = $this->escape_input((int) $id, $detailsArray); + + $values = []; + foreach($detailsArray as $field => $value) $values[] = $field."=".$value; + + $q = "UPDATE ".TB_PREFIX."artefacts SET ".implode(",", $values)." WHERE id = $id"; + echo $q; + return mysqli_query($this->dblink, $q); + } // no need to cache this method function getMovementById($id) { @@ -7945,7 +8025,7 @@ References: User ID/Message ID, Mode return mysqli_query($this->dblink,$q); } - function getPrisoners($wid,$mode = 0, $use_cache = true) { + function getPrisoners($wid, $mode = 0, $use_cache = true) { $array_passed = is_array($wid); $mode = (int) $mode; @@ -8054,21 +8134,21 @@ References: User ID/Message ID, Mode return self::$prisonersCacheByID[$id]; } - function getPrisoners3($from, $use_cache = true) { //change all this function arrange Dayran prisoners - list($from) = $this->escape_input((int) $from); - - // first of all, check if we should be using cache and whether the field - // required is already cached - if ($use_cache && ($cachedValue = self::returnCachedContent(self::$prisonersCacheByVillageAndFromIDs, $from)) && !is_null($cachedValue)) { - return $cachedValue; - } - - $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from"; - $result = mysqli_query($this->dblink,$q); - - self::$prisonersCacheByVillageAndFromIDs[$wid.$from] = $this->mysqli_fetch_all($result); - return self::$prisonersCacheByVillageAndFromIDs[$from]; - }//hasta aki + function getPrisoners3($from, $use_cache = true) { + list($from) = $this->escape_input((int) $from); + + // first of all, check if we should be using cache and whether the field + // required is already cached + if ($use_cache && ($cachedValue = self::returnCachedContent(self::$prisonersCacheByVillageAndFromIDs, $from)) && !is_null($cachedValue)) { + return $cachedValue; + } + + $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from"; + $result = mysqli_query($this->dblink,$q); + + self::$prisonersCacheByVillageAndFromIDs[$wid.$from] = $this->mysqli_fetch_all($result); + return self::$prisonersCacheByVillageAndFromIDs[$from]; + } function deletePrisoners($id) { if (!is_array($id)) { diff --git a/Templates/Build/27_1.tpl b/Templates/Build/27_1.tpl index 03775d30..1a888691 100644 --- a/Templates/Build/27_1.tpl +++ b/Templates/Build/27_1.tpl @@ -1,7 +1,10 @@ getOwnArtefactInfo3($session->uid); +include_once("GameEngine/Artifacts.php"); + +$ownArtifacts = $database->getOwnArtefactsInfo($session->uid); $wref = $village->wid; $coor = $database->getCoor($wref); + ?>
    @@ -21,31 +24,21 @@ $coor = $database->getCoor($wref); '.ANY_ARTIFACTS.''; +if (empty($ownArtifacts)) echo ''.ANY_ARTIFACTS.''; else { - foreach($artefact1 as $artefact){ - $coor2 = $database->getCoor($artefact['vref']); - if($artefact['size'] == 1 && $artefact['type'] != 11){ - $reqlvl = 10; - $effect = "village"; - }else{ - if($artefact['type'] != 11){ - $reqlvl = 20; - }else{ - $reqlvl = 10; - } - $effect = "account"; - } - echo ''; + foreach($ownArtifacts as $ownArtifact){ + $coor2 = $database->getCoor($ownArtifact['vref']); + $ownArtifactInfo = Artifacts::getArtifactInfo($ownArtifact); + echo ''; echo ' -' . $artefact['name'] . ' ' . $artefact['effect'] . ' -
    -Treasury ' . $reqlvl . ', Effect ' . $effect . ' -
    -'; - echo '' . $database->getVillageField($artefact['vref'], "name") . ''; - echo '' . date("d.m.Y H:i", $artefact['conquered']) . ''; + ' . $ownArtifact['name'] . ' ' . $ownArtifact['effect'] . ' +
    + Treasury '.$ownArtifactInfo['requiredLevel'].', Effect '.$ownArtifactInfo['effectInfluence'].' +
    + '; + echo '' . $database->getVillageField($ownArtifact['vref'], "name") . ''; + echo ''.date("d.m.Y H:i", $ownArtifact['conquered']) . ''; } } @@ -72,41 +65,35 @@ Treasury ' . $reqlvl . ', Effect ' . $effect . ' dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "artefacts WHERE del = 0"), MYSQLI_ASSOC); -$count = $count['Total']; -if($count == 0) echo ''.NO_ARTIFACTS_AREA.''; -else -{ - $arts = mysqli_query($database->dblink,"SELECT type, vref, id, name, size, owner, effect FROM " . TB_PREFIX . "artefacts WHERE del = 0"); +$artifacts = $database->getArtifactsBysize([1, 2, 3]); +if(count($artifacts) == 0) echo ''.NO_ARTIFACTS_AREA.''; +else +{ $rows = []; - while($row = mysqli_fetch_array($arts)) { - $query = mysqli_query($database->dblink,'SELECT x, y FROM `' . TB_PREFIX . 'wdata` WHERE `id` = ' . (int) $row['vref']); - $coor2 = mysqli_fetch_assoc($query); - $dist = $database->getDistance($coor['x'], $coor['y'], $coor2['x'], $coor2['y']); - $rows[$dist] = $row; + foreach($artifacts as $artifact){ + $coordinates = $database->getCoor($artifact['vref']); + + $distance = $database->getDistance($village->coor['x'], $village->coor['y'], $coordinates['x'], $coordinates['y']); + $rows[(string)$distance] = $artifact; } + ksort($rows); - foreach($rows as $row) { - $wref = $village->wid; - $coor = $database->getCoor($wref); - $wref2 = $row['vref']; - $coor2 = $database->getCoor($wref2); - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . ''; - echo '
    '; - if($row['size'] == 1 && $row['type'] != 11){ - $reqlvl = 10; - $effect = VILLAGE; - }else{ - $reqlvl = $row['type'] != 11 ? 20 : 10; - $effect = ACCOUNT; - } - echo '
    '.TREASURY.' ' . $reqlvl . ', '.EFFECT.' ' . $effect . ''; - echo '
    ' . $database->getUserField($row['owner'], "username", 0) . ''; - echo ''.$database->getDistance($coor['x'], $coor['y'], $coor2['x'], $coor2['y']).''; - echo ''; + + foreach($rows as $distance => $row) { + echo ' + + + '.$row['name'].' '.$row['effect'].' +
    '; + + $artifactInfo = Artifacts::getArtifactInfo($row); + + echo '
    '.TREASURY.' '.$artifactInfo['requiredLevel'] . ', '.EFFECT.' '.$artifactInfo['effectInfluence'].' +
    + '.$database->getUserField($row['owner'], "username", 0).' + + '.$distance.' + '; } } diff --git a/Templates/Build/27_2.tpl b/Templates/Build/27_2.tpl index c296e6b4..7e6289df 100644 --- a/Templates/Build/27_2.tpl +++ b/Templates/Build/27_2.tpl @@ -30,161 +30,27 @@ dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "artefacts WHERE del = 0"), MYSQLI_ASSOC); - $count = $count['Total']; - if($count == 0) echo ''.NO_ARTIFACTS.''; - else - { - - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 1 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 2 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 3 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 4 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 5 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 6 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 7 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 1 AND type = 8 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - ?> - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE type = 11 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 10, '.EFFECT.' '.VILLAGE.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - } + $artifactsArray = $database->getArtifactsBysize(1); + if(count($artifactsArray) == 0) { + echo ''.NO_ARTIFACTS.''; + } else { + $previous = ""; + foreach($artifactsArray as $artifact){ + + if($previous != "" && $previous != $artifact['type']) echo ''; + $previous = $artifact['type']; + + echo ' + + + '.$artifact['name'] . ' '.$artifact['effect'].'
    '.TREASURY.' 10, '.EFFECT.' '.ACCOUNT.'
    + + '.$database->getUserField($artifact['owner'], "username", 0).' + '.$database->getAllianceName($database->getUserField($artifact['owner'], "alliance", 0)).' + '; + } + } ?> diff --git a/Templates/Build/27_3.tpl b/Templates/Build/27_3.tpl index 345408e4..0d788792 100644 --- a/Templates/Build/27_3.tpl +++ b/Templates/Build/27_3.tpl @@ -31,260 +31,27 @@ dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "artefacts WHERE del = 0"), MYSQLI_ASSOC); - $count = $count['Total']; - if($count == 0) { - echo ''.NO_ARTIFACTS.''; - } else { - //TODO: Merge this in a unique foreach - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 1 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 1 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - + $artifactsArray = $database->getArtifactsBysize([2, 3]); + if(count($artifactsArray) == 0) { + echo ''.NO_ARTIFACTS.''; + } else { + $previous = ""; + foreach($artifactsArray as $artifact){ + + if($previous != "" && $previous != $artifact['type']) echo ''; + $previous = $artifact['type']; + + echo ' + + + '.$artifact['name'] . ' '.$artifact['effect'].'
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    + + '.$database->getUserField($artifact['owner'], "username", 0).' + '.$database->getAllianceName($database->getUserField($artifact['owner'], "alliance", 0)).' + '; + } + } ?> - - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 2 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 2 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 3 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 3 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 4 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 4 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 5 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 5 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 6 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 6 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 2 AND type = 7 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - - unset($artefact); - unset($row); - $artefact = mysqli_query($database->dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 7 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - -?> - - - dblink,"SELECT type, id, name, effect, vref, owner FROM `" . TB_PREFIX . "artefacts` WHERE size = 3 AND type = 8 AND del = 0"); - while($row = mysqli_fetch_array($artefact)) { - echo ''; - echo ''; - echo ''; - echo '' . $row['name'] . ' ' . $row['effect'] . '
    '.TREASURY.' 20, '.EFFECT.' '.ACCOUNT.'
    '; - echo ''; - echo '' . $database->getUserField($row['owner'], "username", 0) . ''; - echo '' . $database->getAllianceName($database->getUserField($row['owner'], "alliance", 0)) . ''; - echo ''; - } - } -?> - -getUserField($artifact['owner'], "username", 0);?> +getUserField($artifact['owner'], "username", 0)) != "[?]"){?> + + +[?] + @@ -38,7 +42,7 @@ $artifactInfo = Artifacts::getArtifactInfo($artifact); checkVilExist($artifact['vref'])){?> getVillageField($artifact['vref'], "name");?> -[?] +[?] @@ -103,7 +107,13 @@ if(!empty($owners)){ foreach($owners as $owner){ ?> -getUserField($owner['uid'], "username", 0);?> + +getUserField($owner['uid'], "username", 0)) != "[?]"){?> + + +[?] + + checkVilExist($owner['vref'])){?> getVillageField($owner['vref'], "name");?> diff --git a/Templates/Build/avaliable.tpl b/Templates/Build/avaliable.tpl index e16df07d..8e37bb1f 100644 --- a/Templates/Build/avaliable.tpl +++ b/Templates/Build/avaliable.tpl @@ -1,6 +1,6 @@ getOwnArtefactInfoByType($village->wid,6); -$largeA = $database->getOwnUniqueArtefactInfo($session->uid,6,2); +$artifactsSum = $database->getArtifactsSumByKind($session->uid, $village->wid, 6); +$GreatGranaryWarehouseBuildable = $artifactsSum['small'] > 0 || $artifactsSum['large'] > 0; $mainbuilding = $building->getTypeLevel(15); $cranny = $building->getTypeLevel(23); @@ -130,10 +130,10 @@ if($wall == 0 && $wall1 == 0) { if((($warehouse == 0 && $warehouse1 == 0) || $warehouse == 20) && $mainbuilding >= 1 && $id != 39 && $id != 40) { include("avaliable/warehouse.tpl"); } -if((($greatwarehouse == 0 && $greatwarehouse1 == 0) || $greatwarehouse == 20) && $mainbuilding >= 10 && ($largeA['owner'] == $session->uid || $normalA['vref'] == $village->wid || $village->natar==1) && ($id != 39 && $id != 40)) { +if((($greatwarehouse == 0 && $greatwarehouse1 == 0) || $greatwarehouse == 20) && $mainbuilding >= 10 && ($GreatGranaryWarehouseBuildable || $village->natar == 1) && ($id != 39 && $id != 40)) { include("avaliable/greatwarehouse.tpl"); } -if((($greatgranary == 0 && $greatgranary1 == 0) || $greatgranary == 20) && $mainbuilding >= 10 && ($largeA['owner'] == $session->uid || $normalA['vref'] == $village->wid || $village->natar==1) && ($id != 39 && $id != 40)) { +if((($greatgranary == 0 && $greatgranary1 == 0) || $greatgranary == 20) && $mainbuilding >= 10 && ($GreatGranaryWarehouseBuildable || $village->natar == 1) && ($id != 39 && $id != 40)) { include("avaliable/greatgranary.tpl"); } if((($trapper == 0 && $trapper1 == 0) || $trapper == 20) && $rallypoint >= 1 && $session->tribe == 3 && $id != 39 && $id != 40) { @@ -232,10 +232,10 @@ if($id != 39 && $id != 40) { if($rallypoint == 0 && $session->tribe == 3 && $trapper == 0 ) { include("soon/trapper.tpl"); } -if($mainbuilding < 10 && $warehouse < 10 && $village->capital == 0 && $largeA['owner'] == $session->uid || $normalA['vref'] == $village->wid ) { +if($mainbuilding < 10 && $warehouse < 10 && $village->capital == 0 && $GreatGranaryWarehouseBuildable) { include("soon/greatwarehouse.tpl"); } -if($mainbuilding < 10 && $granary < 10 && $village->capital == 0 && $largeA['owner'] == $session->uid || $normalA['vref'] == $village->wid ) { +if($mainbuilding < 10 && $granary < 10 && $village->capital == 0 && $GreatGranaryWarehouseBuildable) { include("soon/greatgranary.tpl"); } if($hero == 0 && ($mainbuilding <= 2 || $rallypoint == 0)){ diff --git a/img/admin/acc.gif b/img/admin/acc.gif new file mode 100644 index 0000000000000000000000000000000000000000..d9f435e0b3cd61ec77e180af5625b983f62920a5 GIT binary patch literal 77 zcmZ?wbhEHb