367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
53 lines
4.5 KiB
Python
53 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Repurchase one already-reviewed real merchant buyback entry via normal UI.
|
|
|
|
Requires exact saved fixture/wallet baseline; never grants an item, edits SQL,
|
|
injects a purchase, retries a state change, or exports authentication data.
|
|
Open/review the original Buyback tab first. Coordinates are test-scene inputs,
|
|
not NPC/item-specific protocol behavior. Result is saved even after failure.
|
|
"""
|
|
import argparse,json
|
|
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 ROOT,Controller,local_listeners
|
|
from native_test_guard import require_local_turtle_ports,require_authenticated_turtle_realm,require_native_gameplay_policy
|
|
from native_world_trace import WorldTrace
|
|
|
|
def inventory(character):
|
|
return db(f'SELECT ci.bag,ci.slot,ci.item,ii.itemEntry,ii.count FROM tw_char.character_inventory ci JOIN tw_char.item_instance ii ON ci.item=ii.guid WHERE ci.guid={character} ORDER BY ci.bag,ci.slot;')
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
for name in ('character','fixture','entry','price','money','x','y'):p.add_argument('--'+name,type=int,required=True)
|
|
p.add_argument('--output',type=Path,required=True);a=p.parse_args();out=a.output.resolve()
|
|
if not out.is_relative_to(ROOT/'runtime') or out.exists() or not out.parent.is_dir() or any(not 0<v<2**32 for v in (a.character,a.fixture,a.entry,a.price,a.money)) or not(0<a.x<1920 and 0<a.y<1080):p.error('Require new runtime report and bounded explicit fixture/UI inputs')
|
|
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'))
|
|
baseline=inventory(a.character);rows=[r.split('\t') for r in baseline.splitlines()];fixture=[r for r in rows if int(r[2])==a.fixture]
|
|
if len(fixture)!=1 or fixture[0][0]!='0' or not 69<=int(fixture[0][1])<81 or int(fixture[0][3])!=a.entry or db(f'SELECT money FROM tw_char.characters WHERE guid={a.character};')!=str(a.money):raise RuntimeError('Saved buyback fixture/wallet differs; no action taken')
|
|
if db(f'SELECT sell_price*{int(fixture[0][4])} FROM tw_world.item_template WHERE entry={a.entry};')!=str(a.price):raise RuntimeError('Source price differs; no action taken')
|
|
original=[r for r in rows if int(r[2])!=a.fixture];report=dict(pid=c.pid,external_gateway_running=False,fixture_guid=a.fixture,fixture_entry=a.entry,price=a.price,money_before=a.money,before_inventory=baseline,purchase_attempted=False,verified=False);failure=None;old=ui.KEY_DELAY
|
|
with WorldTrace(c) as trace:
|
|
try:
|
|
with Session(c.pid) as s:
|
|
if s.state()!='world':raise RuntimeError('Require active original world session')
|
|
ui.KEY_DELAY=.03;s.shot(out.with_name(out.stem+'-before.png'))
|
|
report['purchase_attempted']=True
|
|
ui.click_at(s.d,s.win,a.x,a.y,ui.ecodes.BTN_RIGHT)
|
|
report['native_request']=trace.wait(2,0x3f003c,5)
|
|
s.macro('/s .save')
|
|
report['money_after']=c.wait(lambda:(v if (v:=db(f'SELECT money FROM tw_char.characters WHERE guid={a.character};'))==str(a.money-a.price) else False),8)
|
|
report['after_inventory']=inventory(a.character);after=[r.split('\t') for r in report['after_inventory'].splitlines()];saved=[r for r in after if int(r[2])==a.fixture]
|
|
if len(saved)!=1 or (saved[0][0]=='0' and not 23<=int(saved[0][1])<39) or saved[0][3:]!=fixture[0][3:] or [r for r in after if int(r[2])!=a.fixture]!=original:raise RuntimeError('Inventory result differs; inspect before any retry')
|
|
s.macro('/run print("GW buyback result",GetNumBuybackItems(),GetMoney())');s.shot(out.with_suffix('.png'))
|
|
pipe=c.rpc('inspect-engine-pipe');report.update(pipe_error=pipe['error'],pipe_closed=pipe['closed'],verified=not pipe['error'] and not pipe['closed'],ui_review_required=True)
|
|
except Exception as error:failure=type(error).__name__+': '+str(error)
|
|
finally:ui.KEY_DELAY=old
|
|
report.update(trace.report())
|
|
if failure:report['failure']=failure
|
|
out.write_text(json.dumps(report,indent=2)+'\n');out.chmod(0o600)
|
|
print(json.dumps({k:report.get(k) for k in ('pid','native_request','money_before','money_after','verified','ui_review_required','lost_metadata_rows','observer_error','failure')}))
|
|
return 0 if report['verified'] and not trace.error else 2
|
|
if __name__=='__main__':raise SystemExit(main())
|