#!/usr/bin/env python3 """AVA2 bonus numbering: the stone/boss applies the AVA2 stones and guardian weapons carry (docs/FEATURE-AVA2-UNLOCK.md).""" from pathlib import Path import re ROOT=Path(__file__).resolve().parents[2] SRC=ROOT/'src/server' def source(name):return (SRC/name).read_bytes().decode('latin1') length=source('common/length.h') enum=length[length.index('enum EApplyTypes'):] if 'enum EApplyTypes' in length else length[length.index('APPLY_NONE'):] enum=enum[:enum.index('MAX_APPLY_NUM')] assert 'APPLY_ATTBONUS_STONE = 139,' in enum and 'APPLY_ATTBONUS_BOSS = 140,' in enum and enum.rstrip().endswith('= 140,') # the db reads apply names by position, so the array index is the apply number reader=source('db/src/ProtoReader.cpp') names=re.findall(r'"([^"]+)"',re.search(r'arApplyType\[\]\s*=\s*\{(.*?)\};',reader,re.S).group(1)) assert len(names)==141 and names[91]=='APPLY_ANTI_PENETRATE_PCT' and names[139:]==['APPLY_ATTBONUS_STONE','APPLY_ATTBONUS_BOSS'],names[88:] # aApplyInfo is indexed by apply number: 141 rows, the two new ones mapped to the biolog points constants=source('game/src/constants.cpp') table=constants[constants.index('aApplyInfo[MAX_APPLY_NUM]'):] table=table[table.index('{')+1:table.index('};')] rows=re.findall(r'\{\s*(POINT_[A-Z_]+)',table) assert len(rows)==141 and rows[139:]==['POINT_ATTBONUS_STONE','POINT_ATTBONUS_BOSS'] and set(rows[92:98]+rows[100:123]+rows[129:139])=={'POINT_NONE'},len(rows) assert rows[98]=='POINT_RESIST_MAGIC_REDUCTION' and names[98]=='APPLY_RESIST_MAGIC_REDUCTION' assert 'APPLY_RESIST_MAGIC_REDUCTION = 98,' in enum assert rows[99]=='POINT_RESIST_HUMAN' and names[99]=='APPLY_RESIST_HUMAN' assert 'APPLY_RESIST_HUMAN = 99,' in enum ELEM=('ELEC','FIRE','ICE','WIND','EARTH','DARK') # P7 talisman: APPLY_ENCHANT_* 123-128 (AVA2 names, ELECT for the db) -> POINT_ENCHANT_* 242-247 assert rows[123:129]==['POINT_ENCHANT_'+e for e in ELEM],rows[123:129] assert names[123:129]==['APPLY_ENCHANT_'+('ELECT' if e=='ELEC' else e) for e in ELEM],names[123:129] assert '"ATTBONUS_STONE",\tAPPLY_ATTBONUS_STONE' in constants and '"ATTBONUS_BOSS",\tAPPLY_ATTBONUS_BOSS' in constants char=source('game/src/char.cpp') apply=char[char.index('void CHARACTER::ApplyPoint('):char.index('void CHARACTER::MotionPacketEncode(')] assert all('case APPLY_ENCHANT_%s:'%e in apply for e in ELEM) assert 'case APPLY_ATTBONUS_STONE:' in apply and 'case APPLY_ATTBONUS_BOSS:' in apply assert 'case APPLY_RESIST_MAGIC_REDUCTION:' in apply points=source('game/src/char.h') assert all('POINT_ENCHANT_%s = %d,'%(e,242+i) in points for i,e in enumerate(ELEM)),'enchant points' assert 'POINT_ATTBONUS_STONE = 240,' in points and 'POINT_ATTBONUS_BOSS = 241,' in points battle=source('game/src/battle.cpp') assert all('GetPoint(POINT_ENCHANT_%s)'%e in battle for e in ELEM) and 'RACE_FLAG_ATT_ICE' in battle assert 'GetPoint(POINT_ATTBONUS_STONE)' in battle and 'GetPoint(POINT_ATTBONUS_BOSS)' in battle print('PASS: stone/boss applies 139/140 in the db reader, aApplyInfo, apply names and ApplyPoint')