forked from marcosvf132/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatureUpdate.cs
More file actions
87 lines (77 loc) · 3.32 KB
/
CreatureUpdate.cs
File metadata and controls
87 lines (77 loc) · 3.32 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
82
83
84
85
86
87
using System;
using OXGaming.TibiaAPI.Appearances;
using OXGaming.TibiaAPI.Constants;
using OXGaming.TibiaAPI.Creatures;
using System.Collections.Generic;
namespace OXGaming.TibiaAPI.Network.ServerPackets
{
public class CreatureUpdate : ServerPacket
{
public List<(uint id, bool update, ushort counter)> Icons { get; } = new List<(uint id, bool update, ushort counter)>();
public byte UnknownByte1 { get; set; }
public Creature Creature { get; set; }
public ushort CreatureType { get; set; }
public ushort Counter { get; set; }
public uint CreatureId { get; set; }
public byte ManaPercent { get; set; }
public bool Status { get; set; }
public byte Vocation { get; set; }
public byte Type { get; set; }
public bool Update { get; set; }
public bool ShowIcon { get; set; }
public CreatureUpdate(Client client)
{
Client = client;
PacketType = ServerPacketType.CreatureUpdate;
}
public override void ParseFromNetworkMessage(NetworkMessage message)
{
CreatureId = message.ReadUInt32();
Type = message.ReadByte();
if (Type == (byte)CreatureUpdateType.Update) {
CreatureType = message.ReadUInt16();
Creature = message.ReadCreatureInstance(CreatureType);
if (Creature == null)
throw new Exception($"[CreatureUpdate.ParseFromNetworkMessage] Creature instance not found.");
} else if (Type == (byte)CreatureUpdateType.Mana) {
ManaPercent = message.ReadByte();
} else if (Type == (byte)CreatureUpdateType.Status) {
Status = message.ReadBool();
} else if (Type == (byte)CreatureUpdateType.Vocation) {
Vocation = message.ReadByte();
} else if (Type == (byte)CreatureUpdateType.Icon) {
Icons.Capacity = message.ReadByte();
for (var i = 0; i < Icons.Capacity; ++i) {
var id = message.ReadByte();
var update = message.ReadBool();
var counter = message.ReadUInt16();
Icons.Add((id, update, counter));
}
} else {
throw new Exception($"[CreatureUpdate.ParseFromNetworkMessage] Unknown creature update type '{Type}'.");
}
}
public override void AppendToNetworkMessage(NetworkMessage message)
{
message.Write((byte)ServerPacketType.CreatureUpdate);
message.Write(CreatureId);
message.Write(Type);
if (Type == (byte)CreatureUpdateType.Update) {
message.Write(Creature, (CreatureInstanceType) CreatureType);
} else if (Type == (byte)CreatureUpdateType.Mana) {
message.Write(ManaPercent);
} else if (Type == (byte)CreatureUpdateType.Status) {
message.Write(Status);
} else if (Type == (byte)CreatureUpdateType.Vocation) {
message.Write(Vocation);
} else if (Type == (byte)CreatureUpdateType.Icon) {
message.Write((byte)Icons.Capacity);
foreach (var icon in Icons) {
message.Write(icon.id);
message.Write(icon.update);
message.Write(icon.counter);
}
}
}
}
}