feat(client): GameState move targets — remove_item, reveal/gift tracking
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@ var luck_base: int = 0
|
||||
var stats: Dictionary = {} # {str, dex, con, fth, mag}
|
||||
var npc_dispositions: Dictionary = {} # world-npc id -> int (−100..100)
|
||||
var inventory: Dictionary = {} # item_id -> qty
|
||||
var revealed_topics: Dictionary = {} # topic_id -> true
|
||||
var gifts_given: Dictionary = {} # item_id -> true (idempotency for give_item)
|
||||
|
||||
|
||||
func set_luck(v: int) -> void:
|
||||
@@ -29,3 +31,27 @@ func set_npc_disposition(id: String, v: int) -> void:
|
||||
|
||||
func add_item(item_id: String, qty: int) -> void:
|
||||
inventory[item_id] = int(inventory.get(item_id, 0)) + qty
|
||||
|
||||
|
||||
func remove_item(item_id: String, qty: int) -> void:
|
||||
var left := int(inventory.get(item_id, 0)) - qty
|
||||
if left > 0:
|
||||
inventory[item_id] = left
|
||||
else:
|
||||
inventory.erase(item_id)
|
||||
|
||||
|
||||
func mark_revealed(topic_id: String) -> void:
|
||||
revealed_topics[topic_id] = true
|
||||
|
||||
|
||||
func is_revealed(topic_id: String) -> bool:
|
||||
return revealed_topics.has(topic_id)
|
||||
|
||||
|
||||
func mark_gift_given(item_id: String) -> void:
|
||||
gifts_given[item_id] = true
|
||||
|
||||
|
||||
func is_gift_given(item_id: String) -> bool:
|
||||
return gifts_given.has(item_id)
|
||||
|
||||
@@ -28,3 +28,26 @@ func test_luck_descriptor_delegates():
|
||||
var s = GameState.new()
|
||||
s.luck = 4
|
||||
assert_eq(s.luck_descriptor(), "Fortune spits on you")
|
||||
|
||||
|
||||
func test_remove_item_decrements_and_floors_at_zero():
|
||||
var gs = GameState.new()
|
||||
gs.add_item("coin", 3)
|
||||
gs.remove_item("coin", 2)
|
||||
assert_eq(gs.inventory.get("coin", 0), 1)
|
||||
gs.remove_item("coin", 5)
|
||||
assert_eq(gs.inventory.get("coin", 0), 0)
|
||||
|
||||
|
||||
func test_revealed_topics_tracked():
|
||||
var gs = GameState.new()
|
||||
assert_false(gs.is_revealed("varrell_twins"))
|
||||
gs.mark_revealed("varrell_twins")
|
||||
assert_true(gs.is_revealed("varrell_twins"))
|
||||
|
||||
|
||||
func test_gifts_given_tracked():
|
||||
var gs = GameState.new()
|
||||
assert_false(gs.is_gift_given("amulet"))
|
||||
gs.mark_gift_given("amulet")
|
||||
assert_true(gs.is_gift_given("amulet"))
|
||||
|
||||
Reference in New Issue
Block a user