fix(npc): a move applies at most once per reply
The tag extractor returns every occurrence of a move tag and the validator is
a pure membership test, so MoveApplier applied duplicates. A model repeating a
tag N times therefore picked an amount in unary — the AI choosing a number,
which is the §2 breach the bounded vocabulary exists to prevent.
The currency fix (8e1238c) closed this for denominations only. Generalizing it
to every move that names a thing covers real items too — three give_item(amulet)
tags are one amulet, not three — and lets the currency special case be deleted
rather than kept alongside a second mechanism. ID_MOVES is reused from
MoveValidator instead of restated.
Also caps adjust_disposition on the reply's NET swing. MAX_DELTA was clamped
per tag, so three +15s moved standing by 45 — precisely the wholesale swing its
own comment says it forbids. Applied in emission order, so a later
become_hostile still floors what came before it.
offer_quest and reveal needed no change: add_quest self-guards on has_quest and
mark_revealed is idempotent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
This commit is contained in:
@@ -11,20 +11,24 @@ 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
|
||||
# ONE RULE: a move applies AT MOST ONCE PER REPLY. The tag extractor returns
|
||||
# every occurrence and the validator is a membership test, so without this a
|
||||
# model repeating a tag N times picks an amount in unary — the AI choosing a
|
||||
# number, which is the §2 breach the bounded vocabulary exists to prevent.
|
||||
# It is worth the same for real items: three give_item(amulet) tags are one
|
||||
# amulet, not three.
|
||||
var applied := {} # "name(id)" -> true
|
||||
var dispo_total := 0 # the reply's NET disposition swing, capped at MAX_DELTA
|
||||
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):
|
||||
# MoveValidator.ID_MOVES is the one list of moves that name a thing — those
|
||||
# are the ones a (name, id) key can dedupe. Reused, not restated.
|
||||
if name in MoveValidator.ID_MOVES and not args.is_empty():
|
||||
var key := "%s(%s)" % [name, str(args[0])]
|
||||
if applied.has(key):
|
||||
continue
|
||||
currency_applied_this_reply[currency_key] = true
|
||||
applied[key] = true
|
||||
match name:
|
||||
"offer_quest":
|
||||
var q: String = str(args[0])
|
||||
@@ -40,9 +44,17 @@ static func apply(moves: Array, game_state, canon_log, content_db, npc_id: Strin
|
||||
"accept_item":
|
||||
game_state.take(str(args[0]), 1)
|
||||
"adjust_disposition":
|
||||
# MAX_DELTA caps the reply's NET swing, not each tag — clamping per
|
||||
# tag let three +15s move standing by 45, which is exactly the
|
||||
# "wholesale swing" the constant is here to forbid. Applied inside
|
||||
# the loop (not batched at the end) so emission order still holds
|
||||
# and a later become_hostile floors what came before it.
|
||||
var delta: int = clampi(int(str(args[0])), -MAX_DELTA, MAX_DELTA)
|
||||
var capped: int = clampi(dispo_total + delta, -MAX_DELTA, MAX_DELTA)
|
||||
var allowed: int = capped - dispo_total
|
||||
dispo_total = capped
|
||||
var cur: int = int(game_state.npc_dispositions.get(npc_id, 0))
|
||||
game_state.set_npc_disposition(npc_id, cur + delta)
|
||||
game_state.set_npc_disposition(npc_id, cur + allowed)
|
||||
"become_hostile":
|
||||
game_state.set_npc_disposition(npc_id, HOSTILE_FLOOR)
|
||||
_:
|
||||
|
||||
Reference in New Issue
Block a user