-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into inventory
- Loading branch information
Showing
24 changed files
with
365 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.NPC; | ||
|
||
namespace EOLib.Net.Translators | ||
{ | ||
[AutoMappedType] | ||
public class NPCFromPacketFactory : INPCFromPacketFactory | ||
{ | ||
public INPC CreateNPC(IPacket packet) | ||
{ | ||
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); | ||
return npc; | ||
} | ||
} | ||
|
||
public interface INPCFromPacketFactory | ||
{ | ||
INPC CreateNPC(IPacket packet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Extensions; | ||
using EOLib.Domain.Login; | ||
using EOLib.Domain.Map; | ||
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 INPCFromPacketFactory _npcFromPacketFactory; | ||
private readonly IEIFFileProvider _eifFileProvider; | ||
|
||
public override PacketFamily Family => PacketFamily.MapInfo; | ||
|
||
public override PacketAction Action => PacketAction.Reply; | ||
|
||
public MapInfoHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICurrentMapStateRepository currentMapStateRepository, | ||
ICharacterFromPacketFactory characterFromPacketFactory, | ||
INPCFromPacketFactory npcFromPacketFactory, | ||
IEIFFileProvider eifFileProvider | ||
) | ||
: base(playerInfoProvider) | ||
{ | ||
_currentMapStateRepository = currentMapStateRepository; | ||
_characterFromPacketFactory = characterFromPacketFactory; | ||
_npcFromPacketFactory = npcFromPacketFactory; | ||
_eifFileProvider = eifFileProvider; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var numOfEntities = packet.ReadChar(); | ||
|
||
if (packet.PeekByte() == 0xFF) | ||
{ | ||
packet.ReadByte(); | ||
for (var i = 0; i < numOfEntities; 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; | ||
if (packet.ReadByte() != 255) | ||
throw new MalformedPacketException("Missing 255 byte after character data", packet); | ||
} | ||
} | ||
|
||
while (packet.ReadPosition < packet.Length) | ||
{ | ||
var npc = _npcFromPacketFactory.CreateNPC(packet); | ||
_currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == npc.Index); | ||
_currentMapStateRepository.NPCs.Add(npc); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.