forked from jo3bingham/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteOnMap.cs
More file actions
81 lines (70 loc) · 3.04 KB
/
DeleteOnMap.cs
File metadata and controls
81 lines (70 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using OXGaming.TibiaAPI.Constants;
using OXGaming.TibiaAPI.Utilities;
namespace OXGaming.TibiaAPI.Network.ServerPackets
{
public class DeleteOnMap : ServerPacket
{
public Position Position { get; set; }
public uint CreatureId { get; set; }
public byte StackPosition { get; set; }
public DeleteOnMap(Client client)
{
Client = client;
PacketType = ServerPacketType.DeleteOnMap;
}
public override void ParseFromNetworkMessage(NetworkMessage message)
{
var x = message.ReadUInt16();
if (x != ushort.MaxValue)
{
Position = message.ReadPosition(x);
if (!Client.WorldMapStorage.IsVisible(Position.X, Position.Y, Position.Z, true))
{
throw new Exception($"[DeleteOnMap.ParseFromNetworkMessage] Co-ordinate {Position} is out of range.");
}
var mapPosition = Client.WorldMapStorage.ToMap(Position);
StackPosition = message.ReadByte();
var existingObject = Client.WorldMapStorage.GetObject(mapPosition.X, mapPosition.Y, mapPosition.Z, StackPosition);
if (existingObject == null)
{
throw new Exception("[DeleteOnMap.ParseFromNetworkMessage] Object not found.");
}
var existingCreature = Client.CreatureStorage.GetCreature(existingObject.Data);
if (existingCreature == null && existingObject.Id == (uint)CreatureInstanceType.Creature)
{
throw new Exception($"[DeleteOnMap.ParseFromNetworkMessage] Creature not found: {existingObject.Data}");
}
Client.WorldMapStorage.DeleteObject(mapPosition.X, mapPosition.Y, mapPosition.Z, StackPosition);
}
else
{
CreatureId = message.ReadUInt32();
var existingCreature = Client.CreatureStorage.GetCreature(CreatureId);
if (existingCreature == null)
{
throw new Exception($"[DeleteOnMap.ParseFromNetworkMessage] Creature not found: {CreatureId}");
}
var creaturePosition = existingCreature.Position;
if (!Client.WorldMapStorage.IsVisible(creaturePosition.X, creaturePosition.Y, creaturePosition.Z, true))
{
throw new Exception($"[DeleteOnMap.ParseFromNetworkMessage] Co-ordinate {creaturePosition} is out of range.");
}
}
}
public override void AppendToNetworkMessage(NetworkMessage message)
{
message.Write((byte)ServerPacketType.DeleteOnMap);
if (Position.X != ushort.MaxValue)
{
message.Write(Position);
message.Write(StackPosition);
}
else
{
message.Write(ushort.MaxValue);
message.Write(CreatureId);
}
}
}
}