"""End-to-end findings from the Armor Piercer capture. Source: /tmp/aostats-party01.jsonl, a T5 Morgana dungeon run. bionicKatana wore a T6_MAIN_CURSEDSTAFF@1 (Armor Piercer) from 16:48:10 to 16:52:40; Froedrick712 shared the party and finished the mobs. These tests establish the premise the whole effective-damage feature rests on: that applying a debuff measurably raises another player's damage, that the debuff's lifetime is visible, and that the responsible player is recoverable from the packets. The capture lives outside the repository, so everything here is skipped when it is absent. """ import collections import json import os import statistics import pytest CAPTURE = '/tmp/aostats-party01.jsonl' BIOMIC = 90547 FROEDRICK = 90362 # Effect ids bionicKatana applies only while holding the cursed staff. They # appear together on several victims within a millisecond, which is the # multi-target beam of Armor Piercer. ARMOR_PIERCER_EFFECTS = (3097, 3098, 3099) # Armor Piercer's debuff lasts 4 seconds. DEBUFF_SECONDS = 4.0 pytestmark = pytest.mark.skipif( not os.path.exists(CAPTURE), reason='Armor Piercer capture not available') def _records(): with open(CAPTURE, errors='replace') as handle: for line in handle: try: yield json.loads(line) except ValueError: continue def _is_photon_event(record, opcode): if record.get('type') != 'photon_message': return False message = record.get('message') or {} if message.get('code') != 1 or message.get('kind') != 'Event': return False return (message.get('params') or {}).get('252') == opcode def effect_windows(): """Victim -> timestamps at which Armor Piercer landed on it.""" windows = collections.defaultdict(list) for record in _records(): if not _is_photon_event(record, 22): continue params = (record.get('message') or {}).get('params') or {} appliers, effects = params.get('1'), params.get('2') if not isinstance(appliers, list) or not isinstance(effects, list): continue if len(appliers) != len(effects): continue if BIOMIC in appliers and any( e in ARMOR_PIERCER_EFFECTS for e in effects): windows[params.get('0')].append(_ts(record['timestamp'])) return windows def basic_hits(attacker): """(timestamp, victim, damage) for basic auto-attacks.""" out = [] for record in _records(): if record.get('type') != 'game_message': continue message = record.get('message') or {} if message.get('name') != 'HealthUpdate': continue params = message.get('params') or {} if params.get('6') != attacker or params.get('5') != 0: continue out.append((_ts(record['timestamp']), params.get('0'), abs(params.get('2') or 0))) return out def _ts(stamp): import datetime return datetime.datetime.fromisoformat(stamp).timestamp() def _static(name): root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) with open(os.path.join(root, 'src', 'static', name), encoding='utf-8') as handle: return json.load(handle) # --- the premise ------------------------------------------------------------- def test_debuff_raises_another_players_damage(): """The whole feature depends on this being true and measurable. Froedrick712's basic hits on mob 78724 go 35 -> 48 -> 35 across a single Armor Piercer application. Mob 78724 is a T5_MOB_ROAMING_KEEPER_GIANT_CHAMPION with 136 armour. """ windows = effect_windows() assert windows.get(78724), 'no Armor Piercer application found on 78724' hits = [h for h in basic_hits(FROEDRICK) if h[1] == 78724] applied = windows[78724][0] inside = [d for t, _, d in hits if 0 <= t - applied <= DEBUFF_SECONDS] before = [d for t, _, d in hits if applied - 60 <= t < applied] assert before, 'no baseline hits before the debuff' assert inside, 'no hits inside the debuff window' assert statistics.median(inside) > statistics.median(before) def test_damage_returns_to_baseline_after_the_debuff(): """The debuff expires, and the return to baseline is observable. This is what makes the magnitude recoverable from data rather than needing the spell definition: compare a victim's hits inside and outside the window instead of trusting a static table. """ windows = effect_windows() hits = [h for h in basic_hits(FROEDRICK) if h[1] == 78724] applied = windows[78724][0] inside = [d for t, _, d in hits if 0 <= t - applied <= DEBUFF_SECONDS] after = [d for t, _, d in hits if t - applied > DEBUFF_SECONDS] assert inside and after assert statistics.median(after) < statistics.median(inside) def test_surplus_is_positive_across_the_capture(): """Not a one-mob fluke: the same shift shows up over the whole run.""" windows = effect_windows() hits = basic_hits(FROEDRICK) def in_window(t, victim): return any(0 <= t - applied <= DEBUFF_SECONDS for applied in windows.get(victim, [])) inside = [d for t, v, d in hits if in_window(t, v)] outside = [d for t, v, d in hits if not in_window(t, v)] assert len(inside) >= 10 assert statistics.median(inside) > statistics.median(outside) # Every hit inside a debuff window beats the outside median, which is what # a genuine shift in the damage model looks like. assert min(inside) > statistics.median(outside) # --- the attribution chain --------------------------------------------------- def test_applier_is_recoverable_without_inference(): """The responsible player comes from the packet, not from the weapon. This is better than the plan assumed: it removes the need to match spells to equipped weapons for the common case. """ windows = effect_windows() assert windows, 'no Armor Piercer applications found' for victim, applied in windows.items(): assert victim is not None assert applied def test_mob_template_and_max_health_agree(): """Mob 78724's template must agree with the hit points in the spawn.""" mob_armor = _static('mob_armor.json') for record in _records(): if not _is_photon_event(record, 123): continue params = (record.get('message') or {}).get('params') or {} if params.get('0') != 78724: continue entry = mob_armor[str(params.get('1'))] assert entry['hitpointsmax'] == pytest.approx(params.get('13')) assert entry['name'] == 'T5_MOB_ROAMING_KEEPER_GIANT_CHAMPION' assert entry['armor'] == 136 return pytest.fail('mob 78724 spawn not found in capture')