diff --git a/EndlessClient/HUD/Controls/HudControlsFactory.cs b/EndlessClient/HUD/Controls/HudControlsFactory.cs index 93ac15694..4d522d28e 100644 --- a/EndlessClient/HUD/Controls/HudControlsFactory.cs +++ b/EndlessClient/HUD/Controls/HudControlsFactory.cs @@ -25,7 +25,6 @@ using EOLib.Domain.Map; using EOLib.Graphics; using EOLib.Localization; -using EOLib.Net.Communication; using Microsoft.Xna.Framework; using System; using System.Collections.Generic; @@ -72,6 +71,8 @@ public class HudControlsFactory : IHudControlsFactory private readonly IClickDispatcherFactory _clickDispatcherFactory; private readonly IMetadataProvider _weaponMetadataProvider; private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly ICharacterRendererProvider _characterRendererProvider; + private readonly INPCRendererProvider _npcRendererProvider; private IChatController _chatController; private IMainButtonController _mainButtonController; @@ -106,7 +107,9 @@ public HudControlsFactory(IHudButtonController hudButtonController, IFixedTimeStepRepository fixedTimeStepRepository, IClickDispatcherFactory clickDispatcherFactory, IMetadataProvider weaponMetadataProvider, - ILocalizedStringFinder localizedStringFinder) + ILocalizedStringFinder localizedStringFinder, + ICharacterRendererProvider characterRendererProvider, + INPCRendererProvider npcRendererProvider) { _hudButtonController = hudButtonController; _hudPanelFactory = hudPanelFactory; @@ -140,6 +143,8 @@ public HudControlsFactory(IHudButtonController hudButtonController, _clickDispatcherFactory = clickDispatcherFactory; _weaponMetadataProvider = weaponMetadataProvider; _localizedStringFinder = localizedStringFinder; + _characterRendererProvider = characterRendererProvider; + _npcRendererProvider = npcRendererProvider; } public void InjectChatController(IChatController chatController, @@ -547,7 +552,8 @@ private PeriodicStatUpdaterComponent CreatePeriodicStatUpdater() private UnknownEntitiesRequester CreateUnknownEntitiesRequester() { - return new UnknownEntitiesRequester(_endlessGameProvider, _clientWindowSizeRepository, (ICharacterProvider)_characterRepository, _currentMapStateRepository, _unknownEntitiesRequestActions); + return new UnknownEntitiesRequester(_endlessGameProvider, _clientWindowSizeRepository, (ICharacterProvider)_characterRepository, _currentMapStateRepository, + _npcRendererProvider, _characterRendererProvider, _unknownEntitiesRequestActions); } private StatusBarLabel CreateStatusLabel() diff --git a/EndlessClient/Network/UnknownEntitiesRequester.cs b/EndlessClient/Network/UnknownEntitiesRequester.cs index 88cbbb0b9..f6c6466fc 100644 --- a/EndlessClient/Network/UnknownEntitiesRequester.cs +++ b/EndlessClient/Network/UnknownEntitiesRequester.cs @@ -1,5 +1,7 @@ using EndlessClient.GameExecution; using EndlessClient.Rendering; +using EndlessClient.Rendering.Character; +using EndlessClient.Rendering.NPC; using EOLib.Domain.Character; using EOLib.Domain.Map; using EOLib.Domain.NPC; @@ -21,6 +23,8 @@ public class UnknownEntitiesRequester : GameComponent private readonly IClientWindowSizeProvider _clientWindowSizeProvider; private readonly ICharacterProvider _characterProvider; private readonly ICurrentMapStateRepository _currentMapStateRepository; + private readonly INPCRendererProvider _npcRendererProvider; + private readonly ICharacterRendererProvider _characterRendererProvider; private readonly IUnknownEntitiesRequestActions _unknownEntitiesRequestActions; private DateTime _lastRequestTime; @@ -30,12 +34,16 @@ public UnknownEntitiesRequester(IEndlessGameProvider gameProvider, IClientWindowSizeProvider clientWindowSizeProvider, ICharacterProvider characterProvider, ICurrentMapStateRepository currentMapStateRepository, + INPCRendererProvider npcRendererProvider, + ICharacterRendererProvider characterRendererProvider, IUnknownEntitiesRequestActions unknownEntitiesRequestActions) : base((Game) gameProvider.Game) { _clientWindowSizeProvider = clientWindowSizeProvider; _characterProvider = characterProvider; _currentMapStateRepository = currentMapStateRepository; + _npcRendererProvider = npcRendererProvider; + _characterRendererProvider = characterRendererProvider; _unknownEntitiesRequestActions = unknownEntitiesRequestActions; _lastRequestTime = DateTime.Now; } @@ -93,9 +101,9 @@ private void ClearOutOfRangeActors() foreach (var entity in entitiesToRemove) { - if (entity is Character c) + if (entity is Character c && _characterRendererProvider.CharacterRenderers.ContainsKey(c.ID)) _currentMapStateRepository.Characters.Remove(c); - else if (entity is NPC n) + else if (entity is NPC n && _npcRendererProvider.NPCRenderers.ContainsKey(n.Index)) _currentMapStateRepository.NPCs.Remove(n); else if (entity is MapItem i) _currentMapStateRepository.MapItems.Remove(i);