using System;
using System.IO;
using GameServer.Enums;
using ServerEngine.PacketManagement.StaticConvert;
namespace GameServer.ServerData.Items
{
public class ItemStat
{
private readonly ItemStatEnums stat;
private readonly byte value1;
private readonly byte value2;
///
/// Create a new instance of the class
///
///
/// The item-stat found wihtin the enums
///
///
/// This is the first byte of the itemstat, read in littleendian
///
///
/// This is the second byte of the itemstat, read in littleendian
///
public ItemStat(ItemStatEnums stat, byte value1, byte value2)
{
this.stat = stat;
this.value1 = value1;
this.value2 = value2;
}
///
/// Creates a new instance of the class
///
///
/// The raw data of the stat in littleendian byteorder
///
public ItemStat(byte[] rawData)
{
using (var ms = new MemoryStream(rawData))
{
byte buf1 = 0;
ushort buf2 = 0;
RawConverter.ReadByte(ref buf1, ms);
value1 = buf1;
RawConverter.ReadByte(ref buf1, ms);
value2 = buf1;
RawConverter.ReadUInt16(ref buf2, ms);
stat = (ItemStatEnums) Enum.ToObject(typeof (ItemStatEnums), buf2);
}
}
///
/// This property is the second byte (littleendian) of the ItemStat
/// It may be some sort of value or ID...
///
public byte Value2
{
get { return value2; }
}
///
/// This property is the first byte (littleendian) of the ItemStat
/// It may be some sort of value or ID...
///
public byte Value1
{
get { return value1; }
}
///
/// This represents the item stat.
///
public ItemStatEnums Stat
{
get { return stat; }
}
///
/// Generates the GW-Item-Stat code out of this object's data
///
public UInt32 Compile()
{
return (UInt32)(
((ushort) stat << 16) |
(value2 << 8) |
value1);
}
}
}