2018-12-08 13:11:52 -05:00
|
|
|
|
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-12-01 02:44:40 -05:00
|
|
|
|
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-08 01:01:30 -05:00
|
|
|
|
public float MovementSpeed { 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-08 13:11:52 -05:00
|
|
|
|
result.AddRange(BitConverter.GetBytes(PlayerId));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(PlayerX));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(PlayerY));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(MovementDirection));
|
2018-12-01 20:17:51 -05:00
|
|
|
|
result.AddRange(BitConverter.GetBytes((byte)MovementType));
|
2018-12-08 13:11:52 -05:00
|
|
|
|
result.AddRange(BitConverter.GetBytes(MovementSpeed));
|
2018-12-01 02:44:40 -05:00
|
|
|
|
return result.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PlayerLocationDetails FromBytes(byte[] data, int offset = 0)
|
2018-12-08 01:01:30 -05:00
|
|
|
|
{
|
|
|
|
|
var result = new PlayerLocationDetails
|
2018-12-01 02:44:40 -05:00
|
|
|
|
{
|
|
|
|
|
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),
|
2018-12-08 01:01:30 -05:00
|
|
|
|
MovementType = (eMovementType)data[offset + 16],
|
|
|
|
|
MovementSpeed = BitConverter.ToSingle(data, offset + 18)
|
2018-12-01 02:44:40 -05:00
|
|
|
|
};
|
2018-12-08 01:01:30 -05:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
public static int SizeInBytes => 22;
|
2018-12-01 02:44:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PlayerLocationDetailsExtensions
|
|
|
|
|
{
|
|
|
|
|
public static PlayerLocationDetails ToPlayerLocationDetails(this PlayerState source)
|
2018-12-08 01:01:30 -05:00
|
|
|
|
{
|
|
|
|
|
var result = new PlayerLocationDetails
|
2018-12-01 02:44:40 -05:00
|
|
|
|
{
|
|
|
|
|
PlayerId = source.Id,
|
|
|
|
|
PlayerX = source.GetPosition().X,
|
2018-12-01 20:17:51 -05:00
|
|
|
|
PlayerY = source.GetPosition().Y,
|
|
|
|
|
MovementType = source.MovementType,
|
2018-12-08 01:01:30 -05:00
|
|
|
|
MovementDirection = source.MovementDirection,
|
2018-12-08 13:11:52 -05:00
|
|
|
|
MovementSpeed = (source.MovementType == eMovementType.Running ? source.GetRunVelocity() : source.GetWalkVeloicty()) / 4f
|
2018-12-01 02:44:40 -05:00
|
|
|
|
};
|
2018-12-08 01:01:30 -05:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-12-01 02:44:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|