TagExtractor collects every [MOVE:] tag occurrence with no dedupe, and
MoveValidator is a pure membership test against available_moves, so N
copies of one legal move all pass validation. MoveApplier then looped
and applied every copy. A model could therefore pick an arbitrary
amount of money in unary by repeating one tag: [MOVE: accept_item(copper)]
x47 against a 47c purse drains it to 0; [MOVE: give_item(gold)] x10
mints +100,000c. The eight-move vocabulary (§6) takes no quantity
argument precisely so the AI cannot choose a number — this closed that
gap by another door and was a §2 breach (AI owns text, never state).
MoveApplier.apply() now tracks currency moves (give_item/accept_item on
a denomination) already applied within one call, keyed on name+denom,
and skips repeats. Non-currency moves are untouched — repeated
give_item(amulet) still yields multiple copies, which stays bounded by
the pre-existing cross-reply gifts_given gate and is a separate,
already-reported issue. move_validator.gd and tag_extractor.gd are
untouched.
Also adds the Finding-2 test the currency spec (§7) named but never
delivered: after GameState.grant("gold", 1), inventory stays empty, so
accept_item(gold) in available_moves comes only from the affordability
loop, never double-offered via the inventory.keys() loop.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
50 lines
2.2 KiB
GDScript
50 lines
2.2 KiB
GDScript
class_name MoveApplier
|
|
extends RefCounted
|
|
## Writes validated §6 moves to game state. Town-NPC disposition lives in
|
|
## GameState.npc_dispositions (NOT CanonLog.party — that is companions only).
|
|
## Called by the conversation caller after NpcService.speak, so state writes
|
|
## stay explicit (§2). Unknown move names are ignored (they never pass the
|
|
## validator, but this stays defensive).
|
|
|
|
const MAX_DELTA := 15 # one line cannot swing standing wholesale (§7 spirit)
|
|
const HOSTILE_FLOOR := -100
|
|
|
|
|
|
static func apply(moves: Array, game_state, canon_log, content_db, npc_id: String) -> void:
|
|
# A currency move (give_item/accept_item on a denomination) applies AT MOST
|
|
# ONCE per reply. Without this, a model repeating one tag N times would pick
|
|
# an arbitrary amount in unary — the AI choosing a number is a §2 breach.
|
|
# Real-item duplicates are unaffected; that stays bounded by gifts_given.
|
|
var currency_applied_this_reply := {} # "name(denom)" -> true
|
|
for move in moves:
|
|
var name: String = move.get("name", "")
|
|
var args: Array = move.get("args", [])
|
|
if name in ["give_item", "accept_item"] and not args.is_empty() \
|
|
and Currency.is_currency(str(args[0])):
|
|
var currency_key := "%s(%s)" % [name, str(args[0])]
|
|
if currency_applied_this_reply.has(currency_key):
|
|
continue
|
|
currency_applied_this_reply[currency_key] = true
|
|
match name:
|
|
"offer_quest":
|
|
var q: String = str(args[0])
|
|
var qd: Dictionary = content_db.quest(q)
|
|
canon_log.add_quest(q, qd.get("name", ""), qd.get("objective", ""))
|
|
"reveal":
|
|
game_state.mark_revealed(str(args[0]))
|
|
"give_item":
|
|
var i: String = str(args[0])
|
|
game_state.grant(i, 1)
|
|
if not Currency.is_currency(i):
|
|
game_state.mark_gift_given(i) # the one-shot gate is for real items only
|
|
"accept_item":
|
|
game_state.take(str(args[0]), 1)
|
|
"adjust_disposition":
|
|
var delta: int = clampi(int(str(args[0])), -MAX_DELTA, MAX_DELTA)
|
|
var cur: int = int(game_state.npc_dispositions.get(npc_id, 0))
|
|
game_state.set_npc_disposition(npc_id, cur + delta)
|
|
"become_hostile":
|
|
game_state.set_npc_disposition(npc_id, HOSTILE_FLOOR)
|
|
_:
|
|
pass # refuse, end_conversation, and anything unknown: no state
|