forked from jo3bingham/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarketStatistics.cs
More file actions
43 lines (38 loc) · 1.35 KB
/
MarketStatistics.cs
File metadata and controls
43 lines (38 loc) · 1.35 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
using System;
using System.Collections.Generic;
using OXGaming.TibiaAPI.Constants;
namespace OXGaming.TibiaAPI.Network.ServerPackets
{
public class MarketStatistics : ServerPacket
{
public List<(ushort ObjectId, uint Price)> MarketObjects { get; } =
new List<(ushort ObjectId, uint Price)>();
public MarketStatistics(Client client)
{
Client = client;
PacketType = ServerPacketType.MarketStatistics;
}
public override void ParseFromNetworkMessage(NetworkMessage message)
{
MarketObjects.Capacity = message.ReadUInt16();
for (var i = 0; i < MarketObjects.Capacity; ++i)
{
var objectId = message.ReadUInt16();
var price = message.ReadUInt32();
MarketObjects.Add((objectId, price));
}
}
public override void AppendToNetworkMessage(NetworkMessage message)
{
message.Write((byte)ServerPacketType.MarketStatistics);
var count = Math.Min(MarketObjects.Count, ushort.MaxValue);
message.Write((ushort)count);
for (var i = 0; i < count; ++i)
{
var (ObjectId, Price) = MarketObjects[i];
message.Write(ObjectId);
message.Write(Price);
}
}
}
}