mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-12 14:21:03 +00:00
Update Database.php
Fixed chieftain training issue: when player reinforced their chiefs to other villages they could train more so no more unlimited chieftains :)
This commit is contained in:
+79
-71
@@ -7134,90 +7134,98 @@ References: User ID/Message ID, Mode
|
|||||||
public function getAvailableExpansionTraining() {
|
public function getAvailableExpansionTraining() {
|
||||||
global $building, $session, $technology, $village;
|
global $building, $session, $technology, $village;
|
||||||
|
|
||||||
$vilData = $this->getVillage($village->wid);
|
$vilData = $this->getVillage($village->wid);
|
||||||
$maxslots = (($vilData['exp1'] == 0 ? 1 : 0) + ($vilData['exp2'] == 0 ? 1 : 0) + ($vilData['exp3'] == 0 ? 1 : 0));
|
$maxslots = (($vilData['exp1'] == 0 ? 1 : 0) + ($vilData['exp2'] == 0 ? 1 : 0) + ($vilData['exp3'] == 0 ? 1 : 0));
|
||||||
$residence = $building->getTypeLevel(25);
|
$residence = $building->getTypeLevel(25);
|
||||||
$palace = $building->getTypeLevel(26);
|
$palace = $building->getTypeLevel(26);
|
||||||
|
|
||||||
if($residence > 0) {
|
if($residence > 0) {
|
||||||
$maxslots -= (3 - floor($residence / 10));
|
$maxslots -= (3 - floor($residence / 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($palace > 0) {
|
if($palace > 0) {
|
||||||
$maxslots -= (3 - floor(($palace - 5) / 5));
|
$maxslots -= (3 - floor(($palace - 5) / 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT (u10+u20+u30) as R1, (u9+u19+u29) as R2 FROM " . TB_PREFIX . "units WHERE vref = ". (int) $village->wid;
|
// Units at home
|
||||||
$result = mysqli_query($this->dblink,$q);
|
$q = "SELECT (u10+u20+u30) as R1, (u9+u19+u29) as R2
|
||||||
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
FROM " . TB_PREFIX . "units
|
||||||
$settlers = $row['R1'];
|
WHERE vref = " . (int)$village->wid;
|
||||||
$chiefs = $row['R2'];
|
$result = mysqli_query($this->dblink,$q);
|
||||||
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
|
$settlers = (int)$row['R1'];
|
||||||
|
$chiefs = (int)$row['R2'];
|
||||||
|
|
||||||
$settlers += 3 * count($this->getMovement(5, $village->wid, 0));
|
// Movements
|
||||||
|
$settlers += 3 * count($this->getMovement(5, $village->wid, 0));
|
||||||
|
|
||||||
$current_movement = $this->getMovement(3, $village->wid, 0);
|
$current_movement = $this->getMovement(3, $village->wid, 0);
|
||||||
if(!empty($current_movement)) {
|
if(!empty($current_movement)) {
|
||||||
foreach($current_movement as $build) {
|
foreach($current_movement as $build) {
|
||||||
$settlers += $build['t10'];
|
$settlers += (int)$build['t10'];
|
||||||
$chiefs += $build['t9'];
|
$chiefs += (int)$build['t9'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_movement = $this->getMovement(4, $village->wid, 1);
|
$current_movement = $this->getMovement(4, $village->wid, 1);
|
||||||
if(!empty($current_movement)) {
|
if(!empty($current_movement)) {
|
||||||
foreach($current_movement as $build) {
|
foreach($current_movement as $build) {
|
||||||
$settlers += $build['t10'];
|
$settlers += (int)$build['t10'];
|
||||||
$chiefs += $build['t9'];
|
$chiefs += (int)$build['t9'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = ".(int) $village->wid;
|
// FIX: Count ALL reinforcements properly (SUM over ALL rows)
|
||||||
$result = mysqli_query($this->dblink,$q);
|
$q = "SELECT COALESCE(SUM(u10+u20+u30),0) AS s
|
||||||
$row = mysqli_fetch_row($result);
|
FROM " . TB_PREFIX . "enforcement
|
||||||
if(!empty($row)) {
|
WHERE `from` = " . (int)$village->wid;
|
||||||
foreach($row as $reinf) {
|
$result = mysqli_query($this->dblink,$q);
|
||||||
$settlers += $reinf[0];
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
}
|
$settlers += (int)$row['s'];
|
||||||
}
|
|
||||||
|
|
||||||
$q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "enforcement WHERE `from` = ".(int) $village->wid;
|
$q = "SELECT COALESCE(SUM(u9+u19+u29),0) AS c
|
||||||
$result = mysqli_query($this->dblink,$q);
|
FROM " . TB_PREFIX . "enforcement
|
||||||
$row = mysqli_fetch_row($result);
|
WHERE `from` = " . (int)$village->wid;
|
||||||
if(!empty($row)) {
|
$result = mysqli_query($this->dblink,$q);
|
||||||
foreach($row as $reinf) {
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||||
$chiefs += $reinf[0];
|
$chiefs += (int)$row['c'];
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$trainlist = $technology->getTrainingList(4);
|
// Training queue (your existing logic)
|
||||||
if(!empty($trainlist)) {
|
$trainlist = $technology->getTrainingList(4);
|
||||||
foreach($trainlist as $train) {
|
if(!empty($trainlist)) {
|
||||||
if($train['unit'] % 10 == 0) {
|
foreach($trainlist as $train) {
|
||||||
$settlers += $train['amt'];
|
if($train['unit'] % 10 == 0) {
|
||||||
}
|
$settlers += (int)$train['amt'];
|
||||||
if($train['unit'] % 10 == 9) {
|
}
|
||||||
$chiefs += $train['amt'];
|
if($train['unit'] % 10 == 9) {
|
||||||
}
|
$chiefs += (int)$train['amt'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$trappedTroops = $this->getPrisoners($village->wid, 1);
|
// Trapped troops
|
||||||
if(!empty($trappedTroops)){
|
$trappedTroops = $this->getPrisoners($village->wid, 1);
|
||||||
foreach($trappedTroops as $trapped){
|
if(!empty($trappedTroops)){
|
||||||
$settlers += $trapped['t10'];
|
foreach($trappedTroops as $trapped){
|
||||||
$chiefs += $trapped['t9'];
|
$settlers += (int)$trapped['t10'];
|
||||||
}
|
$chiefs += (int)$trapped['t9'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$settlerslots = ($maxslots * 3) - ($chiefs * 3) - $settlers;
|
// Slot math (unchanged, but clamp to 0 to avoid negatives)
|
||||||
$chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
|
$settlerslots = ($maxslots * 3) - ($chiefs * 3) - $settlers;
|
||||||
|
$chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
|
||||||
|
|
||||||
if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
|
if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
|
||||||
$chiefslots = 0;
|
$chiefslots = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($settlerslots < 0) $settlerslots = 0;
|
||||||
|
if ($chiefslots < 0) $chiefslots = 0;
|
||||||
|
|
||||||
|
return ["chiefs" => $chiefslots, "settlers" => $settlerslots];
|
||||||
|
}
|
||||||
|
|
||||||
return ["chiefs" => $chiefslots, "settlers" => $settlerslots];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates how much artifacts affect troops speed, cranny efficency, etc.
|
* Calculates how much artifacts affect troops speed, cranny efficency, etc.
|
||||||
|
|||||||
Reference in New Issue
Block a user