55 lines
2.1 KiB
GDScript
55 lines
2.1 KiB
GDScript
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)
|