fix(necromancy): correct Blood Oath duration, reflection, and expiry timing (#1690) (#2480)

Fixes #1690. Addresses Blood Oath holistically — three bugs found while researching the spell against RunUO, ServUO, the UODemise/uo.com guides, and the archived UOGuide page.

## Bugs fixed

### 1. Expiry timing (the filed issue)
The `ExpireTimer` polled every 1s, so expiry and death/delete cleanup lagged up to ~1s. Replaced with a **single-shot** timer plus centralized `[OnEvent]` handlers on `PlayerDeathEvent`/`PlayerDeletedEvent`/`CreatureDeathEvent`/`CreatureDeletedEvent` — the oath now breaks immediately on death/delete of either party.

### 2. Duration formula
Used `/80` (the bugged in-game tooltip value) instead of the real OSI formula `((SpiritSpeak - Resist) / 8) + 8`. Confirmed by RunUO, ServUO, the emulator guides, and the code's own fixed-point comment. At GM Spirit Speak this changes duration from ~9.5s to 23s and makes Spirit Speak actually affect duration.

### 3. Damage reflection (`BaseCreature.Damage` vs `PlayerMobile.Damage`)
`BaseCreature.Damage` diverged: it attributed the reflected hit to the attacker itself (`from.Damage(amount, from)`) instead of the caster, reflected the bonused (not original) amount, used `×1.1` vs `×1.2`, lacked the caster-survival guard, and had no Publish 48 resist mitigation.

Unified both paths: reflect the **original** damage attributed to the **caster** at `×1.2`. Publish 48 resist mitigation now applies only to creature casters and is gated behind `Core.SA`.

## Internals
- Collapsed the parallel `_oathTable` into a single `_table` keyed by both participants → shared timer, so `RemoveCurse` resolves from either side (required by the event handlers).
- Extracted `GetDurationSeconds` and `ComputeReflectedDamage` as testable statics.

## Tests
13 new tests (duration formula, reflection mitigation, oath lifecycle, end-to-end event-driven removal). Full suite: **436/436 pass**.
This commit is contained in:
Kamron Batman 2026-06-08 23:42:28 -07:00 • committed by GitHub
parent 9d26a44a28
commit 10fb74b827
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 223 additions and 56 deletions

View file

@ -1479,6 +1479,10 @@ namespace Server.Mobiles
{
var oldHits = Hits;
// Blood oath reflects the original damage the attacker dealt, before other modifiers.
var hasBloodOath = from != null && BloodOathSpell.GetBloodOath(from) == this;
var reflectedDamage = hasBloodOath ? amount : 0;
if (Core.AOS && !Summoned && Controlled && Utility.RandomDouble() < 0.2)
{
amount = (int)(amount * BonusPetDamageScalar);
@ -1489,14 +1493,24 @@ namespace Server.Mobiles
amount = (int)(amount * 1.25);
}
if (from != null && BloodOathSpell.GetBloodOath(from) == this)
if (hasBloodOath)
{
amount = (int)(amount * 1.1);
from.Damage(amount, from);
amount = (int)(amount * 1.2);
}
base.Damage(amount, from, informMount);
// If the blood oath caster will die then damage is not reflected back to the attacker.
if (hasBloodOath && Alive && !Deleted && !IsDeadBondedPet)
{
// Reflect the original damage back to the attacker, attributed to the caster.
// The caster is a creature, so the Publish 48 (SA+) resist mitigation applies.
from.Damage(
BloodOathSpell.ComputeReflectedDamage(reflectedDamage, from.Skills.MagicResist.Value, Core.SA),
this
);
}
if (SubdueBeforeTame && !Controlled && oldHits > HitsMax / 10 && Hits <= HitsMax / 10)
{
// * The creature has been beaten into subjugation! *