make automate regenerate troops system (now admin not need to make it every time)

This commit is contained in:
unknown
2012-06-29 04:18:33 +03:00
parent 1d422fe97a
commit 2d86383e81
5 changed files with 84 additions and 4 deletions
+1 -2
View File
@@ -126,8 +126,7 @@ $timeformat = new timeFormatGenerator;
<a href="?p=givePlusRes">Give All Res Bonus</a>
<a href="?p=maintenenceResetPlusBonus">Reset Res Bonus</a>
<br />
<a href="#"><b>Natars & Nature</b></a>
<a href="?p=oasis">Populate Oases</b>
<a href="#"><b>Natars</b></a>
<a href="?p=natarend">Add WW Villages</a>
<a href="?p=natarbuildingplan">Add WW Buildingplan Villages</a>
<br />
+21
View File
@@ -207,6 +207,7 @@ class Automation {
$this->updateStore();
$this->procClimbers();
$this->CheckBan();
$this->regenerateOasisTroops();
}
private function loyaltyRegeneration() {
@@ -3909,6 +3910,26 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
}
}
private function regenerateOasisTroops() {
global $database;
$time = time();
$max = rand(1,4);
if($max == 1){
$max2 = 3600;
}elseif($max == 2){
$max2 = 21600;
}elseif($max == 3){
$max2 = 43200;
}elseif($max == 4){
$max2 = 86400;
}
$q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = 0 and $time - lastupdated > $max2";
$array = $database->query_return($q);
foreach($array as $oasis) {
$database->populateOasisUnits($oasis['wref'],$oasis['high']);
$database->updateOasis($oasis['wref']);
}
}
}
$automation = new Automation;
?>
+61 -1
View File
@@ -508,6 +508,65 @@ class MYSQL_DB {
}
}
function populateOasisUnits($wid, $high) {
$basearray = $this->getMInfo($wid);
$basearray = $this->getOasisInfo($wid);
if($basearray2['high'] == 0){
$max = rand(15,30);
}elseif($basearray2['high'] == 1){
$max = rand(70,90);
}elseif($basearray2['high'] == 2){
$max = rand(100,140);
}
//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']) {
case 1:
case 2:
//+25% lumber per hour
$q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 3:
//+25% lumber and +25% crop per hour
$q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 4:
case 5:
//+25% clay per hour
$q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 6:
//+25% clay and +25% crop per hour
$q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 7:
case 8:
//+25% iron per hour
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 9:
//+25% iron and +25% crop
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 10:
case 11:
//+25% crop per hour
$q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
case 12:
//+50% crop per hour
$q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
$result = mysql_query($q, $this->connection);
break;
}
}
function populateOasisUnitsLow() {
$q2 = "SELECT * FROM " . TB_PREFIX . "odata where conqured = 0";
$result2 = mysql_query($q2, $this->connection);
@@ -2712,6 +2771,7 @@ class MYSQL_DB {
return false;
}
}
function populateOasisdata() {
$q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
$result2 = mysql_query($q2, $this->connection);
@@ -2719,7 +2779,7 @@ class MYSQL_DB {
$wid = $row['id'];
$basearray = $this->getOMInfo($wid);
//We switch type of oasis and instert record with apropriate infomation.
$q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,400,400,400,400,400,400," . time() . ",100,2,'Unoccupied Oasis')";
$q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,400,400,400,400,400,400," . time() . ",100,2,'Unoccupied Oasis',".rand(0,2).")";
$result = mysql_query($q, $this->connection);
}
}
-1
View File
@@ -45,7 +45,6 @@ div.c1 {text-align: center}
echo "<a href=\"medals.php\">Update Top 10</a>";
echo "<a href=\"sysmsg.php\">System message</a>";
echo "<a href=\"create_account.php\">Create Natars</a>";
echo "<a href=\"oasis_populate.php\"><font color=\"blue\">Populate Oasis</font></a>";
} ?> <a href="logout.php"><?php echo LOGOUT; ?></a></p>
<a href="rules.php"><b>Game Rules</b></a>
+1
View File
@@ -1024,6 +1024,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%odata` (
`loyalty` int(11) NOT NULL DEFAULT '100',
`owner` int(11) unsigned NOT NULL DEFAULT '2',
`name` varchar(32) NOT NULL DEFAULT 'Unoccupied Oasis',
`high` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`wref`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;