escape(stripslashes($_POST['name'])); mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "hero SET `name`='" . $_POST['name'] . "' where `uid`='" . $database->escape($session->uid) . "' AND dead = 0") or die("ERROR:" . mysqli_error($database->dblink)); $hero_info['name'] = $_POST['name']; echo "" . NAME_CHANGED . ""; } // Explicit lookup: action from URL (?add=...) => column from `hero` table. // Used for both "(+)" links in the table and for the update // in the DB below. Single source of truth instead of 5 identical blocks. $heroStatColumns = [ 'off' => 'attack', 'deff' => 'defence', 'obonus' => 'attackbonus', 'dbonus' => 'defencebonus', 'reg' => 'regeneration', ]; // Atributul "Resources" apartine sistemului de erou T4: apare si poate primi // puncte doar cand functiile T4 sunt pornite. Tot flag-ul asta decide si daca // productia se aplica (vezi Village::loadHeroProd), deci cele doua nu pot ajunge // in dezacord - altfel jucatorii ar investi in ceva care nu produce nimic. // In plus, cu flag-ul stins interogarile de mai jos nu mai ating coloanele // `resources` / `res_type`, deci pagina merge si pe un server care inca nu a // rulat scriptul add-hero-resources.sql. $t4HeroRes = defined('NEW_FUNCTIONS_HERO_T4') && NEW_FUNCTIONS_HERO_T4; if ($t4HeroRes) { $heroStatColumns['res'] = 'resources'; } // Render the "(+)" link for a stat, or "(+)" uneditable // if the hero has no more points or the stat is already at the top (100). // Identical behavior to the original 5 if/else blocks. $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) { $field = $heroStatColumns[$action]; if ($hero_info['points'] > 0 && $hero_info[$field] < 100) { // 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 "(+)"; } return "(+)"; }; ?>
" . "uid . "\">" . "" . ""; } else { echo "" . $hero_info['name'] . ""; } ?> ( getUnitName($hero_info['unit']) . "\" title=\"" . $technology->getUnitName($hero_info['unit']) . "\" /> " . $technology->getUnitName($hero_info['unit']); ?> )
= 1 && $t4ResType <= 4) ? (int) round($t4ResPoints * $t4PerOne * SPEED) : (int) round($t4ResPoints * $t4PerAll * SPEED); $t4Rows[] = array( defined('HERO_RES_PRODUCTION') ? HERO_RES_PRODUCTION : 'Resources', $t4ResShown, $t4ResPoints, 'res' ); } foreach ($t4Rows as $t4Row) { list($t4Label, $t4Value, $t4Points, $t4Key) = $t4Row; $t4Fill = max(0, min(100, $t4Points)); ?>
array('img' => 'img/hero/res_all.png', 'amount' => (int) round($t4ResPoints * $t4PerAll * SPEED)), 1 => array('icons' => array('r1'), 'amount' => (int) round($t4ResPoints * $t4PerOne * SPEED)), 2 => array('icons' => array('r2'), 'amount' => (int) round($t4ResPoints * $t4PerOne * SPEED)), 3 => array('icons' => array('r3'), 'amount' => (int) round($t4ResPoints * $t4PerOne * SPEED)), 4 => array('icons' => array('r4'), 'amount' => (int) round($t4ResPoints * $t4PerOne * SPEED)), ); foreach ($t4Opts as $t4Val => $t4Opt) { ?>
%
$expCurrent && $curLevel < $t4MaxLevel) { $percent = ($curExp - $expCurrent) / ($expNext - $expCurrent) * 100; $percent = max(0, min(100, $percent)); } else { $percent = 100; } ?>
:
0) { ?>
$t4Col) { ?>
".ERROR_NAME_SHORT."

"; } ?>

3

% .
VillageOasisCount($village->wid); ?> .

= 0 && $t4Type <= 4) { $t4Stmt = $database->dblink->prepare( "UPDATE " . TB_PREFIX . "hero SET `res_type` = ? WHERE `heroid` = ? LIMIT 1" ); if ($t4Stmt) { $t4HeroId = (int) $hero_info['heroid']; $t4Stmt->bind_param('ii', $t4Type, $t4HeroId); $t4Stmt->execute(); $t4Stmt->close(); } } header("Location: build.php?id=" . $id); exit; } // 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) { // Interogarea se construieste din $heroStatColumns, deci acopera exact // atributele active. Cu functiile T4 oprite nu apare deloc coloana // `resources`, asa ca pagina merge si pe un server care inca nu a rulat // scriptul add-hero-resources.sql. $t4Cols = array_values($heroStatColumns); $t4Set = array(); $t4Guard = array(); foreach ($t4Cols as $t4Col) { $t4Set[] = "`" . $t4Col . "` = `" . $t4Col . "` + ?"; $t4Guard[] = "`" . $t4Col . "` + ? <= 100"; } $t4Stmt = $database->dblink->prepare( "UPDATE " . TB_PREFIX . "hero SET " . implode(", ", $t4Set) . ", `points` = `points` - ? WHERE `heroid` = ? AND `points` >= ? AND " . implode(" AND ", $t4Guard) ); if ($t4Stmt) { $t4HeroId = (int) $hero_info['heroid']; // ordinea parametrilor: cresterile, punctele scazute, heroid, garda // de puncte, apoi garzile de maxim 100 pentru fiecare atribut $t4Values = array(); foreach ($t4Cols as $t4Col) { $t4Values[] = $t4Alloc[$t4Col]; } $t4Values[] = $t4Total; $t4Values[] = $t4HeroId; $t4Values[] = $t4Total; foreach ($t4Cols as $t4Col) { $t4Values[] = $t4Alloc[$t4Col]; } $t4Stmt->bind_param(str_repeat('i', count($t4Values)), ...$t4Values); $t4Stmt->execute(); $t4Stmt->close(); } } header("Location: build.php?id=" . $id); exit; } if (isset($_GET['add'])) { $action = $_GET['add']; if ($action == "reset") { if ($hero_info['level'] <= 3) { mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "hero SET `points` = (`level` * 5) + 5, `attack` = 0, `defence` = 0, `attackbonus` = 0, `defencebonus` = 0, `regeneration` = 0 WHERE `heroid` = " . $hero_info['heroid'] . " AND `level` <= 3 AND (`attack` != 0 OR `defence` != 0 OR `attackbonus` != 0 OR `defencebonus` != 0 OR `regeneration` != 0)"); header("Location: build.php?id=" . $id . ""); exit; } // if level > 3, exactly like in the original: nothing happens (no redirect). } elseif (isset($heroStatColumns[$action])) { $column = $heroStatColumns[$action]; mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "hero SET `$column` = `$column` + 1, `points` = `points` - 1 WHERE `heroid` = " . $hero_info['heroid'] . " AND `points` > 0 AND `$column` < 100"); header("Location: build.php?id=" . $id . ""); exit; } } ?>