#include <string>
#include "RoleDataEx.h"

using namespace std;

//-----------------------------------------------------------------------------
int RoleDataEx::GetAttachRuneCount(ItemFieldStruct* item)
{
	if ( item == NULL )
		return 0;

	int count = 0;
	for (int i = 0; i < 4; i++)
	{
		GameObjDbStruct* itemDB = St_GetObjDB(item->Rune[i]);
		if ( itemDB && itemDB->Item.Class == EM_Item_Rune )
			count++;
	}
	return count;
}

//-----------------------------------------------------------------------------
int	RoleDataEx::GetRuneTotalVolume(ItemFieldStruct* item)
{	
	if (item == NULL)
		return 0;
	
	int total = item->RuneVolume;
	for(int i = 0; i < 4; i++)
	{
		GameObjDbStruct* itemDB = St_GetObjDB(item->Rune[i]);
		if ( itemDB && itemDB->Item.Class == EM_Item_Rune )
			total += itemDB->Item.Volume;
	}
	return total;
}

//-----------------------------------------------------------------------------
bool RoleDataEx::GetItemFieldName(ItemFieldStruct* item, char* outName, int size)
{
	if ( item && outName )
	{
		GameObjDbStruct* itemDB = St_GetObjDB(item->OrgObjID);
		if ( itemDB )
		{
			string tmp;

			tmp.clear();
			if ( item->Inherent != 0 )
			{
				GameObjDbStruct* inherit = St_GetObjDB(item->Inherent);
				if ( inherit && inherit->Classification == EM_ObjectClass_Attribute )
					tmp = inherit->Name;
			}
			tmp += itemDB->Name;

			strncpy( outName, tmp.c_str(), size - 1 );
			return true;
		}
	}

	return false;
}