This commit is contained in:
Shadow
2019-05-06 09:18:20 +03:00
parent 3b167c64be
commit 4c116aefea
8 changed files with 104 additions and 108 deletions
+2 -36
View File
@@ -104,7 +104,7 @@ class Automation {
if($building) $popTot += $this->buildingPOP($building, $lvl);
}
$this->recountCP($vid);
Building::recountCP($database, $vid);
$q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid";
mysqli_query($database->dblink, $q);
$owner = $database->getVillageField($vid, "owner");
@@ -113,27 +113,6 @@ class Automation {
return $popTot;
}
function recountCP($vid){
global $database;
$vid = (int) $vid;
$fdata = $database->getResourceLevel($vid);
$popTot = 0;
for ($i = 1; $i <= 40; $i++) {
$lvl = $fdata["f".$i];
$building = $fdata["f".$i."t"];
if($building){
$popTot += $this->buildingCP($building,$lvl);
}
}
$q = "UPDATE ".TB_PREFIX."vdata set cp = $popTot where wref = $vid";
mysqli_query($database->dblink,$q);
return $popTot;
}
function buildingPOP($f, $lvl){
$name = "bid".$f;
global $$name;
@@ -147,19 +126,6 @@ class Automation {
return $popT;
}
function buildingCP($f, $lvl){
$name = "bid".$f;
global $$name;
$popT = 0;
$dataarray = $$name;
for ($i = 0; $i <= $lvl; $i++) {
$popT += ((isset($dataarray[$i]) && isset($dataarray[$i]['cp'])) ? $dataarray[$i]['cp'] : 0);
}
return $popT;
}
private function loyaltyRegeneration() {
global $database;
@@ -2642,7 +2608,7 @@ class Automation {
if($data['from'] == 0){
$DefenderID = $database->getVillageField($data['to'], "owner");
$database->addEnforce($data);
$database->addEnforce(['from' => $data['from'], 'to' => $data['to'], 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 't7' => 0, 't8' => 0, 't9' => 0, 't10' => 0, 't11' => 0]);
$reinf = $database->getEnforce($data['to'], $data['from']);
$database->modifyEnforce($reinf['id'], 31, 1, 1);
$data_fail = '0,0,4,1,0,0,0,0,0,0,0,0,0,0';
+31 -4
View File
@@ -329,7 +329,7 @@ class Building {
}
private function removeBuilding($d) {
global $database, $village;
global $database, $village, $session;
foreach($this->buildArray as $jobs) {
if($jobs['id'] == $d) {
$uprequire = $this->resourceRequired($jobs['field'], $jobs['type']);
@@ -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($village->wid, 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, 1)) || 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($village->wid, 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, 1)) || 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;
@@ -749,7 +749,6 @@ class Building {
if (!isset($exclude_master) && $database->query($q) && ($enought_res == 1 || $jobs['master'] == 0)) {
$database->modifyPop($jobs['wid'],$resource['pop'],0);
$database->addCP($jobs['wid'],$resource['cp']);
$deletIDs[] = (int) $jobs['id'];
if($jobs['type'] == 18) {
$owner = $database->getVillageField($jobs['wid'],"owner");
@@ -796,10 +795,38 @@ class Building {
}
}
self::recountCP($database, $village->wid);
header("Location: ".($redirect_url ? $redirect_url : $session->referrer));
exit;
}
public static function recountCP($database, $vid){
$vid = (int) $vid;
$fdata = $database->getResourceLevel($vid);
$cpTot = 0;
for ($i = 1; $i <= 40; $i++) {
$lvl = $fdata["f".$i];
$building = $fdata["f".$i."t"];
if($building){
$cpTot += self::buildingCP($building,$lvl);
}
}
$q = "UPDATE ".TB_PREFIX."vdata set cp = $cpTot where wref = $vid";
mysqli_query($database->dblink,$q);
}
public static function buildingCP($f, $lvl){
$name = "bid".$f;
global $$name;
$dataarray = $$name;
return ((isset($dataarray[$lvl]) && isset($dataarray[$lvl]['cp'])) ? $dataarray[$lvl]['cp'] : 0);
}
public function resourceRequired($id, $tid, $plus = 1) {
$name = "bid".$tid;
global $$name, $village, $bid15, $database;
+35 -17
View File
@@ -785,9 +785,13 @@ class MYSQLi_DB implements IDbConnection {
// no need to cache this method
public function hasBeginnerProtection($vid) {
list($vid) = $this->escape_input($vid);
$q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v,".TB_PREFIX."odata o WHERE (u.id = v.owner AND v.wref = ".(int) $vid.") OR (u.id = o.owner AND o.wref = ".(int) $vid.") LIMIT 1";
list($vid) = $this->escape_input((int) $vid);
$q = "SELECT u.protect
FROM ". TB_PREFIX ."users u
JOIN ". TB_PREFIX ."vdata v ON u.id = v.owner
JOIN ". TB_PREFIX ."odata o ON u.id = o.owner
WHERE v.wref = ". $vid ." OR o.wref = ". $vid . "
LIMIT 1";
$result = mysqli_query($this->dblink,$q);
$dbarray = mysqli_fetch_array($result);
@@ -1289,7 +1293,7 @@ class MYSQLi_DB implements IDbConnection {
$daysPassedFromStart = ($time - strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME)) / 86400;
$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));
$radiusMax = min(round(pow(4 * ($daysPassedFromStart / 5 * SPEED), 2)) + pow($count, 2), pow(WORLD_MAX, 2) + pow(WORLD_MAX, 2));
break;
case 1:
@@ -1320,19 +1324,19 @@ class MYSQLi_DB implements IDbConnection {
}
switch($sector){
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"; // + | -
case 1: $newSector = "x <= 0 AND y >= 0"; break; // - | +
case 2: $newSector = "x >= 0 AND y >= 0"; break; // + | +
case 3: $newSector = "x <= 0 AND y <= 0"; break; // - | -
default: $newSector = "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";
$q = "SELECT id FROM ".TB_PREFIX."wdata WHERE fieldtype = 3 AND ($newSector) 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);
//Prevent an infinite loop
$resultedRows = mysqli_num_rows($result);
if($resultedRows == 0 && $count >= 20) break;
if($resultedRows == 0 && $count >= WORLD_MAX * 2) break;
//Fill the villages array
$villages = array_merge($villages, $this->mysqli_fetch_all($result));
@@ -1343,7 +1347,7 @@ class MYSQLi_DB implements IDbConnection {
//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);
if ($count > intval(WORLD_MAX / 10)) $sector = rand(1, 4);
}
foreach($villages as $village) $wids[] = $village['id'];
@@ -4727,12 +4731,12 @@ References: User ID/Message ID, Mode
$time = time();
$newTime = $loopTime = 0;
if(empty($fieldsArray)) $fieldsArray = $this->getResourceLevel($wid);
$jobs = $this->getJobs($wid);
$jobs = $this->getJobsOrderByID($wid);
//Search the job which needs to be deleted
foreach($jobs as $job){
//We need to modify waiting loop orders
if(!empty($jobToDelete) && $job['loopcon'] == 1 && ($tribe != 1 || $tribe == 1 && (($jobToDelete['field'] <= 18 && $job['field'] <= 18) || ($jobToDelete['field'] >= 19 && $job['field'] >= 19)))){
if(!empty($jobToDelete) && $job['loopcon'] == 1 && ($tribe != 1 || ($tribe == 1 && (($jobToDelete['field'] <= 18 && $job['field'] <= 18) || ($jobToDelete['field'] >= 19 && $job['field'] >= 19))))){
//Does this job have the same field of the deleted one?
$sameBuilding = $jobToDelete['field'] == $job['field'] ? 1 : 0;
@@ -5261,7 +5265,7 @@ References: User ID/Message ID, Mode
else mysqli_query($this->dblink, $q = "UPDATE " .TB_PREFIX. "bdata SET level = level - $levels[1] + $levels[0] WHERE wid = $wid AND field = $field");
}
private function getBData($wid, $use_cache = true) {
private function getBData($wid, $use_cache = true, $orderByID = false) {
$wid = (int) $wid;
// first of all, check if we should be using cache and whether the field
@@ -5272,7 +5276,7 @@ References: User ID/Message ID, Mode
return self::$buildingsUnderConstructionCache[$wid];
}
$q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by master,timestamp ASC";
$q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by ".(!$orderByID ? "master,timestamp" : "id")." ASC";
$result = $this->mysqli_fetch_all(mysqli_query($this->dblink,$q));
self::$buildingsUnderConstructionCache[$wid] = $result;
@@ -5283,6 +5287,10 @@ References: User ID/Message ID, Mode
function getJobs($wid) {
return $this->getBData($wid, false);
}
function getJobsOrderByID($wid) {
return $this->getBData($wid, false, true);
}
function FinishWoodcutter($wid) {
$bdata = $this->getBData($wid);
@@ -7781,7 +7789,12 @@ References: User ID/Message ID, Mode
function addSlotFarm($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6) {
list($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6) = $this->escape_input($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6);
for($i = 1; $i <= 6; $i++) {
if (${'t'.$i} == '') {
${'t'.$i} = 0;
}
}
$q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`) VALUES ('$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6')";
return mysqli_query($this->dblink,$q);
}
@@ -7789,6 +7802,11 @@ References: User ID/Message ID, Mode
function editSlotFarm($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6) {
list($eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6) = $this->escape_input((int) $eid, $lid, $oldLid, $owner, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6);
for($i = 1; $i <= 6; $i++) {
if (${'t'.$i} == '') {
${'t'.$i} = 0;
}
}
$q = "UPDATE " . TB_PREFIX . "raidlist SET lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6' WHERE id = $eid AND lid = $oldLid AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $lid AND owner = $owner) AND EXISTS(SELECT 1 FROM " . TB_PREFIX . "farmlist WHERE id = $oldLid AND owner = $owner)";
return mysqli_query($this->dblink,$q);
}
+1 -1
View File
@@ -242,7 +242,7 @@ class Market
}
// We don't have enough resources
if($infoarray['wamt'] > ([$village->awood, $village->aclay, $village->airon, $village->acrop])[$infoarray['wtype']])
if($infoarray['wamt'] > ([$village->awood, $village->aclay, $village->airon, $village->acrop])[$infoarray['wtype'] - 1])
{
header("Location: build.php?id=".$get['id']."&t=1&e1");
exit;
+9 -14
View File
@@ -252,7 +252,7 @@ class Technology {
}
}
if($mode == 0){
$enforceoasis = $database->getOasisEnforce($base, 0, $useCache);
$enforceoasis = $database->getOasisEnforce($base, 1, $useCache);
if(count($enforceoasis) > 0){
foreach($enforceoasis as $enforce){
for($i = 1; $i <= 50; $i++){
@@ -261,15 +261,6 @@ class Technology {
$ownunit['hero'] += $enforce['hero'];
}
}
$enforceoasis1 = $database->getOasisEnforce($base, 1, $useCache);
if(count($enforceoasis1) > 0){
foreach($enforceoasis1 as $enforce){
for($i = 1; $i <= 50; $i++){
$ownunit['u' . $i] += $enforce['u' . $i];
}
$ownunit['hero'] += $enforce['hero'];
}
}
$prisoners = $database->getPrisoners($base, 1, $useCache);
if(!empty($prisoners)){
@@ -504,10 +495,14 @@ class Technology {
$each = round(($bid19[$building->getTypeLevel(36)]['attri'] / 100) * ${'u'.$unit}['time'] / SPEED);
}
if($unit % 10 == 0 || $unit % 10 == 9 && $unit != 99) {
$slots = $database->getAvailableExpansionTraining();
if($unit % 10 == 0 && $slots['settlers'] <= $amt) $amt = $slots['settlers'];
if($unit % 10 == 9 && $slots['chiefs'] <= $amt) $amt = $slots['chiefs'];
} else {
if($this->maxUnit($unit, $great) < $amt) $amt = 0;
else
{
$slots = $database->getAvailableExpansionTraining();
if($unit % 10 == 0 && $slots['settlers'] <= $amt) $amt = $slots['settlers'];
if($unit % 10 == 9 && $slots['chiefs'] <= $amt) $amt = $slots['chiefs'];
}
}else{
if($unit != 99){
if($this->maxUnit($unit, $great) < $amt) $amt = 0;
}else{