Files
WoW-Hybrid-gateway/ops/durability_effect_slots.py

120 lines
4.8 KiB
Python

"""Generate the effect-111 slot table from matching Octo and Tortoise spell definitions."""
import argparse
from pathlib import Path
import re
DURABILITY_DAMAGE = 111
HEADER = Path(__file__).resolve().parents[1] / "include/gateway/durability_effect_slots.hpp"
def octo_rows(path):
spells = {}
for line in path.open():
# The first TSV field is a row ordinal. The labeled field is the spell ID.
match = re.match(r"^\d+\tID=(\d+)\t", line)
if not match:
continue
spell = int(match[1])
effects = re.search(r"\tEffect=([-\d,]+)\t", line)
values = re.search(r"\tEffectMiscValue=([-\d,]+)\t", line)
assert effects and values and spell not in spells
slots = list(zip(map(int, effects[1].split(",")), map(int, values[1].split(",")), strict=True))
assert len(slots) == 3
spells[spell] = [(index, value) for index, (effect, value) in enumerate(slots) if effect == DURABILITY_DAMAGE]
return spells
def sql_rows(path):
spells = {}
columns = None
effects = [f"effect{i}" for i in (1, 2, 3)]
values = [f"effectMiscValue{i}" for i in (1, 2, 3)]
for line in path.open():
if line.startswith("INSERT INTO `spell_template` "):
names = re.findall(r"`(\w+)`", line)[1:]
columns = [names.index(name) for name in ["entry", *effects, *values]]
elif columns is not None and line.startswith("("):
# The numeric fields are before the first text column. Stop before
# parsing names or descriptions containing quoted commas or escapes.
head = line[1:].split(",", max(columns) + 1)
assert len(head) == max(columns) + 2 and not any("'" in field for field in head[:-1])
spell, *data = [int(head[column]) for column in columns]
assert spell not in spells
spells[spell] = [(index, data[3 + index]) for index in range(3) if data[index] == DURABILITY_DAMAGE]
return spells
def equipment(path):
body = re.search(r"enum EquipmentSlots\b[^\{]*\{(.*?)\};", path.read_text(), re.S)[1]
entries = re.findall(r"\b(EQUIPMENT_SLOT_(?!START|END)\w+)\s*=\s*(\d+)", body)
return {int(value): name for name, value in entries}
def profiles(octo, sql, legacy_equipment, native_equipment):
rows = []
for spell, effects in sorted(octo.items()):
# The log supplies the effect type but does not carry its source index.
# Both catalogues must agree on the spell's complete effect-111 definition.
if not effects or effects != sql.get(spell):
continue
named_values = {value for _, value in effects if value >= 0}
native_slot = -1
if len(named_values) == 1:
name = legacy_equipment.get(next(iter(named_values)))
matches = [index for index, label in native_equipment.items() if label == name]
if len(matches) == 1:
native_slot = matches[0]
permits_group = any(value < 0 for _, value in effects)
rows.append((spell, native_slot, permits_group))
return rows
def render(rows):
entries = "".join(
f" DurabilityEffectSlot{{{spell}, {slot}, {str(group).lower()}}},\n"
for spell, slot, group in rows
)
return '''#pragma once
#include <array>
#include <cstdint>
namespace gateway::source_combat_events {
// Generated by ops/durability_effect_slots.py. A negative named slot is unresolved.
struct DurabilityEffectSlot {
std::uint32_t spell;
std::int32_t named_slot;
bool permits_group;
};
inline constexpr std::array DurabilityEffectSlots{
''' + entries + '''};
} // namespace gateway::source_combat_events
'''
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("project", type=Path)
parser.add_argument("--write", action="store_true")
args = parser.parse_args()
legacy = args.project / "servers/tortoise-wow-be0706"
native = args.project / "servers/trinity-forever"
dump = args.project / "gateway/runtime/continuation-20261113/claude-lane/octo-dbc-diff-20261122/dump/Spell.octo.tsv"
octo = octo_rows(dump)
sql = sql_rows(legacy / "sql/base/tw_world_spell_template.sql")
source_slots = equipment(legacy / "src/game/Objects/Player.h")
native_slots = equipment(native / "src/server/game/Entities/Player/Player.h")
rows = profiles(octo, sql, source_slots, native_slots)
expected = render(rows)
if args.write:
HEADER.write_text(expected)
elif HEADER.read_text() != expected:
raise SystemExit("Regenerated durability profiles differ from the checked-in header")
matched = sum(len(octo[spell]) for spell, _, _ in rows)
print(f"PASS {len(octo)} Octo spells, {len(sql)} SQL spells, {matched} matching effect-111 slots, {len(rows)} profiles")
if __name__ == "__main__":
main()