367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
139 lines
12 KiB
Python
139 lines
12 KiB
Python
#!/usr/bin/env python3
|
|
"""Observe real NPC aggro/defensive animations without requesting player attacks.
|
|
|
|
Temporary actor only, normal prepared local character, no stat/position resets.
|
|
Optional draw-key toggles an independently verified existing sheath binding;
|
|
it does not assume the initial state is sheathed. Require confirmed standing.
|
|
Images require review; route acceptance never asserts model-facing correctness.
|
|
"""
|
|
import argparse,json,re,time
|
|
from pathlib import Path
|
|
from client_session import Session
|
|
import client_ui as ui
|
|
from local_tortoise import db
|
|
from native_engine_character_test import Controller,ROOT,local_listeners
|
|
from native_test_guard import require_local_turtle_ports,require_authenticated_turtle_realm,require_native_gameplay_policy,require_solo_test_character
|
|
from native_entity_catalog import read_catalog
|
|
from native_targeted_cast_test import TARGET_STATE_PROBE,prepared_melee_invariants
|
|
from native_vendor_buy_test import inventory
|
|
from native_world_trace import WorldTrace
|
|
from native_posture import establish_standing
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
p.add_argument('--character',type=int,required=True);p.add_argument('--entry',type=int,required=True)
|
|
p.add_argument('--seconds',type=float,default=4);p.add_argument('--draw-key',choices=['z'])
|
|
p.add_argument('--onset-seconds',type=float,default=2,help='Bound early passive frames before targeting/probe macros (2..4 seconds)')
|
|
p.add_argument('--onset-only',action='store_true',help='Skip helper/logging and later target/probe checks; observe passive onset and exact cleanup only')
|
|
p.add_argument('--output',type=Path,required=True);a=p.parse_args();out=a.output.resolve()
|
|
if a.character!=4509 or not 0<a.entry<65536 or not 2<=a.seconds<=8 or not 2<=a.onset_seconds<=4 or not out.is_relative_to(ROOT/'runtime') or out.exists():p.error('Require designated disposable fixture and new bounded runtime output')
|
|
if any(out.with_name(out.stem+f'-{phase}-{n}.png').exists() for phase,count in (('baseline',1),('onset',20),('initial',20),('postcleanup',1)) for n in range(count)):p.error('Preserve existing visual evidence; choose a new output stem')
|
|
require_local_turtle_ports(local_listeners());c=Controller(int((ROOT/'runtime/native-client.pid').read_text()))
|
|
require_authenticated_turtle_realm(c.rpc('inspect-wire-account'));require_native_gameplay_policy(c.rpc('inspect-native-channel-policy'))
|
|
require_solo_test_character(a.character,db('SELECT guid FROM tw_char.characters WHERE online<>0 ORDER BY guid;'))
|
|
state=lambda:db(f'SELECT level,health,power2,money,extra_flags FROM tw_char.characters WHERE guid={a.character};')
|
|
before=state()
|
|
if not prepared_melee_invariants(before,before,True) or int(before.split('\t')[1])==0:raise RuntimeError('Require living normal-visible prepared Warrior baseline')
|
|
template=db(f'SELECT name,level_min,level_max,npc_flags,unit_class FROM tw_world.creature_template WHERE entry={a.entry};').split('\t')
|
|
if len(template)!=5 or not re.fullmatch(r'[A-Za-z -]{1,100}',template[0]) or not all(v.isdecimal() for v in template[1:]) or not 1<=int(template[1])<=int(template[2])<=60 or template[3]!='0' or int(template[4]) not in (1,2,4,8):raise RuntimeError('Require real non-service creature with supported source class')
|
|
visible=read_catalog(c)['actors']
|
|
if any(x['entry']==a.entry for x in visible):raise RuntimeError('Same-entry actor already visible; name targeting would be ambiguous; preserve it')
|
|
baseline={x['legacy_guid'] for x in visible};gear=inventory(a.character);spawns=db('SELECT COUNT(*) FROM tw_world.creature;')
|
|
r=dict(pid=c.pid,entry=a.entry,source_template=template,external_gateway_stopped=True,own_attack_requested=False,fixture_cleanup_pending=False,helper_pending=False,facing_verified=False,defensive_animation_verified=False,ui_review_required=True,frames=[],before_state=before,failure=None,onset_seconds=a.onset_seconds,onset_only=a.onset_only,frame_timing_limit='Monotonic intervals and observer bookmarks enclose focus/capture/OCR; they do not identify the exact rendered frame or prove engine application.')
|
|
def save():out.write_text(json.dumps(r,indent=2)+'\n');out.chmod(0o600)
|
|
old=ui.KEY_DELAY;started=time.monotonic()
|
|
try:
|
|
with WorldTrace(c) as tr,Session(c.pid) as s:
|
|
try:
|
|
def note(name):
|
|
r.setdefault('steps',[]).append(dict(name=name,world_index=tr.bookmark(),elapsed_seconds=round(time.monotonic()-started,3)))
|
|
def cleanup_note(name):
|
|
# A diagnostic failure must not prevent fixture cleanup.
|
|
try:note(name)
|
|
except RuntimeError as e:r.setdefault('steps',[]).append(dict(name=name,world_index=None,elapsed_seconds=round(time.monotonic()-started,3),observer_error=str(e)))
|
|
def frame(phase,n,begin):
|
|
path=out.with_name(out.stem+f'-{phase}-{n}.png')
|
|
if path.exists():raise RuntimeError('Preserve existing visual evidence')
|
|
before_index=tr.bookmark();at=time.monotonic();s.shot(path);finished=time.monotonic();after_index=tr.bookmark()
|
|
r['frames'].append(dict(phase=phase,path=str(path),relative_seconds=round(at-begin,3),started_monotonic=at,finished_monotonic=finished,world_index_before=before_index,world_index_after=after_index))
|
|
def sample(phase,seconds,minimum):
|
|
begin=time.monotonic();n=0
|
|
while n<minimum or time.monotonic()-begin<seconds:
|
|
if n>=20:raise RuntimeError('Bounded visual sample exhausted')
|
|
frame(phase,n,begin);n+=1
|
|
def actor():
|
|
rows=[x for x in read_catalog(c)['actors'] if x['legacy_guid'] not in baseline and x['entry']==a.entry and x['sent']]
|
|
return rows[0] if len(rows)==1 else None
|
|
s.wait_world();ui.KEY_DELAY=.03;s.macro('/stopattack');note('stopattack_complete')
|
|
# The observed seated session did not emit a sheath request.
|
|
# Reuse confirmed standing; otherwise establish it through the
|
|
# existing original-input/server-ack helper (no forced packet).
|
|
r['standing_steps']=establish_standing(c,s,self_guid=a.character)
|
|
r['standing_reused']=any(x.get('reused') for x in r['standing_steps'])
|
|
# Setup before aggro: an in-combat toggle may be a legitimate
|
|
# engine no-op. Never label a phase "drawn" merely from a key.
|
|
if a.draw_key:
|
|
r['draw_bookmark']=tr.bookmark();ui.key(s.d,a.draw_key)
|
|
r['draw_request']=tr.wait(2,0x3f001f,4,after_index=r['draw_bookmark'])
|
|
s.macro('/run print("GW initial sheath",GetSheathState(),C_Spell.IsCurrentSpell(6603))');note('initial_sheath_print_complete')
|
|
if not a.onset_only:
|
|
r['helper_pending']=True;s.macro(TARGET_STATE_PROBE)
|
|
s.macro('/run GWDefenderLog=LoggingCombat();LoggingCombat(true)')
|
|
note('helper_and_logging_ready')
|
|
frame('baseline',0,time.monotonic());note('pre_summon_frame_complete')
|
|
r['action_bookmark']=tr.bookmark();r['fixture_cleanup_pending']=True;save();s.macro(f'/s .npc summon {a.entry}')
|
|
note('summon_command_complete')
|
|
# Observe passive onset before catalog waits or chat/probe input
|
|
# can obscure the first combat-flag/hit transition.
|
|
sample('onset',a.onset_seconds,2);note('early_passive_frames_complete')
|
|
r['actor']=c.wait(actor,8);save();note('actor_binding_ready')
|
|
if not a.onset_only:
|
|
s.macro('/targetexact '+template[0]);note('target_selected')
|
|
s.macro('/run GWTargetStateProbe()');note('target_probe_complete')
|
|
# Namespaced API is checked before invocation. No unavailable
|
|
# legacy IsCurrentSpell or unsafe native callback is called.
|
|
s.macro('/run print("GW defensive attack state",C_Spell and type(C_Spell.IsCurrentSpell),C_Spell and C_Spell.IsCurrentSpell and C_Spell.IsCurrentSpell(6603))')
|
|
note('attack_state_print_complete');s.macro('/s .distance');note('distance_query_complete')
|
|
sample('initial',a.seconds,3)
|
|
pipe=c.rpc('inspect-engine-pipe');r.update(pipe_error=pipe['error'],pipe_closed=pipe['closed'])
|
|
except Exception as e:r['failure']=type(e).__name__+': '+str(e)
|
|
finally:
|
|
cleanup_note('cleanup_stopattack_before');s.macro('/stopattack');cleanup_note('cleanup_stopattack_after')
|
|
if r['fixture_cleanup_pending'] and not r.get('actor'):
|
|
# An early screenshot can fail before normal binding.
|
|
# Recover only the same uniquely identified fixture.
|
|
try:r['actor']=c.wait(actor,8)
|
|
except Exception as e:r['cleanup_error']=str(e)
|
|
if r.get('actor'):
|
|
suffix=f'{int(r["actor"]["legacy_guid"])&0xffffff:06X}'
|
|
cleanup_note('cleanup_target_before');s.macro('/targetexact '+template[0]);cleanup_note('cleanup_target_after')
|
|
cleanup_note('cleanup_exact_delete_before')
|
|
s.macro('/run local g=UnitGUID("target");if g and g:find("-'+str(a.entry)+'-",1,true) and g:upper():sub(-6)=="'+suffix+'" then SendChatMessage(".npc delete","SAY") end')
|
|
cleanup_note('cleanup_exact_delete_submitted');cleanup_note('cleanup_actor_absence_before')
|
|
try:c.wait(lambda:not any(x['legacy_guid']==r['actor']['legacy_guid'] for x in read_catalog(c)['actors']),8);r['fixture_cleanup_pending']=False;cleanup_note('cleanup_actor_absence_observed')
|
|
except Exception as e:r['cleanup_error']=str(e)
|
|
if r['helper_pending']:
|
|
cleanup_note('cleanup_helper_restore_before');s.macro('/run GWTargetStateProbe=nil;LoggingCombat(GWDefenderLog or false);GWDefenderLog=nil');r['helper_pending']=False;cleanup_note('cleanup_helper_restore_after')
|
|
if r.get('actor') and not r['fixture_cleanup_pending']:
|
|
pipe=c.rpc('inspect-engine-pipe');r.update(pipe_error=pipe['error'],pipe_closed=pipe['closed'])
|
|
if pipe['error'] or pipe['closed']:raise RuntimeError('Native session unhealthy after fixture removal; skip final frame')
|
|
if a.onset_only:
|
|
cleanup_note('cleanup_final_api_before')
|
|
s.macro('/run print("GW final sheath",GetSheathState(),C_Spell.IsCurrentSpell(6603))')
|
|
cleanup_note('cleanup_final_api_after')
|
|
frame('postcleanup',0,time.monotonic());cleanup_note('cleanup_final_frame_complete')
|
|
r.update(after_state=state(),inventory_unchanged=inventory(a.character)==gear,persistent_spawns_unchanged=db('SELECT COUNT(*) FROM tw_world.creature;')==spawns)
|
|
r.update(tr.report())
|
|
except Exception as e:r['failure']=type(e).__name__+': '+str(e)
|
|
finally:ui.KEY_DELAY=old;r['elapsed_seconds']=round(time.monotonic()-started,3);save()
|
|
try:
|
|
final_pipe=c.rpc('inspect-engine-pipe');r.update(pipe_error=final_pipe['error'],pipe_closed=final_pipe['closed'])
|
|
except Exception as e:r['final_pipe_error']=str(e)
|
|
r['packet_observation_complete']=r.get('lost_metadata_rows')==0
|
|
r['no_player_attack_request_observed']=r['packet_observation_complete'] and not any(x['direction']==2 and x['opcode']==0x3e011e and x['index']>r.get('action_bookmark',-1) for x in r.get('trace',[]))
|
|
r['state_preserved']=prepared_melee_invariants(before,r.get('after_state'),r.get('inventory_unchanged'))
|
|
r['route_observation_passed']=not r['failure'] and not r.get('observer_error') and not r.get('pipe_error') and not r.get('pipe_closed',True) and not r['fixture_cleanup_pending'] and not r['helper_pending'] and r['state_preserved'] and r.get('persistent_spawns_unchanged') and r['no_player_attack_request_observed']
|
|
save();print(json.dumps({k:r.get(k) for k in ('pid','actor','route_observation_passed','no_player_attack_request_observed','fixture_cleanup_pending','helper_pending','lost_metadata_rows','failure','cleanup_error')}))
|
|
return 0 if r['route_observation_passed'] else 2
|
|
if __name__=='__main__':raise SystemExit(main())
|