Files
code_of_conquest_dnd/client/tests/unit/test_move_applier.gd
Phillip Tarrant c106dbbd37 feat(currency): money moves through the bounded vocabulary (§6)
give_item(gold) is +10,000c and does NOT mark gifts_given — that gate is a
global one-shot keyed by item id, so marking money would let an NPC pay you
exactly once per campaign. accept_item(<denom>) is offered only for the
denominations the purse can actually pay.

The eight moves do not grow. MoveValidator is untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
2026-07-12 18:32:14 -05:00

87 lines
3.1 KiB
GDScript

# client/tests/unit/test_move_applier.gd
extends "res://addons/gut/test.gd"
const MoveApplier = preload("res://scripts/npc/move_applier.gd")
const ContentDB = preload("res://scripts/content/content_db.gd")
func _m(name, args := []) -> Dictionary:
return {"name": name, "args": args}
func _content() -> ContentDB:
var c = ContentDB.new()
c.quests = {"find_the_ledger": {"id": "find_the_ledger",
"name": "The Missing Ledger", "objective": "Find who took it"}}
return c
func test_offer_quest_adds_active_quest():
var log = CanonLog.new()
MoveApplier.apply([_m("offer_quest", ["find_the_ledger"])],
GameState.new(), log, _content(), "fenn")
assert_true(log.has_quest("find_the_ledger"))
assert_eq(log.active_quests[0].name, "The Missing Ledger")
func test_reveal_marks_topic():
var gs = GameState.new()
MoveApplier.apply([_m("reveal", ["varrell_twins"])], gs, CanonLog.new(), _content(), "fenn")
assert_true(gs.is_revealed("varrell_twins"))
func test_adjust_disposition_clamps_to_max_delta():
var gs = GameState.new()
MoveApplier.apply([_m("adjust_disposition", ["+50"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.npc_dispositions.get("fenn", 0), MoveApplier.MAX_DELTA)
func test_become_hostile_sets_floor():
var gs = GameState.new()
MoveApplier.apply([_m("become_hostile")], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.npc_dispositions.get("fenn", 0), MoveApplier.HOSTILE_FLOOR)
func test_accept_item_removes_from_inventory():
var gs = GameState.new()
gs.add_item("worn_shortsword", 2)
MoveApplier.apply([_m("accept_item", ["worn_shortsword"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.inventory.get("worn_shortsword", 0), 1)
func test_give_item_currency_pays_the_purse():
var gs = GameState.new()
MoveApplier.apply([_m("give_item", ["gold"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.purse_copper, 10000)
assert_eq(gs.inventory.size(), 0, "money is never an inventory row")
func test_give_item_currency_is_not_a_one_shot_gift():
# gifts_given is a GLOBAL one-shot keyed by item id. If money were marked, an
# NPC could hand over coin exactly once, ever, for the whole campaign.
var gs = GameState.new()
MoveApplier.apply([_m("give_item", ["gold"])], gs, CanonLog.new(), _content(), "fenn")
MoveApplier.apply([_m("give_item", ["gold"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.purse_copper, 20000)
assert_false(gs.is_gift_given("gold"), "currency is exempt from the one-shot gate")
func test_give_item_real_item_still_marks_the_one_shot_gate():
var gs = GameState.new()
MoveApplier.apply([_m("give_item", ["amulet"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.inventory.get("amulet", 0), 1)
assert_true(gs.is_gift_given("amulet"))
func test_accept_item_currency_spends_the_purse():
var gs = GameState.new()
gs.grant("gold", 1)
MoveApplier.apply([_m("accept_item", ["silver"])], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.purse_copper, 9900)
func test_refuse_and_end_are_noops():
var gs = GameState.new()
MoveApplier.apply([_m("refuse"), _m("end_conversation")], gs, CanonLog.new(), _content(), "fenn")
assert_eq(gs.npc_dispositions.size(), 0)