Improve auto-opening box UX with clear messaging
- Auto-opened boxes now show "Box of Boxes opens automatically!" instead of the full opening sequence, making the cascade clear to the player - Items that are immediately auto-consumed (auto-opening boxes) are hidden from loot reveal to reduce noise - BoxOpenedEvent now carries IsAutoOpen flag set by BoxEngine
This commit is contained in:
parent
c580e1cf2e
commit
77c70593ee
3 changed files with 20 additions and 7 deletions
|
|
@ -237,18 +237,31 @@ public static class Program
|
||||||
|
|
||||||
private static async Task RenderEvents(List<GameEvent> events)
|
private static async Task RenderEvents(List<GameEvent> events)
|
||||||
{
|
{
|
||||||
|
// Collect IDs of items that are auto-consumed (auto-opening boxes)
|
||||||
|
// so we don't show "You received" for items the player never actually gets
|
||||||
|
var autoConsumedIds = events.OfType<ItemConsumedEvent>().Select(e => e.InstanceId).ToHashSet();
|
||||||
|
|
||||||
foreach (var evt in events)
|
foreach (var evt in events)
|
||||||
{
|
{
|
||||||
switch (evt)
|
switch (evt)
|
||||||
{
|
{
|
||||||
case BoxOpenedEvent boxEvt:
|
case BoxOpenedEvent boxEvt:
|
||||||
var boxDef = _registry.GetBox(boxEvt.BoxId);
|
var boxDef = _registry.GetBox(boxEvt.BoxId);
|
||||||
_renderer.ShowBoxOpening(
|
var boxName = _loc.Get(boxDef?.NameKey ?? boxEvt.BoxId);
|
||||||
_loc.Get(boxDef?.NameKey ?? boxEvt.BoxId),
|
if (boxEvt.IsAutoOpen)
|
||||||
boxDef?.Rarity.ToString() ?? "Common");
|
{
|
||||||
|
_renderer.ShowMessage(_loc.Get("box.auto_open", boxName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_renderer.ShowBoxOpening(boxName, boxDef?.Rarity.ToString() ?? "Common");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ItemReceivedEvent itemEvt:
|
case ItemReceivedEvent itemEvt:
|
||||||
|
// Skip loot reveal for auto-consumed items (auto-opening boxes)
|
||||||
|
if (autoConsumedIds.Contains(itemEvt.Item.Id))
|
||||||
|
break;
|
||||||
_state.AddItem(itemEvt.Item);
|
_state.AddItem(itemEvt.Item);
|
||||||
var itemDef = _registry.GetItem(itemEvt.Item.DefinitionId);
|
var itemDef = _registry.GetItem(itemEvt.Item.DefinitionId);
|
||||||
var itemBoxDef = itemDef is null ? _registry.GetBox(itemEvt.Item.DefinitionId) : null;
|
var itemBoxDef = itemDef is null ? _registry.GetBox(itemEvt.Item.DefinitionId) : null;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class BoxEngine(ContentRegistry registry)
|
||||||
/// Opens a box, evaluating its loot table against the current game state and returning
|
/// Opens a box, evaluating its loot table against the current game state and returning
|
||||||
/// all resulting events (items received, nested box opens, etc.).
|
/// all resulting events (items received, nested box opens, etc.).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<GameEvent> Open(string boxDefId, GameState state, Random rng)
|
public List<GameEvent> Open(string boxDefId, GameState state, Random rng, bool isAutoOpen = false)
|
||||||
{
|
{
|
||||||
var events = new List<GameEvent>();
|
var events = new List<GameEvent>();
|
||||||
var boxDef = registry.GetBox(boxDefId);
|
var boxDef = registry.GetBox(boxDefId);
|
||||||
|
|
@ -47,7 +47,7 @@ public class BoxEngine(ContentRegistry registry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
events.Add(new BoxOpenedEvent(boxDefId, droppedItemDefIds));
|
events.Add(new BoxOpenedEvent(boxDefId, droppedItemDefIds, isAutoOpen));
|
||||||
|
|
||||||
// Create item instances for each dropped item
|
// Create item instances for each dropped item
|
||||||
foreach (var itemDefId in droppedItemDefIds)
|
foreach (var itemDefId in droppedItemDefIds)
|
||||||
|
|
@ -62,7 +62,7 @@ public class BoxEngine(ContentRegistry registry)
|
||||||
{
|
{
|
||||||
state.RemoveItem(instance.Id);
|
state.RemoveItem(instance.Id);
|
||||||
events.Add(new ItemConsumedEvent(instance.Id));
|
events.Add(new ItemConsumedEvent(instance.Id));
|
||||||
events.AddRange(Open(itemDefId, state, rng));
|
events.AddRange(Open(itemDefId, state, rng, isAutoOpen: true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public abstract record GameEvent
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A box was opened, producing dropped items.
|
/// A box was opened, producing dropped items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed record BoxOpenedEvent(string BoxId, List<string> DroppedItemDefIds) : GameEvent;
|
public sealed record BoxOpenedEvent(string BoxId, List<string> DroppedItemDefIds, bool IsAutoOpen = false) : GameEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An item was received and added to inventory.
|
/// An item was received and added to inventory.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue