Skip to content

Commit

Permalink
Use read-only collections in ICurrentMapStateProvider for unknown pla…
Browse files Browse the repository at this point in the history
…yer/npc indexes
  • Loading branch information
ethanmoffat committed May 31, 2024
1 parent 86e8cb0 commit 7287b10
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 6 additions & 2 deletions EOLib/Domain/Map/CurrentMapStateRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public interface ICurrentMapStateProvider

bool IsSleepWarp { get; }

HashSet<int> UnknownPlayerIDs { get; }
IReadOnlyCollection<int> UnknownPlayerIDs { get; }

HashSet<int> UnknownNPCIndexes { get; }
IReadOnlyCollection<int> UnknownNPCIndexes { get; }
}

[AutoMappedType(IsSingleton = true)]
Expand Down Expand Up @@ -128,6 +128,10 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap

IReadOnlyCollection<MapCoordinate> ICurrentMapStateProvider.VisibleSpikeTraps => VisibleSpikeTraps;

IReadOnlyCollection<int> ICurrentMapStateProvider.UnknownPlayerIDs => UnknownPlayerIDs;

IReadOnlyCollection<int> ICurrentMapStateProvider.UnknownNPCIndexes => UnknownNPCIndexes;

public CurrentMapStateRepository()
{
ResetState();
Expand Down
4 changes: 2 additions & 2 deletions EOLib/PacketHandlers/Chat/GroupChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class GroupChatHandler : PlayerChatByIDHandler<TalkOpenServerPacket>
public override PacketAction Action => PacketAction.Open;

public GroupChatHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateProvider currentMapStateProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterProvider characterProvider,
IChatRepository chatRepository,
IEnumerable<IOtherCharacterEventNotifier> otherCharacterEventNotifiers,
IEnumerable<IChatEventNotifier> chatEventNotifiers)
: base(playerInfoProvider, currentMapStateProvider, characterProvider)
: base(playerInfoProvider, currentMapStateRepository, characterProvider)
{
_chatRepository = chatRepository;
_otherCharacterEventNotifiers = otherCharacterEventNotifiers;
Expand Down
10 changes: 5 additions & 5 deletions EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ namespace EOLib.PacketHandlers.Chat
public abstract class PlayerChatByIDHandler<TPacket> : InGameOnlyPacketHandler<TPacket>
where TPacket : IPacket
{
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly ICharacterProvider _characterProvider;

public override PacketFamily Family => PacketFamily.Talk;

protected PlayerChatByIDHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateProvider currentMapStateProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterProvider characterProvider)
: base(playerInfoProvider)
{
_currentMapStateProvider = currentMapStateProvider;
_currentMapStateRepository = currentMapStateRepository;
_characterProvider = characterProvider;
}

protected bool Handle(TPacket packet, int fromPlayerID)
{
if (!_currentMapStateProvider.Characters.TryGetValue(fromPlayerID, out var character) &&
if (!_currentMapStateRepository.Characters.TryGetValue(fromPlayerID, out var character) &&
_characterProvider.MainCharacter.ID != fromPlayerID)
{
_currentMapStateProvider.UnknownPlayerIDs.Add(fromPlayerID);
_currentMapStateRepository.UnknownPlayerIDs.Add(fromPlayerID);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions EOLib/PacketHandlers/Chat/PublicChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class PublicChatHandler : PlayerChatByIDHandler<TalkPlayerServerPacket>
public override PacketAction Action => PacketAction.Player;

public PublicChatHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateProvider currentMapStateProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterProvider characterProvider,
IChatRepository chatRepository,
IEnumerable<IOtherCharacterEventNotifier> notifiers)
: base(playerInfoProvider, currentMapStateProvider, characterProvider)
: base(playerInfoProvider, currentMapStateRepository, characterProvider)
{
_chatRepository = chatRepository;
_notifiers = notifiers;
Expand Down
8 changes: 4 additions & 4 deletions EOLib/PacketHandlers/Party/PartyAgreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ namespace EOLib.PacketHandlers.Party
public class PartyAgreeHandler : InGameOnlyPacketHandler<PartyAgreeServerPacket>
{
private readonly IPartyDataRepository _partyDataRepository;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;

public override PacketFamily Family => PacketFamily.Party;

public override PacketAction Action => PacketAction.Agree;

public PartyAgreeHandler(IPlayerInfoProvider playerInfoProvider,
IPartyDataRepository partyDataRepository,
ICurrentMapStateProvider currentMapStateProvider)
ICurrentMapStateRepository currentMapStateRepository)
: base(playerInfoProvider)
{
_partyDataRepository = partyDataRepository;
_currentMapStateProvider = currentMapStateProvider;
_currentMapStateRepository = currentMapStateRepository;
}

public override bool HandlePacket(PartyAgreeServerPacket packet)
Expand All @@ -40,7 +40,7 @@ public override bool HandlePacket(PartyAgreeServerPacket packet)
_partyDataRepository.Members.Remove(x);
_partyDataRepository.Members.Add(x.WithPercentHealth(packet.HpPercentage));
},
none: () => _currentMapStateProvider.UnknownPlayerIDs.Add(packet.PlayerId));
none: () => _currentMapStateRepository.UnknownPlayerIDs.Add(packet.PlayerId));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ public void NotifyGroupSpellCast(int playerId, int spellId, int spellHp, List<Gr
Animator.StartOtherCharacterSpellCast(playerId);
_characterRendererProvider.CharacterRenderers[playerId].ShoutSpellCast();
}
else
{
_currentMapStateProvider.UnknownPlayerIDs.Add(playerId);
}

var spellData = _pubFileProvider.ESFFile[spellId];

Expand Down

0 comments on commit 7287b10

Please sign in to comment.