mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-15 00:56:09 +00:00
Merge branch 'master' of https://github.com/Shadowss/TravianZ
This commit is contained in:
@@ -13,25 +13,23 @@
|
||||
if(!isset($_SESSION)) session_start();
|
||||
if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN);
|
||||
include_once("../../Database.php");
|
||||
include_once("../../Technology.php");
|
||||
include_once("../../Data/unitdata.php");
|
||||
|
||||
$id = $_POST['id'];
|
||||
$id = (int)$_POST['id'];
|
||||
$village = $database->getVillage($id);
|
||||
$user = $database->getUserArray($village['owner'],1);
|
||||
$units="";
|
||||
$tribe = $user['tribe'];
|
||||
if($tribe ==1){ $u = 0;}
|
||||
if($tribe ==2){ $u = 10;}
|
||||
if($tribe ==3){ $u = 20;}
|
||||
if($tribe ==4){ $u = 30;}
|
||||
if($tribe ==5){ $u = 40;}
|
||||
if($tribe ==6){ $u = 50;}
|
||||
$user = $database->getUserArray($village['owner'],1);
|
||||
$units = "";
|
||||
$tribe = $user['tribe'];
|
||||
$u = ($tribe - 1) * 10;
|
||||
|
||||
for($i=1; $i<11; $i++) {
|
||||
$units.="u".($u+$i)."=".$database->escape($_POST['u'.($u+$i)].(($i < 10) ? ", " : ""));
|
||||
for($i = 1; $i < 11; $i++) {
|
||||
$units.="u".($u + $i)."=".$database->escape($_POST['u'.($u + $i)].(($i < 10) ? ", " : ""));
|
||||
}
|
||||
$q = "UPDATE ".TB_PREFIX."units SET ".$units." WHERE vref = ".(int) $id;
|
||||
|
||||
$q = "UPDATE ".TB_PREFIX."units SET ".$units." WHERE vref = ".$id;
|
||||
$database->query($q);
|
||||
$database->query("Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop amounts in village <a href=\'admin.php?p=village&did=$id\'>$id</a> ',".time().")");
|
||||
|
||||
$database->addStarvationData($id);
|
||||
header("Location: ../../../Admin/admin.php?p=village&did=".$id."&d");
|
||||
?>
|
||||
@@ -24,57 +24,24 @@ for ($i = 0; $i < 5; $i++) {
|
||||
|
||||
include_once($autoprefix."GameEngine/Database.php");
|
||||
|
||||
$session = (int) $_POST['admid'];
|
||||
$id = (int) $_POST['id'];
|
||||
|
||||
$sql = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$session."");
|
||||
$access = mysqli_fetch_array($sql);
|
||||
$sessionaccess = $access['access'];
|
||||
$bonusDuration = [];
|
||||
$time = time();
|
||||
$bonusDuration['plus'] = (int) $_POST['plus'] * 86400; //Plus
|
||||
$bonusDuration['b1'] = (int) $_POST['wood'] * 86400; //+25% Wood
|
||||
$bonusDuration['b2'] = (int) $_POST['clay'] * 86400; //+25% Clay
|
||||
$bonusDuration['b3'] = (int) $_POST['iron'] * 86400; //+25% Iron
|
||||
$bonusDuration['b4'] = (int) $_POST['crop'] * 86400; //+25% Crop
|
||||
|
||||
if($sessionaccess != 9) die("<h1><font color=\"red\">Access Denied: You are not Admin!</font></h1>");
|
||||
$user = $database->getUserArray($id, 1);
|
||||
|
||||
$pdur = (int) $_POST['plus'] * 86400;
|
||||
$b1dur = (int) $_POST['wood'] * 86400;
|
||||
$b2dur = (int) $_POST['clay'] * 86400;
|
||||
$b3dur = (int) $_POST['iron'] * 86400;
|
||||
$b4dur = (int) $_POST['crop'] * 86400;
|
||||
|
||||
$sql1 = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$id."");
|
||||
$user = mysqli_fetch_array($sql1);
|
||||
|
||||
if($user['plus'] < time()){
|
||||
if($pdur > 1){ $plus = (time() + $pdur); } else { $plus = time(); }
|
||||
}else{
|
||||
if($pdur > 1){ $plus = ($user['plus'] + $pdur); } else { $plus = $user['plus']; }
|
||||
}
|
||||
if($user['b1'] < time()){
|
||||
if($b1dur > 1){ $wood = (time() + $b1dur); } else { $wood = time(); }
|
||||
}else{
|
||||
if($b1dur > 1){ $wood = ($user['b1'] + $b1dur); } else { $wood = $user['b1']; }
|
||||
}
|
||||
if($user['b2'] < time()){
|
||||
if($b2dur > 1){ $clay = (time() + $b2dur); } else { $clay = time(); }
|
||||
}else{
|
||||
if($b2dur > 1){ $clay = ($user['b2'] + $b2dur); } else { $clay = $user['b2']; }
|
||||
}
|
||||
if($user['b3'] < time()){
|
||||
if($b3dur > 1){ $iron = (time() + $b3dur); } else { $iron = time(); }
|
||||
}else{
|
||||
if($b3dur > 1){ $iron = ($user['b3'] + $b3dur); } else { $iron = $user['b3']; }
|
||||
}
|
||||
if($user['b4'] < time()){
|
||||
if($b4dur > 1){ $crop = (time() + $b4dur); } else { $crop = time(); }
|
||||
}else{
|
||||
if($b4dur > 1){ $crop = ($user['b4'] + $b4dur); } else { $crop = $user['b4']; }
|
||||
foreach($bonusDuration as $index => $bonus){
|
||||
$bonusDuration[$index] = $bonusDuration[$index] + ($user[$index] < $time ? $time : $user[$index]);
|
||||
if($bonusDuration[$index] < $time) $bonusDuration[$index] = 0;
|
||||
}
|
||||
|
||||
mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET
|
||||
plus = '".$plus."',
|
||||
b1 = '".$wood."',
|
||||
b2 = '".$clay."',
|
||||
b3 = '".$iron."',
|
||||
b4 = '".$crop."'
|
||||
WHERE id = $id") or die(mysqli_error($database->dblink));
|
||||
$database->updateUserField($id, array_keys($bonusDuration), array_values($bonusDuration), 1);
|
||||
|
||||
header("Location: ../../../Admin/admin.php?p=player&uid=".$id."");
|
||||
?>
|
||||
@@ -30,14 +30,6 @@ for ($i = 0; $i < 5; $i++) {
|
||||
|
||||
include_once($autoprefix."GameEngine/Database.php");
|
||||
|
||||
$session = (int) $_POST['admid'];
|
||||
|
||||
$sql = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$session."");
|
||||
$access = mysqli_fetch_array($sql);
|
||||
$sessionaccess = $access['access'];
|
||||
|
||||
if($sessionaccess != 9) die("<h1><font color=\"red\">Access Denied: You are not Admin!</font></h1>");
|
||||
|
||||
$sql = "SELECT id FROM ".TB_PREFIX."users ORDER BY ID DESC LIMIT 1";
|
||||
$loops = mysqli_result(mysqli_query($GLOBALS["link"], $sql), 0);
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
// # ##
|
||||
// ################################################################################
|
||||
include_once("../GameEngine/Artifacts.php");
|
||||
include_once("../GameEngine/Units.php");
|
||||
include_once("../GameEngine/Generator.php");
|
||||
|
||||
class funct
|
||||
{
|
||||
|
||||
@@ -28,7 +31,7 @@ class funct
|
||||
|
||||
function Act($get)
|
||||
{
|
||||
global $admin, $database;
|
||||
global $admin, $database, $units, $generator;
|
||||
|
||||
$artifact = new Artifacts();
|
||||
|
||||
@@ -71,8 +74,8 @@ class funct
|
||||
// add ban
|
||||
break;
|
||||
case "delOas":
|
||||
$database->query('UPDATE ' . TB_PREFIX . 'odata SET conqured = 0, owner = 2, name = "Unoccupied Oasis" WHERE wref = ' . $get['oid']);
|
||||
// oaza
|
||||
$units->returnTroops($get['did'], 1);
|
||||
$database->removeOases($get['oid']);
|
||||
break;
|
||||
case "logout":
|
||||
$this->LogOut();
|
||||
@@ -93,25 +96,30 @@ class funct
|
||||
$artifactInfo = $database->getArtefactDetails($_GET['artid'], $_GET['del']);
|
||||
|
||||
//Check if the artifact exists
|
||||
if(empty($artifactInfo) || $artifactInfo['owner'] == Artifacts::NATARS_UID) {
|
||||
if(empty($artifactInfo)) {
|
||||
header("location: admin.php");
|
||||
exit;
|
||||
}elseif($artifactInfo['owner'] == Artifacts::NATARS_UID){
|
||||
$database->updateArtifactDetails($_GET['artid'], ['del' => 0]);
|
||||
header("location: admin.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
//Return the artifacts to the Natars' account
|
||||
$artifact->returnArtifactToNatars($artifactInfo);
|
||||
break;
|
||||
|
||||
case "addArtifacts":
|
||||
|
||||
$selectedArtifact = $_POST['selectedArtifact'];
|
||||
$artifactQuantity = $_POST['artifactQuantity'];
|
||||
$playerId = $_POST['playerId'];
|
||||
$artifactQuantity = (int)$_POST['artifactQuantity'];
|
||||
$playerId = (int)$_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");
|
||||
!is_numeric($artifactQuantity) || $artifactQuantity <= 0 || $artifactQuantity > 999 || !is_numeric($playerId) ||
|
||||
strpos($selectedArtifact, ':') === false || $database->getUserField($playerId, "username", 0) == "[?]"){
|
||||
header("location: admin.php?p=natars&error=0");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -125,7 +133,7 @@ class funct
|
||||
|
||||
//Check if the artifact has been found or if doesn't exist
|
||||
if(empty($chosenArtifact)){
|
||||
header("location: admin.php");
|
||||
header("location: admin.php?p=natars&error=1");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -134,9 +142,24 @@ class funct
|
||||
$artifactArrays[$selectedArtifact[2]][] = $chosenArtifact;
|
||||
|
||||
//Add the artifacts
|
||||
$artifact->addArtifactVillages($artifactArrays, $playerId);
|
||||
$artifact->addArtifactVillages($artifactArrays, $playerId, $playerId == Artifacts::NATARS_UID);
|
||||
break;
|
||||
|
||||
case "addWWVillages":
|
||||
|
||||
$numberOfVillages = (int)$_POST['numberOfVillages'];
|
||||
$playerId = (int)$_POST['playerId'];
|
||||
|
||||
//Check if the inserted values are valid
|
||||
if(!is_numeric($numberOfVillages) || $numberOfVillages <= 0 || $numberOfVillages > 999
|
||||
|| !is_numeric($playerId) || $database->getUserField($playerId, "username", 0) == "[?]"){
|
||||
header("location: admin.php?p=natars&error=2");
|
||||
}
|
||||
|
||||
//Create the desired WW villages
|
||||
$artifact->createWWVillages($numberOfVillages, $playerId, $playerId == Artifacts::NATARS_UID);
|
||||
break;
|
||||
|
||||
case "killHero":
|
||||
$varray = $database->getProfileVillages($get['uid']);
|
||||
$killhero = false;
|
||||
|
||||
+41
-35
@@ -2,16 +2,16 @@
|
||||
class Artifacts
|
||||
{
|
||||
|
||||
public const
|
||||
const
|
||||
|
||||
/**
|
||||
* @var integer Default Natars' uid
|
||||
* @var int Default Natars' uid
|
||||
*/
|
||||
|
||||
NATARS_UID = 3,
|
||||
|
||||
/**
|
||||
* @var integer Default Natars' tribe
|
||||
* @var int Default Natars' tribe
|
||||
*/
|
||||
|
||||
NATARS_TRIBE = 5,
|
||||
@@ -35,23 +35,18 @@ class Artifacts
|
||||
*/
|
||||
|
||||
NATARS_CAPITAL_COORDINATES = [[WORLD_MAX, WORLD_MAX],
|
||||
[WORLD_MAX, 0],
|
||||
[WORLD_MAX, -WORLD_MAX],
|
||||
[0, -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]],
|
||||
[-WORLD_MAX, 0],
|
||||
[-WORLD_MAX, WORLD_MAX],
|
||||
[0, WORLD_MAX],
|
||||
[WORLD_MAX / 10, WORLD_MAX / 20],
|
||||
[WORLD_MAX / 10, -WORLD_MAX / 10],
|
||||
[-WORLD_MAX / 20, -WORLD_MAX / 10],
|
||||
[-WORLD_MAX / 10, 0],
|
||||
[-WORLD_MAX / 20, WORLD_MAX / 10]],
|
||||
|
||||
/**
|
||||
* @var array Normal Natars' artifacts
|
||||
@@ -91,7 +86,7 @@ class Artifacts
|
||||
* @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]]],
|
||||
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
|
||||
@@ -128,11 +123,17 @@ class Artifacts
|
||||
"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
|
||||
* @var int The base amount of Natars' spying units, used when Natars account is created
|
||||
*/
|
||||
|
||||
NATARS_BASE_SPY = 1500;
|
||||
NATARS_BASE_SPY = 1500,
|
||||
|
||||
/**
|
||||
* @var int the base amount of Natars' WW villages
|
||||
*/
|
||||
|
||||
NATARS_BASE_WW_VILLAGES = 13;
|
||||
|
||||
public
|
||||
|
||||
/**
|
||||
@@ -178,7 +179,7 @@ class Artifacts
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Natars account need to be created, creates his account and capital village
|
||||
* Called when Natars account needs to be created, creates his account and capital village
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -263,9 +264,10 @@ class Artifacts
|
||||
*
|
||||
* @param array $artifactArrays The array containing the artifacts to insert
|
||||
* @param int $uid The owner's user ID (Natars)
|
||||
* @param bool $addTroops Add troops to the village if true, and vice versa if false
|
||||
*/
|
||||
|
||||
public function addArtifactVillages($artifactArrays, $uid = self::NATARS_UID) {
|
||||
public function addArtifactVillages($artifactArrays, $uid = self::NATARS_UID, $addTroops = true) {
|
||||
global $database;
|
||||
|
||||
//Variables initialization
|
||||
@@ -284,7 +286,7 @@ class Artifacts
|
||||
$unitArrays = ($this->natarsArtifactsUnits)($multiplier);
|
||||
|
||||
//Generate the unit arrays
|
||||
$artifactTroops[1][] = array_values($unitArrays);
|
||||
if($addTroops) $artifactTroops[1][] = array_values($unitArrays);
|
||||
$artifactBuildings[1][] = array_values(self::NATARS_ARTIFACTS_BUILDINGS);
|
||||
|
||||
//Generate the artifacts array
|
||||
@@ -296,11 +298,11 @@ class Artifacts
|
||||
}
|
||||
|
||||
//Set the unit types by using the last $unitArrays
|
||||
$artifactTroops[0] = array_keys($unitArrays);
|
||||
if($addTroops) $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));
|
||||
$wids = array_merge($wids, (array)$database->generateVillages($artifactVillages, $uid, TRIBE5, $addTroops ? $artifactTroops : null, $artifactBuildings));
|
||||
|
||||
//Create the artifacts for the generated wids
|
||||
$database->addArtefacts($wids, $artifactsToAdd);
|
||||
@@ -309,22 +311,25 @@ class Artifacts
|
||||
/**
|
||||
* Called when WW villages need to be created
|
||||
*
|
||||
* @param int $numberOfVillages The number of villages that have to be added
|
||||
* @param int $uid The player ID
|
||||
* @param bool $addTroops Add troops to the village if true, and vice versa if false
|
||||
*/
|
||||
|
||||
public function createWWVillages(){
|
||||
public function createWWVillages($numberOfVillages = self::NATARS_BASE_WW_VILLAGES, $uid = self::NATARS_UID, $addTroops = true){
|
||||
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)());
|
||||
for($i = 1; $i <= $numberOfVillages; $i++){
|
||||
$villageArrays[] = ['wid' => 0, 'mode' => 5, 'type' => 3, 'kid' => ($i == $numberOfVillages ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0, 'pop' => 233, 'name' => WWVILLAGE, 'natar' => 1];
|
||||
if($addTroops) $troopArrays[1][] = array_values(($this->natarsWWVillagesUnits)());
|
||||
$buildingArrays[1][] = array_values(self::NATARS_WW_VILLAGES_BUILDINGS);
|
||||
}
|
||||
|
||||
$troopArrays[0] = array_keys(($this->natarsWWVillagesUnits)());
|
||||
if($addTroops) $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);
|
||||
$wids = $database->generateVillages($villageArrays, $uid, null, $addTroops ? $troopArrays : null, $buildingArrays);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,10 +416,11 @@ class Artifacts
|
||||
global $database;
|
||||
|
||||
//Set the village arrays
|
||||
$artifactArrays = array_merge(self::NATARS_ARTIFACTS, self::NATARS_WW_BUILDING_PLANS);
|
||||
$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]];
|
||||
'name' => $artifactArrays[$artifactArray['desc']][$artifactArray['size'] - 1]['vname'],
|
||||
'natar' => 0]];
|
||||
|
||||
//Set the unit arrays
|
||||
$multiplier = $artifactArray['size'] == 3 ? 4 : $artifactArray['size'];
|
||||
@@ -427,7 +433,7 @@ class Artifacts
|
||||
//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);
|
||||
|
||||
|
||||
Executable → Regular
+50
-72
@@ -383,7 +383,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function buildComplete() {
|
||||
global $database, $bid18, $bid10, $bid11, $bid38, $bid39;
|
||||
global $database, $technology, $bid18, $bid10, $bid11, $bid38, $bid39;
|
||||
|
||||
$time = time();
|
||||
// IDs of villages that were affected by this building completion update,
|
||||
@@ -476,7 +476,7 @@ class Automation {
|
||||
}
|
||||
|
||||
//Update starvation data
|
||||
$this->addStarvationData($indi['wid']);
|
||||
$database->addStarvationData($indi['wid']);
|
||||
|
||||
// update the requested fields, all at once
|
||||
$database->setVillageFields($indi['wid'], array_keys($fieldsToSet), array_values($fieldsToSet));
|
||||
@@ -711,27 +711,33 @@ class Automation {
|
||||
|
||||
if(isset($catapultTarget))
|
||||
{
|
||||
// currently targeted building/field level
|
||||
//Currently targeted building/field level
|
||||
$tblevel = (int) $bdo['f'.$catapultTarget];
|
||||
// currently targetet building/field GID (ID of the building/field type - woodcutter, cropland, embassy...)
|
||||
//Currently targetet building/field GID (ID of the building/field type - woodcutter, cropland, embassy...)
|
||||
$tbgid = (int) $bdo['f'.$catapultTarget.'t'];
|
||||
// currently targeted building/field ID in the database (fdata, the fID field, e.g. f1, f2, f3...)
|
||||
//Currently targeted building/field ID in the database (fdata, the fID field, e.g. f1, f2, f3...)
|
||||
$tbid = (int) $catapultTarget;
|
||||
|
||||
$newLevel = $battle->CalculateNewBuildingLevel($battlepart['catapults']['moral'],
|
||||
$battlepart['catapults']['upgrades'],
|
||||
$battlepart['catapults']['downgrades'],
|
||||
$tblevel,
|
||||
$battlepart['catapults']['realAttackers'] / ($twoRowsCatapultSetup ? 2 : 1),
|
||||
$data['t8'] / ($twoRowsCatapultSetup ? 2 : 1),
|
||||
($catapultTarget == 40 ? 1 : $battlepart['catapults']['strongerBuildings']));
|
||||
//If we're targeting the WW
|
||||
if($catapultTarget == 40){
|
||||
$battlepart['catapults']['strongerBuildings'] = 1;
|
||||
$battlepart['catapults']['moraleBonus'] = 1;
|
||||
}
|
||||
|
||||
$catapultsDamage = $battle->calculateCatapultsDamage($data['t8'],
|
||||
$battlepart['catapults']['upgrades'],
|
||||
$battlepart['catapults']['durability'],
|
||||
$battlepart['catapults']['attackDefenseRatio'],
|
||||
$battlepart['catapults']['strongerBuildings'],
|
||||
$battlepart['catapults']['moraleBonus']);
|
||||
|
||||
$newLevel = $battle->calculateNewBuildingLevel($tblevel, $catapultsDamage / ($twoRowsCatapultSetup ? 2 : 1));
|
||||
|
||||
//If that building was present in the building queue, we have to modify his level or remove it
|
||||
$database->modifyBData($data['to'], $tbid, [$newLevel, $tblevel], $tribe);
|
||||
|
||||
// building/field destroyed
|
||||
if ($newLevel == 0)
|
||||
{
|
||||
if ($newLevel == 0){
|
||||
// prepare data to be updated
|
||||
$fieldsToSet = ["f".$tbid];
|
||||
$fieldValuesToSet = [0];
|
||||
@@ -1266,11 +1272,8 @@ class Automation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//to battle.php
|
||||
|
||||
//fix by ronix
|
||||
//MUST TO BE FIX : You need to filter these values
|
||||
//filter_input_array($battlepart = $battle->calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$residence,$attpop,$defpop,$type,$def_ab,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$tblevel,$stonemason,$walllevel,0,0,0,$AttackerID,$DefenderID,$AttackerWref,$DefenderWref,$conqureby));
|
||||
if (!isset($walllevel)) $walllevel = 0;
|
||||
|
||||
$battlepart = $battle->calculateBattle($Attacker, $Defender, $def_wall, $att_tribe, $def_tribe, $residence, $attpop, $defpop, $type, $def_ab, $att_ab1, $att_ab2, $att_ab3, $att_ab4, $att_ab5, $att_ab6, $att_ab7, $att_ab8, $tblevel, $stonemason, $walllevel, 0, 0, 0, $AttackerID, $DefenderID, $AttackerWref, $DefenderWref, $conqureby, $enforcementarray);
|
||||
@@ -1286,17 +1289,18 @@ class Automation {
|
||||
else $can_destroy = 0;
|
||||
|
||||
//Catapults and rams management
|
||||
//TODO: Move this in Battle.php
|
||||
if($isoasis == 0){
|
||||
if ($type == 3){
|
||||
if (($data['t7'] - $traped7) > 0){
|
||||
if($walllevel > 0){
|
||||
$newLevel = $battle->CalculateNewBuildingLevel($battlepart['rams']['moral'],
|
||||
$battlepart['rams']['upgrades'],
|
||||
$battlepart['rams']['downgrades'],
|
||||
$walllevel,
|
||||
$battlepart['rams']['realAttackers'],
|
||||
$data['t7'],
|
||||
$battlepart['rams']['strongerBuildings']);
|
||||
$ramsDamage = $battle->calculateCatapultsDamage($data['t7'],
|
||||
$battlepart['rams']['upgrades'],
|
||||
$battlepart['rams']['durability'],
|
||||
$battlepart['rams']['attackDefenseRatio'],
|
||||
$battlepart['rams']['strongerBuildings'],
|
||||
$battlepart['rams']['moraleBonus']);
|
||||
$newLevel = $battle->calculateNewBuildingLevel($walllevel, $ramsDamage);
|
||||
|
||||
if ($newLevel == 0){
|
||||
$info_ram = "".$ram_pic.",Wall <b>destroyed</b>.";
|
||||
@@ -2184,7 +2188,7 @@ class Automation {
|
||||
// if the defender pop is 0 with no artefact, then destroy the village
|
||||
if($database->getVillageField($data['to'], "pop") == 0 || $targettribe == 5){
|
||||
$can_destroy = $village_destroyed = 1;
|
||||
$info_hero .= " The village has been destroyed.";
|
||||
if(strpos($info_cat, "The village has") === false) $info_hero .= " The village has been destroyed.";
|
||||
}
|
||||
}
|
||||
else $info_hero = $hero_pic.",".$artifactError.$xp;
|
||||
@@ -2233,7 +2237,7 @@ class Automation {
|
||||
}else{
|
||||
if(isset($village_destroyed) && $village_destroyed == 1 && $can_destroy==1){
|
||||
//check if village pop=0 and no info destroy
|
||||
if (strpos($info_cat,"The village has") === false) {
|
||||
if (strpos($info_cat, "The village has") === false) {
|
||||
$info_cat .= "<tbody class=\"goods\"><tr><th>Information</th><td colspan=\"11\">
|
||||
<img class=\"unit u".$catp_pic."\" src=\"img/x.gif\" alt=\"Catapult\" title=\"Catapult\" /> The village has been destroyed.</td></tr></tbody>";
|
||||
}
|
||||
@@ -2488,7 +2492,7 @@ class Automation {
|
||||
}
|
||||
|
||||
//Update starvation data
|
||||
$this->addStarvationData($to['wref']);
|
||||
$database->addStarvationData($to['wref']);
|
||||
|
||||
//Returning units back to village is not necessary because it will be taken care when processing movement
|
||||
// Fix by AL-Kateb
|
||||
@@ -2579,7 +2583,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function sendreinfunitsComplete() {
|
||||
global $bid23, $database, $battle;
|
||||
global $bid23, $database, $technology, $battle;
|
||||
|
||||
$time = time();
|
||||
$q = "
|
||||
@@ -2717,7 +2721,7 @@ class Automation {
|
||||
}
|
||||
|
||||
//Update starvation data
|
||||
$this->addStarvationData($data['to']);
|
||||
$database->addStarvationData($data['to']);
|
||||
|
||||
//check empty reinforcement in rally point
|
||||
$e_units = '';
|
||||
@@ -2733,7 +2737,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function returnunitsComplete() {
|
||||
global $database;
|
||||
global $database, $technology;
|
||||
|
||||
$time = time();
|
||||
$q = "
|
||||
@@ -2783,7 +2787,7 @@ class Automation {
|
||||
$movementProcIDs[] = $data['moveid'];
|
||||
|
||||
//Update starvation data
|
||||
$this->addStarvationData($data['to']);
|
||||
$database->addStarvationData($data['to']);
|
||||
}
|
||||
|
||||
$database->setMovementProc(implode(', ', $movementProcIDs));
|
||||
@@ -3233,7 +3237,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function trainingComplete() {
|
||||
global $database;
|
||||
global $database, $technology;
|
||||
|
||||
$time = time();
|
||||
$trainlist = $database->getTrainingList();
|
||||
@@ -3287,7 +3291,7 @@ class Automation {
|
||||
if ($valuesUpdated) call_user_func(get_class($database).'::clearUnitsCache');
|
||||
|
||||
//Update starvation data
|
||||
$this->addStarvationData($train['vref']);
|
||||
$database->addStarvationData($train['vref']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3677,30 +3681,6 @@ class Automation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the starvation data in villages with a negative value of crop
|
||||
*
|
||||
* @param int $wref The village ID where the crop is negative
|
||||
*/
|
||||
|
||||
private function addStarvationData($wref){
|
||||
global $database, $technology;
|
||||
|
||||
$getVillage = $database->getVillage($wref);
|
||||
|
||||
//Exlude Support, Nature, Natars, TaskMaster and Multihunter
|
||||
if ($getVillage['owner'] > 5){
|
||||
$crop = $database->getCropProdstarv($wref, false);
|
||||
$unitArrays = $this->getAllUnits($wref, false);
|
||||
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
|
||||
$starv = $getVillage['starv'];
|
||||
if ($crop < $villageUpkeep){
|
||||
//Add starvation data
|
||||
$database->setVillageFields($wref, ['starv'], [$villageUpkeep]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for starvation - by brainiacX and Shadow
|
||||
@@ -3712,23 +3692,23 @@ class Automation {
|
||||
private function starvation() {
|
||||
global $database, $technology;
|
||||
|
||||
//starvation is disabled during Easter/Holidays/Christmas
|
||||
//Starvation is disabled during Easter/Holidays/Christmas
|
||||
if(PEACE) return;
|
||||
|
||||
$time = time();
|
||||
|
||||
//update starvation in every village
|
||||
//Update starvation in every village
|
||||
$starvarray = $database->getProfileVillages(0, 7);
|
||||
foreach($starvarray as $starv) $this->addStarvationData($starv['wref']);
|
||||
foreach($starvarray as $starv) $database->addStarvationData($starv['wref']);
|
||||
|
||||
// load villages with minus prod
|
||||
//Load villages with minus prod
|
||||
$starvarray = [];
|
||||
$starvarray = $database->getStarvation();
|
||||
|
||||
$vilIDs = [];
|
||||
foreach ($starvarray as $starv) $vilIDs[] = $starv['wref'];
|
||||
|
||||
// cache
|
||||
//Cache
|
||||
$database->getEnforceVillage($vilIDs, 0);
|
||||
$database->getOasisEnforce($vilIDs, 2);
|
||||
$database->getOasisEnforce($vilIDs, 3);
|
||||
@@ -3758,7 +3738,7 @@ class Automation {
|
||||
|
||||
$allTroopsArray = [$enforceArrays, $prisonerArrays, $unitArrays, $attackArrays];
|
||||
|
||||
// find the first not-empty array
|
||||
//Find the first not-empty array
|
||||
foreach($allTroopsArray as $type => $allTroops)
|
||||
{
|
||||
if(!empty($allTroops)){
|
||||
@@ -3771,10 +3751,10 @@ class Automation {
|
||||
}
|
||||
}
|
||||
|
||||
// if the player has no troops, then skip the next instructions
|
||||
//If the player has no troops, then skip the next instructions
|
||||
if(empty($starvingTroops)) continue;
|
||||
|
||||
// counting
|
||||
//Counting
|
||||
$timedif = $time - $starv['starvupdate'];
|
||||
$cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv'];
|
||||
if($cropProd < 0){
|
||||
@@ -3783,7 +3763,7 @@ class Automation {
|
||||
$newcrop = 0;
|
||||
$oldcrop = $database->getVillageField($starv['wref'], 'crop');
|
||||
|
||||
//if the grain is then tries to send all
|
||||
//If the grain is then tries to send all
|
||||
if ($oldcrop > 100){
|
||||
$difcrop = $difcrop - $oldcrop;
|
||||
if($difcrop < 0){
|
||||
@@ -3804,7 +3784,7 @@ class Automation {
|
||||
$counting = true;
|
||||
while($difcrop > 0)
|
||||
{
|
||||
// search the highest troop
|
||||
//S earch the highest troop
|
||||
$maxcount = $maxtype = 0;
|
||||
for($i = $start ; $i <= $end ; $i++)
|
||||
{
|
||||
@@ -3837,10 +3817,8 @@ class Automation {
|
||||
else if($maxtype == 0) $newCrop = 0;
|
||||
else $newCrop = $GLOBALS['u'.$maxtype]['crop'];
|
||||
|
||||
if($totalKilledUnits > 0)
|
||||
{
|
||||
switch($type)
|
||||
{
|
||||
if($totalKilledUnits > 0){
|
||||
switch($type){
|
||||
case 0:
|
||||
if($totalKilledUnits < $totalUnits){
|
||||
$database->modifyEnforce($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0);
|
||||
|
||||
+72
-65
@@ -8,7 +8,7 @@
|
||||
## Filename Battle.php ##
|
||||
## Developed by: Dzoki & Dixie ##
|
||||
## Fixed by: Shadow ##
|
||||
## Thanks to: Akakori & Elmar ##
|
||||
## Thanks to: Akakori, Elmar & Kirilloid ##
|
||||
## Reworked and Fix by: ronix ##
|
||||
## Fixed by: InCube - double troops ##
|
||||
## License: TravianZ Project ##
|
||||
@@ -21,6 +21,21 @@
|
||||
|
||||
class Battle {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Kirilloid --> https://github.com/kirilloid/travian/blob/master/src/model/base/combat.ts
|
||||
* @var double The number of attacking catapults: 1 = 100%, 0 = 0%
|
||||
*
|
||||
*/
|
||||
|
||||
private $sigma;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$this->sigma = function($x) { return ($x > 1 ? 2 - $x ** -1.5 : $x ** 1.5) / 2; };
|
||||
|
||||
}
|
||||
|
||||
public function procSim($post) {
|
||||
global $form;
|
||||
|
||||
@@ -374,10 +389,10 @@ class Battle {
|
||||
$abcount += 1;
|
||||
|
||||
// Points catapult the attacker
|
||||
if(in_array($i,$catapult)) $catp += (int) $Attacker['u'.$i];
|
||||
if(in_array($i, $catapult)) $catp += (int) $Attacker['u'.$i];
|
||||
|
||||
// Points of the Rams attacker
|
||||
if(in_array($i,$rams)) $ram += (int) $Attacker['u'.$i];
|
||||
if(in_array($i, $rams)) $ram += (int) $Attacker['u'.$i];
|
||||
|
||||
$involve += (int) $Attacker['u'.$i];
|
||||
$units['Att_unit'][$i] = (int) $Attacker['u'.$i];
|
||||
@@ -459,7 +474,7 @@ class Battle {
|
||||
$result['Defend_points'] = $rdp;
|
||||
$winner = ($rap > $rdp);
|
||||
|
||||
// Formula for calculating the Moral
|
||||
// Formula for calculating the Morale bonus
|
||||
// WW villages aren't affected by this bonus
|
||||
if($attpop > $defpop && !$isWWVillage) {
|
||||
$moralbonus = 1 / round(max(0.667, pow($defpop / $attpop, 0.2 * min(1, $rap / ($rdp > 0 ? $rdp : 1)))), 3);
|
||||
@@ -533,57 +548,54 @@ class Battle {
|
||||
}
|
||||
$result['hero_fealthy'] = $fealthy;
|
||||
}
|
||||
|
||||
$ram -= ($winner) ? round($ram * $result[1] / 100) : round($ram * $result[2] / 100);
|
||||
$catp -= ($winner) ? round($catp * $result[1] / 100) : round($catp * $result[2] / 100);
|
||||
}
|
||||
// Formula for the calculation of catapults needed
|
||||
|
||||
if($catp > 0 && $tblevel != 0) {
|
||||
|
||||
//catapults upgrades
|
||||
$upgrades = round(200 * pow(1.0205, $att_ab8) ) / 200;
|
||||
//Catapults blacksmith upgrades
|
||||
$upgrades = round(200 * pow(1.0205, $att_ab8)) / 200;
|
||||
|
||||
$wctp = pow(($rap / $rdp), 1.5);
|
||||
$wctp = ($wctp >= 1) ? 1 - 0.5 / $wctp : 0.5 * $wctp;
|
||||
$wctp *= ($catp + $upgrades);
|
||||
|
||||
//catapults downgrades
|
||||
$downgrades = ($stonemason > 0 ? $bid34[$stonemason]['attri'] / 100 : 1);
|
||||
|
||||
//catapults moral
|
||||
$catpMoral = pow($attpop / ($defpop > 0 ? $defpop : 1) , 0.3);
|
||||
|
||||
// New level of the building (only for warsim.php)
|
||||
$result[3] = $this->calculateNewBuildingLevel($catpMoral, $upgrades, $downgrades, $tblevel, $wctp, $catp, $strongerbuildings);
|
||||
//Buildings durability
|
||||
$durability = ($stonemason > 0 ? $bid34[$stonemason]['attri'] / 100 : 1);
|
||||
|
||||
//Calculates the catapults morale bonus
|
||||
$catpMoraleBonus = min(max(($attpop / ($defpop > 0 ? $defpop : 1)) ** 0.3, 1), 3);
|
||||
|
||||
//New level of the building (only for warsim.php)
|
||||
$catapultsDamage = $this->calculateCatapultsDamage($catp, $upgrades, $durability, $rap / $rdp, $strongerbuildings, $catpMoraleBonus);
|
||||
$result[3] = $this->calculateNewBuildingLevel($tblevel, $catapultsDamage);
|
||||
$result[4] = $tblevel;
|
||||
|
||||
// Results for Automation.php
|
||||
$result['catapults']['moral'] = $catpMoral;
|
||||
//Results for Automation.php
|
||||
$result['catapults']['upgrades'] = $upgrades;
|
||||
$result['catapults']['downgrades'] = $downgrades;
|
||||
$result['catapults']['realAttackers'] = $wctp;
|
||||
$result['catapults']['durability'] = $durability;
|
||||
$result['catapults']['attackDefenseRatio'] = $rap / $rdp;
|
||||
$result['catapults']['strongerBuildings'] = $strongerbuildings;
|
||||
$result['catapults']['moraleBonus'] = $catpMoraleBonus;
|
||||
}
|
||||
|
||||
if($ram > 0 && $walllevel != 0) {
|
||||
|
||||
//Rams blacksmith upgrades
|
||||
$upgrades = round(200 * pow(1.0205, $att_ab7)) / 200;
|
||||
|
||||
$wctp = pow(($rap / $rdp), 1.5);
|
||||
$wctp = ($wctp >= 1) ? 1 - 0.5 / $wctp : 0.5 * $wctp;
|
||||
$wctp *= ($ram) + $upgrades;
|
||||
|
||||
$downgrades = ($stonemason > 0 ? $bid34[$stonemason]['attri'] / 100 : 1);
|
||||
//Building durability
|
||||
$durability = ($stonemason > 0 ? $bid34[$stonemason]['attri'] / 100 : 1);
|
||||
|
||||
// New level of the building (only for warsim.php)
|
||||
$result[7] = $this->calculateNewBuildingLevel(1, $upgrades, $downgrades, $walllevel, $wctp, $ram, $strongerbuildings * 5);
|
||||
$ramsDamage = $this->calculateCatapultsDamage($ram, $upgrades, $durability, $rap / $rdp, $strongerbuildings, 1);
|
||||
$result[7] = $this->calculateNewBuildingLevel($walllevel, $ramsDamage);
|
||||
$result[8] = $walllevel;
|
||||
|
||||
// Results for Automation.php
|
||||
$result['rams']['moral'] = 1;
|
||||
$result['rams']['upgrades'] = $upgrades;
|
||||
$result['rams']['downgrades'] = $downgrades;
|
||||
$result['rams']['realAttackers'] = $wctp;
|
||||
$result['rams']['strongerBuildings'] = $strongerbuildings * 5;
|
||||
$result['rams']['durability'] = $durability;
|
||||
$result['rams']['attackDefenseRatio'] = $rap / $rdp;
|
||||
$result['rams']['strongerBuildings'] = $strongerbuildings;
|
||||
$result['rams']['moraleBonus'] = 1;
|
||||
}
|
||||
|
||||
$result[6] = pow($rap / ($rdp * $moralbonus > 0 ? $rdp * $moralbonus : 1), $Mfactor);
|
||||
@@ -608,7 +620,7 @@ class Battle {
|
||||
|
||||
if ($hero_health <= $damage_health || $damage_health > 90){
|
||||
//hero die
|
||||
$result['casualties_attacker']['11'] = 1;
|
||||
$result['casualties_attacker'][11] = 1;
|
||||
mysqli_query($database->dblink,"update " . TB_PREFIX . "hero set `dead` = 1, `health` = 0 where `heroid`=".(int) $hero_id);
|
||||
}else{
|
||||
mysqli_query($database->dblink,"update " . TB_PREFIX . "hero set `health`=`health`-".(int) $damage_health." where `heroid`=".(int) $hero_id);
|
||||
@@ -735,46 +747,41 @@ class Battle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the new building level, after catapults/rams have damaged it
|
||||
* @author Kirilloid --> https://github.com/kirilloid/travian/blob/master/src/model/base/combat.ts
|
||||
*
|
||||
* @param float $moral The catapults/rams battle moral, 1 < moral < 3 => (Total attacker points / Total defender points)^3
|
||||
* @param int $upgrades Upgrades of catapults/rams made in the blacksmith
|
||||
* @param int $downgrades Defender bonuses, such as the stonemason's lodge
|
||||
* @param int $actualLevel The level of the building before the battle
|
||||
* @param int $realAttackers Effective catapults/rams involved in the building damage
|
||||
* @param int $totalAttackers Total catapults/rams sent in the attack
|
||||
* @param int $strongerBuildings Indicates the defender artifacts bonus against catapults
|
||||
* @return int Returns the new level of the damaged building
|
||||
* Calculates the new building level, after damaging it
|
||||
*
|
||||
* @param int $oldLevel The old building level
|
||||
* @param float $damage The damage done by catapults
|
||||
* @return int Returns the new building level
|
||||
*/
|
||||
|
||||
public function CalculateNewBuildingLevel($moral, $upgrades, $downgrades, $actualLevel, $realAttackers, $totalAttackers, $strongerBuildings)
|
||||
{
|
||||
if($moral < 1) $moral = 1;
|
||||
elseif($moral > 3) $moral = 3;
|
||||
|
||||
$needMax = round($this->CalculateNeededCatapults($moral, $upgrades / ($downgrades * $strongerBuildings), $actualLevel));
|
||||
if($needMax <= $realAttackers) return 0;
|
||||
for($i = $actualLevel - 1; $i >= 1; $i--)
|
||||
{
|
||||
$need = $this->CalculateNeededCatapults($moral, $upgrades / ($downgrades * $strongerBuildings), $i);
|
||||
if(min($realAttackers, $totalAttackers) / ($needMax - $need) <= 1) return ++$i;
|
||||
}
|
||||
|
||||
return $actualLevel;
|
||||
public function calculateNewBuildingLevel($oldLevel, $damage){
|
||||
$damage -= 0.5;
|
||||
if ($damage < 0) return $oldLevel;
|
||||
|
||||
while ($damage >= $oldLevel && $oldLevel) $damage -= $oldLevel--;
|
||||
|
||||
return $oldLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the needed catapults/rams to completely destroy a building/wall
|
||||
* @author Kirilloid --> https://github.com/kirilloid/travian/blob/master/src/model/base/combat.ts
|
||||
*
|
||||
* @param float $moral The catapults/rams battle moral
|
||||
* @param int $upDown (Upgrades / Downgrades / Stronger buildings) ratio of catapults/rams
|
||||
* @param int $actualLevel The level of the building before the battle
|
||||
* @return float Returns the needed catapults/rams to destroy a building/wall
|
||||
* Calculates the damage done by catapults
|
||||
*
|
||||
* @param int $catapultsQuantity The quantity of catapults which take part in the attack
|
||||
* @param double $catapultsUpgrade The catapults upgrade multiplier, affected by the cataputls level in the blacksmith
|
||||
* @param double $durability The building durability, affected by the stonemason's lodge
|
||||
* @param double $ADRatio The attack points / defensive points ratio
|
||||
* @param double $strongerBuildings The artifacts multiplier, which strengthens the building, affected by durability artifacts
|
||||
* @param double $moraleBonus The defender morale bonus
|
||||
* @return double Returns the damage done by catapults
|
||||
*/
|
||||
|
||||
public function CalculateNeededCatapults($moral, $upDown, $actualLevel)
|
||||
{
|
||||
return ($moral * (pow($actualLevel, 2) + $actualLevel + 1) / ($upDown == 0 ? 1 : 8 * $upDown)) + 0.5;
|
||||
public function calculateCatapultsDamage($catapultsQuantity, $catapultsUpgrade, $durability, $ADRatio, $strongerBuildings, $moraleBonus){
|
||||
$catapultsEfficiency = floor($catapultsQuantity / ($durability * $strongerBuildings));
|
||||
return 4 * ($this->sigma)($ADRatio) * $catapultsEfficiency * $catapultsUpgrade / $moraleBonus;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+55
-24
@@ -808,11 +808,8 @@ class MYSQLi_DB implements IDbConnection {
|
||||
$pairs[] = $this->escape($fieldName) . ' = ' . (Math::isInt($value[$index]) ? $value[$index] : '"'.$this->escape($value[$index]).'"');
|
||||
}
|
||||
|
||||
if(!$switch) {
|
||||
$q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where username = '$ref'";
|
||||
} else {
|
||||
$q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where id = " . (int) $ref;
|
||||
}
|
||||
if(!$switch) $q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where username = '$ref'";
|
||||
else $q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where id = " . (int) $ref;
|
||||
|
||||
// update cached values
|
||||
if ($ret = mysqli_query($this->dblink,$q)) {
|
||||
@@ -858,7 +855,9 @@ class MYSQLi_DB implements IDbConnection {
|
||||
if(!is_array($coordinatesArray[0])) $coordinatesArray = [$coordinatesArray];
|
||||
|
||||
$conditions = [];
|
||||
foreach($coordinatesArray as $coordinate) $conditions[] = "(x = ".$coordinate[0]." AND y = ".$coordinate[1].")";
|
||||
foreach($coordinatesArray as $coordinate){
|
||||
$conditions[] = "(x = ".round($coordinate[0])." AND y = ".round($coordinate[1]).")";
|
||||
}
|
||||
|
||||
$q = "SELECT id FROM " . TB_PREFIX . "wdata WHERE ".implode(" OR ", $conditions);
|
||||
$result = mysqli_query($this->dblink, $q);
|
||||
@@ -1138,20 +1137,20 @@ class MYSQLi_DB implements IDbConnection {
|
||||
function modifyGold($userid, $amt, $mode) {
|
||||
list($userid, $amt, $mode) = $this->escape_input((int) $userid, (int) $amt, $mode);
|
||||
|
||||
if(!$mode) {
|
||||
$q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
|
||||
} else {
|
||||
$q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
|
||||
}
|
||||
if(!$mode) $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
|
||||
else $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
|
||||
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
Function to retrieve user array via Username or ID
|
||||
Mode 0: Search by Username
|
||||
Mode 1: Search by ID
|
||||
References: Alliance ID
|
||||
*****************************************/
|
||||
/**
|
||||
* Retrieves the user array via Username or ID
|
||||
*
|
||||
* @param int $ref The user ID or the username
|
||||
* @param int $mode 0 --> Search by username, 1 --> Search by user ID
|
||||
* @param bool $use_cache Will use the cache if true
|
||||
* @return array Returns the user array
|
||||
*/
|
||||
|
||||
function getUserArray($ref, $mode, $use_cache = true) {
|
||||
list($ref, $mode) = $this->escape_input($ref, $mode);
|
||||
@@ -1162,11 +1161,9 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return $cachedValue;
|
||||
}
|
||||
|
||||
if(!$mode) {
|
||||
$q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
|
||||
} else {
|
||||
$q = "SELECT * FROM " . TB_PREFIX . "users where id = " . (int) $ref . " LIMIT 1";
|
||||
}
|
||||
if(!$mode) $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
|
||||
else $q = "SELECT * FROM " . TB_PREFIX . "users where id = " . (int) $ref . " LIMIT 1";
|
||||
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
|
||||
self::$fieldsCache[$ref.$mode] = mysqli_fetch_array($result);
|
||||
@@ -7697,7 +7694,6 @@ References: User ID/Message ID, Mode
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -7858,7 +7854,7 @@ References: User ID/Message ID, Mode
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
$cropo ++;
|
||||
$cropo++;
|
||||
break;
|
||||
case 12:
|
||||
$cropo += 2;
|
||||
@@ -7883,6 +7879,41 @@ References: User ID/Message ID, Mode
|
||||
return self::$cropProductionStarvationValueCache[$wref];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the starvation data in villages with a negative value of crop
|
||||
*
|
||||
* @param int $wref The village ID where the crop is negative
|
||||
*/
|
||||
|
||||
public function addStarvationData($wref){
|
||||
global $technology;
|
||||
|
||||
$getVillage = $this->getVillage($wref);
|
||||
|
||||
//Exlude Support, Nature, Natars, TaskMaster and Multihunter
|
||||
if ($getVillage['owner'] > 5){
|
||||
$crop = $this->getCropProdstarv($wref, false);
|
||||
$unitArrays = $technology->getAllUnits($wref, false, 0, false);
|
||||
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
|
||||
$starv = $getVillage['starv'];
|
||||
|
||||
if ($crop < $villageUpkeep){
|
||||
//Add starvation data
|
||||
$fields = ['starv'];
|
||||
$values = [$villageUpkeep];
|
||||
|
||||
//Update the starvupdate if it's set to 0
|
||||
if($getVillage['starvupdate'] == 0) {
|
||||
$fields[] = 'starvupdate';
|
||||
$values[] = time();
|
||||
}
|
||||
|
||||
//Update the starvation datas
|
||||
$this->setVillageFields($wref, $fields, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//general statistics
|
||||
|
||||
function addGeneralAttack($casualties) {
|
||||
|
||||
@@ -1031,6 +1031,7 @@ define("YOU_CONSTRUCT","You can construct ");
|
||||
define("CRANNY_INCREASED","Cranny capacity is increased by");
|
||||
define("CRANNY_DECRESE","Cranny capacity is decrese by");
|
||||
define("WW_BUILDING_PLAN","You can build the Wonder of the World");
|
||||
define("NO_WW","There are no Wonders of the World");
|
||||
define("NO_PREVIOUS_OWNERS","There are no previous owners.");
|
||||
define("TREASURY_DESC","The riches of your empire are kept in the treasury. The treasury has room for one treasure. After you have captured an artefact it takes 24 hours on a normal server or 12 hours on a thrice speed server to be effective.");
|
||||
|
||||
|
||||
+26
-33
@@ -11,7 +11,7 @@
|
||||
|
||||
class Ranking {
|
||||
|
||||
public $rankarray = array();
|
||||
public $rankarray = [];
|
||||
private $rlastupdate;
|
||||
|
||||
public function getRank() {
|
||||
@@ -20,14 +20,15 @@
|
||||
|
||||
public function getUserRank($id) {
|
||||
global $database;
|
||||
|
||||
$ranking = $this->getRank();
|
||||
$users = "SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE access < " . (INCLUDE_ADMIN ? "10" : "8");
|
||||
$users2 = mysqli_fetch_array(mysqli_query($database->dblink,$users), MYSQLI_ASSOC);
|
||||
$users2 = $users2['Total'];
|
||||
$users3 = $users2+1;
|
||||
$users3 = $users2 + 1;
|
||||
$myrank = 0;
|
||||
if(count($ranking) > 0) {
|
||||
for($i=0;$i<($users3);$i++) {
|
||||
for($i = 0;$i < $users3; $i++) {
|
||||
if( isset( $ranking[$i]['userid'] ) ) {
|
||||
if($ranking[$i]['userid'] == $id && $ranking[$i] != "pad") {
|
||||
$myrank = $i;
|
||||
@@ -197,31 +198,25 @@
|
||||
}
|
||||
|
||||
public function searchRank($name, $field) {
|
||||
while(1) {
|
||||
//$key = key($this->rankarray);
|
||||
for($key=0;$key<count($this->rankarray);$key++){
|
||||
if($this->rankarray[$key]!="pad") {
|
||||
if($this->rankarray[$key][$field] == $name) {
|
||||
return $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!next($this->rankarray)) {
|
||||
if($field != "userid"){
|
||||
return $name;
|
||||
break;
|
||||
}else{
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(1) {
|
||||
//$key = key($this->rankarray);
|
||||
for($key = 0; $key < count($this->rankarray); $key++){
|
||||
if($this->rankarray[$key]!="pad") {
|
||||
if($this->rankarray[$key][$field] == $name) return $key;
|
||||
}
|
||||
}
|
||||
if(!next($this->rankarray)) {
|
||||
if($field != "userid") return $name;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function procRankArray() {
|
||||
global $multisort, $database;
|
||||
|
||||
if($GLOBALS['db']->countUser() > 0){
|
||||
$holder = array();
|
||||
if(SHOW_NATARS == True){
|
||||
@@ -272,12 +267,10 @@
|
||||
ORDER BY totalpop DESC, totalvillages DESC, userid DESC";
|
||||
}
|
||||
|
||||
$datas = array();
|
||||
$datas = [];
|
||||
|
||||
$result = (mysqli_query($database->dblink,$q));
|
||||
while($row = mysqli_fetch_assoc($result)) {
|
||||
$datas[] = $row;
|
||||
}
|
||||
while($row = mysqli_fetch_assoc($result)) $datas[] = $row;
|
||||
|
||||
if (count($datas)) {
|
||||
foreach($datas as $result) {
|
||||
@@ -292,12 +285,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
$newholder = array("pad");
|
||||
foreach($holder as $key) {
|
||||
array_push($newholder, $key);
|
||||
}
|
||||
$newholder = ["pad"];
|
||||
foreach($holder as $key) array_push($newholder, $key);
|
||||
|
||||
$this->rankarray = $newholder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function procRankRaceArray($race) {
|
||||
|
||||
@@ -236,13 +236,13 @@ class Technology {
|
||||
return $ownunit;
|
||||
}
|
||||
|
||||
function getAllUnits($base, $InVillageOnly = false, $mode=0) {
|
||||
function getAllUnits($base, $InVillageOnly = false, $mode = 0, $useCache = true) {
|
||||
global $database;
|
||||
|
||||
$ownunit = $database->getUnit($base);
|
||||
$ownunit = $database->getUnit($base, $useCache);
|
||||
$ownunit['u99'] -= $ownunit['u99'];
|
||||
$ownunit['u99o'] -= $ownunit['u99o'];
|
||||
$enforcementarray = $database->getEnforceVillage($base, 0);
|
||||
$enforcementarray = $database->getEnforceVillage($base, 0, $useCache);
|
||||
if(count($enforcementarray) > 0){
|
||||
foreach($enforcementarray as $enforce){
|
||||
for($i = 1; $i <= 50; $i++){
|
||||
@@ -252,7 +252,7 @@ class Technology {
|
||||
}
|
||||
}
|
||||
if($mode == 0){
|
||||
$enforceoasis = $database->getOasisEnforce($base, 0);
|
||||
$enforceoasis = $database->getOasisEnforce($base, 0, $useCache);
|
||||
if(count($enforceoasis) > 0){
|
||||
foreach($enforceoasis as $enforce){
|
||||
for($i = 1; $i <= 50; $i++){
|
||||
@@ -261,7 +261,7 @@ class Technology {
|
||||
$ownunit['hero'] += $enforce['hero'];
|
||||
}
|
||||
}
|
||||
$enforceoasis1 = $database->getOasisEnforce($base, 1);
|
||||
$enforceoasis1 = $database->getOasisEnforce($base, 1, $useCache);
|
||||
if(count($enforceoasis1) > 0){
|
||||
foreach($enforceoasis1 as $enforce){
|
||||
for($i = 1; $i <= 50; $i++){
|
||||
@@ -271,7 +271,7 @@ class Technology {
|
||||
}
|
||||
}
|
||||
|
||||
$prisoners = $database->getPrisoners($base, 1);
|
||||
$prisoners = $database->getPrisoners($base, 1, $useCache);
|
||||
if(!empty($prisoners)){
|
||||
foreach($prisoners as $prisoner){
|
||||
$owner = $database->getVillageField($base, "owner");
|
||||
|
||||
@@ -224,6 +224,7 @@ class Units {
|
||||
|
||||
$to = $database->getVillage($enforce['from']);
|
||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||
$start = ($tribe - 1) * 10 + 1;
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $enforce, 1);
|
||||
$time = $database->getArtifactsValueInfluence($from['owner'], $enforce['from'], 2, $troopsTime);
|
||||
|
||||
Reference in New Issue
Block a user