mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-14 00:26:07 +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)
|
||||
|
||||
Reference in New Issue
Block a user