From 7f1cf234b2df0ad98751c8d18a22ddbb357ad7a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jun 2012 22:15:27 +0300 Subject: [PATCH] big update (trade routes, less hungry troops artefact, somethings in hero table, fix peace reports...) --- GameEngine/Automation.php | 37 +++++++--- GameEngine/Database/db_MYSQL.php | 65 +++++++++++++++-- GameEngine/Technology.php | 13 +++- Templates/Build/17_3.tpl | 8 +- Templates/Build/17_4.tpl | 74 +++++++++++++++++++ Templates/Build/17_create.tpl | 78 ++++++++++++++++++++ Templates/Build/17_edit.tpl | 40 ++++++++++ Templates/Build/17_menu.tpl | 8 +- Templates/Build/37_hero.tpl | 1 - Templates/Notice/22.tpl | 12 +-- build.php | 121 ++++++++++++++++++++++++++++++- dorf2.php | 3 +- install/data/sql.sql | 36 ++++++++- 13 files changed, 460 insertions(+), 36 deletions(-) create mode 100644 Templates/Build/17_4.tpl create mode 100644 Templates/Build/17_create.tpl create mode 100644 Templates/Build/17_edit.tpl diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 895d0927..f08f080d 100644 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -169,6 +169,8 @@ class Automation { $this->demolitionComplete(); } $this->updateStore(); + $this->delTradeRoute(); + $this->TradeRoute(); if(!file_exists("GameEngine/Prevention/market.txt") or time()-filemtime("GameEngine/Prevention/market.txt")>10) { $this->marketComplete(); } @@ -528,9 +530,28 @@ class Automation { $cp = $dataarray[($level+1)]['cp']; return array($pop,$cp); } + + private function delTradeRoute() { + global $database; + $time = time(); + $q = "DELETE from ".TB_PREFIX."route where timeleft < $time"; + $database->query($q); + } + + private function TradeRoute() { + global $database; + $time = time(); + $q = "SELECT * FROM ".TB_PREFIX."route where timestamp < $time"; + $dataarray = $database->query_return($q); + foreach($dataarray as $data) { + $targettribe = $database->getUserField($database->getVillageField($data['from'],"owner"),"tribe",0); + $this->sendResource2($data['wood'],$data['clay'],$data['iron'],$data['crop'],$data['from'],$data['wid'],$targettribe,$data['deliveries']); + $database->editTradeRoute($data['id'],"timestamp",86400,1); + } + } private function marketComplete() { - global $database,$generator; + global $database; $ourFileHandle = @fopen("GameEngine/Prevention/market.txt", 'w'); @fclose($ourFileHandle); $time = time(); @@ -2143,13 +2164,9 @@ $crannyimg = "0){ - $unitssend_att_check=$unitssend_att.','.$data['t11']; - }else{ - $unitssend_att_check=$unitssend_att; - } + $unitssend_att= $unitssend_att1.','.$herosend_att; $speeds = array(); @@ -2172,8 +2189,8 @@ $crannyimg = "procDistanceTime($from,$to,min($speeds),1) + time(); $database->setMovementProc($data['moveid']); $database->addMovement(4,$to['wref'],$from['wref'],$data['ref'],time(),$endtime); - - $data2 = ''.$from['owner'].','.$from['wref'].','.$to['owner'].','.$owntribe.','.$unitssend_att_check.''; + $peace = PEACE; + $data2 = ''.$from['owner'].','.$from['wref'].','.$to['owner'].','.$owntribe.','.$unitssend_att.','.$peace.''; $database->addNotice($from['owner'],$to['wref'],$ownally,22,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data2,time()); $database->addNotice($to['owner'],$to['wref'],$targetally,22,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data2,time()); } @@ -3049,7 +3066,7 @@ $crannyimg = "modifyHero("lastupdate",time(),$hdata['heroid']); } - if ($hdata['experience'] > $hero_levels[$hdata['level']+1]) { + if ($hdata['experience'] > $hero_levels[$hdata['level']+1] && $hdata['level'] < 100) { mysql_query("UPDATE " . TB_PREFIX ."hero SET level = level + 1 WHERE heroid = '".$hdata['heroid']."'"); mysql_query("UPDATE " . TB_PREFIX ."hero SET points = points + 5 WHERE heroid = '".$hdata['heroid']."'"); } diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index c0f9d1a0..cab861bf 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -565,13 +565,11 @@ } function populateOasisUnitsHigh() { - $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)) { - $wid = $row['id']; - $basearray = $this->getMInfo($wid); - //each Troop is a Set for oasis type like mountains have rats spiders and snakes fields tigers elphants clay wolves so on stonger one more not so less - switch($basearray['oasistype']) { + $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; + $result2 = mysql_query($q2, $this->connection); + while($row = mysql_fetch_array($result2)) { + $wid = $row['id']; + switch($row['oasistype']) { case 1: case 2: //+25% lumber per hour @@ -1603,6 +1601,48 @@ $result = mysql_query($q, $this->connection); return $this->mysql_fetch_all($result); } + + function createTradeRoute($uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time) { + $x = "UPDATE " . TB_PREFIX . "users SET gold = gold - 2 WHERE id = ".$uid.""; + mysql_query($x, $this->connection); + $timeleft = time()+604800; + $q = "INSERT into " . TB_PREFIX . "route values (0,$uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time,$timeleft)"; + return mysql_query($q, $this->connection); + } + + function getTradeRoute($uid) { + $q = "SELECT * FROM " . TB_PREFIX . "route where uid = $uid ORDER BY timestamp ASC"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function getTradeRoute2($id) { + $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray; + } + + function getTradeRouteUid($id) { + $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['uid']; + } + + function editTradeRoute($id,$column,$value,$mode) { + if(!$mode){ + $q = "UPDATE " . TB_PREFIX . "route set $column = $value where id = $id"; + }else{ + $q = "UPDATE " . TB_PREFIX . "route set $column = $column + $value where id = $id"; + } + return mysql_query($q, $this->connection); + } + + function deleteTradeRoute($id) { + $q = "DELETE FROM " . TB_PREFIX . "route where id = $id"; + return mysql_query($q, $this->connection); + } function addBuilding($wid, $field, $type, $loop, $time, $master, $level) { $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid; @@ -2720,7 +2760,7 @@ } function getOwnArtefactInfoByType($vref, $type) { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type"; + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type order by size"; $result = mysql_query($q, $this->connection); return mysql_fetch_array($result); } @@ -2737,6 +2777,15 @@ return mysql_fetch_array($result); } + function getOwnUniqueArtefactInfo2($id, $type, $size, $mode) { + if(!$mode){ + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size"; + }else{ + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $id AND type = $type AND size=$size"; + } + return mysql_query($q, $this->connection); + } + function getArtefactInfo() { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id > 0"; $result = mysql_query($q, $this->connection); diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index a5b657c3..468af50c 100644 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -401,7 +401,18 @@ class Technology { // $unit = "hero"; // global $$unit; // $dataarray = $$unit; - $upkeep += $array['hero'] * 6; + $upkeep += $array['hero'] * 6; + $artefact = count($database->getOwnUniqueArtefactInfo2($session->uid,4,3,0)); + $artefact1 = count($database->getOwnUniqueArtefactInfo2($vid,4,1,1)); + $artefact2 = count($database->getOwnUniqueArtefactInfo2($session->uid,4,2,0)); + if($artefact > 0){ + $upkeep /= 2; + }else if($artefact1 > 1){ + $upkeep /= 2; + }else if($artefact2 > 1){ + $upkeep /= 4; + $upkeep *= 3; + } return $upkeep; } diff --git a/Templates/Build/17_3.tpl b/Templates/Build/17_3.tpl index 4b647b27..81cf171f 100644 --- a/Templates/Build/17_3.tpl +++ b/Templates/Build/17_3.tpl @@ -1,3 +1,4 @@ +gold > 2){ ?>
@@ -262,4 +263,9 @@ function testSum() {

-
\ No newline at end of file + + \ No newline at end of file diff --git a/Templates/Build/17_4.tpl b/Templates/Build/17_4.tpl new file mode 100644 index 00000000..50421b7e --- /dev/null +++ b/Templates/Build/17_4.tpl @@ -0,0 +1,74 @@ +goldclub == 1 && $database->getProfileVillages($session->uid) > 1) { ?> +
+

Marketplace level resarray['f'.$id]; ?>

+

At the Marketplace you can trade resources with other players. The higher its level, the more resources can be transported at the same time. +

+ +gold > 1){ +$routeaccess = 1; +include("17_create.tpl"); +}else if($_GET['action'] == 'editRoute' && isset($_GET['routeid']) && $_GET['routeid'] != ""){ +$traderoute = $database->getTradeRouteUid($_GET['routeid']); +if($traderoute == $session->uid){ +include("17_edit.tpl"); +} +}else{ +?> + +

Trade route allows you to set up routes for your merchant that he will walk every day at a certain hour.

+Standard this holds on for 7 days, but you can extend it with 7 days for the cost of Gold2.

+ + + + + + + + + + +getTradeRoute($session->uid); + if(count($routes) == 0) { + echo ""; + }else{ +foreach($routes as $route){ +?> + + + + + + + + + + +
descriptionstartMerchantstime left
No active trade route.
+getMapCheck($route['wid']).">".$database->getVillageField($route['wid'],"name")."" +?> + 9){ echo $route['start'];}else{ echo "0".$route['start'];} echo ":00"; ?>
+ + extend* + | edit + | delete +
+ * Extend the trade route by 7 days for Gold2 +
+ +
+ \ No newline at end of file diff --git a/Templates/Build/17_create.tpl b/Templates/Build/17_create.tpl new file mode 100644 index 00000000..59c4617a --- /dev/null +++ b/Templates/Build/17_create.tpl @@ -0,0 +1,78 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Create trade route
+ target village: + + +
+ Resources: + Lumber Clay Iron Crop +
+ start time: + +
+ deliveries: + +
+ costs: + Gold 2 +
+ Duration: + 7 days +
+ +
+
+

+
+ \ No newline at end of file diff --git a/Templates/Build/17_edit.tpl b/Templates/Build/17_edit.tpl new file mode 100644 index 00000000..393578d2 --- /dev/null +++ b/Templates/Build/17_edit.tpl @@ -0,0 +1,40 @@ +getTradeRoute2($_GET['routeid']); ?> +
+
+ + + + + + + + + + + + + + + + + + + + + +
Edit trade route
+ Resources: + Lumber Clay Iron Crop +
+ start time: + +
+ deliveries: + +
+ +
+
+

+
+ \ No newline at end of file diff --git a/Templates/Build/17_menu.tpl b/Templates/Build/17_menu.tpl index b2c09223..99966193 100644 --- a/Templates/Build/17_menu.tpl +++ b/Templates/Build/17_menu.tpl @@ -2,10 +2,16 @@ ">Send Resouces | >Buy | >Offer - userinfo['gold'] > 3) { + userinfo['gold'] > 2) { ?> | >NPC trading + goldclub == 1 && $database->getProfileVillages($session->uid) > 1) { + ?> + | >trade routes + \ No newline at end of file diff --git a/Templates/Build/37_hero.tpl b/Templates/Build/37_hero.tpl index e6db4a3a..2350a21c 100644 --- a/Templates/Build/37_hero.tpl +++ b/Templates/Build/37_hero.tpl @@ -21,7 +21,6 @@ include_once("GameEngine/Data/hero_full.php"); ?> = 495000) { - mysql_query("UPDATE ".TB_PREFIX."hero SET `level` = 100 where `uid`='".$session->uid."'"); ?> diff --git a/Templates/Notice/22.tpl b/Templates/Notice/22.tpl index 0d6a2d16..1916eb01 100644 --- a/Templates/Notice/22.tpl +++ b/Templates/Notice/22.tpl @@ -1,20 +1,20 @@ readingNotice['data']); if(isset($dataarray[14]) and $dataarray[14]!=0){$colspan="11";}else{$colspan="10";} -if(PEACE == 1){ +if($dataarray[15] == 1){ $image = "peace"; -}else if(PEACE == 2){ +}else if($dataarray[15] == 2){ $image = "xmas"; -}else if(PEACE == 3){ +}else if($dataarray[15] == 3){ $image = "newy"; }else{ $image = "easter"; } -if(PEACE == 1){ +if($dataarray[15] == 1){ $message1 = "".$database->getUserField($dataarray[0],"username",0)." visited ".$database->getUserField($dataarray[2],"username",0)."'s troops"; -}else if(PEACE == 2){ +}else if($dataarray[15] == 2){ $message1 = "".$database->getUserField($dataarray[0],"username",0)." wishes you Merry Christmas"; -}else if(PEACE == 3){ +}else if($dataarray[15] == 3){ $message1 = "".$database->getUserField($dataarray[0],"username",0)." wishes you Happy New Year"; }else{ $message1 = "".$database->getUserField($dataarray[0],"username",0)." wishes you Happy Easter"; diff --git a/build.php b/build.php index 1056b76b..add7b357 100644 --- a/build.php +++ b/build.php @@ -49,7 +49,121 @@ if(isset($_GET['id'])) { $technology->procTechno($_GET); } } -if($session->goldclub){ +if($session->goldclub == 1 && count($session->villages) > 1){ + if(isset($_GET['routeid'])){ + $routeid = $_GET['routeid']; + } +if($routeaccess = 1){ + if(isset($_POST['action']) && $_POST['action'] == 'addRoute') { + if($session->access != BANNED){ + if($session->gold >= 2) { + for($i=1;$i<=4;$i++){ + if($_POST['r'.$i] == ""){ + $_POST['r'.$i] = 0; + } + } + $totalres = $_POST['r1']+$_POST['r2']+$_POST['r3']+$_POST['r4']; + $reqMerc = ceil(($totalres-0.1)/$market->maxcarry); + $second = date("s"); + $minute = date("i"); + $hour = date("G")-$_POST['start']; + if(date("G") > $_POST['start']){ + $day = 1; + }else{ + $day = 0; + } + $timestamp = strtotime("-$hour hours -$second second -$minute minutes +$day day"); + if($totalres > 0){ + $database->createTradeRoute($session->uid,$_POST['tvillage'],$village->wid,$_POST['r1'],$_POST['r2'],$_POST['r3'],$_POST['r4'],$_POST['start'],$_POST['deliveries'],$reqMerc,$timestamp); + header("Location: build.php?gid=17&t=4"); + $route = 1; + }else{ + header("Location: build.php?gid=17&t=4&create"); + $route = 1; + } + } + }else{ + $route = 0; + header("Location: banned.php"); + } + } + if(isset($_GET['action']) && $_GET['action'] == 'extendRoute') { + if($session->access != BANNED){ + if($session->gold >= 2) { + $traderoute = $database->getTradeRouteUid($_GET['routeid']); + if($traderoute == $session->uid){ + $database->editTradeRoute($_GET['routeid'],"timeleft",604800,1); + $newgold = $session->gold-2; + $database->updateUserField($session->uid,'gold',$newgold,1); + header("Location: build.php?gid=17&t=4"); + $route = 1; + unset($routeid); + }else{ + header("Location: build.php?gid=17&t=4"); + $route = 1; + unset($routeid); + } + }else{ + header("Location: build.php?gid=17&t=4"); + $route = 1; + } + }else{ + $route = 0; + header("Location: banned.php"); + } + } + if(isset($_POST['action']) && $_POST['action'] == 'editRoute') { + if($session->access != BANNED){ + $totalres = $_POST['r1']+$_POST['r2']+$_POST['r3']+$_POST['r4']; + $reqMerc = ceil(($totalres-0.1)/$market->maxcarry); + if($totalres > 0){ + $database->editTradeRoute($_POST['routeid'],"wood",$_POST['r1'],0); + $database->editTradeRoute($_POST['routeid'],"clay",$_POST['r2'],0); + $database->editTradeRoute($_POST['routeid'],"iron",$_POST['r3'],0); + $database->editTradeRoute($_POST['routeid'],"crop",$_POST['r4'],0); + $database->editTradeRoute($_POST['routeid'],"start",$_POST['start'],0); + $database->editTradeRoute($_POST['routeid'],"deliveries",$_POST['deliveries'],0); + $database->editTradeRoute($_POST['routeid'],"merchant",$reqMerc,0); + $second = date("s"); + $minute = date("i"); + $hour = date("G")-$_POST['start']; + if(date("G") > $_POST['start']){ + $day = 1; + }else{ + $day = 0; + } + $timestamp = strtotime("-$hour hours -$second seconds -$minute minutes +$day day"); + $database->editTradeRoute($_POST['routeid'],"timestamp",$timestamp,0); + } + header("Location: build.php?gid=17&t=4"); + $route = 1; + unset($routeid); + }else{ + $route = 0; + header("Location: banned.php"); + } + } + if(isset($_GET['action']) && $_GET['action'] == 'delRoute') { + if($session->access != BANNED){ + $traderoute = $database->getTradeRouteUid($_GET['routeid']); + if($traderoute == $session->uid){ + $database->deleteTradeRoute($_GET['routeid']); + header("Location: build.php?gid=17&t=4"); + $route = 1; + unset($routeid); + }else{ + header("Location: build.php?gid=17&t=4"); + $route = 1; + unset($routeid); + } + }else{ + $route = 0; + header("Location: banned.php"); + } + } +} +} +if($session->goldclub == 1 && $session->access != BANNED){ if(isset($_GET['t'])==99) { if($_GET['action'] == 'addList') { @@ -73,6 +187,9 @@ if($session->goldclub){ } }else{ $create = 0; +if($session->access == BANNED){ +header("Location: banned.php"); +} } if (isset($_POST['a']) == 533374 && isset($_POST['id']) == 39){ @@ -161,7 +278,7 @@ $automation->isWinner();
-

vname; ?>

- +

vname; if($village->loyalty!='100'){ if($village->loyalty>'33'){ $color="gr"; }else{ $color="re"; } ?>
loyalty); ?>%

NewBuilding) { include("Templates/Building.tpl"); diff --git a/install/data/sql.sql b/install/data/sql.sql index 6ac7addc..4f0e4538 100644 --- a/install/data/sql.sql +++ b/install/data/sql.sql @@ -789,14 +789,14 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%gold_fin_log` ( -- CREATE TABLE IF NOT EXISTS `%PREFIX%hero` ( - `heroid` smallint(2) unsigned NOT NULL AUTO_INCREMENT, - `uid` smallint(2) unsigned NOT NULL, + `heroid` int(11) unsigned NOT NULL AUTO_INCREMENT, + `uid` int(11) unsigned NOT NULL, `unit` smallint(2) unsigned NOT NULL, `name` tinytext NOT NULL, `wref` mediumint(3) unsigned NOT NULL, `level` tinyint(1) unsigned NOT NULL, - `points` smallint(2) unsigned NOT NULL, - `experience` mediumint(3) NOT NULL, + `points` mediumint(3) unsigned NOT NULL, + `experience` int(11) NOT NULL, `dead` tinyint(1) unsigned NOT NULL, `health` float(12,9) unsigned NOT NULL, `attack` tinyint(1) unsigned NOT NULL, @@ -1092,6 +1092,34 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%research` ( -- +-- -------------------------------------------------------- + +-- +-- Table structure for table `%prefix%route` +-- + +CREATE TABLE IF NOT EXISTS `%PREFIX%route` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `uid` int(11) unsigned NOT NULL, + `wid` int(11) unsigned NOT NULL, + `from` int(11) unsigned NOT NULL, + `wood` int(5) unsigned NOT NULL, + `clay` int(5) unsigned NOT NULL, + `iron` int(5) unsigned NOT NULL, + `crop` int(5) unsigned NOT NULL, + `start` tinyint(2) unsigned NOT NULL, + `deliveries` tinyint(1) unsigned NOT NULL, + `merchant` int(11) unsigned NOT NULL, + `timestamp` int(11) unsigned NOT NULL, + `timeleft` int(11) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `%prefix%route` +-- + + -- -------------------------------------------------------- --