mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-26 14:36:06 +00:00
Add T4 Hero Resource and some fix
Add T4 Hero Resource and some fix
This commit is contained in:
@@ -23,6 +23,36 @@ $t4Auction = new HeroAuction();
|
||||
$t4Msg = '';
|
||||
|
||||
if (isset($_POST['t4action'])) {
|
||||
// --- SCHIMB AUR <-> ARGINT -------------------------------------------
|
||||
// Validarea si atomicitatea sunt in HeroItems::exchange*(); aici doar
|
||||
// afisam rezultatul si tinem sesiunea sincronizata cu noul sold de aur.
|
||||
if (($_POST['t4action'] === 'g2s' || $_POST['t4action'] === 's2g') && isset($_POST['amount'])) {
|
||||
$t4Items = new HeroItems();
|
||||
$t4Amount = (int) $_POST['amount'];
|
||||
|
||||
$t4Ex = ($_POST['t4action'] === 'g2s')
|
||||
? $t4Items->exchangeGoldToSilver($session->uid, $t4Amount)
|
||||
: $t4Items->exchangeSilverToGold($session->uid, $t4Amount);
|
||||
|
||||
if ($t4Ex === HeroItems::EXCHANGE_OK) {
|
||||
$t4Msg = defined('HERO_EXCHANGE_OK') ? HERO_EXCHANGE_OK : 'Exchange completed.';
|
||||
|
||||
// soldul de aur din sesiune trebuie reimprospatat, altfel pagina ar
|
||||
// arata vechea valoare pana la expirarea cache-ului de utilizator
|
||||
$t4NewGold = (int) $database->getUserField($session->uid, 'gold', 0);
|
||||
$session->gold = $t4NewGold;
|
||||
$_SESSION['gold'] = $t4NewGold;
|
||||
unset($_SESSION['cache_user_' . (isset($_SESSION['username']) ? $_SESSION['username'] : '')]);
|
||||
|
||||
} elseif ($t4Ex === HeroItems::EXCHANGE_NOT_ENOUGH) {
|
||||
$t4Msg = defined('HERO_EXCHANGE_NOTENOUGH') ? HERO_EXCHANGE_NOTENOUGH : 'You do not have enough for this exchange.';
|
||||
} elseif ($t4Ex === HeroItems::EXCHANGE_NO_HERO) {
|
||||
$t4Msg = defined('HERO_LOCKED_NOHERO') ? HERO_LOCKED_NOHERO : 'You have no hero yet.';
|
||||
} else {
|
||||
$t4Msg = defined('HERO_EXCHANGE_FAIL') ? HERO_EXCHANGE_FAIL : 'The exchange could not be completed.';
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['t4action'] === 'bid' && isset($_POST['aucid'], $_POST['maxbid'])) {
|
||||
$t4Result = $t4Auction->placeBid($session->uid, (int) $_POST['aucid'], (int) $_POST['maxbid']);
|
||||
if ($t4Result === HeroAuction::BID_OK) {
|
||||
@@ -62,6 +92,53 @@ foreach ($t4HeroItems->getInventory($session->uid) as $t4Row) {
|
||||
<p class="message" style="font-weight:bold;"><?php echo $t4Msg; ?></p>
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
// Soldurile curente si ratele de schimb (configurabile din config.php).
|
||||
$t4ExItems = isset($t4ExItems) ? $t4ExItems : new HeroItems();
|
||||
$t4Silver = $t4ExItems->getSilver($session->uid);
|
||||
$t4Gold = (int) $session->gold;
|
||||
$t4RateG2S = HeroItems::silverPerGold();
|
||||
$t4RateS2G = HeroItems::silverForOneGold();
|
||||
?>
|
||||
<table id="distribution" cellpadding="1" cellspacing="1">
|
||||
<thead>
|
||||
<tr><th colspan="2"><?php echo defined('HERO_EXCHANGE') ? HERO_EXCHANGE : 'Exchange office'; ?></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width:290px;vertical-align:top;">
|
||||
<p style="margin:0 0 6px 0;">
|
||||
<b><?php echo HERO_SILVER; ?>:</b> <?php echo $t4Silver; ?>
|
||||
|
||||
<b><?php echo defined('GOLD') ? GOLD : 'Gold'; ?>:</b> <?php echo $t4Gold; ?>
|
||||
</p>
|
||||
|
||||
<form action="" method="POST" style="margin:0 0 5px 0;">
|
||||
<input type="hidden" name="t4action" value="g2s">
|
||||
<input type="number" name="amount" min="1" max="100000" value="1" style="width:70px">
|
||||
<input type="submit" value="<?php echo defined('HERO_EXCHANGE_G2S') ? HERO_EXCHANGE_G2S : 'Gold to silver'; ?>">
|
||||
<small>(1 : <?php echo $t4RateG2S; ?>)</small>
|
||||
</form>
|
||||
|
||||
<form action="" method="POST" style="margin:0;">
|
||||
<input type="hidden" name="t4action" value="s2g">
|
||||
<input type="number" name="amount" min="1" max="100000" value="1" style="width:70px">
|
||||
<input type="submit" value="<?php echo defined('HERO_EXCHANGE_S2G') ? HERO_EXCHANGE_S2G : 'Silver to gold'; ?>">
|
||||
<small>(<?php echo $t4RateS2G; ?> : 1)</small>
|
||||
</form>
|
||||
|
||||
<p style="margin:6px 0 0 0;color:#777;font-size:11px;">
|
||||
<?php echo defined('HERO_EXCHANGE_HINT') ? HERO_EXCHANGE_HINT
|
||||
: 'The amount you type is the gold given or received; silver is calculated at the rate shown.'; ?>
|
||||
</p>
|
||||
</td>
|
||||
<td style="text-align:center;vertical-align:middle;">
|
||||
<img src="img/hero/merchant.png" alt="" style="max-width:280px;">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table id="distribution" cellpadding="1" cellspacing="1">
|
||||
<thead>
|
||||
<tr><th colspan="5"><?php echo HERO_AUC_OPEN; ?></th></tr>
|
||||
|
||||
+123
-4
@@ -40,6 +40,19 @@ $heroStatColumns = [
|
||||
'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.
|
||||
@@ -113,6 +126,58 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
|
||||
</td>
|
||||
<td class="po" id="t4po_reg"><?php echo $hero_info['regeneration']; ?></td>
|
||||
</tr>
|
||||
<?php if ($t4HeroRes) { ?>
|
||||
<tr>
|
||||
<th><?php echo defined('HERO_RES_PRODUCTION') ? HERO_RES_PRODUCTION : 'Resources'; ?></th>
|
||||
<td class="val">
|
||||
<?php
|
||||
// Cate resurse produce, dupa cum e setat: 3 din fiecare sau 10 dintr-una.
|
||||
$t4ResPoints = (int) ($hero_info['resources'] ?? 0);
|
||||
$t4ResType = (int) ($hero_info['res_type'] ?? 0);
|
||||
$t4PerAll = defined('HERO_RES_PER_POINT_ALL') ? (int) HERO_RES_PER_POINT_ALL : 3;
|
||||
$t4PerOne = defined('HERO_RES_PER_POINT_ONE') ? (int) HERO_RES_PER_POINT_ONE : 10;
|
||||
$t4ResIcons = [1 => 'r1', 2 => 'r2', 3 => 'r3', 4 => 'r4'];
|
||||
|
||||
if ($t4ResType >= 1 && $t4ResType <= 4) {
|
||||
echo '<img class="' . $t4ResIcons[$t4ResType] . '" src="img/x.gif" alt="" /> ';
|
||||
echo (int) round($t4ResPoints * $t4PerOne * SPEED);
|
||||
} else {
|
||||
foreach ($t4ResIcons as $t4Ico) {
|
||||
echo '<img class="' . $t4Ico . '" src="img/x.gif" alt="" /> '
|
||||
. (int) round($t4ResPoints * $t4PerAll * SPEED) . ' ';
|
||||
}
|
||||
}
|
||||
?>
|
||||
/<?php echo defined('HOUR') ? HOUR : 'h'; ?></td>
|
||||
<td class="xp"><img class="bar" src="img/x.gif" style="width:<?php echo ($t4ResPoints*2)+1; ?>px;" alt="" title="" /></td>
|
||||
<td class="up"><span class="none">
|
||||
<?php echo $renderAddLink('res'); ?>
|
||||
</td>
|
||||
<td class="po" id="t4po_res"><?php echo $t4ResPoints; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5" class="empty"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<form action="" method="POST" style="margin:0;">
|
||||
<?php echo defined('HERO_RES_TYPE') ? HERO_RES_TYPE : 'Produced resource'; ?>:
|
||||
<select name="t4restype" onchange="this.form.submit();">
|
||||
<option value="0" <?php if ($t4ResType === 0) echo 'selected'; ?>><?php echo defined('HERO_RES_ALL') ? HERO_RES_ALL : 'All resources'; ?> (<?php echo $t4PerAll; ?>)</option>
|
||||
<option value="1" <?php if ($t4ResType === 1) echo 'selected'; ?>><?php echo LUMBER; ?> (<?php echo $t4PerOne; ?>)</option>
|
||||
<option value="2" <?php if ($t4ResType === 2) echo 'selected'; ?>><?php echo CLAY; ?> (<?php echo $t4PerOne; ?>)</option>
|
||||
<option value="3" <?php if ($t4ResType === 3) echo 'selected'; ?>><?php echo IRON; ?> (<?php echo $t4PerOne; ?>)</option>
|
||||
<option value="4" <?php if ($t4ResType === 4) echo 'selected'; ?>><?php echo CROP; ?> (<?php echo $t4PerOne; ?>)</option>
|
||||
</select>
|
||||
<noscript><input type="submit" value="OK"></noscript>
|
||||
<span style="color:#777;font-size:11px;margin-left:6px;">
|
||||
<?php echo defined('HERO_RES_TYPE_HINT') ? HERO_RES_TYPE_HINT
|
||||
: 'Can be changed at any time, free of charge.'; ?>
|
||||
</span>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="5" class="empty"></td>
|
||||
</tr>
|
||||
@@ -260,6 +325,58 @@ $renderAddLink = function ($action) use ($hero_info, $id, $heroStatColumns) {
|
||||
// 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.
|
||||
// Schimbarea resursei favorizate. In T4 setarea asta e libera: nu costa puncte
|
||||
// si nu are nevoie de Book of Wisdom, doar redistribuie acelasi bonus.
|
||||
if ($t4HeroRes && isset($_POST['t4restype'])) {
|
||||
|
||||
$t4Type = (int) $_POST['t4restype'];
|
||||
|
||||
if ($t4Type >= 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();
|
||||
@@ -284,6 +401,7 @@ if (isset($_POST['t4points'])) {
|
||||
`attackbonus` = `attackbonus` + ?,
|
||||
`defencebonus` = `defencebonus` + ?,
|
||||
`regeneration` = `regeneration` + ?,
|
||||
`resources` = `resources` + ?,
|
||||
`points` = `points` - ?
|
||||
WHERE `heroid` = ?
|
||||
AND `points` >= ?
|
||||
@@ -291,19 +409,20 @@ if (isset($_POST['t4points'])) {
|
||||
AND `defence` + ? <= 100
|
||||
AND `attackbonus` + ? <= 100
|
||||
AND `defencebonus` + ? <= 100
|
||||
AND `regeneration` + ? <= 100"
|
||||
AND `regeneration` + ? <= 100
|
||||
AND `resources` + ? <= 100"
|
||||
);
|
||||
|
||||
if ($t4Stmt) {
|
||||
$t4HeroId = (int) $hero_info['heroid'];
|
||||
|
||||
$t4Stmt->bind_param(
|
||||
'iiiiiiiiiiiii',
|
||||
'iiiiiiiiiiiiiii',
|
||||
$t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'],
|
||||
$t4Alloc['defencebonus'], $t4Alloc['regeneration'],
|
||||
$t4Alloc['defencebonus'], $t4Alloc['regeneration'], $t4Alloc['resources'],
|
||||
$t4Total, $t4HeroId, $t4Total,
|
||||
$t4Alloc['attack'], $t4Alloc['defence'], $t4Alloc['attackbonus'],
|
||||
$t4Alloc['defencebonus'], $t4Alloc['regeneration']
|
||||
$t4Alloc['defencebonus'], $t4Alloc['regeneration'], $t4Alloc['resources']
|
||||
);
|
||||
|
||||
$t4Stmt->execute();
|
||||
|
||||
@@ -92,10 +92,10 @@ $diffLabel = $difficulty === 1
|
||||
<tr>
|
||||
<td><?php echo tz_hero_adv('RESOURCES', 'Resources'); ?></td>
|
||||
<td style="text-align:right;">
|
||||
<span class="res wood"><?php echo number_format($wood); ?></span>
|
||||
<span class="res clay"><?php echo number_format($clay); ?></span>
|
||||
<span class="res iron"><?php echo number_format($iron); ?></span>
|
||||
<span class="res crop"><?php echo number_format($crop); ?></span>
|
||||
<img class="r1" src="img/x.gif" alt="<?php echo LUMBER; ?>" title="<?php echo LUMBER; ?>"> <?php echo number_format($wood); ?>
|
||||
<img class="r2" src="img/x.gif" alt="<?php echo CLAY; ?>" title="<?php echo CLAY; ?>"> <?php echo number_format($clay); ?>
|
||||
<img class="r3" src="img/x.gif" alt="<?php echo IRON; ?>" title="<?php echo IRON; ?>"> <?php echo number_format($iron); ?>
|
||||
<img class="r4" src="img/x.gif" alt="<?php echo CROP; ?>" title="<?php echo CROP; ?>"> <?php echo number_format($crop); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
@@ -170,6 +170,30 @@ if ($hour > 1759 || $hour < 500) {
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ===================== GOLD (MUTAT DIN RES.TPL - CERCUL VERDE) ===================== -->
|
||||
<?php
|
||||
/**
|
||||
* Gold display - mutat din res.tpl
|
||||
* Afisare intre Messages si Plus
|
||||
*/
|
||||
if (!$isRestrictedUser && isset($session->gold)) {
|
||||
?>
|
||||
<div id="goldHeader">
|
||||
<?php
|
||||
if ($session->gold <= 1) {
|
||||
echo '<font color="#B3B3B3">
|
||||
<img src="' . GP_LOCATE . 'img/a/gold_g.gif" alt="' . GOLD . '" title="' . GOLD . '"/>
|
||||
' . $session->gold . ' ' . GOLD . '
|
||||
</font>';
|
||||
} else {
|
||||
echo '<img src="' . GP_LOCATE . 'img/a/gold.gif" alt="' . GOLD . '" title="' . GOLD . '"/>
|
||||
' . $session->gold . ' ' . GOLD;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<!-- ===================== END GOLD ===================== -->
|
||||
|
||||
<?php
|
||||
/**
|
||||
* PLUS button
|
||||
@@ -253,6 +277,26 @@ if ($hour > 1759 || $hour < 500) {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* GOLD IN CERCUL VERDE */
|
||||
#goldHeader {
|
||||
position: absolute;
|
||||
left: 380px; /* << AICI ESTE CERCUL VERDE - muta 370-400 daca e nevoie */
|
||||
top: 18px; /* centrat pe bara gri */
|
||||
width: auto;
|
||||
min-width: 100px;
|
||||
height: 22px;
|
||||
line-height: 22px;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
#goldHeader img {
|
||||
vertical-align: middle;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<!-- ===================== DAY/NIGHT ICON ===================== -->
|
||||
|
||||
@@ -112,35 +112,6 @@ if (!empty($village)) {
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- ================= GOLD / STATUS ================= -->
|
||||
<table cellpadding="1" cellspacing="1">
|
||||
<tr>
|
||||
|
||||
<!-- spacing (kept as original layout) -->
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td></td>
|
||||
|
||||
<!-- Gold display -->
|
||||
<td>
|
||||
<?php
|
||||
if ($session->gold <= 1) {
|
||||
echo '<font color="#B3B3B3">
|
||||
<img src="' . GP_LOCATE . 'img/a/gold_g.gif" alt="' . GOLD . '" title="' . GOLD . '"/>
|
||||
' . $session->gold . ' ' . GOLD . '
|
||||
</font>';
|
||||
} else {
|
||||
echo '<img src="' . GP_LOCATE . 'img/a/gold.gif" alt="' . GOLD . '" title="' . GOLD . '"/>
|
||||
' . $session->gold . ' ' . GOLD;
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user