From 6be6256ba45381d600393a1a8c0743b505c2878d Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Wed, 14 Sep 2022 14:40:39 -0700 Subject: [PATCH] Show "The NPC dropped" message when NPCs drop an item --- EOLib/Domain/Notifiers/INPCActionNotifier.cs | 5 ++++ EOLib/PacketHandlers/NPCLeaveMapHandler.cs | 11 +++++--- EndlessClient/Rendering/NPC/NPCActions.cs | 28 +++++++++++++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/EOLib/Domain/Notifiers/INPCActionNotifier.cs b/EOLib/Domain/Notifiers/INPCActionNotifier.cs index e92cd4763..79964d194 100644 --- a/EOLib/Domain/Notifiers/INPCActionNotifier.cs +++ b/EOLib/Domain/Notifiers/INPCActionNotifier.cs @@ -1,4 +1,5 @@ using AutomaticTypeMapper; +using EOLib.Domain.Map; using Optional; namespace EOLib.Domain.Notifiers @@ -14,6 +15,8 @@ public interface INPCActionNotifier void ShowNPCSpeechBubble(int npcIndex, string message); void NPCTakeDamage(short npcIndex, int fromPlayerId, int damageToNpc, short npcPctHealth, Option spellId); + + void NPCDropItem(MapItem item); } [AutoMappedType] @@ -28,5 +31,7 @@ public class NoOpNPCActionNotifier : INPCActionNotifier public void ShowNPCSpeechBubble(int npcIndex, string message) { } public void NPCTakeDamage(short npcIndex, int fromPlayerId, int damageToNpc, short npcPctHealth, Option spellId) { } + + public void NPCDropItem(MapItem item) { } } } diff --git a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs index 1957dccbc..569ed3759 100644 --- a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs +++ b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs @@ -17,7 +17,7 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler protected readonly ICurrentMapStateRepository _currentMapStateRepository; protected readonly ICharacterRepository _characterRepository; private readonly ICharacterSessionRepository _characterSessionRepository; - private readonly IEnumerable _npcAnimationNotifiers; + private readonly IEnumerable _npcActionNotifiers; private readonly IEnumerable _mainCharacterEventNotifiers; public override PacketFamily Family => PacketFamily.NPC; @@ -28,14 +28,14 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler ICurrentMapStateRepository currentMapStateRepository, ICharacterRepository characterRepository, ICharacterSessionRepository characterSessionRepository, - IEnumerable npcAnimationNotifiers, + IEnumerable npcActionNotifiers, IEnumerable mainCharacterEventNotifiers) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; _characterRepository = characterRepository; _characterSessionRepository = characterSessionRepository; - _npcAnimationNotifiers = npcAnimationNotifiers; + _npcActionNotifiers = npcActionNotifiers; _mainCharacterEventNotifiers = mainCharacterEventNotifiers; } @@ -97,7 +97,7 @@ public override bool HandlePacket(IPacket packet) private void RemoveNPCFromView(short deadNPCIndex, int playerId, Option spellId, Option damage, bool showDeathAnimation) { - foreach (var notifier in _npcAnimationNotifiers) + foreach (var notifier in _npcActionNotifiers) notifier.RemoveNPCFromView(deadNPCIndex, playerId, spellId, damage, showDeathAnimation); _currentMapStateRepository.NPCs.RemoveWhere(npc => npc.Index == deadNPCIndex); @@ -142,6 +142,9 @@ private void ShowDroppedItem(short playerID, short droppedItemUID, short dropped _currentMapStateRepository.MapItems.RemoveWhere(item => item.UniqueID == droppedItemUID); _currentMapStateRepository.MapItems.Add(mapItem); + + foreach (var notifier in _npcActionNotifiers) + notifier.NPCDropItem(mapItem); } } diff --git a/EndlessClient/Rendering/NPC/NPCActions.cs b/EndlessClient/Rendering/NPC/NPCActions.cs index ca70d08ca..3749964d5 100644 --- a/EndlessClient/Rendering/NPC/NPCActions.cs +++ b/EndlessClient/Rendering/NPC/NPCActions.cs @@ -4,15 +4,16 @@ using EndlessClient.HUD.Chat; using EndlessClient.HUD.Controls; using EndlessClient.Rendering.Character; -using EndlessClient.Rendering.Chat; -using EOLib; +using EOLib.Domain.Chat; +using EOLib.Domain.Map; using EOLib.Domain.Notifiers; using EOLib.IO.Repositories; +using EOLib.Localization; using Optional; namespace EndlessClient.Rendering.NPC { - [MappedType(BaseType = typeof(INPCActionNotifier))] + [AutoMappedType] public class NPCActions : INPCActionNotifier { private readonly IHudControlProvider _hudControlProvider; @@ -20,6 +21,9 @@ public class NPCActions : INPCActionNotifier private readonly INPCRendererRepository _npcRendererRepository; private readonly ICharacterRendererRepository _characterRendererRepository; private readonly IChatBubbleActions _chatBubbleActions; + private readonly IChatRepository _chatRepository; + private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly IEIFFileProvider _eifFileProvider; private readonly IESFFileProvider _esfFileProvider; private readonly ISfxPlayer _sfxPlayer; @@ -28,6 +32,9 @@ public class NPCActions : INPCActionNotifier INPCRendererRepository npcRendererRepository, ICharacterRendererRepository characterRendererRepository, IChatBubbleActions chatBubbleActions, + IChatRepository chatRepository, + ILocalizedStringFinder localizedStringFinder, + IEIFFileProvider eifFileProvider, IESFFileProvider esfFileProvider, ISfxPlayer sfxPlayer) { @@ -36,6 +43,9 @@ public class NPCActions : INPCActionNotifier _npcRendererRepository = npcRendererRepository; _characterRendererRepository = characterRendererRepository; _chatBubbleActions = chatBubbleActions; + _chatRepository = chatRepository; + _localizedStringFinder = localizedStringFinder; + _eifFileProvider = eifFileProvider; _esfFileProvider = esfFileProvider; _sfxPlayer = sfxPlayer; } @@ -105,6 +115,18 @@ public void NPCTakeDamage(short npcIndex, int fromPlayerId, int damageToNpc, sho }); } + public void NPCDropItem(MapItem item) + { + // todo: not sure if it is better to do this here in a notifier or modify the chat repository in the packet handler + // however, I don't want to introduce a dependency on localized text in the packet handler + var itemName = _eifFileProvider.EIFFile[item.ItemID].Name; + var chatData = new ChatData(ChatTab.System, + string.Empty, + $"{_localizedStringFinder.GetString(EOResourceID.STATUS_LABEL_THE_NPC_DROPPED)} {item.Amount} {itemName}", + ChatIcon.DownArrow); + _chatRepository.AllChat[ChatTab.System].Add(chatData); + } + private void ShoutSpellCast(int playerId) { _characterRendererRepository.MainCharacterRenderer.Match(