2018-12-01 02:44:40 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-12-01 20:17:51 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
2018-12-01 02:44:40 -05:00
|
|
|
|
using OpenDiablo2.Common.Models.Mobs;
|
|
|
|
|
|
2018-12-01 20:17:51 -05:00
|
|
|
|
namespace OpenDiablo2.Common.Models
|
2018-12-01 02:44:40 -05:00
|
|
|
|
{
|
|
|
|
|
public sealed class PlayerLocationDetails
|
|
|
|
|
{
|
|
|
|
|
public int PlayerId { get; set; }
|
|
|
|
|
public float PlayerX { get; set; }
|
|
|
|
|
public float PlayerY { get; set; }
|
2018-12-01 20:17:51 -05:00
|
|
|
|
public eMovementType MovementType { get; set; }
|
|
|
|
|
public int MovementDirection { get; set; }
|
2018-12-01 02:44:40 -05:00
|
|
|
|
// TODO: They may not be on the same 'anchor map'...
|
|
|
|
|
|
|
|
|
|
public byte[] GetBytes()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<byte>();
|
2018-12-01 20:17:51 -05:00
|
|
|
|
result.AddRange(BitConverter.GetBytes((Int32)PlayerId));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes((float)PlayerX));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes((float)PlayerY));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes((Int32)MovementDirection));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes((byte)MovementType));
|
2018-12-01 02:44:40 -05:00
|
|
|
|
return result.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PlayerLocationDetails FromBytes(byte[] data, int offset = 0)
|
|
|
|
|
=> new PlayerLocationDetails
|
|
|
|
|
{
|
|
|
|
|
PlayerId = BitConverter.ToInt32(data, offset + 0),
|
|
|
|
|
PlayerX = BitConverter.ToSingle(data, offset + 4),
|
2018-12-01 20:17:51 -05:00
|
|
|
|
PlayerY = BitConverter.ToSingle(data, offset + 8),
|
|
|
|
|
MovementDirection = BitConverter.ToInt32(data, offset + 12),
|
|
|
|
|
MovementType = (eMovementType)data[offset + 16]
|
2018-12-01 02:44:40 -05:00
|
|
|
|
};
|
|
|
|
|
|
2018-12-01 20:17:51 -05:00
|
|
|
|
public static int SizeInBytes => 17;
|
2018-12-01 02:44:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PlayerLocationDetailsExtensions
|
|
|
|
|
{
|
|
|
|
|
public static PlayerLocationDetails ToPlayerLocationDetails(this PlayerState source)
|
|
|
|
|
=> new PlayerLocationDetails
|
|
|
|
|
{
|
|
|
|
|
PlayerId = source.Id,
|
|
|
|
|
PlayerX = source.GetPosition().X,
|
2018-12-01 20:17:51 -05:00
|
|
|
|
PlayerY = source.GetPosition().Y,
|
|
|
|
|
MovementType = source.MovementType,
|
|
|
|
|
MovementDirection = source.MovementDirection
|
2018-12-01 02:44:40 -05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|