#pragma once
#include "stdafx.h"
#include "ApcItem.h"
enum enumUIOBJ_TYPE{LOCALPLAYER_TYPE=0x0000,CREATURE_TYPE=0x0001,LOCALPLAYERPACKAGE_TYPE=0x0002};
template<typename T1>
class UIObj;
template<typename T1>
class UIObjProperty
{
public:
UIObjProperty()
:m_ObjID(INVALID_OBJECT_ID)
,m_pUIObj(NULL)
{}
~UIObjProperty(){}
void SetObjID(T1 ObjID)
{
m_ObjID = ObjID;
}
T1 GetObjID()
{
return m_ObjID;
}
void SetUIObj(UIObj<T1>* pUIObj)
{
m_pUIObj = pUIObj;
}
UIObj<T1>* GetUIObj()
{
return m_pUIObj;
}
private:
T1 m_ObjID;
UIObj<T1>* m_pUIObj;
};
template<typename T>
class UIObjProperty_Creature : public UIObjProperty<T>
{
public:
UIObjProperty_Creature()
:m_strName("")
,m_ulHP(0)
,m_ulMP(0)
,m_ulSP(0)
,m_ulLevel(0)
,m_uint64EXP(0)
{
}
~UIObjProperty_Creature()
{
}
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationName,m_strName,string)
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationHP,m_ulHP,unsigned long)
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationMP,m_ulMP,unsigned long)
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationSP,m_ulSP,unsigned long)
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationLevel,m_ulLevel,unsigned long)
GET_OR_SET_ATTRIBUTE_FUNCTIONDEFINE_EX(OperationEXP,m_uint64EXP,unsigned __int64)
private:
string m_strName;
unsigned long m_ulHP;
unsigned long m_ulMP;
unsigned long m_ulSP;
unsigned long m_ulLevel;
unsigned __int64 m_uint64EXP;
};
template<typename T1,typename T2>
class UIObjProperty_Package : public UIObjProperty<T1>
{
public:
UIObjProperty_Package()
{
m_mapApcItemGrid.clear();
}
~UIObjProperty_Package()
{
for (map<T1,T2*>::iterator iter=m_mapApcItemGrid.begin();iter!=m_mapApcItemGrid.end();++iter)
delete iter->second;
m_mapApcItemGrid.clear();
}
bool IsEmptyPackage()
{
return m_mapApcItemGrid.empty();
}
bool InsertApcItem(T1 ObjID,T2* pApcItemGrid)
{
if (!pApcItemGrid || (m_mapApcItemGrid.find(ObjID) != m_mapApcItemGrid.end()))
return false;
m_mapApcItemGrid.insert(::make_pair<T1,T2*>(ObjID,pApcItemGrid));
return true;
}
void RemoveApcItem(T1 ObjID)
{
if (IsEmptyPackage())
return ;
if (m_mapApcItemGrid.find(ObjID) == m_mapApcItemGrid.end())
return ;
delete m_mapApcItemGrid[ObjID];
m_mapApcItemGrid.erase(ObjID);
}
bool QueryApcItem(T1 ObjID,T2** ppApcItemGrid)
{
*ppApcItemGrid = NULL;
if (IsEmptyPackage())
return false;
if (m_mapApcItemGrid.find(ObjID) == m_mapApcItemGrid.end())
return false;
*ppApcItemGrid = m_mapApcItemGrid[ObjID];
return false;
}
//private:
map<T1,T2*> m_mapApcItemGrid;
};
template<typename T1>
class UIObj
{
public:
UIObj()
{
m_mapObjProperty.clear();
}
~UIObj()
{
for (map<enumUIOBJ_TYPE,UIObjProperty<T1>*>::iterator iter=m_mapObjProperty.begin();iter!=m_mapObjProperty.end();++iter)
delete iter->second;
m_mapObjProperty.clear();
}
bool IsHasProperty(enumUIOBJ_TYPE UIObjType)
{
if (m_mapObjProperty.empty() || (m_mapObjProperty.find(UIObjType) == m_mapObjProperty.end()))
return false;
return true;
}
bool InsertProperty(enumUIOBJ_TYPE UIObjType)
{
if (m_mapObjProperty.find(UIObjType) != m_mapObjProperty.end())
return true;
UIObjProperty<T1>* pUIObjProperty = NULL;
switch (UIObjType)
{
case CREATURE_TYPE:
case LOCALPLAYER_TYPE:
pUIObjProperty = new UIObjProperty_Creature<T1>;
break;
default:
return false;
}
pUIObjProperty->SetUIObj(this);
m_mapObjProperty.insert(::make_pair<enumUIOBJ_TYPE,UIObjProperty<T1>*>(UIObjType,pUIObjProperty));
}
template<typename T>
bool QueryProperty(enumUIOBJ_TYPE UIObjType,T** ppT)
{
*ppT = NULL;
if (!IsHasProperty(UIObjType))
return false;
*ppT = static_cast<T*>(m_mapObjProperty[UIObjType]);
return true;
}
protected:
map<enumUIOBJ_TYPE,UIObjProperty<T1>*> m_mapObjProperty;
};