2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Item.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
#include <json/json.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-10 17:40:30 -04:00
|
|
|
cItem cItem::CopyOne(void) const
|
|
|
|
{
|
|
|
|
cItem res(*this);
|
|
|
|
res.m_ItemCount = 1;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-11 06:05:53 -04:00
|
|
|
short cItem::GetMaxDamage(void) const
|
|
|
|
{
|
|
|
|
switch (m_ItemType)
|
|
|
|
{
|
|
|
|
case E_ITEM_DIAMOND_AXE: return 1563;
|
|
|
|
case E_ITEM_DIAMOND_HOE: return 1563;
|
|
|
|
case E_ITEM_DIAMOND_PICKAXE: return 1563;
|
|
|
|
case E_ITEM_DIAMOND_SHOVEL: return 1563;
|
|
|
|
case E_ITEM_DIAMOND_SWORD: return 1563;
|
|
|
|
case E_ITEM_FLINT_AND_STEEL: return 65;
|
|
|
|
case E_ITEM_GOLD_AXE: return 32;
|
|
|
|
case E_ITEM_GOLD_HOE: return 32;
|
|
|
|
case E_ITEM_GOLD_PICKAXE: return 32;
|
|
|
|
case E_ITEM_GOLD_SHOVEL: return 32;
|
|
|
|
case E_ITEM_GOLD_SWORD: return 32;
|
|
|
|
case E_ITEM_IRON_AXE: return 251;
|
|
|
|
case E_ITEM_IRON_HOE: return 251;
|
|
|
|
case E_ITEM_IRON_PICKAXE: return 251;
|
|
|
|
case E_ITEM_IRON_SHOVEL: return 251;
|
|
|
|
case E_ITEM_IRON_SWORD: return 251;
|
|
|
|
case E_ITEM_SHEARS: return 251;
|
|
|
|
case E_ITEM_STONE_AXE: return 132;
|
|
|
|
case E_ITEM_STONE_HOE: return 132;
|
|
|
|
case E_ITEM_STONE_PICKAXE: return 132;
|
|
|
|
case E_ITEM_STONE_SHOVEL: return 132;
|
|
|
|
case E_ITEM_STONE_SWORD: return 132;
|
|
|
|
case E_ITEM_WOODEN_AXE: return 60;
|
|
|
|
case E_ITEM_WOODEN_HOE: return 60;
|
|
|
|
case E_ITEM_WOODEN_PICKAXE: return 60;
|
|
|
|
case E_ITEM_WOODEN_SHOVEL: return 60;
|
|
|
|
case E_ITEM_WOODEN_SWORD: return 60;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cItem::DamageItem(void)
|
|
|
|
{
|
|
|
|
short MaxDamage = GetMaxDamage();
|
|
|
|
if (MaxDamage == 0)
|
|
|
|
{
|
|
|
|
// Item doesn't have damage
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ItemDamage++;
|
|
|
|
return (m_ItemDamage >= MaxDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-10 15:52:03 -04:00
|
|
|
bool cItem::IsStackableWith(const cItem & a_OtherStack)
|
|
|
|
{
|
|
|
|
if (a_OtherStack.m_ItemType != m_ItemType)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: match enchantments etc.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cItem::GetJson( Json::Value & a_OutValue ) const
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
a_OutValue["ID"] = m_ItemType;
|
|
|
|
if( m_ItemType > 0 )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
a_OutValue["Count"] = m_ItemCount;
|
2013-01-11 23:46:01 -05:00
|
|
|
a_OutValue["Health"] = m_ItemDamage;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cItem::FromJson( const Json::Value & a_Value )
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
m_ItemType = (ENUM_ITEM_ID)a_Value.get("ID", -1 ).asInt();
|
|
|
|
if( m_ItemType > 0 )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_ItemCount = (char)a_Value.get("Count", -1 ).asInt();
|
2013-01-11 23:46:01 -05:00
|
|
|
m_ItemDamage = (short)a_Value.get("Health", -1 ).asInt();
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cItem::IsEnchantable(short item)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 256) && (item <= 259))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 267) && (item <= 279))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 283) && (item <= 286))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 290) && (item <= 294))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 298) && (item <= 317))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item >= 290) && (item <= 294))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
if ((item == 346) || (item == 359) || (item == 261))
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-18 05:56:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|