Skip to content

Commit

Permalink
Show "The NPC dropped" message when NPCs drop an item
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Sep 14, 2022
1 parent ebf5dcc commit 6be6256
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions EOLib/Domain/Notifiers/INPCActionNotifier.cs
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using EOLib.Domain.Map;
using Optional;

namespace EOLib.Domain.Notifiers
Expand All @@ -14,6 +15,8 @@ public interface INPCActionNotifier
void ShowNPCSpeechBubble(int npcIndex, string message);

void NPCTakeDamage(short npcIndex, int fromPlayerId, int damageToNpc, short npcPctHealth, Option<int> spellId);

void NPCDropItem(MapItem item);
}

[AutoMappedType]
Expand All @@ -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<int> spellId) { }

public void NPCDropItem(MapItem item) { }
}
}
11 changes: 7 additions & 4 deletions EOLib/PacketHandlers/NPCLeaveMapHandler.cs
Expand Up @@ -17,7 +17,7 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler
protected readonly ICurrentMapStateRepository _currentMapStateRepository;
protected readonly ICharacterRepository _characterRepository;
private readonly ICharacterSessionRepository _characterSessionRepository;
private readonly IEnumerable<INPCActionNotifier> _npcAnimationNotifiers;
private readonly IEnumerable<INPCActionNotifier> _npcActionNotifiers;
private readonly IEnumerable<IMainCharacterEventNotifier> _mainCharacterEventNotifiers;

public override PacketFamily Family => PacketFamily.NPC;
Expand All @@ -28,14 +28,14 @@ public class NPCLeaveMapHandler : InGameOnlyPacketHandler
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
ICharacterSessionRepository characterSessionRepository,
IEnumerable<INPCActionNotifier> npcAnimationNotifiers,
IEnumerable<INPCActionNotifier> npcActionNotifiers,
IEnumerable<IMainCharacterEventNotifier> mainCharacterEventNotifiers)
: base(playerInfoProvider)
{
_currentMapStateRepository = currentMapStateRepository;
_characterRepository = characterRepository;
_characterSessionRepository = characterSessionRepository;
_npcAnimationNotifiers = npcAnimationNotifiers;
_npcActionNotifiers = npcActionNotifiers;
_mainCharacterEventNotifiers = mainCharacterEventNotifiers;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public override bool HandlePacket(IPacket packet)

private void RemoveNPCFromView(short deadNPCIndex, int playerId, Option<short> spellId, Option<int> 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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
28 changes: 25 additions & 3 deletions EndlessClient/Rendering/NPC/NPCActions.cs
Expand Up @@ -4,22 +4,26 @@
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;
private readonly INPCStateCache _npcStateCache;
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;

Expand All @@ -28,6 +32,9 @@ public class NPCActions : INPCActionNotifier
INPCRendererRepository npcRendererRepository,
ICharacterRendererRepository characterRendererRepository,
IChatBubbleActions chatBubbleActions,
IChatRepository chatRepository,
ILocalizedStringFinder localizedStringFinder,
IEIFFileProvider eifFileProvider,
IESFFileProvider esfFileProvider,
ISfxPlayer sfxPlayer)
{
Expand All @@ -36,6 +43,9 @@ public class NPCActions : INPCActionNotifier
_npcRendererRepository = npcRendererRepository;
_characterRendererRepository = characterRendererRepository;
_chatBubbleActions = chatBubbleActions;
_chatRepository = chatRepository;
_localizedStringFinder = localizedStringFinder;
_eifFileProvider = eifFileProvider;
_esfFileProvider = esfFileProvider;
_sfxPlayer = sfxPlayer;
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6be6256

Please sign in to comment.