Last fix for Hero T4 & V11

/*
|--------------------------------------------------------------------------
| FIX List
|--------------------------------------------------------------------------
|
| 1. Hero Attribute Points
|    - When adding attribute points to the hero, the page currently refreshes
|      after every click on the "+" button.
|    - Implement a faster allocation method (AJAX or similar) so multiple
|      points can be assigned without a full page refresh.
|    - The implementation must remain secure and not be exploitable
|      (validate requests server-side, prevent double submissions,
|      verify available points, etc.).
|
| 2. Hero Equipment Restrictions (Original Travian Behavior)
|    - Prevent equipping or unequipping hero items while the hero is:
|        • On an adventure.
|        • Attacking (alone or with troops).
|        • Away as reinforcements.
|
| 3. Oasis Navigation
|    - When opening an oasis (37_land.tpl), the 37_t4nav.tpl navigation
|      disappears.
|    - Include the navigation menu on the oasis page as well.
|
| 4. Auction House Redesign
|    - Redesign 37_auction.tpl to match the Merchant.png mockup.
|    - Keep the existing auction functionality exactly as it is.
|    - Only improve the UI/UX.
|    - You may crop and reuse graphics from Merchant.png.
|    - Add Gold ⇄ Silver exchange functionality.
|
| 5. Hero Item Bonuses (Highest Priority)
|    - Verify that hero equipment bonuses are applied correctly.
|    - Example:
|        • Helmet of the Ruler should reduce Barracks training time by 20%.
|        • Currently, training time remains unchanged whether the helmet
|          is equipped or not.
|    - Also verify:
|        • Stable training speed bonuses.
|        • Boots bonuses.
|        • Any other related hero equipment effects.
|
| 6. Adventures Page Redesign
|    - Redesign 37_adventures.tpl to match the Adventure.png mockup.
|    - Keep the "Expires in" column intact.
|
*/
This commit is contained in:
novgorodschi catalin
2026-07-23 15:16:51 +03:00
parent 34e3d88e39
commit 1e19f117ca
19 changed files with 620 additions and 29 deletions
+60 -2
View File
@@ -121,13 +121,48 @@ trait AutomationHero {
// Passive HP regeneration: returns the new health value, or -1 if unchanged.
private function calculateHealthRegen($hdata) {
// Eroii morti nu se regenereaza (se ridica prin inviere, nu singuri).
if ((int) $hdata['dead'] === 1) {
return -1;
}
if((time()-$hdata['lastupdate']) >= 1){
if($hdata['health'] < 100 and $hdata['health'] > 0){
// FIX: conditia veche era "health > 0", deci un erou VIU ajuns exact
// la 0 ramanea blocat acolo pentru totdeauna. Acum conteaza doar sa
// fie viu si sub 100.
if($hdata['health'] < 100){
if(SPEED <= 10) $speed = SPEED;
else if(SPEED <= 100) $speed = ceil(SPEED / 10);
else $speed = ceil(SPEED / 100);
$reg = $hdata['health'] + $hdata['regeneration'] * 5 * $speed / 86400 * (time() - $hdata['lastupdate']);
// FIX: bonusul HB_REGEN_HP al coifurilor (Regeneration / Health /
// Healing = +10/15/20 HP pe zi) nu era aplicat nicaieri - exista
// doar in definitia itemelor. Se adauga la regenerarea proprie a
// eroului, scalat cu aceeasi viteza de server ca aceasta, altfel
// pe un server rapid ar fi complet nesemnificativ.
// ANOMALIE DE SEMNALAT: in T4 valoarea e "HP pe zi" fixa; aici o
// scalam cu $speed pentru consecventa cu regenerarea din atribute.
// Daca preferi valoarea fixa, scoate "* $speed" de mai jos.
$itemRegen = $this->heroItemRegen($hdata);
// FIX PRINCIPAL: pana acum regenerarea depindea EXCLUSIV de
// atributul 'regeneration'. Un erou nou porneste cu acest atribut
// pe 0 (vezi INSERT-ul din 37_train.tpl), deci daca jucatorul nu
// punea puncte acolo, viata NU se refacea niciodata: scadea la
// fiecare aventura sau lupta si nu urca inapoi. Dupa destule
// aventuri ajungea la 0 si eroul murea chiar si la o aventura
// "Normal" (care ia doar 0-8 HP) - exact simptomul raportat.
//
// Acum exista o regenerare de BAZA, independenta de atribute, ca
// in Travian T4 (implicit 10 HP pe zi). Se poate regla din
// GameEngine/config.php: define('HERO_BASE_REGEN', 10);
$baseRegen = defined('HERO_BASE_REGEN') ? (float) HERO_BASE_REGEN : 10;
// HP pe zi din toate sursele: baza + atribut (5 per punct) + iteme
$perDay = $baseRegen + ($hdata['regeneration'] * 5) + $itemRegen;
$reg = $hdata['health']
+ $perDay * $speed / 86400 * (time() - $hdata['lastupdate']);
return ($reg <= 100) ? $reg : 100;
}
@@ -135,6 +170,29 @@ trait AutomationHero {
return -1;
}
/**
* HP pe zi adaugat de itemele echipate (HB_REGEN_HP).
*
* HeroBattleBonus::bonuses() are gard de feature flag, cache per request si
* intoarce null cand sistemul T4 e oprit - deci pe serverele fara erou T4
* comportamentul ramane exact ca inainte.
*/
private function heroItemRegen($hdata) {
if (!class_exists('HeroBattleBonus') || !HeroBattleBonus::enabled()) {
return 0;
}
$uid = isset($hdata['uid']) ? (int) $hdata['uid'] : 0;
if ($uid <= 0) {
return 0;
}
$bonuses = HeroBattleBonus::bonuses($uid);
return $bonuses ? (float) $bonuses[HB_REGEN_HP] : 0;
}
// Level-up + score points. Returns a column fragment.
private function calculateLevelUp($hdata) {
global $hero_levels;
@@ -212,10 +212,84 @@ trait AutomationVillageUpkeep {
private function culturePoints() {
global $database;
// FIX: punctele de cultura date de coifuri (Gladiator/Tribune/Consul =
// 100/400/800 pe zi) nu erau adaugate nicaieri - HB_CP exista doar in
// definitia itemelor si in agregarea din HeroItems::getBonuses().
// Se aplica INAINTE de updateVSumField, fiindca acela reseteaza
// users.lastupdate; asa ambele folosesc exact aceeasi fereastra de timp.
$this->applyHeroCulturePoints();
$database->updateVSumField('cp');
}
/**
* Adauga in users.cp punctele de cultura ale coifurilor echipate.
*
* Acumularea imita formula din updateVSumField(): valoarea e "pe zi", iar
* ziua de joc e 86400/SPEED (minim o ora), la fel ca pentru cladiri.
* Valorile sunt luate din catalog prin scaledBonusValue(), care aplica deja
* regula de server rapid (coifurile de cultura se injumatatesc la SPEED>=3).
*
* Se numara doar eroii vii (hero.dead = 0). Cum exista un singur slot de
* coif, un jucator nu poate avea doua iteme cu CP echipate simultan, deci
* join-ul nu poate dubla castigul.
*/
private function applyHeroCulturePoints() {
global $database, $heroItemCatalog;
if (!class_exists('HeroBattleBonus') || !HeroBattleBonus::enabled()) {
return;
}
if (empty($heroItemCatalog) || !is_array($heroItemCatalog)) {
return;
}
$heroItems = new HeroItems();
$cpValues = array();
foreach ($heroItemCatalog as $itemid => $def) {
if (!isset($def['bonus']) || !is_array($def['bonus']) || !isset($def['bonus'][HB_CP])) {
continue;
}
$value = (int) $heroItems->scaledBonusValue($def, (int) $def['bonus'][HB_CP]);
if ($value > 0) {
$cpValues[(int) $itemid] = $value;
}
}
if (empty($cpValues)) {
return;
}
$durDay = 86400 / SPEED;
if ($durDay < 3600) {
$durDay = 3600;
}
$case = '';
foreach ($cpValues as $itemid => $value) {
$case .= ' WHEN ' . (int) $itemid . ' THEN ' . (int) $value;
}
$ids = implode(',', array_map('intval', array_keys($cpValues)));
$q = "UPDATE " . TB_PREFIX . "users AS u
INNER JOIN " . TB_PREFIX . "hero_items AS hi
ON hi.uid = u.id AND hi.equipped = 1 AND hi.itemid IN (" . $ids . ")
INNER JOIN " . TB_PREFIX . "hero AS h
ON h.uid = u.id AND h.dead = 0
SET u.cp = u.cp + ((CASE hi.itemid" . $case . " END) * (UNIX_TIMESTAMP() - u.lastupdate) / " . $durDay . ")
WHERE u.lastupdate < (UNIX_TIMESTAMP() - 600)";
mysqli_query($database->dblink, $q);
}
/**
* Recompute a warehouse/granary capacity after a build completion.
* Returns [$fieldDbName, $max]: the vdata column to update and its new value.