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 "(+)"; }; ?> $expCurrent && $curLevel < 100){ $percent = ($curExp - $expCurrent) / ($expNext - $expCurrent) * 100; $percent = max(0, min(100, $percent)); ?>
uid."\">"; }else{ echo "".$hero_info['name'].""; } ?> ( getUnitName($hero_info['unit'])."\" title=\"".$technology->getUnitName($hero_info['unit'])."\" /> ".$technology->getUnitName($hero_info['unit']); ?> )
<?php echo $hero_info['atk']; ?>
<?php echo ($hero_info['di']) . " title="" />
% <?php echo ($hero_info['ob']-1)*100; ?>%
% <?php echo ($hero_info['db']-1)*100; ?>%
/ <?php echo ($hero_info['regeneration']*5*SPEED); ?>%/Day
'r1', 2 => 'r2', 3 => 'r3', 4 => 'r4']; if ($t4ResType >= 1 && $t4ResType <= 4) { echo ' '; echo (int) round($t4ResPoints * $t4PerOne * SPEED); } else { foreach ($t4ResIcons as $t4Ico) { echo ' ' . (int) round($t4ResPoints * $t4PerAll * SPEED) . ' '; } } ?> /
:
: % <?php echo (int)$percent; ?>% : 100% 100%
0) { ?>
$t4Col) { ?>
".ERROR_NAME_SHORT."

"; } ?>

3

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

= 0 && $t4Type <= 4) { // Interogarea se construieste din $heroStatColumns, deci acopera automat // exact atributele active (cu sau fara "resources"). $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("\n\t\t\t AND ", $t4Guard) ); if ($t4Stmt) { $t4HeroId = (int) $hero_info['heroid']; // ordinea parametrilor: cresteri, 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($_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` + ?, `resources` = `resources` + ?, `points` = `points` - ? WHERE `heroid` = ? AND `points` >= ? AND `attack` + ? <= 100 AND `defence` + ? <= 100 AND `attackbonus` + ? <= 100 AND `defencebonus` + ? <= 100 AND `regeneration` + ? <= 100 AND `resources` + ? <= 100" ); if ($t4Stmt) { $t4HeroId = (int) $hero_info['heroid']; $t4Stmt->bind_param( 'iiiiiiiiiiiiiii', $t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'], $t4Alloc['defencebonus'], $t4Alloc['regeneration'], $t4Alloc['resources'], $t4Total, $t4HeroId, $t4Total, $t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'], $t4Alloc['defencebonus'], $t4Alloc['regeneration'], $t4Alloc['resources'] ); $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; } } ?>