forked from jo3bingham/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectDailyReward.cs
More file actions
46 lines (40 loc) · 1.43 KB
/
CollectDailyReward.cs
File metadata and controls
46 lines (40 loc) · 1.43 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
using System;
using System.Collections.Generic;
using OXGaming.TibiaAPI.Constants;
namespace OXGaming.TibiaAPI.Network.ClientPackets
{
public class CollectDailyReward : ClientPacket
{
public List<(ushort ObjectId, byte Amount)> Rewards { get; } = new List<(ushort ObjectId, byte Amount)>();
public bool UseToken { get; set; }
public CollectDailyReward(Client client)
{
Client = client;
PacketType = ClientPacketType.CollectDailyReward;
}
public override void ParseFromNetworkMessage(NetworkMessage message)
{
UseToken = message.ReadBool();
Rewards.Capacity = message.ReadByte();
for (var i = 0; i < Rewards.Capacity; ++i)
{
var itemId = message.ReadUInt16();
var amount = message.ReadByte();
Rewards.Add((itemId, amount));
}
}
public override void AppendToNetworkMessage(NetworkMessage message)
{
message.Write((byte)ClientPacketType.CollectDailyReward);
message.Write(UseToken);
var count = Math.Min(Rewards.Count, byte.MaxValue);
message.Write((byte)count);
for (var i = 0; i < count; ++i)
{
var (ObjectId, Amount) = Rewards[i];
message.Write(ObjectId);
message.Write(Amount);
}
}
}
}