fix: align loot feedback with pickup outcomes
This commit is contained in:
+10
-5
@@ -1274,9 +1274,9 @@ func _record_narrative_event(kind: StringName, event_id: StringName, payload: Di
|
||||
|
||||
func _process_ground_pickup() -> Array[TurnResult]:
|
||||
var pickup := run_state.inventory.pick_up_ground_item(game_state.floor_state, game_state.player.cell)
|
||||
var item: ItemInstance = pickup.item
|
||||
var item: ItemInstance = pickup.get("item", null)
|
||||
var result: TurnResult
|
||||
if bool(pickup.accepted):
|
||||
if bool(pickup.get("accepted", false)) and item != null:
|
||||
result = TurnResult.new(
|
||||
game_state.player.id,
|
||||
&"item_picked_up",
|
||||
@@ -1285,9 +1285,14 @@ func _process_ground_pickup() -> Array[TurnResult]:
|
||||
&"",
|
||||
0,
|
||||
"Picked up %s x%d." % [item.definition.name, item.quantity],
|
||||
{"item_id": item.definition.id, "instance_id": item.instance_id, "quantity": item.quantity, "stack_merged_into": pickup.stack_merged_into}
|
||||
{"item_id": item.definition.id, "instance_id": item.instance_id, "quantity": item.quantity, "stack_merged_into": pickup.get("stack_merged_into", &"")}
|
||||
)
|
||||
else:
|
||||
var reason := StringName(pickup.get("reason", &"no_ground_item"))
|
||||
var payload := {"reason": reason}
|
||||
if item != null:
|
||||
payload.merge({"item_id": item.definition.id, "instance_id": item.instance_id, "quantity": item.quantity}, true)
|
||||
var message := "Rien à ramasser." if reason == &"no_ground_item" else "Inventaire plein." if reason == &"capacity" else "Ramassage impossible."
|
||||
result = TurnResult.new(
|
||||
game_state.player.id,
|
||||
&"pickup_refused",
|
||||
@@ -1295,8 +1300,8 @@ func _process_ground_pickup() -> Array[TurnResult]:
|
||||
game_state.player.cell,
|
||||
&"",
|
||||
0,
|
||||
"Inventory is full.",
|
||||
{"item_id": item.definition.id, "instance_id": item.instance_id, "quantity": item.quantity, "reason": pickup.reason}
|
||||
message,
|
||||
payload
|
||||
)
|
||||
_resolve_player_action([result], false)
|
||||
return [result]
|
||||
|
||||
@@ -333,8 +333,13 @@ func _localized_loot_taken(payload: Dictionary) -> String:
|
||||
return message + "."
|
||||
|
||||
func _localized_pickup_refused(payload: Dictionary) -> String:
|
||||
var reason := StringName(payload.get("reason", ""))
|
||||
if reason == &"no_ground_item":
|
||||
return "Rien à ramasser."
|
||||
var item := _localized_item_quantity(payload)
|
||||
return "Inventaire plein : %s non ramassé." % item if not item.is_empty() else "Inventaire plein."
|
||||
if reason == &"capacity" or reason == &"inventory_full":
|
||||
return "Inventaire plein : %s non ramassé." % item if not item.is_empty() else "Inventaire plein."
|
||||
return "Ramassage impossible."
|
||||
|
||||
func _localized_reward_parts(payload: Dictionary) -> PackedStringArray:
|
||||
var parts := _localized_items(payload.get("items", []))
|
||||
|
||||
@@ -21,15 +21,17 @@ func get_last_feedback_state() -> Dictionary:
|
||||
|
||||
func begin(event: GameEvent, presentation_kind: StringName) -> void:
|
||||
var color := _color_for(presentation_kind)
|
||||
var feedback_label := label_for_event(event, presentation_kind)
|
||||
_last_feedback_state = {
|
||||
"kind": presentation_kind,
|
||||
"duration_ms": EFFECT_DURATION_MS,
|
||||
"color": color,
|
||||
"label": feedback_label,
|
||||
}
|
||||
if _test_mode:
|
||||
return
|
||||
var label := Label.new()
|
||||
label.text = _label_for(event, presentation_kind)
|
||||
label.text = feedback_label
|
||||
label.modulate = color
|
||||
label.position = Vector2(390, 80)
|
||||
label.z_index = 20
|
||||
@@ -47,9 +49,20 @@ func _color_for(presentation_kind: StringName) -> Color:
|
||||
&"quest": return QUEST_COLOR
|
||||
_: return LOOT_COLOR
|
||||
|
||||
func _label_for(event: GameEvent, presentation_kind: StringName) -> String:
|
||||
func label_for_event(event: GameEvent, presentation_kind: StringName) -> String:
|
||||
if presentation_kind == &"loot":
|
||||
match event.kind:
|
||||
&"loot_dropped": return "✦ BUTIN AU SOL"
|
||||
&"item_picked_up": return "✦ OBJET RAMASSÉ"
|
||||
&"loot_taken": return "✦ BUTIN RÉCUPÉRÉ"
|
||||
&"pickup_refused":
|
||||
var reason := StringName(event.payload.get("reason", ""))
|
||||
if reason == &"no_ground_item":
|
||||
return "! RIEN À RAMASSER"
|
||||
if reason == &"capacity" or reason == &"inventory_full":
|
||||
return "! INVENTAIRE PLEIN"
|
||||
return "! RAMASSAGE IMPOSSIBLE"
|
||||
match presentation_kind:
|
||||
&"loot": return "✦ BUTIN AU SOL"
|
||||
&"trap": return "! TRAP"
|
||||
&"quest": return "✦ QUEST UPDATED"
|
||||
_: return event.message
|
||||
|
||||
@@ -47,6 +47,26 @@ func test_real_interact_picks_visible_ground_item_then_inventory_action_opens_li
|
||||
assert_string_contains(entries.get_parsed_text(), "Bandage x2")
|
||||
assert_eq(game.get_run_state().recent_events(1)[0].kind, &"inventory_opened")
|
||||
|
||||
func test_direct_ground_pickup_refuses_an_empty_injected_ground_item_list_without_item_fields() -> void:
|
||||
var state := game.get_game_state()
|
||||
state.floor_state.ground_items[state.player.cell] = []
|
||||
|
||||
var results := game._process_ground_pickup()
|
||||
|
||||
assert_eq(results.size(), 1)
|
||||
assert_eq(results[0].kind, &"pickup_refused")
|
||||
assert_eq(results[0].payload.reason, &"no_ground_item")
|
||||
assert_false(results[0].payload.has("item_id"))
|
||||
assert_false(results[0].payload.has("instance_id"))
|
||||
assert_false(results[0].payload.has("quantity"))
|
||||
assert_eq(results[0].message, "Rien à ramasser.")
|
||||
var refusal := game.get_run_state().recent_events(1)[0]
|
||||
assert_eq(refusal.kind, &"pickup_refused")
|
||||
assert_eq(refusal.payload.reason, &"no_ground_item")
|
||||
assert_false(refusal.payload.has("item_id"))
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
assert_string_contains(hud.event_log.get_parsed_text(), "Rien à ramasser.")
|
||||
|
||||
func test_real_interact_refuses_non_stackable_ground_item_when_inventory_is_full() -> void:
|
||||
var state := game.get_game_state()
|
||||
var inventory := game.get_run_state().inventory
|
||||
|
||||
@@ -53,13 +53,15 @@ func test_temporary_rewards_grant_ammunition_and_teach_the_offensive_spell_throu
|
||||
game.pending_loot = ranged_reward.duplicate(true)
|
||||
var ammunition_before := state.player.ammunition
|
||||
var awarded_ammunition := int(ranged_reward.get("ammunition", 0))
|
||||
assert_gt(awarded_ammunition, 0)
|
||||
assert_eq(awarded_ammunition, 20)
|
||||
game._take_all_loot()
|
||||
assert_eq(state.player.ammunition, ammunition_before + awarded_ammunition)
|
||||
assert_eq(state.player.ammunition, ammunition_before + 20)
|
||||
assert_true(game.get_run_state().inventory.items.any(func(item: ItemInstance) -> bool: return item.definition.id == &"weapon_hand_crossbow"))
|
||||
var loot_event := game.get_run_state().recent_events(1)[0]
|
||||
assert_eq(loot_event.kind, &"loot_taken")
|
||||
assert_eq(loot_event.payload.ammunition, awarded_ammunition)
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "%d munitions récupérées" % awarded_ammunition)
|
||||
assert_eq(loot_event.payload.ammunition, 20)
|
||||
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "20 munitions récupérées")
|
||||
|
||||
game.pending_loot = spell_reward.duplicate(true)
|
||||
game._take_all_loot()
|
||||
|
||||
@@ -83,7 +83,8 @@ func test_hud_describes_pickup_and_loot_take_outcomes_in_french() -> void:
|
||||
var events: Array[GameEvent] = [
|
||||
GameEvent.new(1, 0, &"item_picked_up", {"item_id": &"consumable_bandage", "quantity": 2}, "Picked up consumable_bandage x2.", &"player"),
|
||||
GameEvent.new(2, 0, &"pickup_refused", {"item_id": &"consumable_bandage", "quantity": 2, "reason": "inventory_full"}, "Inventory is full.", &"player"),
|
||||
GameEvent.new(3, 0, &"loot_taken", {"items": [{"item_id": &"consumable_bandage", "quantity": 1}], "gold": 4, "ammunition": 3, "refused_items": [{"item_id": &"weapon_hunting_knife", "quantity": 1, "reason": "inventory_full"}]}, "Loot taken.", &"player"),
|
||||
GameEvent.new(3, 0, &"pickup_refused", {"reason": "no_ground_item"}, "Nothing to pick up.", &"player"),
|
||||
GameEvent.new(4, 0, &"loot_taken", {"items": [{"item_id": &"consumable_bandage", "quantity": 1}], "gold": 4, "ammunition": 3, "refused_items": [{"item_id": &"weapon_hunting_knife", "quantity": 1, "reason": "inventory_full"}]}, "Loot taken.", &"player"),
|
||||
]
|
||||
|
||||
hud.refresh(state, events, game.get_run_state())
|
||||
@@ -91,6 +92,7 @@ func test_hud_describes_pickup_and_loot_take_outcomes_in_french() -> void:
|
||||
var journal_text := hud.event_log.get_parsed_text()
|
||||
assert_string_contains(journal_text, "Ramassé : Bandage x2.")
|
||||
assert_string_contains(journal_text, "Inventaire plein")
|
||||
assert_string_contains(journal_text, "Rien à ramasser.")
|
||||
assert_string_contains(journal_text, "Butin récupéré : Bandage x1, 4 or, 3 munitions récupérées")
|
||||
assert_string_contains(journal_text, "Couteau de chasse x1 non ramassé (inventaire plein)")
|
||||
for technical_id: String in ["consumable_bandage", "weapon_hunting_knife"]:
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
extends GutTest
|
||||
|
||||
const LootFeedback = preload("res://scripts/presentation/loot_feedback.gd")
|
||||
const GameEvent = preload("res://scripts/domain/run/game_event.gd")
|
||||
|
||||
func test_label_for_event_distinguishes_each_loot_outcome() -> void:
|
||||
var feedback := LootFeedback.new()
|
||||
add_child_autofree(feedback)
|
||||
var cases: Array[Dictionary] = [
|
||||
{"event": GameEvent.new(1, 0, &"loot_dropped"), "expected": "✦ BUTIN AU SOL"},
|
||||
{"event": GameEvent.new(1, 0, &"item_picked_up"), "expected": "✦ OBJET RAMASSÉ"},
|
||||
{"event": GameEvent.new(1, 0, &"loot_taken"), "expected": "✦ BUTIN RÉCUPÉRÉ"},
|
||||
{"event": GameEvent.new(1, 0, &"pickup_refused", {"reason": &"capacity"}), "expected": "! INVENTAIRE PLEIN"},
|
||||
{"event": GameEvent.new(1, 0, &"pickup_refused", {"reason": &"inventory_full"}), "expected": "! INVENTAIRE PLEIN"},
|
||||
{"event": GameEvent.new(1, 0, &"pickup_refused", {"reason": &"no_ground_item"}), "expected": "! RIEN À RAMASSER"},
|
||||
]
|
||||
|
||||
for test_case: Dictionary in cases:
|
||||
assert_eq(feedback.label_for_event(test_case.event, &"loot"), test_case.expected)
|
||||
|
||||
func test_begin_records_label_in_test_mode() -> void:
|
||||
var feedback := LootFeedback.new()
|
||||
add_child_autofree(feedback)
|
||||
feedback.set_test_mode_for_testing(true)
|
||||
feedback.begin(GameEvent.new(1, 0, &"item_picked_up"), &"loot")
|
||||
|
||||
assert_eq(feedback.get_last_feedback_state().label, "✦ OBJET RAMASSÉ")
|
||||
@@ -0,0 +1 @@
|
||||
uid://5uw6cqftw4sw
|
||||
Reference in New Issue
Block a user