2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "cPacket_ItemData.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-17 06:18:07 -04:00
|
|
|
int cPacket_ItemData::Parse(cByteBuffer & a_Buffer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
int TotalBytes = 0;
|
2012-08-18 05:56:28 -04:00
|
|
|
HANDLE_PACKET_READ(ReadBEShort, m_Dst.m_ItemType, TotalBytes);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
if (m_Dst.m_ItemType <= -1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
m_Dst.Empty();
|
2012-06-14 09:06:06 -04:00
|
|
|
return TotalBytes;
|
|
|
|
}
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
HANDLE_PACKET_READ(ReadChar, m_Dst.m_ItemCount, TotalBytes);
|
|
|
|
HANDLE_PACKET_READ(ReadBEShort, m_Dst.m_ItemDamage, TotalBytes);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
if (cItem::IsEnchantable(m_Dst.m_ItemType))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
short EnchantNumBytes;
|
|
|
|
HANDLE_PACKET_READ(ReadBEShort, EnchantNumBytes, TotalBytes);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
if (EnchantNumBytes > 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
// TODO: Enchantment not implemented yet!
|
2012-08-18 05:56:28 -04:00
|
|
|
a_Buffer.SkipRead(EnchantNumBytes);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TotalBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cPacket_ItemData::GetSize(short a_ItemID)
|
|
|
|
{
|
|
|
|
if(a_ItemID <= -1)
|
|
|
|
return 2;
|
|
|
|
if(cItem::IsEnchantable((ENUM_ITEM_ID) a_ItemID))
|
|
|
|
return 7;
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
void cPacket_ItemData::AppendItem(AString & a_Data, const cItem & a_Item)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
return AppendItem(a_Data, a_Item.m_ItemType, a_Item.m_ItemCount, a_Item.m_ItemDamage);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
void cPacket_ItemData::AppendItem(AString & a_Data, short a_ItemType, char a_Quantity, short a_Damage)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
short ItemType = a_ItemType;
|
|
|
|
ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
|
|
|
|
if (ItemType <= 0)
|
|
|
|
{
|
|
|
|
// Fix, to make sure no invalid values are sent.
|
|
|
|
ItemType = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendShort(a_Data, ItemType);
|
|
|
|
if (a_ItemType > -1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
AppendByte (a_Data, a_Quantity);
|
|
|
|
AppendShort(a_Data, a_Damage);
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
if (cItem::IsEnchantable(a_ItemType))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
// TODO: Implement enchantments
|
|
|
|
AppendShort(a_Data, (short) -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|