1 Commits

Author SHA1 Message Date
bionickatana 7279b3c207 Working advanced tracking code
Build / Build source distribution (push) Failing after 13s
Build / Execute unit tests (push) Failing after 8s
Build / Verify generated game data is current (push) Failing after 7s
Build / Upload Release Asset (push) Has been skipped
Build / upload_pypi (push) Has been skipped
2026-10-13 09:08:38 -06:00
23 changed files with 336893 additions and 7521 deletions
+16
View File
@@ -35,6 +35,22 @@ jobs:
python -m pip install --upgrade tox
- name: Run unit tests
run: python -m tox -e ut
gamedata:
name: Verify generated game data is current
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: '3.7'
# The tables under src/static are generated from the game data dumps.
# They are committed, so this job fails if someone edits them by hand or
# if upstream game data moved on and nobody regenerated them.
- name: Check committed tables match the dumps
run: make gamedata-check
upload_pypi:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [build_sdist]
+2
View File
@@ -15,3 +15,5 @@ albion-online-stats.cfg
aoaddons.log
.eggs
.idea
# fetched game data dumps (scripts/fetch_gamedata.py)
.cache
+32
View File
@@ -0,0 +1,32 @@
PYTHON ?= python3
CACHE ?= .cache/gamedata
.PHONY: help gamedata gamedata-check gamedata-force test lint clean-gamedata
help:
@echo 'Targets:'
@echo ' gamedata regenerate src/static tables from the game dumps'
@echo ' gamedata-check verify the committed tables are up to date'
@echo ' test run the unit tests'
# Regenerate the shipped lookup tables. Fetches the game dumps first if the
# cache is missing. Tables land in src/static and should be committed.
gamedata:
$(PYTHON) scripts/fetch_gamedata.py --cache $(CACHE)
$(PYTHON) scripts/gen_gamedata.py --cache $(CACHE)
# Regenerate from a fresh checkout of the dumps.
gamedata-force:
$(PYTHON) scripts/fetch_gamedata.py --cache $(CACHE) --force
$(PYTHON) scripts/gen_gamedata.py --cache $(CACHE)
# CI guard: fail if the committed tables have drifted from the dumps.
gamedata-check:
$(PYTHON) scripts/fetch_gamedata.py --cache $(CACHE)
$(PYTHON) scripts/gen_gamedata.py --cache $(CACHE) --check
test:
$(PYTHON) -m pytest tests
clean-gamedata:
rm -rf .cache
+141
View File
@@ -0,0 +1,141 @@
"""Fetch the large game data dumps that generated tables are built from.
The app ships small, generated lookup tables (see ``src/static/vendor``). The
dumps they are derived from are far too large to version, so they are fetched
on demand into a gitignored cache.
This is a shallow, blobless, sparse clone, so it transfers only the handful of
files listed below rather than the repository's full history.
Usage:
python scripts/fetch_gamedata.py [--cache DIR] [--force] [--check]
"""
import argparse
import hashlib
import json
import os
import shutil
import subprocess
import sys
UPSTREAM_URL = 'https://github.com/ao-data/ao-bin-dumps.git'
PINNED_COMMIT = '47e4f5aca4d30b7495afa5a625ce0d5795e32050'
# Only what the generators actually read. `localization.json` is deliberately
# absent: it is 90 MB, and it cannot supply a display name for every mob
# anyway (883 of 5479 mob definitions have no namelocatag). Nothing in
# attribution depends on it. See src/static/vendor/PROVENANCE.md.
REQUIRED_FILES = (
'items.json',
'spells.json',
'mobs.json',
'gamedata.json',
# Source for the vendored src/static/vendor/item_ids.txt.
'formatted/items.txt',
)
# Anchored to the repo root. Without the leading slash gitcone matches the
# basename anywhere in the tree, which drags in the redundant 24 MB
# formatted/items.json alongside the root one.
SPARSE_PATTERNS = tuple('/' + name for name in REQUIRED_FILES)
DEFAULT_CACHE = os.path.join('.cache', 'gamedata')
def _run(args, cwd=None):
result = subprocess.run(
args,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if result.returncode != 0:
sys.stderr.write(result.stdout.decode('utf-8', 'replace'))
raise SystemExit('command failed: {}'.format(' '.join(args)))
return result.stdout.decode('utf-8', 'replace')
def _checksums(directory):
"""Map of filename -> sha256 for the required files."""
digests = {}
for name in REQUIRED_FILES:
path = os.path.join(directory, name)
digest = hashlib.sha256()
with open(path, 'rb') as handle:
for chunk in iter(lambda: handle.read(1 << 20), b''):
digest.update(chunk)
digests[name] = digest.hexdigest()
return digests
def is_populated(directory):
return all(os.path.exists(os.path.join(directory, name))
for name in REQUIRED_FILES)
def fetch(cache_dir, force=False):
"""Ensure the dumps are present in ``cache_dir`` and return that path."""
if force and os.path.isdir(cache_dir):
shutil.rmtree(cache_dir)
elif is_populated(cache_dir):
return cache_dir
parent = os.path.dirname(os.path.abspath(cache_dir)) or '.'
os.makedirs(parent, exist_ok=True)
if os.path.isdir(cache_dir):
shutil.rmtree(cache_dir)
# --filter=blob:none avoids the full history; --sparse plus the final
# checkout limits us to the files we name.
_run([
'git', 'clone',
'--filter=blob:none',
'--no-checkout',
'--depth', '1',
UPSTREAM_URL,
cache_dir,
])
_run(['git', 'sparse-checkout', 'set', '--no-cone', *SPARSE_PATTERNS],
cwd=cache_dir)
_run(['git', 'checkout', PINNED_COMMIT], cwd=cache_dir)
missing = [name for name in REQUIRED_FILES
if not os.path.exists(os.path.join(cache_dir, name))]
if missing:
raise SystemExit('fetch incomplete, missing: {}'.format(missing))
return cache_dir
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--cache', default=DEFAULT_CACHE,
help='cache directory (default: %(default)s)')
parser.add_argument('--force', action='store_true',
help='re-fetch even if the cache is already populated')
parser.add_argument('--check', action='store_true',
help='verify the cache matches the pinned commit, '
'without fetching')
args = parser.parse_args(argv)
if args.check:
if not is_populated(args.cache):
print('cache is not populated: {}'.format(args.cache))
return 1
head = _run(['git', 'rev-parse', 'HEAD'], cwd=args.cache).strip()
if head != PINNED_COMMIT:
print('cache at {}, expected {}'.format(head, PINNED_COMMIT))
return 1
print('cache OK at {}'.format(PINNED_COMMIT))
print(json.dumps(_checksums(args.cache), indent=2, sort_keys=True))
return 0
fetch(args.cache, force=args.force)
print('game data ready in {}'.format(args.cache))
return 0
if __name__ == '__main__':
raise SystemExit(main())
+466
View File
@@ -0,0 +1,466 @@
"""Generate the small game-data lookup tables the app actually ships.
The raw dumps are ~50 MB and are fetched on demand (see fetch_gamedata.py).
This reduces them to a handful of compact tables under ``src/static``.
Everything here is derived mechanically from the dumps. There are no
hand-written mappings, and no observed damage is ever used to infer a value --
strength comes from item power, which is a property of the item definition.
Usage:
python scripts/gen_gamedata.py [--cache DIR] [--check]
"""
import argparse
import json
import os
import re
import sys
STATIC_DIR = os.path.join('src', 'static')
DEFAULT_CACHE = os.path.join('.cache', 'gamedata')
# Mob template IDs are the enumeration index of the mobs.bin XML, which differs
# from the order of mobs.json by a constant. Six independent template IDs seen
# in real captures resolve to the correct mob on both name and max HP with this
# offset, across ~2300 entries of the file. The rule producing it is not
# understood -- the 16 skipped entries are all category=roaming, which is the
# signature of a filtered enumeration rather than a statement of the filter.
# Accepted as a constant by decision; see .opencode/plans/effective-damage.md.
MOB_TEMPLATE_OFFSET = 16
ARMOR_TYPES = ('physicalarmor', 'magicresistance')
_ITEM_LINE = re.compile(r'\s*(\d+):\s*(\S+?)\s*(?::|$)')
def _load(cache_dir, name):
with open(os.path.join(cache_dir, name), encoding='utf-8') as handle:
return json.load(handle)
def _as_list(value):
if value is None:
return []
if isinstance(value, list):
return value
return [value]
# --------------------------------------------------------------------------
# item_ids.txt
# --------------------------------------------------------------------------
def gen_item_ids(cache_dir):
"""Rewrite src/static/item_ids.txt in the format the app reads.
The app's loader expects ``<id>,<uniquename>``. Upstream ships
`` <id>: <uniquename> : <display name>``; 846 entries have no display
name and end after the unique name.
"""
out_path = os.path.join(STATIC_DIR, 'item_ids.txt')
lines = []
src = os.path.join(cache_dir, 'formatted', 'items.txt')
with open(src, encoding='utf-8', errors='replace') as handle:
for line in handle:
match = _ITEM_LINE.match(line)
if match:
lines.append('{},{}'.format(match.group(1), match.group(2)))
lines.sort(key=lambda entry: int(entry.split(',', 1)[0]))
_write_text(out_path, '\n'.join(lines) + '\n')
return out_path, len(lines)
# --------------------------------------------------------------------------
# item_spells.json
# --------------------------------------------------------------------------
def _index_items(items_root):
"""Unique name -> definition, in document order across all groups."""
index = {}
for group, value in items_root.items():
if group.startswith('@') or group == 'shopcategories':
continue
for entry in _as_list(value):
if isinstance(entry, dict) and entry.get('@uniquename'):
index[entry['@uniquename']] = entry
return index
def _resolve_spells(item_index, name, depth=0, seen=None):
"""Flatten craftingspelllist, following @reference and removespell.
Most weapons carry no spells of their own -- they inherit a whole ability
set from a base item. Resolving that inheritance is what turns 471 weapons
with an apparently empty spell list into full coverage.
"""
seen = seen if seen is not None else set()
if name in seen or depth > 12:
return []
seen.add(name)
entry = item_index.get(name)
if not entry:
return []
spell_list = entry.get('craftingspelllist')
if not spell_list:
return []
if not isinstance(spell_list, dict):
return []
spells = []
reference = spell_list.get('@reference')
if reference:
spells += _resolve_spells(item_index, reference, depth + 1, seen)
removed = set()
for rem in _as_list(spell_list.get('removespell')):
if isinstance(rem, dict) and rem.get('@uniquename'):
removed.add(rem['@uniquename'])
for craft in _as_list(spell_list.get('craftspell')):
if isinstance(craft, dict) and craft.get('@uniquename'):
spells.append(craft)
return [s for s in spells if s['@uniquename'] not in removed]
def gen_item_spells(cache_dir):
item_index = _index_items(_load(cache_dir, 'items.json')['items'])
result = {}
for name in item_index:
spells = _resolve_spells(item_index, name)
if not spells:
continue
entries = [{'slot': s.get('@slots'), 'spell': s['@uniquename']}
for s in spells]
result[name] = entries
# A packet identifies an enchanted item as BASE@LEVEL, but only the
# base item exists in the dump. Emit the variants as aliases so a
# lookup straight from a packet id finds the abilities, rather than
# silently getting nothing.
enchantments = item_index[name].get('enchantments')
if not enchantments:
continue
variants = _as_list(
enchantments.get('enchantment') if isinstance(enchantments, dict)
else enchantments)
for variant in variants:
if isinstance(variant, dict) and variant.get('@enchantmentlevel'):
result['{}@{}'.format(name, variant['@enchantmentlevel'])] = \
entries
out_path = os.path.join(STATIC_DIR, 'item_spells.json')
_write_json(out_path, result, sort_keys=True)
return out_path, len(result)
# --------------------------------------------------------------------------
# debuff_spells.json
# --------------------------------------------------------------------------
def _index_spells(spells_root):
index = {}
for group in ('activespell', 'passivespell', 'togglespell'):
for spell in spells_root.get(group) or []:
if spell.get('@uniquename'):
index[spell['@uniquename']] = spell
return index
def _spell_links(spell_index, name):
"""Spells one hop downstream of ``name``.
An ability rarely carries its debuff directly. ARMORPIERCER declares no
buffovertime at all: it points at ARMORPIERCER_EFFECT via spelleffectarea,
which in turn applies ARMORPIERCER_DEBUFF_EFFECT via applyspell. Only the
last link actually holds the armour numbers, so every hop has to be walked.
"""
spell = spell_index.get(name)
if not spell:
return []
out = []
for applied in _as_list(spell.get('applyspell')):
if isinstance(applied, dict) and applied.get('@spell'):
out.append(applied['@spell'])
for area in _as_list(spell.get('spelleffectarea')):
if isinstance(area, dict) and area.get('@effect'):
out.append(area['@effect'])
return out
def _collect_debuffs(spell_index, name, depth=0, seen=None):
"""Negative armour/resistance effects reachable from ``name``."""
seen = seen if seen is not None else set()
if name in seen or depth > 3:
return []
seen.add(name)
found = []
spell = spell_index.get(name)
if spell:
for effect in _as_list(spell.get('buffovertime')):
if not isinstance(effect, dict):
continue
if effect.get('@type') not in ARMOR_TYPES:
continue
try:
value = float(effect.get('@value') or 0)
except ValueError:
continue
if value < 0:
found.append((name, effect))
for nxt in _spell_links(spell_index, name):
found += _collect_debuffs(spell_index, nxt, depth + 1, seen)
return found
def _flatten_effect(effect):
flat = {
'type': effect.get('@type'),
'value': float(effect.get('@value') or 0),
'time': float(effect.get('@time') or 0),
}
# Armour Piercer scales with how many targets the caster hit, so its
# magnitude must be read off the observed effect, never assumed.
bonus = effect.get('@targetcountvaluebonusfactor')
if bonus:
flat['targetcountvaluebonusfactor'] = float(bonus)
# SUNDERARMOR2 is weaker against players than mobs; pick per victim type.
target_type = effect.get('IfTargetType')
if isinstance(target_type, dict) and target_type.get('@type'):
flat['iftargettype'] = target_type['@type']
target = effect.get('@target')
if target:
flat['target'] = target
return flat
def gen_debuff_spells(cache_dir):
item_index = _index_items(_load(cache_dir, 'items.json')['items'])
spell_index = _index_spells(_load(cache_dir, 'spells.json')['spells'])
abilities = set()
for name in item_index:
for spell in _resolve_spells(item_index, name):
unique = spell.get('@uniquename')
if unique and not unique.startswith('PASSIVE'):
abilities.add(unique)
# effect spell -> abilities that produce it
producers = {}
for ability in abilities:
for effect_name, effect in _collect_debuffs(spell_index, ability):
producers.setdefault(effect_name, {}).setdefault(
ability, []).append(_flatten_effect(effect))
result = {}
for effect_name, by_ability in sorted(producers.items()):
spell = spell_index.get(effect_name, {})
result[effect_name] = {
'abilities': sorted(by_ability),
'category': spell.get('@category'),
'uitype': spell.get('@uitype'),
'maxstack': _maybe_int(spell.get('@maxstack')),
'maxcharges': _maybe_int(spell.get('@maxcharges')),
'effects': sorted(
{json.dumps(e, sort_keys=True): e
for group in by_ability.values() for e in group}.values(),
key=lambda e: (e['type'], e['value']),
),
}
out_path = os.path.join(STATIC_DIR, 'debuff_spells.json')
_write_json(out_path, result, sort_keys=True)
return out_path, len(result)
def _maybe_int(value):
if value in (None, ''):
return None
try:
return int(value)
except (TypeError, ValueError):
return None
# --------------------------------------------------------------------------
# progression.json
# --------------------------------------------------------------------------
def gen_progression(cache_dir):
"""Item-power progression constants for armour and damage.
Albion scales a character's stats from item power, so attacker strength is
a property of the equipped item and not of any observed hit. This keeps the
arithmetic correct as players level their gear.
"""
game = _load(cache_dir, 'gamedata.json')['AO-GameData']
source = game['Items']['ItemPowerProgression']
result = {'slots': {}, 'shares': {}}
for key, value in source.items():
if key in ('armorshare', 'ccrshare', 'hitpointsshare', 'energyshare',
'trackingtime'):
result['shares'][key] = value
elif isinstance(value, dict) and '@armorbase' in value:
result['slots'][key] = {
'armorbase': float(value['@armorbase']),
'armorprogression': float(value['@armorprogression']),
'attackdamageprogression': float(
value.get('@attackdamageprogression') or 0),
'hitpointsprogression': float(
value.get('@hitpointsprogression') or 0),
}
out_path = os.path.join(STATIC_DIR, 'progression.json')
_write_json(out_path, result, sort_keys=True)
return out_path, len(result['slots'])
# --------------------------------------------------------------------------
# mob_armor.json
# --------------------------------------------------------------------------
def gen_mob_armor(cache_dir):
mobs = _load(cache_dir, 'mobs.json')['Mobs']['Mob']
result = {}
for position, mob in enumerate(mobs):
template_id = position + MOB_TEMPLATE_OFFSET
result[str(template_id)] = {
'name': mob.get('@uniquename'),
'tier': _maybe_int(mob.get('@tier')),
'armor': _maybe_int(mob.get('@physicalarmor')),
'resistance': _maybe_int(mob.get('@magicresistance')),
'hitpointsmax': _maybe_int(mob.get('@hitpointsmax')),
'category': mob.get('@category'),
}
out_path = os.path.join(STATIC_DIR, 'mob_armor.json')
_write_json(out_path, result, sort_keys=True)
return out_path, len(result)
# --------------------------------------------------------------------------
# item_power.json
# --------------------------------------------------------------------------
def gen_item_power(cache_dir):
"""Item power per unique name, including enchantment variants.
A packet carries the enchanted variant as part of the item id
(``T5_MAIN_HOLYSTAFF_AVALON@1``), and item power scales with the
enchantment level, so both are needed.
"""
item_index = _index_items(_load(cache_dir, 'items.json')['items'])
result = {}
for name, entry in item_index.items():
base = _maybe_int(entry.get('@itempower'))
if base is not None:
result[name] = base
enchantments = entry.get('enchantments')
if not enchantments:
continue
for variant in _as_list(enchantments.get('enchantment')
if isinstance(enchantments, dict)
else enchantments):
if not isinstance(variant, dict):
continue
level = variant.get('@enchantmentlevel')
power = _maybe_int(variant.get('@itempower'))
if level is None or power is None:
continue
result['{}@{}'.format(name, level)] = power
out_path = os.path.join(STATIC_DIR, 'item_power.json')
_write_json(out_path, result, sort_keys=True)
return out_path, len(result)
# --------------------------------------------------------------------------
def _write_json(path, data, sort_keys=True):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w', encoding='utf-8') as handle:
json.dump(data, handle, indent=1, sort_keys=sort_keys)
handle.write('\n')
def _write_text(path, text):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w', encoding='utf-8') as handle:
handle.write(text)
GENERATORS = (
('item_ids.txt', gen_item_ids),
('item_spells.json', gen_item_spells),
('debuff_spells.json', gen_debuff_spells),
('progression.json', gen_progression),
('mob_armor.json', gen_mob_armor),
('item_power.json', gen_item_power),
)
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--cache', default=DEFAULT_CACHE)
parser.add_argument('--check', action='store_true',
help='regenerate into a temp dir and report drift '
'instead of overwriting the committed tables')
args = parser.parse_args(argv)
if not os.path.isdir(args.cache):
raise SystemExit(
'no game data at {}; run scripts/fetch_gamedata.py first'.format(
args.cache))
if args.check:
return _check(args.cache)
for label, generator in GENERATORS:
path, count = generator(args.cache)
print('{:24s} {:>7d} entries {}'.format(
label, count, os.path.relpath(path)))
return 0
def _check(cache_dir):
import tempfile
import shutil
global STATIC_DIR
original = STATIC_DIR
drifted = []
tmp = tempfile.mkdtemp(prefix='gamedata-check-')
try:
STATIC_DIR = tmp
for label, generator in GENERATORS:
generated, _ = generator(cache_dir)
committed = os.path.join(original, label)
if not os.path.exists(committed):
drifted.append('{}: missing from src/static'.format(label))
elif _read(generated) != _read(committed):
drifted.append('{}: committed copy is stale'.format(label))
finally:
STATIC_DIR = original
shutil.rmtree(tmp, ignore_errors=True)
if drifted:
print('game data is out of date:')
for line in drifted:
print(' - {}'.format(line))
print('\nrun: make gamedata')
return 1
print('game data tables are up to date')
return 0
def _read(path):
with open(path, encoding='utf-8') as handle:
return handle.read()
if __name__ == '__main__':
sys.exit(main())
+172 -2
View File
@@ -9,12 +9,15 @@ PHOTON_GAME_CODE = 1
# Current opcodes (albion-lens numbering, verified against captured traffic)
EVENT_LEAVE = 1
EVENT_HEALTH_UPDATE = 6
EVENT_BATCHED_HEALTH_UPDATE = 7
EVENT_EFFECT_STACK_UPDATE = 22
EVENT_NEW_CHARACTER = 29
EVENT_ITEM_GAINED = 32
EVENT_TAKE_SILVER = 62
EVENT_UPDATE_FAME = 82
EVENT_CHARACTER_EQUIPMENT_CHANGED = 90
EVENT_REGENERATION_HEALTH_CHANGED = 91
EVENT_MOB_SPAWNED = 123
EVENT_KNOCKED_DOWN = 166
EVENT_PARTY_INVITATION = 229
EVENT_PARTY_JOIN_REQUEST = 230
@@ -75,6 +78,24 @@ def _as_int_list(value) -> List[int]:
return []
def _as_byte_list(value) -> List[int]:
"""Unpack a Photon byte array into ints.
Batched health-update params arrive either as ``bytes`` or as a dict with a
``bytes_hex`` field (which is how the discovery log serialises them), and
occasionally as an already-decoded list. All three shapes occur for the
same parameter, so accept each of them.
"""
if isinstance(value, (bytes, bytearray)):
return list(value)
if isinstance(value, dict):
raw = value.get('bytes_hex')
if isinstance(raw, str):
return [int(raw[i:i + 2], 16) for i in range(0, len(raw) - 1, 2)]
return []
return _as_int_list(value)
@dataclass
class GameMessage:
name: str
@@ -85,6 +106,17 @@ class GameMessage:
return self.params.get(key)
@dataclass(frozen=True)
class EffectApplication:
"""One entry of a victim's active effect list.
``applier`` is the entity that put the effect on the target; the game
sends it explicitly rather than leaving it to be inferred.
"""
applier: int
effect_id: int
def into_game_message(message: PhotonMessage) -> Optional[GameMessage]:
if message.code != PHOTON_GAME_CODE:
return None
@@ -113,12 +145,15 @@ def into_game_message(message: PhotonMessage) -> Optional[GameMessage]:
EVENT_NAMES = {
EVENT_LEAVE: 'Leave',
EVENT_HEALTH_UPDATE: 'HealthUpdate',
EVENT_BATCHED_HEALTH_UPDATE: 'BatchedHealthUpdate',
EVENT_EFFECT_STACK_UPDATE: 'EffectStackUpdate',
EVENT_NEW_CHARACTER: 'NewCharacter',
EVENT_ITEM_GAINED: 'ItemGained',
EVENT_TAKE_SILVER: 'TakeSilver',
EVENT_UPDATE_FAME: 'UpdateFame',
EVENT_CHARACTER_EQUIPMENT_CHANGED: 'CharacterEquipmentChanged',
EVENT_REGENERATION_HEALTH_CHANGED: 'RegenerationHealthChanged',
EVENT_MOB_SPAWNED: 'MobSpawned',
EVENT_KNOCKED_DOWN: 'KnockedDown',
EVENT_PARTY_INVITATION: 'PartyInvitation',
EVENT_PARTY_JOIN_REQUEST: 'PartyJoinRequest',
@@ -137,7 +172,18 @@ OPERATION_NAMES = {
# Parameter accessors used by the world state machine. Field names follow
# aoaddons' messages.json layouts, with the current opcode space from albion-lens.
def msg_source(msg: GameMessage) -> int:
#
# Naming note: the older messages.json labelled HealthUpdate params as
# ``source@0`` / ``target@6``, but the capture data shows the opposite of what
# those names suggest -- param 0 is the entity whose health changed (the victim)
# and param 6 is the entity that caused it (the attacker). The accessors below
# are named for what the wire actually carries.
def msg_subject_id(msg: GameMessage) -> int:
"""Param 0: the entity the event is about.
For most events that is simply the subject (the character that joined, left,
or changed equipment). For HealthUpdate it is the *victim*.
"""
v = _int(msg.params.get(0))
return v if v is not None else 0
@@ -156,16 +202,140 @@ def msg_map_index(msg: GameMessage) -> Optional[str]:
return _string(msg.params.get(8))
def msg_target(msg: GameMessage) -> int:
def msg_attacker_id(msg: GameMessage) -> int:
"""Param 6: the entity responsible for a health change (attacker or healer)."""
v = _int(msg.params.get(6))
return v if v is not None else 0
def msg_value(msg: GameMessage) -> float:
"""Param 2: the signed health delta. Negative is damage, positive is healing."""
v = _float(msg.params.get(2))
return v if v is not None else 0.0
def msg_health_after(msg: GameMessage) -> Optional[float]:
"""Param 3: the victim's health once the hit has been applied."""
return _float(msg.params.get(3))
def msg_hit_type(msg: GameMessage) -> Optional[int]:
"""Param 5: hit-type enum.
Observed values split into two groups. ``0`` and ``1`` accompany basic
attacks (median damage ~45) and always carry ``-1`` for param 7; ``2``, ``3``,
``5`` and ``6`` accompany ability hits (median ~164-242). The exact meaning
of each value is not yet known, so it is carried through untranslated.
"""
return _int(msg.params.get(5))
def msg_batched_victim_id(msg: GameMessage) -> int:
"""Param 0 of a batched health update: the entity every hit landed on."""
return msg_subject_id(msg)
def msg_batched_ticks(msg: GameMessage) -> List[int]:
"""Param 1: one tick counter per hit."""
return _as_int_list(msg.params.get(1))
def msg_batched_values(msg: GameMessage) -> List[float]:
"""Param 2: one signed health delta per hit."""
v = msg.params.get(2)
if not isinstance(v, list):
return []
out = []
for item in v:
f = _float(item)
if f is not None:
out.append(f)
return out
def msg_batched_health_after(msg: GameMessage) -> List[float]:
"""Param 3: one resulting-health value per hit."""
v = msg.params.get(3)
if not isinstance(v, list):
return []
out = []
for item in v:
f = _float(item)
if f is not None:
out.append(f)
return out
def msg_batched_hit_types(msg: GameMessage) -> List[int]:
"""Param 5: one hit-type enum per hit.
These arrive as a raw byte array rather than a decoded list, so they need
unpacking rather than the usual int coercion.
"""
return _as_byte_list(msg.params.get(5))
def msg_batched_attacker_ids(msg: GameMessage) -> List[int]:
"""Param 6: one attacker entity id per hit.
Also a raw byte array. Unlike param 2/3/5 the decoder sometimes produces a
plain list here instead, so both shapes are accepted.
"""
return _as_byte_list(msg.params.get(6))
def msg_effect_stack_appliers(msg: GameMessage) -> List[int]:
"""Param 1: the entity responsible for each effect on the victim.
Index-aligned with ``msg_effect_stack_ids``. The game sends the applier
outright, so attribution does not have to infer who applied a debuff from
the attacker's weapon -- which is what the original plan assumed.
"""
return _as_int_list(msg.params.get(1))
def msg_effect_stack_ids(msg: GameMessage) -> List[int]:
"""Param 2: one effect id per entry in the victim's active effect list.
These are runtime-assigned ids. They are stable for the life of a session
and usually unique to one (spell, caster) pair, but they are not the spell
ids used by the game data files, so they cannot be looked up statically.
"""
return _as_int_list(msg.params.get(2))
def msg_effect_stack_applications(msg: GameMessage) -> List[EffectApplication]:
"""Pair up the applier and effect id lists.
The two arrays are index-aligned and the same length on every observed
message. If a capture ever produced a ragged pair the mismatched tail is
dropped rather than guessed at.
"""
appliers = msg_effect_stack_appliers(msg)
effects = msg_effect_stack_ids(msg)
return [EffectApplication(applier, effect)
for applier, effect in zip(appliers, effects)]
def msg_mob_template_id(msg: GameMessage) -> Optional[int]:
"""Param 1: the numeric mob template this entity spawned from.
Template ids are the enumeration index of the mob table. They are a
different id space from item ids -- 454 is the Giant Snake as a mob but a
gathering skillbook as an item -- so this must never be resolved through
the item table.
"""
return _int(msg.params.get(1))
def msg_mob_hitpoints_max(msg: GameMessage) -> Optional[float]:
"""Param 13: the mob's maximum hit points at spawn.
Doubles as a cross-check on the template id: the two must agree.
"""
return _float(msg.params.get(13))
def msg_items(msg: GameMessage) -> List[int]:
return _as_int_list(msg.params.get(2))
+74 -22
View File
@@ -171,6 +171,8 @@ class World:
return self._on_leave(message)
if message.name == 'HealthUpdate':
return self._on_health_update(message)
if message.name == 'BatchedHealthUpdate':
return self._on_batched_health_update(message)
if message.name == 'RegenerationHealthChanged':
return self._on_regeneration(message)
if message.name == 'KnockedDown':
@@ -206,7 +208,7 @@ class World:
def _on_new_character(self, msg: GameMessage) -> List[dict]:
name = translate.msg_new_character_name(msg)
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
if not name:
return []
self.cache.save(dynamic_id, name)
@@ -231,7 +233,7 @@ class World:
def _on_join(self, msg: GameMessage) -> List[dict]:
name = translate.msg_character_name(msg)
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
if not name:
return []
self.cache.save(dynamic_id, name)
@@ -265,7 +267,7 @@ class World:
return [{'name': 'ZoneChange'}]
def _on_leave(self, msg: GameMessage) -> List[dict]:
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None:
return []
@@ -278,35 +280,85 @@ class World:
return []
def _on_health_update(self, msg: GameMessage) -> List[dict]:
# params: [0]=target (entity whose health changed), [2]=signed delta,
# [6]=source (attacker/healer). aoaddons emits Damage{source: params[6],
# target: params[0]} which the app attributes to the dealer/healer.
# Params: [0]=victim (entity whose health changed), [2]=signed delta,
# [3]=victim health after the hit, [5]=hit type, [6]=attacker/healer.
value = translate.msg_value(msg)
if value == 0.0:
return []
actor_id = _dyn(translate.msg_target(msg)) # param 6
victim_id = _dyn(translate.msg_source(msg)) # param 0
actor_static = self.cache.get_static_id(actor_id)
victim_id = _dyn(translate.msg_subject_id(msg))
attacker_id = _dyn(translate.msg_attacker_id(msg))
hit_type = translate.msg_hit_type(msg)
health_after = translate.msg_health_after(msg)
return self._health_events(
attacker_id=attacker_id,
victim_id=victim_id,
value=value,
hit_type=hit_type,
health_after=health_after)
def _on_batched_health_update(self, msg: GameMessage) -> List[dict]:
# Batched form of HealthUpdate: one victim, several hits delivered in a
# single packet, with parallel arrays indexed per hit. Verified against
# captures to be additional damage rather than a repeat of the scalar
# form -- see PLAN.md F2.
values = translate.msg_batched_values(msg)
if not values:
return []
victim_id = _dyn(translate.msg_batched_victim_id(msg))
health_after = translate.msg_batched_health_after(msg)
hit_types = translate.msg_batched_hit_types(msg)
attackers = translate.msg_batched_attacker_ids(msg)
events: List[dict] = []
for index, value in enumerate(values):
if value == 0.0:
continue
attacker = attackers[index] if index < len(attackers) else None
hit_type = hit_types[index] if index < len(hit_types) else None
after = health_after[index] if index < len(health_after) else None
events.extend(self._health_events(
attacker_id=_dyn(attacker) if attacker is not None else None,
victim_id=victim_id,
value=value,
hit_type=hit_type,
health_after=after))
return events
def _health_events(self, attacker_id: Optional[int], victim_id: int,
value: float, hit_type: Optional[int],
health_after: Optional[float]) -> List[dict]:
"""Build the damage/heal events for a single health change.
``DamageDone`` and ``DamageTaken`` are emitted independently so a hit
from an unknown attacker (a mob, say) still registers against a tracked
victim, and a hit on an untracked victim still registers for a tracked
attacker.
"""
attacker_static = (self.cache.get_static_id(attacker_id)
if attacker_id is not None else None)
victim_static = self.cache.get_static_id(victim_id)
events = []
if actor_static is not None:
event_name = 'DamageDone' if value < 0.0 else 'HealthReceived'
if attacker_static is not None:
payload = {'source': attacker_static,
'target': victim_static,
'value': float(abs(value)),
'hit_type': hit_type,
'health_after': health_after}
events.append({
'name': event_name,
'value': {'source': actor_static,
'target': victim_static,
'value': float(abs(value))},
'name': 'DamageDone' if value < 0.0 else 'HealthReceived',
'value': payload,
})
if value < 0.0 and victim_static is not None:
events.append({
'name': 'DamageTaken',
'value': {'source': victim_static,
'value': float(abs(value))},
'value': float(abs(value)),
'hit_type': hit_type},
})
return events
def _on_regeneration(self, msg: GameMessage) -> List[dict]:
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None:
return []
@@ -318,7 +370,7 @@ class World:
return [{'name': event_name, 'value': {'id': static_id, 'name': name}}]
def _on_knocked_down(self, msg: GameMessage) -> List[dict]:
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None:
return []
@@ -328,7 +380,7 @@ class World:
return [{'name': 'LeaveCombat', 'value': {'id': static_id, 'name': name}}]
def _on_update_fame(self, msg: GameMessage) -> List[dict]:
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None:
return []
@@ -358,7 +410,7 @@ class World:
def _on_item_gained(self, msg: GameMessage) -> List[dict]:
if not self._main_player_joined:
return []
source_id = _dyn(translate.msg_source(msg))
source_id = _dyn(translate.msg_subject_id(msg))
item_id = translate.msg_collected_item_id(msg)
quantity = translate.msg_collected_item_quantity(msg)
if item_id is None or quantity is None or quantity <= 0:
@@ -381,7 +433,7 @@ class World:
def _on_take_silver(self, msg: GameMessage) -> List[dict]:
if not self._main_player_joined:
return []
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None or static_id != self.main_player_id:
return []
@@ -400,7 +452,7 @@ class World:
}}]
def _on_character_equipment_changed(self, msg: GameMessage) -> List[dict]:
dynamic_id = _dyn(translate.msg_source(msg))
dynamic_id = _dyn(translate.msg_subject_id(msg))
static_id = self.cache.get_static_id(dynamic_id)
if static_id is None:
self.unconsumed_messages.add(dynamic_id, msg)
+53 -2
View File
@@ -16,6 +16,47 @@ def _event_value(event: dict) -> dict:
return event.get(consts.EvKeyValue) or {}
def _player_names(events: List[dict]) -> dict:
"""Map static player ids to names using the appearance events."""
names = {}
for event in events:
name = event[consts.EvKeyName]
if name in (consts.EvNamePlayerAppeared, consts.EvNameMainPlayerAppeared):
value = _event_value(event)
if value.get('id') is not None and value.get('name'):
names[value['id']] = value['name']
return names
def _damage_by_player(events: List[dict], names: dict, event_name: str):
"""Total damage per player, most first.
Reporting only a combined figure is misleading: the summary sits next to
"main player: <name>", so a party-wide total reads as if it belonged to
that one player.
"""
totals = Counter()
for event in events:
if event[consts.EvKeyName] != event_name:
continue
totals[_event_value(event).get(consts.EvKeySource, 0)] += \
_event_value(event).get('value', 0.0)
return totals, names
def _format_player_lines(totals, names: dict, limit: int = 8) -> List[str]:
if not totals:
return [' (none)']
ordered = sorted(totals.items(), key=lambda item: item[1], reverse=True)
lines = []
for player_id, total in ordered[:limit]:
label = names.get(player_id, f'player #{player_id}')
lines.append(f' {label}: {_fmt(total)}')
if len(ordered) > limit:
lines.append(f' ... and {len(ordered) - limit} more')
return lines
def summarize(events: List[dict], path: Optional[str] = None,
packet_count: Optional[int] = None) -> str:
"""Build a human readable summary of the events produced by a replay."""
@@ -39,6 +80,12 @@ def summarize(events: List[dict], path: Optional[str] = None,
main_player = _event_value(event).get('name')
break
names = _player_names(events)
damage_by_player, _ = _damage_by_player(
events, names, consts.EvNameDamageDone)
damage_taken_by_player, _ = _damage_by_player(
events, names, consts.EvNameDamageTaken)
lines = ['Replay summary']
if path:
lines.append(f' log: {path}')
@@ -49,8 +96,12 @@ def summarize(events: List[dict], path: Optional[str] = None,
lines.append(f' zone changes: {counts.get(consts.EvNameZoneChange, 0)}')
lines.append(f' fame gained: {_fmt(fame)}')
lines.append(f' silver looted: {_fmt(silver)}')
lines.append(f' damage done: {_fmt(damage)}')
lines.append(f' damage taken: {_fmt(damage_taken)}')
lines.append(f' damage done: {_fmt(damage)} (all players)')
lines.append(f' damage taken: {_fmt(damage_taken)} (all players)')
lines.append(' damage done by player:')
lines.extend(_format_player_lines(damage_by_player, names))
lines.append(' damage taken by player:')
lines.extend(_format_player_lines(damage_taken_by_player, names))
top = counts.most_common(8)
if top:
+372
View File
@@ -0,0 +1,372 @@
{
"ACID_BOMB_EFFECT": {
"abilities": [
"ACID_BOMB"
],
"category": "instant",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 3.5,
"type": "magicresistance",
"value": -0.14
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 3.5,
"type": "physicalarmor",
"value": -0.14
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "damage"
},
"ARMORPIERCER_DEBUFF_EFFECT": {
"abilities": [
"ARMORPIERCER"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "magicresistance",
"value": -0.17
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "physicalarmor",
"value": -0.17
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "debuff"
},
"AXESMASH_EFFECT": {
"abilities": [
"AXESMASH"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"time": 8.0,
"type": "magicresistance",
"value": -0.16
},
{
"target": "enemy",
"time": 8.0,
"type": "physicalarmor",
"value": -0.16
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "debuff"
},
"BEARTRAP_HIDEMOB_BONUS": {
"abilities": [
"BEARTRAP"
],
"category": "crowdcontrol",
"effects": [
{
"target": "enemy",
"time": 8.0,
"type": "magicresistance",
"value": -0.55
},
{
"target": "enemy",
"time": 8.0,
"type": "physicalarmor",
"value": -0.55
}
],
"maxcharges": null,
"maxstack": 3,
"uitype": "crowdcontrol"
},
"CURSEULTIMATE_EFFECT": {
"abilities": [
"CURSEULTIMATE"
],
"category": "damage",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 6.0,
"type": "magicresistance",
"value": -0.18
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 6.0,
"type": "physicalarmor",
"value": -0.18
}
],
"maxcharges": null,
"maxstack": 1,
"uitype": "damage"
},
"DEADLYSHOT_DEBUFF": {
"abilities": [
"DEADLYSHOT"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 5.0,
"type": "magicresistance",
"value": -0.03
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 5.0,
"type": "physicalarmor",
"value": -0.03
}
],
"maxcharges": 3,
"maxstack": 5,
"uitype": "debuff"
},
"FROST_LANCE_EFFECT": {
"abilities": [
"FROST_LANCE"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 3.0,
"type": "magicresistance",
"value": -0.12
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 3.0,
"type": "physicalarmor",
"value": -0.12
}
],
"maxcharges": 1,
"maxstack": 1,
"uitype": "damage"
},
"IRONBREAKER_EFFECT": {
"abilities": [
"IRONBREAKER"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "magicresistance",
"value": -0.12
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "physicalarmor",
"value": -0.12
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "debuff"
},
"SHAPE_Q_CONE_PIERCE": {
"abilities": [
"SHAPE_Q_CONE_MELEE"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"time": 6.0,
"type": "magicresistance",
"value": -0.02
},
{
"target": "enemy",
"time": 6.0,
"type": "physicalarmor",
"value": -0.02
}
],
"maxcharges": 3,
"maxstack": null,
"uitype": "damage"
},
"SMELLOFBLOOD_DEBUFF": {
"abilities": [
"SMELLOFBLOOD"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"time": 4.0,
"type": "magicresistance",
"value": -0.35
},
{
"target": "enemy",
"time": 4.0,
"type": "physicalarmor",
"value": -0.35
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "debuff"
},
"SNIPESHOT_CROSSBOW_DEBUFF": {
"abilities": [
"SNIPESHOT_CROSSBOW"
],
"category": "damage",
"effects": [
{
"target": "enemy",
"time": 4.0,
"type": "magicresistance",
"value": -0.15
},
{
"target": "enemy",
"time": 4.0,
"type": "physicalarmor",
"value": -0.15
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "debuff"
},
"SUNDERARMOR2": {
"abilities": [
"SUNDERARMOR2"
],
"category": "debuff",
"effects": [
{
"iftargettype": "mob",
"target": "enemy",
"time": 8.0,
"type": "magicresistance",
"value": -0.06
},
{
"iftargettype": "player",
"target": "enemy",
"time": 8.0,
"type": "magicresistance",
"value": -0.04
},
{
"iftargettype": "mob",
"target": "enemy",
"time": 8.0,
"type": "physicalarmor",
"value": -0.06
},
{
"iftargettype": "player",
"target": "enemy",
"time": 8.0,
"type": "physicalarmor",
"value": -0.04
}
],
"maxcharges": 3,
"maxstack": 3,
"uitype": "debuff"
},
"SUNDERSHOT_DEBUFF": {
"abilities": [
"SUNDERSHOT"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"time": 4.0,
"type": "magicresistance",
"value": -0.027
},
{
"target": "enemy",
"time": 4.0,
"type": "physicalarmor",
"value": -0.027
}
],
"maxcharges": 10,
"maxstack": null,
"uitype": "debuff"
},
"TAINTED_STEEL_AREA": {
"abilities": [
"TAINTED_STEEL"
],
"category": "instant",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "magicresistance",
"value": -0.04
}
],
"maxcharges": null,
"maxstack": 1,
"uitype": "damage"
},
"TAINTED_STEEL_EFFECT": {
"abilities": [
"TAINTED_STEEL"
],
"category": "debuff",
"effects": [
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "magicresistance",
"value": -0.12
},
{
"target": "enemy",
"targetcountvaluebonusfactor": 0.08,
"time": 4.0,
"type": "physicalarmor",
"value": -0.12
}
],
"maxcharges": null,
"maxstack": null,
"uitype": "damage"
}
}
+12237 -7493
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+195
View File
@@ -0,0 +1,195 @@
{
"shares": {
"armorshare": {
"@armor": "1.0",
"@avalonshield": "0",
"@book": "0",
"@cane": "0",
"@cape": "0",
"@censer": "0",
"@crystalbook": "0",
"@crystalshield": "0",
"@crystaltorch": "0",
"@demonskull": "0",
"@head": "0",
"@horn": "0",
"@lamp": "0",
"@mainhand": "0",
"@orb": "0",
"@prototype": "0",
"@shield": "0",
"@shoes": "0",
"@skullshield": "0",
"@spikedshield": "0",
"@talisman": "0",
"@torch": "0",
"@totem": "0",
"@towershield": "0",
"@transformation": "1.0"
},
"ccrshare": {
"@armor": "1.0",
"@avalonshield": "0",
"@book": "0",
"@cane": "0",
"@cape": "0",
"@censer": "0",
"@crystalbook": "0",
"@crystalshield": "0",
"@crystaltorch": "-1.2",
"@demonskull": "0",
"@head": "0",
"@horn": "0",
"@lamp": "0",
"@mainhand": "0",
"@orb": "0",
"@prototype": "0",
"@shield": "0.60",
"@shoes": "0",
"@skullshield": "0",
"@spikedshield": "0",
"@talisman": "1.8",
"@torch": "0",
"@totem": "0",
"@towershield": "0",
"@transformation": "1.0"
},
"energyshare": {
"@armor": "0.25",
"@avalonshield": "0",
"@book": "0.15",
"@cane": "0",
"@cape": "0.10",
"@censer": "0",
"@crystalbook": "0",
"@crystalshield": "0.125",
"@crystaltorch": "0",
"@demonskull": "0",
"@head": "0.5",
"@horn": "0",
"@lamp": "0",
"@mainhand": "0",
"@orb": "0.5",
"@prototype": "0",
"@shield": "0",
"@shoes": "0.15",
"@skullshield": "0",
"@spikedshield": "0",
"@talisman": "0",
"@torch": "0",
"@totem": "0",
"@towershield": "0",
"@transformation": "1.0"
},
"hitpointsshare": {
"@armor": "0.5",
"@avalonshield": "0",
"@book": "0",
"@cane": "0",
"@cape": "0",
"@censer": "0",
"@crystalbook": "0",
"@crystalshield": "0",
"@crystaltorch": "0",
"@demonskull": "0",
"@head": "0.25",
"@horn": "0",
"@lamp": "0",
"@mainhand": "0",
"@orb": "0",
"@prototype": "0.125",
"@shield": "0",
"@shoes": "0.25",
"@skullshield": "0",
"@spikedshield": "0",
"@talisman": "0",
"@torch": "0",
"@totem": "0.25",
"@towershield": "0",
"@transformation": "1.0"
},
"trackingtime": {
"@base": "0"
}
},
"slots": {
"armor": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"bag": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"cape": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"food": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"head": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"legendaryitemtraits": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"mainhand_1h": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0825,
"hitpointsprogression": 1.06
},
"mainhand_2h": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"mount": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"offhand": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"potion": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"shoes": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
},
"transformation": {
"armorbase": 100.0,
"armorprogression": 1.03,
"attackdamageprogression": 1.0918,
"hitpointsprogression": 1.06
}
}
}
+60
View File
@@ -0,0 +1,60 @@
# Game data provenance
This directory contains data vendored from the Albion Online game client.
It is **not** hand-maintained and must not be edited by hand.
## `item_ids.txt`
| | |
| --- | --- |
| Upstream | [`ao-data/ao-bin-dumps`](https://github.com/ao-data/ao-bin-dumps) |
| Path in upstream | `formatted/items.txt` |
| Commit | `47e4f5aca4d30b7495afa5a625ce0d5795e32050` |
| Commit date | 2026-09-23 |
| Retrieved | 2026-10-11 |
| Licence | MIT |
| Entries | 12,237 (IDs 1–12237, contiguous, no duplicates) |
Format is ` <id>: <uniquename> : <localized display name>`. Some entries have
no display name (846 of them), in which case the line ends after the unique
name.
`src/static/item_ids.txt` is generated from this file by `make gamedata`. It is
what the app reads, in the `<id>,<uniquename>` form its loader expects.
### Why this replaces the previous table
The table previously committed at `src/static/item_ids.txt` held 7,493 entries
and was a valid **older build** of this same data. Albion re-orders IDs between
builds, so the two agree on almost nothing: on the overlapping 7,239 IDs they
disagree on **100%**.
It is not merely stale — it is actively wrong. Scoring both tables against a
real equipment array from a capture, where each slot's position is known:
- this file: **8/8** slots resolve to the correct item and slot
- the old table: **0/8** (a helmet resolved to a firestaff, armor to a backpack)
Regenerate with `make gamedata`; the same command rewrites this file.
## Everything else is fetched, not committed
The remaining game data is too large to version, so `scripts/fetch_gamedata.py`
pulls it at build time into a gitignored cache:
| File | Size | Used for |
| --- | --- | --- |
| `items.json` | 17 MB | item → ability-slot bindings |
| `spells.json` | 15 MB | spell and debuff effect definitions |
| `mobs.json` | 19 MB | mob armor/resistance, mob template IDs |
| `gamedata.json` | 184 KB | item-power → armor/damage progression constants |
`localization.json` (90 MB) is deliberately **not** fetched. It is only needed
for localized display strings, and it cannot supply a display name for every
mob anyway — 883 of 5,479 mob definitions have no `namelocatag` at all,
including `T5_MOB_HIDE_SWAMP_GIANTSNAKE`. Nothing in attribution depends on it.
## Attribution
MIT, from the upstream repositories. See the upstream `LICENSE` file for the
authoritative text.
+12237
View File
File diff suppressed because it is too large Load Diff
+242
View File
@@ -0,0 +1,242 @@
"""Helpers for analysing captured discovery logs.
Captures are large (tens of MB) and live outside the repository, so tests that
use them skip themselves when none are available. Set ``AOSTATS_CAPTURE_GLOB``
to point at a different location, e.g.::
AOSTATS_CAPTURE_GLOB='/tmp/aostats-in-party*.jsonl' pytest tests
Records are read from the ``photon_message`` stream rather than the decoder's
``game_message`` stream. That matters for opcode research: ``game_message`` only
contains opcodes that ``src/decode/translate.py`` currently knows about, which
is exactly the set we are trying to extend.
"""
import glob
import json
import os
from dataclasses import dataclass
from typing import Any, Dict, Iterator, List, Optional
CAPTURE_GLOB_ENV = 'AOSTATS_CAPTURE_GLOB'
DEFAULT_CAPTURE_GLOB = '/tmp/aostats-in-party-with-items-and-silver*.jsonl'
# Opcodes under investigation, by Photon parameter id.
EVENT_PARAM = 252
OPCODE_HEALTH_UPDATE = 6
OPCODE_DAMAGE_BATCH = 7
OPCODE_ENTITY_STATS = 18
@dataclass(frozen=True)
class DecodedMessage:
"""A Photon message as captured, before opcode translation."""
timestamp: str
kind: str
opcode: Optional[int]
params: Dict[str, Any]
@dataclass(frozen=True)
class DamageHit:
"""One damage or healing tick against a victim.
``opcode`` is retained so a hit can be attributed to either the scalar
(``OPCODE_HEALTH_UPDATE``) or batched (``OPCODE_DAMAGE_BATCH``) encoding.
"""
timestamp: str
opcode: int
victim: Any
attacker: Any
delta: float
health_after: Optional[float]
def capture_glob() -> str:
return os.getenv(CAPTURE_GLOB_ENV) or DEFAULT_CAPTURE_GLOB
def capture_paths() -> List[str]:
return sorted(path for path in glob.glob(capture_glob()) if not path.endswith('.app.log'))
def captures_available() -> bool:
return bool(capture_paths())
def param(params: Dict[str, Any], key: int, default: Any = None) -> Any:
"""Read a Photon parameter by numeric id (JSON keys are strings)."""
return params.get(str(key), default)
def byte_list(value: Any) -> List[int]:
"""Normalise a parameter that may arrive as raw bytes or a decoded list."""
if isinstance(value, dict) and 'bytes_hex' in value:
raw = value['bytes_hex']
return [int(raw[i:i + 2], 16) for i in range(0, len(raw), 2)]
if isinstance(value, list):
return [v for v in value if isinstance(v, int)]
return []
def iter_messages(path: str) -> Iterator[DecodedMessage]:
"""Yield every captured Photon message in ``path`` in arrival order."""
with open(path, encoding='utf-8', errors='replace') as log:
for line in log:
if '"photon_message"' not in line:
continue
try:
record = json.loads(line)
except json.JSONDecodeError:
continue
message = record.get('message') or {}
params = message.get('params') or {}
kind = message.get('kind')
if kind == 'Event':
opcode = param(params, EVENT_PARAM)
elif kind in ('Request', 'Response'):
opcode = param(params, 253)
else:
opcode = None
yield DecodedMessage(
timestamp=record.get('timestamp') or '',
kind=kind,
opcode=opcode if isinstance(opcode, int) else None,
params=params,
)
def damage_hits(path: str) -> Iterator[DamageHit]:
"""Yield every damage/healing tick from both health-update encodings."""
for message in iter_messages(path):
if message.kind != 'Event':
continue
if message.opcode == OPCODE_HEALTH_UPDATE:
delta = param(message.params, 2)
health_after = param(message.params, 3)
if not isinstance(delta, (int, float)):
continue
yield DamageHit(
timestamp=message.timestamp,
opcode=OPCODE_HEALTH_UPDATE,
victim=param(message.params, 0),
attacker=param(message.params, 6),
delta=float(delta),
health_after=health_after if isinstance(health_after, (int, float)) else None,
)
elif message.opcode == OPCODE_DAMAGE_BATCH:
deltas = param(message.params, 2) or []
health_afters = param(message.params, 3) or []
attackers = byte_list(param(message.params, 6))
for index, delta in enumerate(deltas):
if not isinstance(delta, (int, float)):
continue
attacker = attackers[index] if index < len(attackers) else None
health_after = health_afters[index] if index < len(health_afters) else None
yield DamageHit(
timestamp=message.timestamp,
opcode=OPCODE_DAMAGE_BATCH,
victim=param(message.params, 0),
attacker=attacker,
delta=float(delta),
health_after=health_after if isinstance(health_after, (int, float)) else None,
)
def entity_multipliers(path: str) -> Iterator[tuple]:
"""Yield ``(timestamp, entity, multiplier)`` from the entity-stats opcode."""
for message in iter_messages(path):
if message.kind != 'Event' or message.opcode != OPCODE_ENTITY_STATS:
continue
multiplier = param(message.params, 6)
if isinstance(multiplier, (int, float)):
yield message.timestamp, param(message.params, 0), float(multiplier)
def damage_type(message: DecodedMessage) -> Any:
"""Param 5 of a health update: an ability/hit category enum."""
return param(message.params, 5)
def perfect_scalar_chains(path: str, min_steps: int = 5) -> List[List[DamageHit]]:
"""Victims whose scalar-opcode health chain is perfectly consistent.
These are the calibration set for the duplicate test: a stream that merely
repeats known hits cannot survive being injected into an already-exact
chain, so the damage a stream adds to this set is genuine.
"""
by_victim: Dict[Any, List[DamageHit]] = {}
for hit in damage_hits(path):
by_victim.setdefault(hit.victim, []).append(hit)
perfect = []
for victim_hits in by_victim.values():
scalar = check_chain(victim_hits, include_batched=False)
if scalar.steps >= min_steps and scalar.breaks == 0:
perfect.append(victim_hits)
return perfect
@dataclass
class ChainReport:
"""Whether each victim's reported health can be explained by observed hits.
Every health update reports the health the victim was left at. Walking a
victim's hits in time order and applying each delta to the running total
should land exactly on the next reported value:
previous.health_after + delta == health_after
When it does not, something moved the victim's health that we did not
observe -- regeneration, food, an offline update, or simply a hit missing
from this stream. Those are ``breaks``.
The decisive property: a stream that is a *duplicate* of another adds no
information while perturbing the running total, so it can only increase
breaks. The correct encoding therefore has the fewest breaks.
"""
steps: int = 0
breaks: int = 0
@property
def break_rate(self) -> float:
return self.breaks / self.steps if self.steps else 0.0
def merge(self, other: 'ChainReport') -> 'ChainReport':
return ChainReport(self.steps + other.steps, self.breaks + other.breaks)
def check_chain(hits: List[DamageHit],
include_batched: bool) -> ChainReport:
"""Walk each victim's health chain using one encoding or both.
Healing is included in the walk (it is a real health change) but a step is
only counted when both endpoints reported their resulting health.
"""
by_victim: Dict[Any, List[DamageHit]] = {}
for hit in hits:
if not include_batched and hit.opcode == OPCODE_DAMAGE_BATCH:
continue
by_victim.setdefault(hit.victim, []).append(hit)
report = ChainReport()
for victim_hits in by_victim.values():
ordered = sorted(victim_hits, key=lambda h: (h.timestamp, h.opcode))
previous = ordered[0]
if previous.health_after is None:
continue
running = previous.health_after
for current in ordered[1:]:
if current.health_after is None:
previous = current
continue
report.steps += 1
if abs(running + current.delta - current.health_after) > 0.01:
report.breaks += 1
# Trust the server's reported value; re-anchor after any break.
running = current.health_after
previous = current
return report
+196
View File
@@ -0,0 +1,196 @@
"""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')
+249
View File
@@ -0,0 +1,249 @@
"""Findings about the Albion health-update protocol, verified against captures.
These tests double as the specification for the Phase 1 decode work. They read
raw ``photon_message`` records rather than the decoder's ``game_message``
stream, because several of the behaviours under test concern opcodes that
``src/decode/translate.py`` does not handle yet.
Captures live outside the repository and are skipped when absent.
"""
import collections
import statistics
import pytest
from capture_analysis import (
OPCODE_DAMAGE_BATCH,
OPCODE_ENTITY_STATS,
OPCODE_HEALTH_UPDATE,
DamageHit,
capture_paths,
check_chain,
damage_hits,
damage_type,
iter_messages,
param,
perfect_scalar_chains,
)
pytestmark = pytest.mark.skipif(
not capture_paths(),
reason='discovery captures are not available')
def _scalar_messages():
for path in capture_paths():
for message in iter_messages(path):
if message.opcode == OPCODE_HEALTH_UPDATE:
yield message
def _all_hits():
for path in capture_paths():
for hit in damage_hits(path):
yield hit
# --- Opcode 7 is additional damage, not a repeat of opcode 6 ---------------
def test_batched_damage_is_not_a_duplicate_of_scalar_damage():
"""Echoing known hits destroys an exact health chain; real E7 does not.
Each victim picked here has a scalar-opcode health chain that reconciles
perfectly. Injecting a stream that merely repeats those same hits makes
every step inconsistent, because the repeated delta is applied twice. If
the batched opcode were such a repeat it would behave the same way.
Rates are pooled across captures rather than compared per capture: a
single-break sample from a two-step victim would otherwise dominate.
"""
real_breaks = real_steps = 0
synthetic_breaks = synthetic_steps = 0
for path in capture_paths():
for group in perfect_scalar_chains(path):
base = check_chain(group, include_batched=False)
actual = check_chain(group, include_batched=True)
real_steps += actual.steps - base.steps
real_breaks += actual.breaks - base.breaks
echoed = list(group) + [
DamageHit(h.timestamp, OPCODE_DAMAGE_BATCH, h.victim,
h.attacker, h.delta, h.health_after)
for h in group]
doubled = check_chain(echoed, include_batched=True)
synthetic_steps += doubled.steps - base.steps
synthetic_breaks += doubled.breaks - base.breaks
assert real_steps > 20, f'only {real_steps} extra steps introduced'
assert synthetic_steps > 20, f'only {synthetic_steps} synthetic steps'
real_rate = real_breaks / real_steps
synthetic_rate = synthetic_breaks / synthetic_steps
assert real_rate < 0.25, \
f'real batched damage should not double-count, got {real_rate:.2%}'
assert synthetic_rate > 0.75, \
f'a genuine duplicate should double-count, got {synthetic_rate:.2%}'
def test_batched_damage_carries_substantial_volume():
"""The batched opcode accounts for a large share of total damage.
This is the size of the undercount that Phase 1 exists to fix.
"""
scalar = batched = 0.0
for hit in _all_hits():
if hit.delta >= 0:
continue
if hit.opcode == OPCODE_HEALTH_UPDATE:
scalar += -hit.delta
else:
batched += -hit.delta
assert scalar > 0 and batched > 0
share = batched / (scalar + batched)
assert 0.3 < share < 0.5, f'batched share of damage drifted to {share:.2%}'
def test_batched_damage_reports_health_after_each_hit():
"""Every batched hit carries its own resulting health and attacker.
These are the fields Phase 1 needs to credit damage without guessing.
"""
checked = 0
for hit in _all_hits():
if hit.opcode != OPCODE_DAMAGE_BATCH or hit.delta >= 0:
continue
assert hit.health_after is not None, 'batched hit without resulting health'
assert hit.attacker is not None, 'batched hit without an attacker'
checked += 1
assert checked > 100, f'only {checked} batched damage hits to check'
# --- Health-update parameter layout ---------------------------------------
def test_health_after_param_reconciles_with_deltas():
"""Param 3 is the victim's health once the hit has been applied."""
report = check_chain(list(_all_hits()), include_batched=False)
assert report.steps > 1000, f'only {report.steps} steps to reconcile'
assert report.break_rate < 0.6, \
f'param 3 does not reconcile (break rate {report.break_rate:.2%})'
def test_damage_type_separates_basic_hits_from_abilities():
"""Param 5 splits basic attacks (0, 1) from ability hits (2+).
The groups do not overlap and differ sharply in magnitude, which is what
makes param 5 useful for splitting damage by hit type.
"""
magnitudes = collections.defaultdict(list)
for message in _scalar_messages():
delta = param(message.params, 2)
if not isinstance(delta, (int, float)) or delta >= 0:
continue
magnitudes[damage_type(message)].append(-delta)
assert set(magnitudes) >= {0, 1, 2, 3}, f'unexpected param 5 domain: {sorted(magnitudes)}'
basic = magnitudes[0] + magnitudes[1]
abilities = magnitudes[2] + magnitudes[3]
assert statistics.median(basic) < statistics.median(abilities) * 0.5, \
f'basic {statistics.median(basic):.0f} vs ability ' \
f'{statistics.median(abilities):.0f} are not separable'
def test_max_health_param_presence_is_a_function_of_damage_type():
"""Param 7 is populated for exactly the param 5 values 2 and above.
"Populated" means a value of at least zero; basic hits carry -1 as a
placeholder. Presence therefore carries no information beyond param 5, so
param 7 adds no independent damage signal. Recorded so Phase 1 does not
model the same partition twice.
"""
populated = collections.defaultdict(set)
for message in _scalar_messages():
value = damage_type(message)
raw = param(message.params, 7)
populated[value].add(isinstance(raw, (int, float)) and raw >= 0)
for value, flags in populated.items():
assert len(flags) == 1, \
f'param 7 presence varies within param 5={value}: {flags}'
absent = {value for value, flags in populated.items() if flags == {False}}
assert absent == {0, 1}, f'param 7 absent for {sorted(absent)}, expected 0 and 1'
# --- Opcode 18 param 6 is not a damage multiplier --------------------------
def test_entity_stats_multiplier_does_not_track_damage():
"""Damage does not change across opcode 18 multiplier transitions.
This refutes the Phase 0 hypothesis that opcode 18 carries a live incoming
damage multiplier. The multiplier moves while the median damage either side
of the transition stays flat, so it cannot be used to infer mitigation
state. Recorded here so Phase 2 does not build on it.
"""
import statistics as stats
followed = 0
for path in capture_paths():
multipliers = collections.defaultdict(list)
damage = collections.defaultdict(list)
for message in iter_messages(path):
if message.opcode == OPCODE_ENTITY_STATS:
value = param(message.params, 6)
if isinstance(value, (int, float)):
multipliers[param(message.params, 0)].append(
(message.timestamp, value))
for hit in damage_hits(path):
damage[hit.victim].append((hit.timestamp, hit))
for entity, sequence in multipliers.items():
if not damage.get(entity):
continue
for index in range(1, len(sequence)):
(before_ts, before_m), (after_ts, after_m) = sequence[index - 1], sequence[index]
if before_m == after_m:
continue
earlier = [-hit.delta for ts, hit in damage[entity]
if hit.delta < 0 and before_ts < ts <= after_ts]
later = [-hit.delta for ts, hit in damage[entity]
if hit.delta < 0 and ts > after_ts][:20]
if len(earlier) < 3 or len(later) < 3:
continue
followed += 1
expected = abs(after_m / before_m)
observed = abs(stats.median(later) / stats.median(earlier))
assert abs(observed - expected) > 0.2 * max(expected, 1e-9), \
f'damage tracked the multiplier x{expected:.2f} ' \
f'(observed x{observed:.2f}) -- it may be a damage multiplier'
assert followed > 0, 'no opcode 18 multiplier transitions with surrounding damage'
def test_entity_stats_multiplier_is_often_constant_per_entity():
"""Where param 6 varies, it is a minority of samples for that entity.
Consistent with a cosmetic or interpolation factor rather than a
continuously tracked combat statistic.
"""
unstable = seen = 0
for path in capture_paths():
per_entity = collections.defaultdict(collections.Counter)
for message in iter_messages(path):
if message.opcode != OPCODE_ENTITY_STATS:
continue
value = param(message.params, 6)
if isinstance(value, (int, float)):
per_entity[param(message.params, 0)][round(value, 4)] += 1
for counts in per_entity.values():
seen += 1
if len(counts) > 1:
unstable += 1
assert seen > 0, 'no opcode 18 records found'
assert unstable / seen < 0.5, \
f'{unstable}/{seen} entities vary, too many for a cosmetic value'
+121 -1
View File
@@ -308,6 +308,122 @@ def test_world_health_update_known_actor_unknown_target_emits_damage_done():
assert events[0]['value']['target'] is None
# --- Health update accessors ---------------------------------------------------
def test_health_update_accessors():
msg = game('HealthUpdate', {0: 10, 2: -80.0, 3: 420.0, 5: 3, 6: 20, 7: -1})
assert translate.msg_subject_id(msg) == 10 # param 0 is the victim
assert translate.msg_attacker_id(msg) == 20 # param 6 is the attacker
assert translate.msg_value(msg) == -80.0
assert translate.msg_health_after(msg) == 420.0
assert translate.msg_hit_type(msg) == 3
def test_health_update_accessors_tolerate_missing_params():
msg = game('HealthUpdate', {})
assert translate.msg_subject_id(msg) == 0
assert translate.msg_attacker_id(msg) == 0
assert translate.msg_value(msg) == 0.0
assert translate.msg_health_after(msg) is None
assert translate.msg_hit_type(msg) is None
def test_byte_list_unpacks_every_encoded_shape():
# Batched params arrive as raw bytes, as the discovery log's dict form, or
# as an already-decoded list depending on the decoder path.
assert translate._as_byte_list(b'\x01\x02') == [1, 2]
assert translate._as_byte_list({'bytes_hex': 'c5c5', 'len': 2}) == [197, 197]
assert translate._as_byte_list([3, 4]) == [3, 4]
assert translate._as_byte_list(None) == []
def test_batched_health_update_accessors():
msg = game('BatchedHealthUpdate', {
0: 76,
1: [11, 12],
2: [-41.0, -135.0],
3: [3416.0, 3281.0],
5: b'\x00\x02',
6: b'\xc5\x58',
})
assert translate.msg_batched_victim_id(msg) == 76
assert translate.msg_batched_ticks(msg) == [11, 12]
assert translate.msg_batched_values(msg) == [-41.0, -135.0]
assert translate.msg_batched_health_after(msg) == [3416.0, 3281.0]
assert translate.msg_batched_hit_types(msg) == [0, 2]
assert translate.msg_batched_attacker_ids(msg) == [197, 88]
# --- Batched health update -----------------------------------------------------
def test_world_batched_health_update_emits_one_event_per_hit():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
world.transform(game('NewCharacter', {0: 20, 1: 'Attacker'}))
world.transform(game('NewCharacter', {0: 30, 1: 'Other'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10,
2: [-41.0, -135.0],
3: [3416.0, 3281.0],
5: b'\x00\x02',
6: b'\x14\x1e',
}))
# two hits, each producing DamageDone and DamageTaken
assert len(events) == 4
assert [e['name'] for e in events] == [
'DamageDone', 'DamageTaken', 'DamageDone', 'DamageTaken']
assert [e['value']['value'] for e in events] == [41.0, 41.0, 135.0, 135.0]
# the attacker differs per hit and must be credited per hit, not per packet
assert events[0]['value']['source'] == 1 # attacker 20
assert events[2]['value']['source'] == 2 # attacker 30
assert [e['value']['hit_type'] for e in (events[0], events[2])] == [0, 2]
assert [e['value']['health_after'] for e in (events[0], events[2])] == [3416.0, 3281.0]
def test_world_batched_health_update_skips_zero_and_unknown():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
world.transform(game('NewCharacter', {0: 20, 1: 'Attacker'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10, 2: [0.0, -25.0], 3: [500.0, 475.0], 6: b'\x14\x14'}))
assert [e['name'] for e in events] == ['DamageDone', 'DamageTaken']
assert events[0]['value']['value'] == 25.0
# a victim nobody tracks, hit by nobody tracked, produces nothing
assert world.transform(game('BatchedHealthUpdate', {
0: 777, 2: [-10.0], 3: [90.0], 6: b'\x88'})) == []
def test_world_batched_health_update_tolerates_short_arrays():
"""A missing attacker list must not raise or misattribute the hit."""
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
events = world.transform(game('BatchedHealthUpdate', {
0: 10, 2: [-25.0], 3: [475.0]}))
assert [e['name'] for e in events] == ['DamageTaken']
assert events[0]['value']['source'] == 0
def test_world_batched_health_update_empty_yields_nothing():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Victim'}))
assert world.transform(game('BatchedHealthUpdate', {0: 10, 2: []})) == []
def test_batched_health_update_opcode_is_translated():
from src.decode.pipeline import Pipeline
events = []
pipeline = Pipeline(events.append)
payload = enet_unreliable_packet(
0x07, event_payload(7, [(0, p18_short(76)), (2, p18_string('x'))]))
pipeline.on_udp(payload)
# recognised as a game message even though it carries no usable deltas
assert events == []
def test_world_regeneration_combat_states():
world = World()
world.transform(game('NewCharacter', {0: 10, 1: 'Alice'}))
@@ -360,11 +476,15 @@ def test_world_item_gained_emits_collected_item():
world = World()
world.transform(game('Join', {0: 63, 2: 'Alice'}))
events = world.transform(game('ItemGained', {1: 522, 2: 3, 4: 10000000}))
# Item 522 is T1_SILVERBAG_NONTRADABLE in the current game data. This test
# previously expected T4_MEAL_SALAD_FISH@3, which is what the stale item id
# table claimed; ids are reassigned between game builds, and that table
# resolved 0 of 8 slots on a real equipment array.
assert events == [{
'name': 'ItemCollected',
'value': {
'item_id': 522,
'item_name': 'T4_MEAL_SALAD_FISH@3',
'item_name': 'T1_SILVERBAG_NONTRADABLE',
'quantity': 3,
'estimated_value': 10000000,
},
+171
View File
@@ -0,0 +1,171 @@
"""Protocol tests for the effect stack and mob spawn opcodes.
Both were identified from /tmp/aostats-party01.jsonl, a T5 Morgana dungeon run
in which one player applied Armor Piercer and a party mate finished the mobs.
Every assertion here is anchored to a specific observation in that capture.
"""
import json
import pytest
from src.decode.translate import (
EffectApplication,
GameMessage,
into_game_message,
msg_effect_stack_applications,
msg_mob_hitpoints_max,
msg_mob_template_id,
)
def effect_msg(victim, appliers, effect_ids, flags='00', values='00'):
"""Build the EffectStackUpdate shape seen on the wire."""
n = len(appliers)
return GameMessage('EffectStackUpdate', 22, {
0: victim,
1: list(appliers),
2: list(effect_ids),
3: {'bytes_hex': flags * n, 'len': n},
4: {'bytes_hex': values * n, 'len': n},
})
def mob_msg(entity, template, hitpoints_max):
return GameMessage('MobSpawned', 123, {
0: entity,
1: template,
2: 255,
13: float(hitpoints_max),
14: float(hitpoints_max),
})
# --- effect stack ------------------------------------------------------------
def test_effect_stack_pairs_applier_with_effect():
msg = effect_msg(78724, [90362, 90547, 90547], [3163, 3097, 3098])
assert msg_effect_stack_applications(msg) == [
EffectApplication(applier=90362, effect_id=3163),
EffectApplication(applier=90547, effect_id=3097),
EffectApplication(applier=90547, effect_id=3098),
]
def test_applier_is_sent_explicitly():
"""Attribution does not have to guess who applied a debuff.
This is the reason the game sends the applier per effect. The original
plan assumed it would have to be inferred from the attacker's equipped
weapon; the packets do not require that.
"""
msg = effect_msg(78724, [90547, 90547, 90547], [3097, 3098, 3099])
appliers = {a.applier for a in msg_effect_stack_applications(msg)}
assert appliers == {90547}
def test_one_applier_can_hold_several_effects():
"""Armor Piercer is a beam that hits several targets at once.
Observed at 16:49:54.256: bionicKatana's three effect ids landed on three
different victims within a millisecond of each other, which is the
multi-target shape of the spell.
"""
msg = effect_msg(78724,
[90547, 90547, 90547, 90547, 90547],
[3097, 3098, 3099, 3092, 3093])
apps = msg_effect_stack_applications(msg)
assert len(apps) == 5
assert all(a.applier == 90547 for a in apps)
assert {a.effect_id for a in apps} == {3092, 3093, 3097, 3098, 3099}
def test_ragged_arrays_are_truncated_not_guessed():
"""A mismatched pair drops the tail rather than pairing unrelated ids."""
msg = effect_msg(78724, [90547, 90547, 90547], [3097, 3098])
assert len(msg_effect_stack_applications(msg)) == 2
def test_effect_stack_opcode_is_named():
"""Opcode 22 resolves to a name instead of being dropped."""
raw = _photon(code=1, kind='Event',
params={0: 78724, 1: [90547], 2: [3097], 252: 22})
msg = into_game_message(raw)
assert msg is not None
assert msg.name == 'EffectStackUpdate'
# --- mob spawn ---------------------------------------------------------------
def test_mob_spawn_carries_template_and_max_hp():
"""Template 2501 is a T5 Keeper Giant Champion, and max HP agrees.
Both fields were cross-checked against the packet, which is what makes the
template id safe to trust.
"""
msg = mob_msg(78724, 2501, 3282.0)
assert msg_mob_template_id(msg) == 2501
assert msg_mob_hitpoints_max(msg) == pytest.approx(3282.0)
def test_mob_spawn_opcode_is_named():
raw = _photon(code=1, kind='Event',
params={0: 78724, 1: 2501, 13: 3282.0, 252: 123})
msg = into_game_message(raw)
assert msg is not None
assert msg.name == 'MobSpawned'
def test_mob_template_is_not_an_item_id():
"""Mob template ids and item ids are different id spaces.
The discovery logger labels every integer it sees using the item table, so
this separation has to hold or every spawned mob would be reported as
whatever item happens to share its number.
"""
from src.decode import items as itemdb
db = itemdb.get_db()
# 454 was observed as a mob template for a Giant Snake...
msg = mob_msg(1, 454, 1162.0)
assert msg_mob_template_id(msg) == 454
# ...while item 454 is something else entirely.
assert db[454] == 'T5_SKILLBOOK_GATHER_FIBER'
assert mob_armor_name(454) == 'T5_MOB_HIDE_SWAMP_GIANTSNAKE'
def mob_armor_name(template_id):
with open(_static_path('mob_armor.json'), encoding='utf-8') as handle:
return json.load(handle)[str(template_id)]['name']
def _static_path(name):
import os
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(root, 'src', 'static', name)
# --- capture-derived findings ------------------------------------------------
@pytest.mark.parametrize('applier,effect_ids', [
(90547, [3097, 3098, 3099]),
(90547, [3092, 3093]),
(90362, [3163]),
])
def test_real_payload_shapes_decode(applier, effect_ids):
"""Shapes taken verbatim from the capture still decode cleanly."""
msg = effect_msg(78724, [applier] * len(effect_ids), effect_ids)
apps = msg_effect_stack_applications(msg)
assert [a.effect_id for a in apps] == effect_ids
assert all(a.applier == applier for a in apps)
def _photon(code, kind, params):
class Raw:
pass
raw = Raw()
raw.code = code
raw.kind = kind
raw.params = params
raw.debug_message = None
return raw
+312
View File
@@ -0,0 +1,312 @@
"""Regression tests for the generated game data tables.
These assert facts established against real captures. Each one is anchored to a
specific observation, and the item-id assertions in particular fail against the
table this project used to ship -- which is the point: that table was silently
wrong, and nothing caught it.
"""
import json
import os
import pytest
from src.decode import items as itemdb
_ARMOR_TYPES = ('physicalarmor', 'magicresistance')
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC = os.path.join(_REPO, 'src', 'static')
def _load(name):
with open(os.path.join(STATIC, name), encoding='utf-8') as handle:
return json.load(handle)
@pytest.fixture(scope='module')
def item_spells():
return _load('item_spells.json')
@pytest.fixture(scope='module')
def debuff_spells():
return _load('debuff_spells.json')
@pytest.fixture(scope='module')
def mob_armor():
return _load('mob_armor.json')
@pytest.fixture(scope='module')
def item_power():
return _load('item_power.json')
@pytest.fixture(scope='module')
def progression():
return _load('progression.json')
# --- item ids ----------------------------------------------------------------
def test_real_equipment_array_resolves_by_position():
"""Every slot of a real equipment array resolves to the matching item.
The array is the equipment payload from a capture in
/tmp/aostats-debuff-test03, in wire order: weapon, offhand, helmet, armor,
boots, bag, cape, mount. The table this replaces scored 0 of these 8; it
reported a helmet as a firestaff and armor as a backpack.
"""
array = [7739, 2372, 5054, 4168, 4648, 2888, 2600, 3030]
expected = [
'T5_MAIN_HOLYSTAFF_AVALON@1',
'T7_OFF_TORCH',
'T7_HEAD_CLOTH_HELL',
'T6_ARMOR_LEATHER_SET2',
'T7_SHOES_LEATHER_AVALON',
'T4_BAG',
'T7_CAPEITEM_FW_LYMHURST@1',
'T5_MOUNT_HORSE',
]
assert [itemdb.get_db()[i] for i in array] == expected
def test_cursed_staff_resolves_to_armor_piercer(item_spells):
"""The weapon that actually cast Armor Piercer in the capture.
The packet carries the enchanted variant, T6_MAIN_CURSEDSTAFF@1, but only
the base item exists in the dump -- so the table aliases the variants.
Without that alias a lookup straight from a packet id finds nothing.
"""
assert item_spells['T6_MAIN_CURSEDSTAFF@1'] == \
item_spells['T6_MAIN_CURSEDSTAFF']
by_slot = {}
for entry in item_spells['T6_MAIN_CURSEDSTAFF@1']:
by_slot.setdefault(entry['slot'], []).append(entry['spell'])
assert by_slot['2'] == ['ARMORPIERCER', 'CURSENOVA', 'CURSEDHANDS_STACKUP',
'CURSEDBEAM', 'DARKMATTER']
assert by_slot['3'] == ['DEATHCURSE2']
def test_enchantment_variants_have_distinct_ids():
"""Enchantment level is in the item id, not folded into the base."""
db = itemdb.get_db()
assert db[7738] == 'T5_MAIN_HOLYSTAFF_AVALON'
assert db[7739] == 'T5_MAIN_HOLYSTAFF_AVALON@1'
assert db[7740] == 'T5_MAIN_HOLYSTAFF_AVALON@2'
# --- item power --------------------------------------------------------------
def test_item_power_follows_enchantment(item_power):
"""Item power scales with enchantment, so it can anchor damage maths.
This is what keeps the model correct as a player levels their weapon,
rather than inferring a constant from observed hits.
"""
assert item_power['T5_MAIN_HOLYSTAFF_AVALON'] == 900
assert item_power['T5_MAIN_HOLYSTAFF_AVALON@1'] == 1000
assert item_power['T5_MAIN_HOLYSTAFF_AVALON@4'] == 1300
# --- item -> spell binding ---------------------------------------------------
def test_spell_binding_follows_reference_inheritance(item_spells):
"""T5_MAIN_HOLYSTAFF_AVALON has no craftingspelllist of its own.
It inherits through two levels of @reference, and only the base carries
the abilities. Unresolved, it would have no spells at all.
"""
spells = item_spells['T5_MAIN_HOLYSTAFF_AVALON']
assert spells, 'inherited spell list is empty'
by_slot = {}
for entry in spells:
by_slot.setdefault(entry['slot'], []).append(entry['spell'])
assert 'HEALINGBEAM' in by_slot['2']
assert 'DIVINE_JUMP' in by_slot['3']
def test_removespell_drops_inherited_ability(item_spells):
"""T4_MAIN_HOLYSTAFF_AVALON inherits the base but drops one spell."""
inherited = {e['spell'] for e in item_spells['T4_MAIN_HOLYSTAFF']}
avalon = {e['spell'] for e in item_spells['T4_MAIN_HOLYSTAFF_AVALON']}
assert 'HOLYDESPERATEPRAYER2' in inherited
assert 'HOLYDESPERATEPRAYER2' not in avalon
assert 'DIVINE_JUMP' in avalon
def test_every_spell_bearing_item_resolves(item_spells):
"""100% coverage: no item that has ability slots lacks its spell list.
Naively 471 weapons look empty until @reference is resolved.
"""
cache = os.path.join('.cache', 'gamedata', 'items.json')
if not os.path.exists(cache):
pytest.skip('game data cache absent; run scripts/fetch_gamedata.py')
with open(cache, encoding='utf-8') as handle:
items_root = json.load(handle)['items']
index = {}
for group, value in items_root.items():
if group.startswith('@') or group == 'shopcategories':
continue
entries = value if isinstance(value, list) else (
[value] if isinstance(value, dict) else [])
for entry in entries:
if isinstance(entry, dict) and entry.get('@uniquename'):
index[entry['@uniquename']] = entry
missing = []
for name, entry in index.items():
slots = entry.get('@activespellslots')
if not slots or str(slots) in ('0', ''):
continue
if not item_spells.get(name):
missing.append(name)
assert not missing, 'items with ability slots but no spells: {}'.format(
missing[:5])
# --- debuff resolution ------------------------------------------------------
def test_debuff_reached_through_spell_chain(debuff_spells):
"""ARMORPIERCER carries no buffovertime of its own.
The armour numbers live two hops away:
ARMORPIERCER -> spelleffectarea -> ARMORPIERCER_EFFECT
-> applyspell -> ARMORPIERCER_DEBUFF_EFFECT
Matching only an ability's own effects would find nothing at all.
"""
entry = debuff_spells['ARMORPIERCER_DEBUFF_EFFECT']
assert entry['abilities'] == ['ARMORPIERCER']
physical = [e for e in entry['effects'] if e['type'] == 'physicalarmor']
assert len(physical) == 1
assert physical[0]['value'] == pytest.approx(-0.17)
assert physical[0]['time'] == pytest.approx(4.0)
def test_debuff_magnitude_scaling_is_preserved(debuff_spells):
"""Armor Piercer is stronger against more targets.
The multiplier must be carried through, because attribution has to read the
magnitude off the observed effect rather than assume the base value.
"""
for effect in debuff_spells['ARMORPIERCER_DEBUFF_EFFECT']['effects']:
assert effect['targetcountvaluebonusfactor'] == pytest.approx(0.08)
def test_mob_and_player_variants_are_distinguished(debuff_spells):
"""SUNDERARMOR2 is weaker against players than against mobs."""
effects = debuff_spells['SUNDERARMOR2']['effects']
by_target = {}
for effect in effects:
if effect['type'] == 'physicalarmor':
by_target[effect.get('iftargettype')] = effect['value']
assert by_target['player'] == pytest.approx(-0.04)
assert by_target['mob'] == pytest.approx(-0.06)
assert debuff_spells['SUNDERARMOR2']['maxstack'] == 3
def test_every_debuff_is_attributable_to_an_ability(debuff_spells):
"""Each debuff effect names the ability that caused it.
That link is what turns an observed effect into a player, via the ability's
slot on the attacker's weapon.
"""
for name, entry in debuff_spells.items():
assert entry['abilities'], '{} has no producing ability'.format(name)
assert entry['effects'], '{} has no effects'.format(name)
def test_armour_debuffs_combine_additively(debuff_spells):
"""No armour debuff uses a stacking rule.
Absence of @stackingrule means same-type effects sum, which is what makes
the combined victim reduction a plain sum rather than a priority puzzle.
"""
cache = os.path.join('.cache', 'gamedata', 'spells.json')
if not os.path.exists(cache):
pytest.skip('game data cache absent; run scripts/fetch_gamedata.py')
with open(cache, encoding='utf-8') as handle:
spells_root = json.load(handle)['spells']
checked = 0
for group in ('activespell', 'passivespell', 'togglespell'):
for spell in spells_root.get(group) or []:
bot = spell.get('buffovertime')
entries = bot if isinstance(bot, list) else ([bot] if bot else [])
if not any(isinstance(e, dict)
and e.get('@type') in _ARMOR_TYPES
for e in entries):
continue
checked += 1
assert not spell.get('@stackingrule'), (
'armour debuff {} declares a stacking rule'.format(
spell.get('@uniquename')))
assert not spell.get('@stackinggroup'), (
'armour debuff {} declares a stacking group'.format(
spell.get('@uniquename')))
assert checked > 100
# --- mob templates ----------------------------------------------------------
def test_mob_template_resolves_to_known_mob(mob_armor):
"""Template 454 is the Giant Snake from the controlled capture.
Opcode 252/123 carries the template id in param 1 and max HP in param 13;
both were cross-checked against the packet.
"""
assert mob_armor['454'] == {
'name': 'T5_MOB_HIDE_SWAMP_GIANTSNAKE',
'tier': 5,
'armor': 136,
'resistance': 136,
'hitpointsmax': 1162,
'category': 'hidemob',
}
@pytest.mark.parametrize('template_id,expected_name,expected_hp', [
('448', 'T1_MOB_HIDE_SWAMP_TOAD', 20),
('2722', 'T5_MOB_CITY_SWAMP_GUARD', 1509),
('2724', 'T4_MOB_CITY_SWAMP_KNIGHT_ELITE', 11606),
('2725', 'T5_MOB_CITY_SWAMP_BOSS', 27795),
('2757', 'T6_MOB_GUARD_TOWER', 153572),
])
def test_mob_templates_match_observed_max_hp(
mob_armor, template_id, expected_name, expected_hp):
"""Each was seen in a capture alongside its max HP."""
entry = mob_armor[template_id]
assert entry['name'] == expected_name
assert entry['hitpointsmax'] == expected_hp
def test_mob_and_item_ids_are_separate_spaces(mob_armor):
"""Template 454 and item 454 are different things.
Worth pinning: the discovery logger walks every integer in every message
and labels it with the item table, so decoding opcode 123 naively would
report the Giant Snake as a gathering skillbook.
"""
assert mob_armor['454']['name'] == 'T5_MOB_HIDE_SWAMP_GIANTSNAKE'
assert itemdb.get_db()[454] == 'T5_SKILLBOOK_GATHER_FIBER'
# --- progression ------------------------------------------------------------
def test_progression_constants_present(progression):
"""Armour and damage scale off item power using these constants."""
slot = progression['slots']['mainhand_2h']
assert slot['armorbase'] == pytest.approx(100.0)
assert slot['armorprogression'] == pytest.approx(1.03)
assert slot['attackdamageprogression'] == pytest.approx(1.0918)
share = progression['shares']['armorshare']
assert float(share['@armor']) == pytest.approx(1.0)
assert float(share['@head']) == pytest.approx(0.0)
+47
View File
@@ -113,6 +113,53 @@ def test_summarize_reports_fame_silver_and_player():
assert 'packets: 42' in report
def test_summarize_breaks_damage_down_per_player():
"""A combined total next to "main player" reads as that player's damage.
Two players damaged a mob; the report must attribute each share rather
than printing one ambiguous number.
"""
events = [
{'name': 'MainPlayerAppeared', 'value': {'id': 0, 'name': 'Alice'}},
{'name': 'PlayerAppeared', 'value': {'id': 1, 'name': 'Bob'}},
{'name': 'DamageDone', 'value': {'source': 1, 'value': 1309.0}},
{'name': 'DamageDone', 'value': {'source': 1, 'value': 100.0}},
{'name': 'DamageDone', 'value': {'source': 0, 'value': 232.0}},
{'name': 'DamageTaken', 'value': {'source': 1, 'value': 244.0}},
]
report = summarize(events)
assert 'Bob: 1409.00' in report
assert 'Alice: 232.00' in report
# the party-wide figure is still reported, but labelled as such
assert 'damage done: 1641.00 (all players)' in report
assert 'damage taken by player:' in report
assert 'Bob: 244.00' in report
def test_summarize_labels_unknown_player_ids():
events = [
{'name': 'MainPlayerAppeared', 'value': {'id': 0, 'name': 'Alice'}},
{'name': 'DamageDone', 'value': {'source': 7, 'value': 50.0}},
]
report = summarize(events)
# no appearance event for id 7, so it must not be silently attributed
assert 'player #7: 50.00' in report
def test_summarize_reports_empty_damage_sections():
report = summarize([
{'name': 'MainPlayerAppeared', 'value': {'id': 0, 'name': 'Alice'}},
])
assert 'damage done by player:' in report
assert 'damage taken by player:' in report
assert '(none)' in report
pytestmark = pytest.mark.skipif(
not os.path.exists(RAW_LOG_PATH),
reason='aoaddons.log capture fixture is not available')