feat(client): CanonLog.add_quest/has_quest for offer_quest
This commit is contained in:
@@ -58,6 +58,20 @@ func adjust_disposition(id: String, delta: int) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func has_quest(id: String) -> bool:
|
||||
for q in active_quests:
|
||||
if q.id == id:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func add_quest(id: String, name: String, objective: String) -> bool:
|
||||
if has_quest(id):
|
||||
return false
|
||||
active_quests.append(Quest.new(id, name, "active", objective))
|
||||
return true
|
||||
|
||||
|
||||
func set_quest_status(id: String, status: String) -> bool:
|
||||
for q in active_quests:
|
||||
if q.id == id:
|
||||
|
||||
@@ -46,3 +46,15 @@ func test_set_quest_status_rejects_bad_enum():
|
||||
|
||||
func test_unsupported_schema_version_returns_null():
|
||||
assert_null(CanonLog.from_dict({"schema_version": 2}))
|
||||
|
||||
|
||||
func test_add_quest_appends_active_and_is_idempotent():
|
||||
var log = CanonLog.new()
|
||||
assert_false(log.has_quest("find_the_ledger"))
|
||||
assert_true(log.add_quest("find_the_ledger", "The Missing Ledger", "Find who took it"))
|
||||
assert_true(log.has_quest("find_the_ledger"))
|
||||
assert_eq(log.active_quests.size(), 1)
|
||||
assert_eq(log.active_quests[0].status, "active")
|
||||
# second add is a no-op
|
||||
assert_false(log.add_quest("find_the_ledger", "x", "y"))
|
||||
assert_eq(log.active_quests.size(), 1)
|
||||
|
||||
Reference in New Issue
Block a user