forked from marcosvf132/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarketBrowse.cs
More file actions
69 lines (53 loc) · 2.37 KB
/
MarketBrowse.cs
File metadata and controls
69 lines (53 loc) · 2.37 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
using System;
using System.Collections.Generic;
using OXGaming.TibiaAPI.Constants;
using OXGaming.TibiaAPI.Market;
namespace OXGaming.TibiaAPI.Network.ServerPackets
{
public class MarketBrowse : ServerPacket
{
public List<Offer> BuyOffers { get; } = new List<Offer>();
public List<Offer> SellOffers { get; } = new List<Offer>();
public ushort TypeId { get; set; }
public byte Tier { get; set; }
public MarketBrowse(Client client)
{
Client = client;
PacketType = ServerPacketType.MarketBrowse;
}
public override void ParseFromNetworkMessage(NetworkMessage message)
{
var classification = message.ReadByte();
TypeId = message.ReadUInt16();
var obectType = Client.AppearanceStorage.GetObjectType(TypeId);
if (obectType == null)
throw new Exception($"[MarketDetail.ParseFromNetworkMessage] Object type not found.");
if (obectType.Flags.Upgradeclassification != null)
Tier = message.ReadByte();
BuyOffers.Capacity = (int)message.ReadUInt32();
for (uint i = 0; i < BuyOffers.Capacity; ++i)
BuyOffers.Add(message.ReadMarketOffer((int)MarketOfferType.Buy, TypeId));
SellOffers.Capacity = (int)message.ReadUInt32();
for (uint i = 0; i < SellOffers.Capacity; ++i)
SellOffers.Add(message.ReadMarketOffer((int)MarketOfferType.Sell, TypeId));
}
public override void AppendToNetworkMessage(NetworkMessage message)
{
message.Write((byte)ServerPacketType.MarketBrowse);
message.Write(TypeId);
var obectType = Client.AppearanceStorage.GetObjectType(TypeId);
if (obectType == null)
throw new Exception($"[MarketDetail.ParseFromNetworkMessage] Object type not found.");
if (obectType.Flags.Upgradeclassification != null)
message.Write(Tier);
var count = Math.Min(BuyOffers.Count, uint.MaxValue);
message.Write((uint)count);
for (var i = 0; i < count; ++i)
message.Write(BuyOffers[i], TypeId);
count = Math.Min(SellOffers.Count, uint.MaxValue);
message.Write((uint)count);
for (var i = 0; i < count; ++i)
message.Write(SellOffers[i], TypeId);
}
}
}