extends GutTest const ItemDefinitionType = preload("res://scripts/domain/items/item_definition.gd") const ItemInstanceType = preload("res://scripts/domain/items/item_instance.gd") const InventoryStateType = preload("res://scripts/domain/inventory/inventory_state.gd") const ItemIdentificationType = preload("res://scripts/domain/items/item_identification.gd") const PlayerStateType = preload("res://scripts/domain/entities/player_state.gd") func _item(data: Dictionary, instance_id: StringName, quantity: int = 1) -> ItemInstance: return ItemInstanceType.new(ItemDefinitionType.new(data), quantity, instance_id) func test_unidentified_items_hide_name_and_stats_until_identified_or_equipped() -> void: var identification := ItemIdentificationType.new() var mysterious_blade := _item({"id": "mysterious_blade", "name": "Sun Blade", "category": "weapon", "equip_slot": "main_hand", "damage": 9, "unidentified": true}, &"mystery") assert_false(identification.is_identified(mysterious_blade)) assert_eq(identification.display_name(mysterious_blade), "Unidentified weapon") assert_eq(identification.display_stats(mysterious_blade), "Unknown properties") identification.reveal(mysterious_blade) assert_true(identification.is_identified(mysterious_blade)) assert_eq(identification.display_name(mysterious_blade), "Sun Blade") assert_string_contains(identification.display_stats(mysterious_blade), "Damage +9") func test_using_consumable_auto_reveals_applies_effects_and_consumes_one_from_stack() -> void: var inventory := InventoryStateType.new() var identification := ItemIdentificationType.new() var player := PlayerStateType.new({"hit_points": 10}) var medkit := _item({"id": "mystery_medkit", "name": "Mystery Medkit", "category": "consumable", "consumable": true, "stackable": true, "unidentified": true, "on_use": [{"type": "heal", "amount": 20}]}, &"medkit", 2) inventory.add_item(medkit) var result := inventory.use_item(medkit.instance_id, player, identification) assert_true(result.accepted) assert_true(result.revealed) assert_true(identification.is_identified(medkit)) assert_eq(player.hit_points, 30) assert_eq(inventory.item_by_id(medkit.instance_id).quantity, 1) assert_eq(result.effects, [{"type": &"heal", "amount": 20}]) func test_using_an_actor_state_uses_its_maximum_hit_points_contract() -> void: var inventory := InventoryStateType.new() var identification := ItemIdentificationType.new() var actor := ActorState.new(&"player", Vector2i.ZERO, 12, 3) actor.hit_points = 10 actor.max_hit_points = 50 var medkit := _item({"id": "medkit", "name": "Medkit", "category": "consumable", "consumable": true, "on_use": [{"type": "heal", "amount": 40}]}, &"actor-medkit") inventory.add_item(medkit) var result := inventory.use_item(medkit.instance_id, actor, identification) assert_true(result.accepted) assert_eq(actor.hit_points, 50) assert_eq(inventory.item_by_id(medkit.instance_id), null) func test_dropping_one_stack_unit_places_it_on_floor_and_keeps_the_remainder() -> void: var inventory := InventoryStateType.new() var floor := FloorState.new(GridMapState.new(Vector2i(3, 3))) var bandage := _item({"id": "bandage", "name": "Bandage", "category": "consumable", "consumable": true, "stackable": true}, &"bandage", 2) inventory.add_item(bandage) var result := inventory.drop_item(floor, Vector2i(1, 1), bandage.instance_id) assert_true(result.accepted) assert_eq(inventory.item_by_id(bandage.instance_id).quantity, 1) assert_eq(floor.ground_items[Vector2i(1, 1)][0].definition.id, &"bandage") assert_eq(floor.ground_items[Vector2i(1, 1)][0].quantity, 1) func test_ally_target_hook_requires_a_target_and_can_apply_to_the_selected_ally() -> void: var inventory := InventoryStateType.new() var identification := ItemIdentificationType.new() var player := PlayerStateType.new({"hit_points": 10}) var ally := PlayerStateType.new({"id": "ally", "hit_points": 5}) var medkit := _item({"id": "ally_medkit", "name": "Ally Medkit", "category": "consumable", "consumable": true, "target": "ally", "on_use": [{"type": "heal", "amount": 10}]}, &"ally-medkit") inventory.add_item(medkit) var pending := inventory.use_item(medkit.instance_id, player, identification) var applied := inventory.use_item(medkit.instance_id, player, identification, ally) assert_false(pending.accepted) assert_eq(pending.reason, &"target_required") assert_true(applied.accepted) assert_eq(ally.hit_points, 15) assert_eq(inventory.item_by_id(medkit.instance_id), null)