mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-13 08:06:06 +00:00
Fix cage and animal release for hero T4
Fix cage and animal release for hero T4
This commit is contained in:
@@ -469,19 +469,23 @@ class HeroBattleBonus
|
||||
$used = array_sum($captured);
|
||||
$heroItems->removeItem((int) $uid, (int) $cageRow['id'], $used);
|
||||
|
||||
// Station the animals at home: reuse the self-enforcement row if one
|
||||
// exists (vref = from = home), otherwise create it.
|
||||
// Station the animals at home as a NATURE reinforcement: `from` = 0 is
|
||||
// the engine's existing convention for non-player enforcements (the
|
||||
// "taskmaster" rows) - 16.tpl renders those with tribe 4 columns
|
||||
// (u31-u40, the animal icons) and disables the normal Send back flow,
|
||||
// which would otherwise crash on speed lookup for nature units.
|
||||
// Reuse the row if one exists, otherwise create it.
|
||||
$homeWref = (int) $homeWref;
|
||||
$res = mysqli_query(
|
||||
$database->dblink,
|
||||
"SELECT id FROM " . TB_PREFIX . "enforcement
|
||||
WHERE vref = $homeWref AND `from` = $homeWref LIMIT 1"
|
||||
WHERE vref = $homeWref AND `from` = 0 LIMIT 1"
|
||||
);
|
||||
$rowE = $res ? mysqli_fetch_assoc($res) : null;
|
||||
if (!$rowE) {
|
||||
mysqli_query(
|
||||
$database->dblink,
|
||||
"INSERT INTO " . TB_PREFIX . "enforcement (vref, `from`) VALUES ($homeWref, $homeWref)"
|
||||
"INSERT INTO " . TB_PREFIX . "enforcement (vref, `from`) VALUES ($homeWref, 0)"
|
||||
);
|
||||
$enfId = (int) mysqli_insert_id($database->dblink);
|
||||
} else {
|
||||
|
||||
@@ -2821,3 +2821,7 @@ tz_def('HB_TXT_CAGE', 'Captures 1 oasis animal per cage');
|
||||
tz_def('HB_TXT_NEEDS_HORSE','requires an equipped horse');
|
||||
tz_def('HB_TXT_ONLY', 'only for a');
|
||||
tz_def('HB_TXT_HERO', 'hero');
|
||||
|
||||
/* T4 hero port - captured animals release action */
|
||||
tz_def('HERO_RELEASE_ANIMALS', 'Release');
|
||||
tz_def('HERO_RELEASE_CONFIRM', 'Release these animals? They will be gone for good.');
|
||||
|
||||
@@ -692,6 +692,33 @@ class Units {
|
||||
* @param int the ID of the prisoners you want to release
|
||||
*/
|
||||
|
||||
/**
|
||||
* T4 hero port: destroy a NATURE enforcement row (captured oasis animals,
|
||||
* `from` = 0) stationed in the CURRENT village. Mirrors deletePrisoners'
|
||||
* ownership model: the row must belong to the village the player is
|
||||
* viewing, which the session already validated as theirs. Nature rows
|
||||
* never travel back (no owner village to walk to) - releasing kills them.
|
||||
*/
|
||||
public function releaseNatureEnforcement($id){
|
||||
global $village, $database;
|
||||
|
||||
$id = (int) $id;
|
||||
if ($id <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stmt = $database->dblink->prepare(
|
||||
"DELETE FROM " . TB_PREFIX . "enforcement
|
||||
WHERE id = ? AND `from` = 0 AND vref = ? LIMIT 1"
|
||||
);
|
||||
$wid = (int) $village->wid;
|
||||
$stmt->bind_param('ii', $id, $wid);
|
||||
$stmt->execute();
|
||||
$ok = $stmt->affected_rows > 0;
|
||||
$stmt->close();
|
||||
return $ok;
|
||||
}
|
||||
|
||||
public function deletePrisoners($id){
|
||||
global $village, $database, $session, $building, $bid19, $u99;
|
||||
|
||||
@@ -796,6 +823,16 @@ class Units {
|
||||
$speeds[] = $GLOBALS['u'.$heroUnit]['speed'];
|
||||
}
|
||||
|
||||
// Defensive: the tribe-offset loop above only inspects the owner's
|
||||
// own 10 unit columns, so an army made purely of foreign/nature units
|
||||
// (e.g. captured oasis animals) yields no speeds and min() would
|
||||
// fatal (the "Send back" crash). Unreachable through normal flows
|
||||
// now that nature rows disable Send back, but never crash movement
|
||||
// creation - fall back to the slowest common speed.
|
||||
if (empty($speeds)) {
|
||||
$speeds[] = 3;
|
||||
}
|
||||
|
||||
$walkTime = $generator->procDistanceTime($fromCor, $toCor, min($speeds), $mode, $from);
|
||||
|
||||
// T4 hero port (Phase 5): boots (>20 tiles), pennant (own villages)
|
||||
|
||||
@@ -93,7 +93,7 @@ $hasRally = $village->resarray['f39'] > 0;
|
||||
</tbody>
|
||||
<tbody class="infos"><tr><th><?= UPKEEP ?></th><td colspan="<?= $colspan ?>">
|
||||
<div class="sup"><?= $technology->getUpkeep($e,$tribe) ?><img class="r4" src="img/x.gif"> <?= PER_HR ?></div>
|
||||
<div class="sback"><?php if(!$isTaskmaster): ?><a href="a2b.php?w=<?= $e['id'] ?>"><?= SEND_BACK ?></a><?php else: ?><span class="none"><b><?= SEND_BACK ?></b></span><?php endif; ?></div>
|
||||
<div class="sback"><?php if(!$isTaskmaster): ?><a href="a2b.php?w=<?= $e['id'] ?>"><?= SEND_BACK ?></a><?php elseif (defined('NEW_FUNCTIONS_HERO_T4') && NEW_FUNCTIONS_HERO_T4): ?><a href="a2b.php?releaseanimals=<?= $e['id'] ?>" onclick="return confirm('<?= defined('HERO_RELEASE_CONFIRM') ? HERO_RELEASE_CONFIRM : 'Release these animals? They will be gone for good.' ?>');"><?= defined('HERO_RELEASE_ANIMALS') ? HERO_RELEASE_ANIMALS : 'Release' ?></a><?php else: ?><span class="none"><b><?= SEND_BACK ?></b></span><?php endif; ?></div>
|
||||
</td></tr></tbody>
|
||||
</table>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -60,6 +60,11 @@ if(isset($_GET['r'])) $r = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['r']);
|
||||
if(isset($_GET['delprisoners'])){
|
||||
$delprisoners = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['delprisoners']);
|
||||
}
|
||||
// T4 hero port: release (destroy) captured oasis animals from a nature
|
||||
// enforcement row (from = 0). Same sanitization as delprisoners.
|
||||
if(isset($_GET['releaseanimals'])){
|
||||
$releaseanimals = preg_replace("/[^0-9]/", "", $_GET['releaseanimals']);
|
||||
}
|
||||
if(isset($_GET['o'])){
|
||||
$o = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['o']);
|
||||
$oid = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['z']);
|
||||
@@ -156,6 +161,12 @@ if(!empty($id)){
|
||||
include("Templates/a2b/search.tpl");
|
||||
}
|
||||
}else if(isset($delprisoners) && !empty($delprisoners)) $units->deletePrisoners($delprisoners);
|
||||
else if(isset($releaseanimals) && !empty($releaseanimals)){
|
||||
// T4 hero port: destroy captured animals, then back to the rally point.
|
||||
$units->releaseNatureEnforcement($releaseanimals);
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
}
|
||||
else{
|
||||
if(isset($process['0'])){
|
||||
$coor = $database->getCoor($process['0']);
|
||||
|
||||
Reference in New Issue
Block a user