74 lines
4.9 KiB
Python
74 lines
4.9 KiB
Python
"""Owner-approved weapon rules for the 773-item lane (2026-11-22), layered on the pinned ops/item_damage_profile.py.
|
|
|
|
The pinned module (accepted item build base, sha 295c11c4) is never edited. install() wraps its projection/verifier
|
|
in-process for this lane's conversion only:
|
|
- clamp_variance: a source band whose minimum is above the native average (item level x quality DPS curve x speed)
|
|
cannot be expressed by DmgVariance; the row uses variance 0 (min = max = native average) and records
|
|
variance_clamped_to_native_bound. The tooltip shows the source band; the server sends the real damage.
|
|
- metadata fallback: every Turtle weapon must exist client-side (GM-spawnable). When no native curve can carry it
|
|
(no speed, 0-0 damage, item level without a curve row, non-physical primary), keep the source school with variance 0.
|
|
"""
|
|
import hashlib, math
|
|
import item_damage_profile as D
|
|
|
|
_pinned_projection = D.native_weapon_projection
|
|
_pinned_verify = D.verify_native_weapon_projection
|
|
METADATA_KIND = 'native-70334-source-weapon-metadata-only'
|
|
|
|
def _clamped(source, tables, presentation):
|
|
"""Pinned projection with the variance bound clamped (same arithmetic, see item_damage_profile.py)."""
|
|
try:
|
|
return _pinned_projection(source, tables, presentation)
|
|
except ValueError as error:
|
|
if str(error) != 'Source minimum outside native variance capacity': raise
|
|
original = D.weapon_record(source)
|
|
name = 'ItemDamageTwoHand' if source['inventory_type'] == 17 or D.physical_ranged(source) else 'ItemDamageOneHand'
|
|
curve = [r for r in tables.get(name, []) if r.get('ID') == source['item_level']][0]
|
|
quality = 3 if source['quality'] == 7 else source['quality']
|
|
dps = D.native_curve_dps(source, curve['Quality'][quality])
|
|
average = D.f32(D.f32(D.f32(dps) * original['delay_ms']) * D.f32(.001))
|
|
band = original['bands'][0]
|
|
variance = D.f32(0.0)
|
|
minimum = D.f32(D.f32(D.f32(variance * D.f32(-.5)) + D.f32(1)) * average)
|
|
maximum = math.floor(D.f32(D.f32(average * D.f32(D.f32(variance * D.f32(.5)) + D.f32(1))) + D.f32(.5)))
|
|
context = dict(curve_multiplier=.6) if D.physical_ranged(source) else {}
|
|
return dict(kind='native-70334-source-presented-weapon-projection',
|
|
identity={k: source[k] for k in ('entry', 'class', 'subclass', 'inventory_type', 'item_level', 'quality', 'delay')},
|
|
source_record_sha256=hashlib.sha256(D.canonical(source)).hexdigest(), curve_table=name, curve=curve,
|
|
dmg_variance=variance, damage_type=0, native_primary_minimum=minimum, native_primary_maximum=maximum,
|
|
source_primary=band, source_presentation_profile_sha256=hashlib.sha256(D.canonical(presentation)).hexdigest(),
|
|
native_damage_source_exact=False, requires_source_primary_presentation=True,
|
|
engine_verified=False, gameplay_verified=False, variance_clamped_to_native_bound=True, **context)
|
|
|
|
def metadata(source, presentation, reason):
|
|
school = source.get('dmg_type1')
|
|
if type(school) is not int or not 0 <= school <= 6: raise ValueError('Unreviewed source primary weapon school')
|
|
try: original = D.weapon_record(source)
|
|
except ValueError: original = None
|
|
presented = bool(original and isinstance(presentation, dict) and source['entry'] in presentation.get('primary_item_ids', [])
|
|
and [r for r in presentation.get('records', []) if r.get('item_id') == source['entry']] == [original])
|
|
return dict(kind=METADATA_KIND,
|
|
identity={k: source[k] for k in ('entry', 'class', 'subclass', 'inventory_type', 'item_level', 'quality', 'delay')},
|
|
source_record_sha256=hashlib.sha256(D.canonical(source)).hexdigest(), dmg_variance=D.f32(0.0), damage_type=school,
|
|
source_primary_presented=presented, no_native_curve_reason=reason,
|
|
source_presentation_profile_sha256=hashlib.sha256(D.canonical(presentation)).hexdigest() if presented else None,
|
|
native_damage_source_exact=False, engine_verified=False, gameplay_verified=False)
|
|
|
|
def project(source, tables, presentation):
|
|
try: return _clamped(source, tables, presentation)
|
|
except (ValueError, IndexError) as error: return metadata(source, presentation, str(error) or type(error).__name__)
|
|
|
|
def _verify(source, projection, presentation):
|
|
if isinstance(projection, dict) and projection.get('kind') == METADATA_KIND:
|
|
rebuilt = metadata(source, presentation, projection.get('no_native_curve_reason'))
|
|
elif isinstance(projection, dict) and projection.get('variance_clamped_to_native_bound') is True:
|
|
rebuilt = _clamped(source, {projection.get('curve_table'): [projection.get('curve', {})]}, presentation)
|
|
else:
|
|
return _pinned_verify(source, projection, presentation)
|
|
if projection != rebuilt: raise ValueError('Weapon projection/source/profile identity differs')
|
|
return rebuilt
|
|
|
|
def install():
|
|
"""Make item_sparse_compat.convert's verifier accept this lane's two opt-in projection forms."""
|
|
D.verify_native_weapon_projection = _verify
|