Files
WoW-Hybrid-gateway/ops/octo_parity/spell_effect_coefficients.py

127 lines
6.5 KiB
Python

"""Qualify ordinary SpellEffect SP/AP terms against classic source calculations."""
import math
import struct
AREA_TARGETS = frozenset((7, 8, 15, 16, 20, 24, 28, 30, 31, 33, 34, 37, 52, 56, 61))
DIRECT = frozenset((2, 9, 10))
PERIODIC = frozenset((3, 8, 53))
def f32(value):
return struct.unpack('<f', struct.pack('<f', value))[0]
def default_coefficient(spell, periodic, cast_rows, duration_rows):
"""SpellEntry::GetCastTimeForBonus, GetAuraMaxTicks and CalculateDefaultCoefficient."""
slots = spell['slots']
cast = cast_rows.get(spell['cast'])
if cast is None:
cast_ms = 0
else:
cast_ms = max(cast[1] - cast[2] * spell['base_level'], cast[3])
if spell['attributes'] & 2:
cast_ms += 500
cast_ms = max(0, cast_ms)
duration = duration_rows.get(spell['duration'])
duration = 0 if duration is None else duration[1]
if duration == -1 and periodic:
return None
if duration != -1:
duration = abs(duration)
channeled = bool(spell['attributes_ex'] & 68)
def capped(value):
return min(7000, max(1500, value))
cast_bonus = capped(duration if channeled else cast_ms)
if periodic and (not channeled):
cast_bonus = 3500
periodic_slot = next((s for s in slots if s['effect'] == 6 and s['aura'] in PERIODIC), None)
if periodic_slot and duration > 0 and any((s['effect'] in (2, 7, 8, 9, 10, 62) for s in slots)):
time = f32(duration / 15000)
share = f32(time / f32(time + f32(capped(cast_ms) / 3500)))
cast_bonus = int(f32(cast_bonus * (share if periodic else f32(1 - share))))
if any((set(s['targets']) & AREA_TARGETS for s in slots)):
cast_bonus //= 2
if any((s['effect'] == 9 or (s['effect'] == 6 and s['aura'] == 53) for s in slots)):
cast_bonus //= 2
aura_penalties = {4: 1, 33: 1, 5: 2, 12: 2, 26: 2}
penalties = sum((aura_penalties.get(s['aura'], 0) for s in slots if s['effect'] == 6))
for _ in range(penalties):
cast_bonus = int(f32(cast_bonus * f32(0.95)))
factor = 1.0
if periodic:
factor = 1.0 if channeled else f32(duration / 15000)
ticks = 1 if not duration else 6
if duration and periodic_slot and periodic_slot['period']:
ticks = min(duration, 30000) // periodic_slot['period']
if ticks:
factor = f32(factor / ticks)
return f32(f32(cast_bonus / 3500) * factor)
def decision(spell, index, original, selected, native_level, known, cast_rows, duration_rows):
"""Return status, expected stored terms, source coefficient origin and calculator terms."""
s = spell['slots'][index]
eff, aura = (s['effect'], s['aura'])
has_bonus = eff in DIRECT or (eff == 6 and aura in PERIODIC)
if not has_bonus:
return ('other-effect-path', None, None, None)
if original != (eff, aura) or (int(selected['Effect']), int(selected['EffectAura'])) != (eff, aura):
return ('source-native-role-differs', None, None, None)
heal = eff == 10 or (eff == 6 and aura == 8)
# Classic damage and healing call sites return before applying the coefficient.
if spell['attributes_ex3'] & 0x20000000:
return ('caster-modifiers-bypassed', None, None, None)
if heal and spell['dmg_class'] == 0 and spell['attributes'] & 64:
return ('passive-heal-bypass', None, None, None)
if not heal and spell['family'] == 3 and spell['family_mask'] & 1 << 27:
return ('ignite-bonus-already-included', None, None, None)
script = spell['script']
if script and script != 'spell_warrior_bloodthirst':
return ('script-dependent', None, None, None)
if eff == 6 and aura == 3 and (spell['family'] == 7 and spell['family_mask'] & 1 << 23 or (spell['family'] == 8 and spell['family_mask'] & 1 << 8)):
return ('special-calculation', None, None, None)
if spell['name'] in ('Garrote', 'Rip', 'Seal of Command') or spell['id'] in (1510, 14294, 14295, 20424):
return ('special-calculation', None, None, None)
if spell['family'] == 11 and spell['family_mask'] & 322:
return ('chain-target-dependent', None, None, None)
if not (spell['school'] and spell['dmg_class'] in (0, 1)) and (not (spell['custom'] & 0x800000 or script)):
return ('physical-or-weapon-bonus-path', None, None, None)
if spell['custom'] & 16:
raw = (0.0, 0.0)
origin = 'fixed'
elif script:
if index != 0 or known is None:
return ('script-secondary-effect', None, None, None)
raw = (known['sp'], known['ap'])
origin = 'bloodthirst-script'
else:
coeff = s['bonus']
origin = 'explicit' if coeff >= 0 else 'default'
if coeff < 0:
coeff = default_coefficient(spell, eff == 6, cast_rows, duration_rows)
if coeff is None:
return ('unrepresentable-duration', None, origin, None)
raw = (0.0, coeff) if spell['custom'] & 0x800000 else (coeff, 0.0)
raw = tuple((f32(v) for v in raw))
if not s['source_parity'] or (eff == 6 and int(selected['EffectAuraPeriod']) != s['period']):
return ('source-shape-differs', None, origin, raw)
if s['targets'] != tuple(map(int, selected['ImplicitTarget'].split(','))):
return ('native-targets-differ', None, origin, raw)
if native_level != spell['level']:
return ('native-level-differs', None, origin, raw)
for field in ('ScalingClass', 'Coefficient', 'ResourceCoefficient'):
if float(selected[field]):
return ('other-native-scaling', None, origin, raw)
mean = s['mean']
if not math.isclose(mean, float(selected['EffectBasePointsF']), rel_tol=1e-06, abs_tol=1e-06):
return ('native-base-differs', None, origin, raw)
level_matches = math.isclose(float(selected['EffectRealPointsPerLevel']), s['per_level'], abs_tol=1e-6)
resource_matches = math.isclose(float(selected['EffectPointsPerResource']), s['combo'], abs_tol=1e-6)
if not level_matches or not resource_matches:
return ('native-level-resource-slope-differs', None, origin, raw)
current = tuple((f32(float(selected[k])) for k in ('EffectBonusCoefficient', 'BonusCoefficientFromAP')))
# Explicit classic coefficients can already include the sub-20 penalty.
# The native renderer needs observation before choosing a stored value.
if 0 < spell['level'] < 20 and (raw[0] or current[0]):
return ('low-level-penalty-consumer', None, origin, raw)
if current == raw:
return ('exact', raw, origin, raw)
return ('change', raw, origin, raw)