feat: add deterministic world chest loot
This commit is contained in:
@@ -41,7 +41,11 @@ func test_opening_chest_replaces_it_with_floor_refreshes_fov_and_gets_one_enemy_
|
||||
enemy_response_count += 1
|
||||
|
||||
assert_eq(results[0].kind, &"chest_opened")
|
||||
assert_eq(results[0].message, "You open the chest.")
|
||||
assert_string_contains(results[0].message, "Coffre ouvert :")
|
||||
assert_true(results[0].payload.has("items"))
|
||||
assert_true(results[0].payload.has("gold"))
|
||||
assert_true(results[0].payload.has("empty"))
|
||||
assert_true(results[0].payload.has("trap"))
|
||||
assert_eq(results[0].to_cell, chest)
|
||||
assert_eq(state.map.get_cell(chest), GridMapState.CellKind.FLOOR)
|
||||
assert_true(state.map.is_walkable(chest))
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
extends GutTest
|
||||
|
||||
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
|
||||
const LootResolverType = preload("res://scripts/domain/items/loot_resolver.gd")
|
||||
const WorldChestType = preload("res://scripts/domain/items/world_chest.gd")
|
||||
|
||||
var catalog: ContentCatalog
|
||||
|
||||
func before_each() -> void:
|
||||
catalog = ContentCatalogType.load_from_directory("res://data/ascii")
|
||||
|
||||
func test_catalog_table_resolution_is_deterministic_and_preserves_gold_items_and_empty_shape() -> void:
|
||||
var table := catalog.get_loot_table(&"floor1_reward")
|
||||
|
||||
var first: Dictionary = LootResolverType.resolve(table, "D2-LOOT-SEED", "floor-1/chest-4-7")
|
||||
var second: Dictionary = LootResolverType.resolve(table, "D2-LOOT-SEED", "floor-1/chest-4-7")
|
||||
|
||||
assert_eq(first, second)
|
||||
assert_eq(first.items is Array, true)
|
||||
assert_typeof(first.gold, TYPE_INT)
|
||||
assert_typeof(first.empty, TYPE_BOOL)
|
||||
assert_eq(first.empty, first.items.is_empty() and first.gold == 0)
|
||||
for item: Dictionary in first.items:
|
||||
assert_true(item.has("item_id"))
|
||||
assert_true(item.has("quantity"))
|
||||
assert_gt(int(item.quantity), 0)
|
||||
|
||||
func test_world_chest_keeps_table_trap_lock_and_opened_state_and_stores_its_single_reward() -> void:
|
||||
var chest: WorldChest = WorldChestType.new({
|
||||
"loot_table_id": "floor1_reward",
|
||||
"trap_id": "trap_spikes",
|
||||
"lock_id": "tutorial_lock",
|
||||
"opened": false,
|
||||
})
|
||||
|
||||
assert_eq(chest.loot_table_id, &"floor1_reward")
|
||||
assert_eq(chest.trap_id, &"trap_spikes")
|
||||
assert_eq(chest.lock_id, &"tutorial_lock")
|
||||
assert_false(chest.opened)
|
||||
assert_true(chest.is_locked())
|
||||
assert_false(chest.open({"items": [], "gold": 0, "empty": true, "trap": &"trap_spikes"}))
|
||||
assert_false(chest.opened)
|
||||
|
||||
chest.lock_id = &""
|
||||
var reward := {"items": [{"item_id": &"consumable_bandage", "quantity": 2}], "gold": 12, "empty": false, "trap": &"trap_spikes"}
|
||||
assert_true(chest.open(reward))
|
||||
assert_true(chest.opened)
|
||||
assert_eq(chest.reward, reward)
|
||||
assert_false(chest.open(reward))
|
||||
assert_eq(chest.to_dict().loot_table_id, &"floor1_reward")
|
||||
assert_eq(chest.to_dict().trap_id, &"trap_spikes")
|
||||
assert_eq(chest.to_dict().lock_id, &"")
|
||||
assert_true(chest.to_dict().opened)
|
||||
assert_eq(chest.to_dict().reward, reward)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bytnd0jif37jo
|
||||
Reference in New Issue
Block a user