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
+6
View File
@@ -90,6 +90,12 @@
}
if(isset($_GET['land']) && $village->resarray['f' . $id] >= 1) {
// FIX: pagina de oaze pierdea meniul T4 - ramura asta e inaintea
// celei cu tab-uri si nu includea navigatia deloc.
if (defined('NEW_FUNCTIONS_HERO_T4') && NEW_FUNCTIONS_HERO_T4) {
$t4tab = 'land';
include_once("37_t4nav.tpl");
}
include_once("37_land.tpl");
} else if (defined('NEW_FUNCTIONS_HERO_T4') && NEW_FUNCTIONS_HERO_T4
&& $village->resarray['f' . $id] >= 1
+55 -14
View File
@@ -17,6 +17,9 @@
## License : TravianZ Project ##
## Copyright : TravianZ (c) 2010-2026. All rights reserved. ##
## --------------------------------------------------------------------------- ##
## NOTA: doar prezentarea a fost refacuta (aspect ca in Travian original). ##
## Logica - generarea ofertelor, pornirea aventurii, mesajele - e neschimbata.##
## Coloana "Expires in" a fost pastrata (nu exista in originalul T4). ##
#################################################################################
$t4Adventures = new HeroAdventure();
@@ -41,6 +44,32 @@ $t4Adventures->generateOffers($session->uid);
$t4Offers = $t4Adventures->getOffers($session->uid);
$t4Running = $t4Adventures->getRunning($session->uid);
$t4Now = time();
/**
* Numele locului tintit de aventura, ca in Travian: "Abandoned valley" pentru
* un teren liber, "Unoccupied oasis" pentru o oaza libera. Tintele sunt mereu
* tile-uri neocupate (vezi HeroAdventure::generateOffers).
* getCoor() e cache-uit per request, deci nu adauga query-uri pe rand.
*/
$t4PlaceInfo = function ($wref) use ($database, $generator) {
$tile = $database->getCoor((int) $wref);
if (!is_array($tile) || !isset($tile['x'])) {
return null;
}
$isOasis = isset($tile['oasistype']) && (int) $tile['oasistype'] > 0;
return array(
'name' => $isOasis
? (defined('UNOCCUPIED') && defined('OASIS') ? UNOCCUPIED . ' ' . strtolower(OASIS) : 'Unoccupied oasis')
: (defined('ABANDVALLEY') ? ABANDVALLEY : 'Abandoned valley'),
'x' => (int) $tile['x'],
'y' => (int) $tile['y'],
'wref' => (int) $wref,
'check' => $generator->getMapCheck((int) $wref),
);
};
?>
<?php if ($t4Msg !== '') { ?>
@@ -59,10 +88,11 @@ $t4Now = time();
<table id="distribution" cellpadding="1" cellspacing="1" style="margin-top:10px;">
<thead>
<tr><th colspan="4"><?php echo HERO_ADV_LIST; ?></th></tr>
<tr><th colspan="5"><?php echo HERO_ADV_LIST; ?></th></tr>
<tr>
<td><b><?php echo HERO_ADV_DIFFICULTY; ?></b></td>
<td><b><?php echo defined('HERO_ADV_PLACE') ? HERO_ADV_PLACE : 'Place'; ?></b></td>
<td><b><?php echo HERO_ADV_DURATION; ?></b></td>
<td><b><?php echo defined('HERO_ADV_DANGER') ? HERO_ADV_DANGER : 'Danger'; ?></b></td>
<td><b><?php echo HERO_ADV_EXPIRES; ?></b></td>
<td></td>
</tr>
@@ -70,31 +100,42 @@ $t4Now = time();
<tbody>
<?php if (count($t4Offers)) { ?>
<?php foreach ($t4Offers as $t4Offer) { ?>
<?php
$t4Place = $t4PlaceInfo($t4Offer['wref']);
$t4Hard = ((int) $t4Offer['difficulty'] === 1);
?>
<tr>
<td>
<?php if ((int)$t4Offer['difficulty'] === 1): ?>
<img src="img/hero/dangerGreat.gif" alt="hard" title="<?php echo HERO_ADV_DIFF_HARD; ?>" style="vertical-align:middle; margin-right:4px; width:16px; height:16px;">
<?php echo HERO_ADV_DIFF_HARD; ?>
<?php else: ?>
<img src="img/hero/danger.gif" alt="normal" title="<?php echo HERO_ADV_DIFF_NORMAL; ?>" style="vertical-align:middle; margin-right:4px; width:16px; height:16px;">
<?php echo HERO_ADV_DIFF_NORMAL; ?>
<?php endif; ?>
</td>
<?php echo $t4Place ? $t4Place['name'] : '&mdash;'; ?>
<?php if ($t4Place) { ?>
<a href="karte.php?d=<?php echo $t4Place['wref']; ?>&amp;c=<?php echo $t4Place['check']; ?>"><b>(<?php echo $t4Place['x']; ?>|<?php echo $t4Place['y']; ?>)</b></a>
<?php } ?>
</td>
<td><?php echo $generator->getTimeFormat((int) $t4Offer['duration']); ?></td>
<td style="text-align:center;">
<img src="img/hero/<?php echo $t4Hard ? 'dangerGreat.gif' : 'danger.gif'; ?>"
alt="<?php echo $t4Hard ? HERO_ADV_DIFF_HARD : HERO_ADV_DIFF_NORMAL; ?>"
title="<?php echo $t4Hard ? HERO_ADV_DIFF_HARD : HERO_ADV_DIFF_NORMAL; ?>"
style="width:16px;height:16px;vertical-align:middle;">
</td>
<td><span id="timer<?php echo ++$session->timer; ?>"><?php echo $generator->getTimeFormat(max(0, $t4Offer['expire'] - $t4Now)); ?></span></td>
<td style="width:140px;text-align:center;">
<td style="width:150px;">
<?php if (!$t4Running) { ?>
<form action="" method="POST" style="margin:0;">
<form action="" method="POST" style="margin:0;display:inline;">
<input type="hidden" name="t4action" value="startadv">
<input type="hidden" name="advid" value="<?php echo (int) $t4Offer['id']; ?>">
<input type="submit" value="<?php echo HERO_ADV_GO; ?>">
<button type="submit" style="background:none;border:0;padding:0;cursor:pointer;font-size:inherit;font-family:inherit;color:#3a6f1e;font-weight:bold;">&#9658; <?php echo HERO_ADV_GO; ?></button>
</form>
<?php } else { ?>-<?php } ?>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr><td colspan="4"><?php echo HERO_ADV_NONE; ?></td></tr>
<tr><td colspan="5"><?php echo HERO_ADV_NONE; ?></td></tr>
<?php } ?>
</tbody>
</table>
+167 -8
View File
@@ -46,7 +46,11 @@ $heroStatColumns = [
$renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
$field = $heroStatColumns[$action];
if ($hero_info['points'] > 0 && $hero_info[$field] < 100) {
return "<a href=\"build.php?id=" . $id . "&add=" . $action . "\">(<b>+</b>)</a>";
// class + data-* pentru JS; linkul ramane un GET valid, deci fara JS
// pagina se comporta exact ca inainte (un punct per click, cu refresh).
return "<a href=\"build.php?id=" . $id . "&add=" . $action . "\""
. " class=\"t4AddPoint\" data-stat=\"" . $action . "\""
. " data-base=\"" . (int) $hero_info[$field] . "\">(<b>+</b>)</a>";
}
return "<span class=\"none\">(+)</span>";
};
@@ -71,7 +75,7 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="up"><span class="none">
<?php echo $renderAddLink('off'); ?>
</td>
<td class="po"><?php echo $hero_info['attack']; ?></td>
<td class="po" id="t4po_off"><?php echo $hero_info['attack']; ?></td>
</tr>
<tr>
<th><?php echo DEFENCE; ?></th>
@@ -80,7 +84,7 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="up"><span class="none">
<?php echo $renderAddLink('deff'); ?>
</td>
<td class="po"><?php echo $hero_info['defence']; ?></td>
<td class="po" id="t4po_deff"><?php echo $hero_info['defence']; ?></td>
</tr>
<tr>
<th><?php echo OFF_BONUS; ?></th>
@@ -89,7 +93,7 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="up"><span class="none">
<?php echo $renderAddLink('obonus'); ?>
</td>
<td class="po"><?php echo $hero_info['attackbonus']; ?></td>
<td class="po" id="t4po_obonus"><?php echo $hero_info['attackbonus']; ?></td>
</tr>
<tr>
<th><?php echo DEF_BONUS; ?></th>
@@ -98,7 +102,7 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="up"><span class="none">
<?php echo $renderAddLink('dbonus'); ?>
</td>
<td class="po"><?php echo $hero_info['defencebonus']; ?></td>
<td class="po" id="t4po_dbonus"><?php echo $hero_info['defencebonus']; ?></td>
</tr>
<tr>
<th><?php echo REGENERATION; ?></th>
@@ -107,7 +111,7 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="up"><span class="none">
<?php echo $renderAddLink('reg'); ?>
</td>
<td class="po"><?php echo $hero_info['regeneration']; ?></td>
<td class="po" id="t4po_reg"><?php echo $hero_info['regeneration']; ?></td>
</tr>
<tr>
<td colspan="5" class="empty"></td>
@@ -130,17 +134,111 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
<td class="val"><?php echo (int)$percent; ?>%</td>
<td class="xp"><img class="bar" src="img/x.gif" style="width:<?php echo $percent*2; ?>px;" alt="<?php echo (int)$percent; ?>%" title="<?php echo (int)$percent; ?>%" /></td>
<td class="up"></td>
<td class="rem"><?php echo $hero_info['points']; ?></td>
<td class="rem" id="t4rem"><?php echo $hero_info['points']; ?></td>
<?php }else{ ?>
<th title="<?php echo TZ_UNTIL_THE_NEXT_LEVEL; ?>"><?php echo EXPERIENCE; ?>:</th>
<td class="val">100%</td>
<td class="xp"><img class="bar" src="img/x.gif" style="width:200px;" alt="100%" title="100%" /></td>
<td class="up"></td>
<td class="rem"><?php echo $hero_info['points']; ?></td>
<td class="rem" id="t4rem"><?php echo $hero_info['points']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
<?php if ((int) $hero_info['points'] > 0) { ?>
<form id="t4PointsForm" action="" method="POST" style="margin:6px 0;">
<input type="hidden" name="t4points" value="1">
<?php foreach ($heroStatColumns as $t4Key => $t4Col) { ?>
<input type="hidden" name="p_<?php echo $t4Key; ?>" id="t4in_<?php echo $t4Key; ?>" value="0">
<?php } ?>
<div id="t4PointsBar" style="display:none;">
<button type="submit" id="t4PointsSave"><b>&#10003;</b> <?php echo defined('HERO_POINTS_SAVE') ? HERO_POINTS_SAVE : 'Save points'; ?> (<span id="t4PointsCount">0</span>)</button>
<a href="#" id="t4PointsCancel" style="margin-left:8px;"><?php echo defined('HERO_POINTS_CANCEL') ? HERO_POINTS_CANCEL : 'Cancel'; ?></a>
</div>
</form>
<script type="text/javascript">
/* Distribuirea punctelor fara reincarcarea paginii la fiecare click.
Fara JS, linkurile (+) raman GET-uri normale si merg ca inainte.
JS-ul doar ADUNA local; adevarul ramane la server, care valideaza totul
intr-un singur UPDATE atomic (vezi handlerul t4points din acest fisier). */
(function () {
var available = <?php echo (int) $hero_info['points']; ?>;
var links = document.getElementsByClassName('t4AddPoint');
if (!links.length) { return; }
var pending = {}, base = {};
var bar = document.getElementById('t4PointsBar');
var counter = document.getElementById('t4PointsCount');
var remCell = document.getElementById('t4rem');
function render() {
var used = 0, stat;
for (stat in pending) {
if (pending.hasOwnProperty(stat)) {
used += pending[stat];
var cell = document.getElementById('t4po_' + stat);
if (cell) {
cell.innerHTML = pending[stat] > 0
? base[stat] + ' <span style="color:#0a0;">(+' + pending[stat] + ')</span>'
: String(base[stat]);
}
var input = document.getElementById('t4in_' + stat);
if (input) { input.value = pending[stat]; }
}
}
if (remCell) { remCell.innerHTML = String(available - used); }
if (counter) { counter.innerHTML = String(used); }
if (bar) { bar.style.display = used > 0 ? '' : 'none'; }
}
for (var i = 0; i < links.length; i++) {
(function (link) {
var stat = link.getAttribute('data-stat');
base[stat] = parseInt(link.getAttribute('data-base'), 10) || 0;
pending[stat] = 0;
link.onclick = function (e) {
e.preventDefault();
var used = 0;
for (var k in pending) { if (pending.hasOwnProperty(k)) { used += pending[k]; } }
// nu poti aloca mai mult decat ai, nici trece de 100 pe o statistica
if (used >= available) { return false; }
if (base[stat] + pending[stat] >= 100) { return false; }
pending[stat]++;
render();
return false;
};
// click dreapta pe (+) scade alocarea, ca sa poti corecta fara reload
link.oncontextmenu = function (e) {
e.preventDefault();
if (pending[stat] > 0) { pending[stat]--; render(); }
return false;
};
})(links[i]);
}
var cancel = document.getElementById('t4PointsCancel');
if (cancel) {
cancel.onclick = function (e) {
e.preventDefault();
for (var k in pending) { if (pending.hasOwnProperty(k)) { pending[k] = 0; } }
render();
return false;
};
}
})();
</script>
<?php } ?>
<?php if(isset($_GET['e'])){
echo "<p><font size=\"1\" color=\"red\"><b>".ERROR_NAME_SHORT."</b></font></p>";
}
@@ -156,6 +254,67 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
// NOTE: the actions below are triggered by GET (?add=...) and modify
// data in the DB. This was the original (without CSRF), I did not change this aspect -
// it is an existing behavior in all build.php, not specific to this file.
// Distribuire IN BLOC (butonul "Save" din interfata cu JS).
// Siguranta: totul se valideaza pe server intr-un SINGUR UPDATE atomic, cu
// garzi in WHERE. Daca cineva trimite un POST modificat (mai multe puncte decat
// are, sau peste 100 la o statistica), conditiile nu se potrivesc, UPDATE-ul nu
// afecteaza niciun rand si nu se schimba nimic. Fiind o singura instructiune,
// nici doua cereri trimise simultan nu pot cheltui aceleasi puncte de doua ori.
if (isset($_POST['t4points'])) {
$t4Alloc = array();
$t4Total = 0;
foreach ($heroStatColumns as $t4Key => $t4Col) {
$t4Value = isset($_POST['p_' . $t4Key]) ? (int) $_POST['p_' . $t4Key] : 0;
if ($t4Value < 0) {
$t4Value = 0;
}
$t4Alloc[$t4Col] = $t4Value;
$t4Total += $t4Value;
}
if ($t4Total > 0) {
$t4Stmt = $database->dblink->prepare(
"UPDATE " . TB_PREFIX . "hero SET
`attack` = `attack` + ?,
`defence` = `defence` + ?,
`attackbonus` = `attackbonus` + ?,
`defencebonus` = `defencebonus` + ?,
`regeneration` = `regeneration` + ?,
`points` = `points` - ?
WHERE `heroid` = ?
AND `points` >= ?
AND `attack` + ? <= 100
AND `defence` + ? <= 100
AND `attackbonus` + ? <= 100
AND `defencebonus` + ? <= 100
AND `regeneration` + ? <= 100"
);
if ($t4Stmt) {
$t4HeroId = (int) $hero_info['heroid'];
$t4Stmt->bind_param(
'iiiiiiiiiiiii',
$t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'],
$t4Alloc['defencebonus'], $t4Alloc['regeneration'],
$t4Total, $t4HeroId, $t4Total,
$t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'],
$t4Alloc['defencebonus'], $t4Alloc['regeneration']
);
$t4Stmt->execute();
$t4Stmt->close();
}
}
header("Location: build.php?id=" . $id);
exit;
}
if (isset($_GET['add'])) {
$action = $_GET['add'];
+33 -1
View File
@@ -21,6 +21,27 @@
$t4Msg = '';
// Eroul poate schimba echipamentul doar cat timp e in sat (ca in Travian
// original). Motivul e calculat o singura data si folosit atat pentru mesaj,
// cat si pentru ascunderea butoanelor. Regula e impusa si in HeroItems, deci
// un POST trimis manual nu o poate ocoli.
$t4AwayReason = $t4HeroItems->heroAwayReason($session->uid);
$t4AwayText = '';
if ($t4AwayReason === 'nohero') {
$t4AwayText = defined('HERO_LOCKED_NOHERO') ? HERO_LOCKED_NOHERO
: 'You have no hero yet. Train one in the Hero\'s Mansion before equipping items.';
} elseif ($t4AwayReason === 'adventure') {
$t4AwayText = defined('HERO_LOCKED_ADVENTURE') ? HERO_LOCKED_ADVENTURE
: 'Your hero is on an adventure. Equipment can only be changed while the hero is in a village.';
} elseif ($t4AwayReason === 'attack') {
$t4AwayText = defined('HERO_LOCKED_ATTACK') ? HERO_LOCKED_ATTACK
: 'Your hero is on the move with the army. Equipment can only be changed while the hero is in a village.';
} elseif ($t4AwayReason === 'reinforcement') {
$t4AwayText = defined('HERO_LOCKED_REINFORCEMENT') ? HERO_LOCKED_REINFORCEMENT
: 'Your hero is reinforcing another village. Equipment can only be changed while the hero is in a village.';
}
if (isset($_POST['t4action'], $_POST['rowid'])) {
$t4RowId = (int) $_POST['rowid'];
@@ -53,6 +74,11 @@ $t4Inventory = $t4HeroItems->getInventory($session->uid);
$t4Equipped = $t4HeroItems->getEquipped($session->uid);
?>
<?php if ($t4AwayText !== '') { ?>
<p class="message" style="font-weight:bold;color:#8a6d3b;background:#fcf8e3;border:1px solid #faebcc;padding:6px 9px;border-radius:4px;">
<?php echo $t4AwayText; ?>
</p>
<?php } ?>
<?php if ($t4Msg !== '') { ?>
<p class="message" style="font-weight:bold;"><?php echo $t4Msg; ?></p>
<?php } ?>
@@ -69,11 +95,15 @@ $t4Equipped = $t4HeroItems->getEquipped($session->uid);
<td title="<?php echo htmlspecialchars(heroItemBonusText((int) $t4Row['itemid'])); ?>"><span class="heroT4Item item<?php echo (int) $t4Row['itemid']; ?>"></span> <?php echo $t4Row['name']; ?></td>
<td style="width:60px;text-align:center;"><?php echo 'T' . (int) $t4Row['def']['tier']; ?></td>
<td style="width:110px;text-align:center;">
<?php if ($t4AwayReason === '') { ?>
<form action="" method="POST" style="margin:0;">
<input type="hidden" name="t4action" value="unequip">
<input type="hidden" name="rowid" value="<?php echo (int) $t4Row['id']; ?>">
<input type="submit" value="<?php echo HERO_UNEQUIP; ?>">
</form>
<?php } else { ?>
<span style="color:#999;">&mdash;</span>
<?php } ?>
</td>
<?php } else { ?>
<td colspan="3" style="color:#888;">-</td>
@@ -110,9 +140,11 @@ $t4Equipped = $t4HeroItems->getEquipped($session->uid);
<input type="hidden" name="t4action" value="useitem">
<input type="text" name="qty" value="1" size="3" style="text-align:center;">
<input type="submit" value="<?php echo HERO_USE_ITEM; ?>">
<?php } else { ?>
<?php } elseif ($t4AwayReason === '') { ?>
<input type="hidden" name="t4action" value="equip">
<input type="submit" value="<?php echo HERO_EQUIP; ?>">
<?php } else { ?>
<span style="color:#999;">&mdash;</span>
<?php } ?>
</form>
</td>
+3
View File
@@ -24,6 +24,9 @@ $t4HeroItems = new HeroItems();
$t4Silver = $t4HeroItems->getSilver($session->uid);
$t4Tabs = [
'hero' => ['label' => HERO_T4_TAB_HERO, 'url' => 'build.php?id=' . $id],
// Oaze: pagina foloseste parametrul "land", nu "t4tab" (flux mai vechi).
'land' => ['label' => defined('HERO_T4_TAB_OASIS') ? HERO_T4_TAB_OASIS : 'Oasis',
'url' => 'build.php?id=' . $id . '&land'],
'items' => ['label' => HERO_T4_TAB_ITEMS, 'url' => 'build.php?id=' . $id . '&t4tab=items'],
'adventures' => ['label' => HERO_T4_TAB_ADVENTURES, 'url' => 'build.php?id=' . $id . '&t4tab=adventures'],
'auction' => ['label' => HERO_T4_TAB_AUCTION, 'url' => 'build.php?id=' . $id . '&t4tab=auction'],