Skip to content

Commit

Permalink
Rename AutoRefresh to CharacterMapInfo
Browse files Browse the repository at this point in the history
Rename AutoRefresh2 to NPCMapInfo
Rename Appear to MapInfo
Change NPCEnterMapHandler to MapInfoHandler
Make MapInfoHandler read character data
  • Loading branch information
sorokya committed Mar 28, 2022
1 parent dfe4ec6 commit 0ba65eb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 52 deletions.
6 changes: 3 additions & 3 deletions EOLib/Net/PacketFamily.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public enum PacketFamily : byte
Party = (byte)24,
Refresh = (byte)25,
NPC = (byte)26,
AutoRefresh = (byte)27,
AutoRefresh2 = (byte)28,
Appear = (byte)29,
CharacterMapInfo = (byte)27,
NPCMapInfo = (byte)28,
MapInfo = (byte)29,
PaperDoll = (byte)30,
Effect = (byte)31,
Trade = (byte)32,
Expand Down
73 changes: 73 additions & 0 deletions EOLib/PacketHandlers/MapInfoHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using AutomaticTypeMapper;
using EOLib.Domain.Extensions;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.NPC;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Handlers;
using EOLib.Net.Translators;

namespace EOLib.PacketHandlers
{
[AutoMappedType]
public class MapInfoHandler : InGameOnlyPacketHandler
{
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly ICharacterFromPacketFactory _characterFromPacketFactory;
private readonly IEIFFileProvider _eifFileProvider;

public override PacketFamily Family => PacketFamily.MapInfo;

public override PacketAction Action => PacketAction.Reply;

public MapInfoHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterFromPacketFactory characterFromPacketFactory,
IEIFFileProvider eifFileProvider
)
: base(playerInfoProvider)
{
_currentMapStateRepository = currentMapStateRepository;
_characterFromPacketFactory = characterFromPacketFactory;
}

public override bool HandlePacket(IPacket packet)
{
var num_entities = packet.ReadChar();

if (packet.PeekByte() == 0xFF)
{
for (var i = 0; i < num_entities; i++)
{
var character = _characterFromPacketFactory.CreateCharacter(packet);
if (_currentMapStateRepository.Characters.ContainsKey(character.ID))
{
var existingCharacter = _currentMapStateRepository.Characters[character.ID];
var isRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(character.RenderProperties.WeaponGraphic);
character = existingCharacter.WithAppliedData(character, isRangedWeapon);
}
_currentMapStateRepository.Characters[character.ID] = character;
}
}

while (packet.ReadPosition < packet.Length)
{
var index = packet.ReadChar();
var id = packet.ReadShort();
var x = packet.ReadChar();
var y = packet.ReadChar();
var direction = (EODirection)packet.ReadChar();

INPC npc = new NPC(id, index);
npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing);

_currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == index);
_currentMapStateRepository.NPCs.Add(npc);
}

return true;
}
}
}
49 changes: 0 additions & 49 deletions EOLib/PacketHandlers/NPCEnterMapHandler.cs

This file was deleted.

0 comments on commit 0ba65eb

Please sign in to comment.