75 lines
2.9 KiB
GDScript
75 lines
2.9 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_multi_roll_reward_never_selects_the_same_item_id_twice() -> void:
|
|
var table := {
|
|
"rolls": 4,
|
|
"entries": [
|
|
{"item": "weapon_hunting_knife", "weight": 100},
|
|
{"item": "consumable_bandage", "weight": 1, "min_qty": 2, "max_qty": 2},
|
|
],
|
|
}
|
|
|
|
var reward := LootResolverType.resolve(table, "NO-DUPLICATES", "chest")
|
|
var ids: Array = (reward.items as Array).map(func(item: Dictionary) -> StringName: return StringName(item.item_id))
|
|
var unique_ids := {}
|
|
for item_id in ids:
|
|
unique_ids[item_id] = true
|
|
|
|
assert_eq(ids.size(), unique_ids.size())
|
|
assert_lte(ids.size(), 2)
|
|
for item: Dictionary in reward.items:
|
|
assert_eq(int(item.quantity), 2 if item.item_id == &"consumable_bandage" else 1, "Repeated rolls must not inflate quantity beyond the authored range.")
|
|
|
|
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)
|