📄 gcharacter.h
字号:
//GCharacter.h
/*/////////////////////////////////////////////////////////////////
李亦
liease@163.com 4040719
2006-7-13
/*/////////////////////////////////////////////////////////////////
#ifndef _RPG__GCHARACTER_H_
#define _RPG__GCHARACTER_H_
#ifndef _RPG__RPGDEFINE_H_
#include "rpg/RPGDefine.h"
#endif
#ifndef _RPG__GEFFICACY_H_
#include "GEfficacy.h"
#endif
#ifndef _RPG__GSKILL_H_
#include "GSkill.h"
#endif
#ifndef _RPG__GGOODSARRAY_H_
#include "GGoodsArray.h"
#endif
#ifndef _RPG__GTASK_H_
#include "GTask.h"
#endif
#ifndef _RPG__RPGBASE_H_
#include "RPGBase.h"
#endif
#ifndef _RPGSETTING_H_
#include "rpg/RPGSetting.h"
#endif
class SceneObject;
namespace RPG
{
class GTaskBase;
typedef struct tagGCharacterResult
{
S32 nHP; //生命
S32 nMP; //魔法
//以下2成员,皆由等级、各类装备、技能综合得到的结果
S32 nHPMax; //生命最大值,
S32 nMPMax; //魔法最大值,
S32 nAttack; //攻击
S32 nDefence; //防御
/////////////////////////////////
//所有的人物都有力量、智力、体力、敏捷、精神(MENtality),还有等6种能力值。
GABILITIES abilities;
///////////////////////////////////
//附加能力值 extra abiliby
S32 eMagic; //魔力
S32 eStamina; //耐力
S32 eLuck; //幸运
F32 eMoveSpeed; //移动速度,运算结果
F32 eMoveRate; //移动比率,n/10000
}GCHARACTERRESULT;
/////////////////////////////////////////////////////////////////
//人物属性
typedef struct tagGCharacter
{
////////////////////////////////////////////////////////
StringTableEntry pCharName;
U32 dwLevel; //等级
U32 dwExp; //经验
EGGender gender; //性别
EGCareer career; //职业类型
EGClan clan; //部族类型
EGZone zone; //人种区域
EGBodyTypes bodyType;//
GCHARACTERRESULT dataResult;
//S32 nHP; //生命
//S32 nMP; //魔法
////以下2成员,皆由等级、各类装备、技能综合得到的结果
//S32 nHPMax; //生命最大值,
//S32 nMPMax; //魔法最大值,
//S32 nAttack; //攻击
//S32 nDefence; //防御
///////////////////////////////////
////基本能力值 base ability pointer
////所有的人物都有力量、智力、体力、敏捷、精神(MENtality),还有等6种能力值。
//GABILITIES abilities;
/////////////////////////////////////
////附加能力值 extra abiliby
//S32 eMagic; //魔力
//S32 eStamina; //耐力
//S32 eLuck; //幸运
//S32 eMoveSpeed; //移动速度,运算结果
///////////////////////////////////
//携带相关
S32 nMoney; //身上金钱
F32 x,y,z,rot;
}GCHARACTER;
//////////////////////////////////////////////////////////
//属性存取定义宏
#define DELCARE_CHARACTER_PRY(Name,pre,type)\
inline const type Get##Name()const{ return m_dataCharacter.##pre##Name;}
#define DELCARE_CHARACTER_PRY2(Name,field,type)\
inline const type Get##Name()const{ return m_dataCharacter.##field;}
#define DELCARE_CHARACTER_F32(Name,field)\
DELCARE_CHARACTER_PRY2(Name,field,F32);\
inline const S32 Get##Name##Int()const{ return (S32)mFloor(m_dataCharacter.##field);}
#define DELCARE_CHARACTER_U32(Name) DELCARE_CHARACTER_PRY(Name,dw,U32)
#define DELCARE_CHARACTER_S32(Name) DELCARE_CHARACTER_PRY(Name,n,S32)
#define DELCARE_CHARACTER_STE(Name) DELCARE_CHARACTER_PRY(Name,p,StringTableEntry)
#define DELCARE_CHARACTERRESULT_S32(Name) DELCARE_CHARACTER_PRY(Name,dataResult.n,S32)
//////////////////////////////////////////////////////////////////////////
#define DECLARE_CHAR_TYPE0(CLASSNAME,NAME,FIELD,KIND)\
StringTableEntry Get##NAME##KIND()\
{\
AssertWarn(g_pRPGSetting,"需要创建RPGSetting实例");\
return g_pRPGSetting->Get##NAME##KIND(m_dataCharacter.##FIELD);\
}
#define DECLARE_CHAR_TYPE(CLASSNAME,NAME,FIELD)\
DECLARE_CHAR_TYPE0(CLASSNAME,NAME,FIELD,Name);\
DECLARE_CHAR_TYPE0(CLASSNAME,NAME,FIELD,Label)
//////////////////////////////////////////////////////////////////////////
#define CONSOLEMETHOD_CHAR_TYPE0(CLASSNAME,NAME,KIND,NAME2,KIND2)\
ConsoleMethod(CLASSNAME,Get##NAME##KIND,const char*, 2,2,"Object.Get"##NAME2##KIND2##"()")\
{\
argc;argv;\
return object->Get##NAME##KIND();\
}
#define CONSOLEMETHOD_CHAR_TYPE(CLASSNAME,NAME,NAME2)\
CONSOLEMETHOD_CHAR_TYPE0(CLASSNAME,NAME,Label,NAME2,"Label");\
CONSOLEMETHOD_CHAR_TYPE0(CLASSNAME,NAME,Name,NAME2,"Name")
//////////////////////////////////////////////////////////////////////////
#define CONSOLEMETHOD_CHAR_STR(CLASSNAME,NAME,NAME2)\
ConsoleMethod(CLASSNAME,NAME,const char*, 2,2,"Object."##NAME2##"();")\
{\
argc;argv;\
return object->NAME();\
}
#define CONSOLEMETHOD_CHAR_VOID(CLASSNAME,NAME,NAME2)\
ConsoleMethod(CLASSNAME,NAME,void, 2,2,"Object."##NAME2##"();")\
{\
argc;argv;\
object->NAME();\
}
/////////////////////////////////////////////////////////////////
// 人物基本封装
//
class GCharacter : public RPGBase
{
typedef RPGBase Parent;
friend class RPGDatabase;
friend class RPGSetting;
//U32 m_dwID;
protected:
GCHARACTER m_dataCharacter; //自身数据,因为GCHARACTER可能存在子类,故使用指针较为适合
GCHARACTERRESULT m_dataResult;
GCHARACTERRESULT m_dataAffect;
#ifdef TGE_RPGCLIENT
struct CharAction
{
U32 dwCmd;
union{
U32 dwData;
STE sData;
};
};
Vector<CharAction> m_arActionQueues;
#endif
public:
GGoodsArray m_arEquipments; //装备槽
GGoodsArray m_arBagGoods; //怪物身上拥有物品,也可能是检回来的
Vector<GSKILL*> m_arSkills; //怪物所能技能
public:
#ifdef TGE_RPGCLIENT
enum
{
CA_PLAYMOTION
};
#endif
enum EGCharacterMasks
{
//InitialUpdateMask = 1,//Parent::NextFreeMask,
};
enum EGCharacterClears
{
PCS_ALL = 0xFFFFFFFF,
PCS_EQUIPMENTS = BIT(0),
PCS_BAGGOODS = BIT(1),
PCS_SKILLS = BIT(2),
PCS_LAST = 3
};
enum EGTShapeUpdate
{
TSU_ALL = -1,
TSU_EQUIPS = BIT(0),
TSU_POS = BIT(1),
TSU_PROPERTY = BIT(2),
TSU_MOVE = BIT(3),
TSU_EFFICACY = TSU_MOVE,
TSU_BAG = BIT(4),
TSU_EQUIPSLOT = BIT(5),
};
public:
//构造/析构函数
GCharacter();
virtual ~GCharacter();
public:
virtual void ClearData(U32 dwState){}
virtual void SetCharacter(EGCareer career,EGClan clan,EGZone zone,U32 dwLevel=0);
///@name 人物控制
///@{
#ifdef TGE_RPGCLIENT
void AddAction(U32 uCmd,U32 dwData);
virtual void UpdateToUI(GGoodsArray* pSlot,U32 nIndex);
virtual void UpdateToTShape(U32 nUpdates=TSU_ALL);
virtual void UpdateEquipToTShape(EGEquipTypes slot,GGoods* pEquip,BOOL bUpdate=TRUE);
#endif
virtual bool PlayMotion (StringTableEntry pIconTag);
void SetPos(Point3F &ptPos);
//void MoveTo(Point3F &ptPos);
void CalcEquipMoveSpeed();
bool AffectMoveSpeed(F32 fSpeed);
bool AffectMoveRate(F32 fRate);
bool AddMoney(S32 nMoney);
bool ExistGoods(U32 nGoodsCode, EGGoodsKind kind, U32 nLevel, U32 nAmount);
bool RemoveGoods(U32 nGoodsCode, EGGoodsKind kind, U32 nLevel, U32 nAmount);
bool ExistGoods(const GGOODSREF& ref);
bool RemoveGoods(const GGOODSREF& ref);
bool AddGoods(const GGOODSREF& ref);
//bool ExistGoods(const GEFFICACY& effData,GNpc* pNpc=NULL,GTaskBase* pTask=NULL);
//bool RemoveGoods(const GEFFICACY& effData,GNpc* pNpc=NULL,GTaskBase* pTask=NULL);
//bool AddGoods(const GEFFICACY& effData,GNpc* pNpc=NULL,GTaskBase* pTask=NULL);
//bool AddGoods(U32 nGoodsCode, EGGoodsKind kind, U32 nLevel,GEfficacy* pEfficacy, U32 nAmount);
U32 AddGoodsToBag (GGoods* pGGoods,GGoodsArray*& pOwnerAdd);
U32 ApplyGoodsToEquip (GGoods* pGGoods,U32 nBagIndex,GGoodsArray*& pOwnerAdd);
#ifdef TGE_RPGCLIENT
void AddSkinModifier(U32 slot, StringTableEntry skinName, StringTableEntry printName);
void RemoveSkinModifier(U32 slot);
void ClearSkinModifiers();
void WearEquipment(EGEquipTypes slot,GGoods* pEquip);
#endif
///@}
#ifdef TGE_RPGCLIENT
///@name GameBase操作
///@{
GameBase* CreateGameBase(CSTR sClass);
bool AttachTSDatablock(GameBaseData* pGBDatablock);
///@}
#endif
public:
///@name 人物属性存取
///@{
DELCARE_CHARACTER_STE(CharName);
DELCARE_CHARACTER_U32(Level);
DELCARE_CHARACTER_U32(Exp);
DELCARE_CHARACTER_PRY2(Gender, gender, EGGender);
DELCARE_CHARACTER_PRY2(Career, career, EGCareer);
DELCARE_CHARACTER_PRY2(Clan, clan, EGClan);
DELCARE_CHARACTER_PRY2(Zone, zone, EGZone);
DELCARE_CHARACTER_PRY2(BodyType, bodyType, EGBodyTypes);
DELCARE_CHARACTER_F32(X, x);
DELCARE_CHARACTER_F32(Y, y);
DELCARE_CHARACTER_F32(Z, z);
DELCARE_CHARACTER_F32(Rot, rot);
DELCARE_CHARACTERRESULT_S32(HP);
DELCARE_CHARACTERRESULT_S32(MP);
DELCARE_CHARACTERRESULT_S32(HPMax);
DELCARE_CHARACTERRESULT_S32(MPMax);
DELCARE_CHARACTERRESULT_S32(Attack);
DELCARE_CHARACTERRESULT_S32(Defence);
DELCARE_CHARACTER_S32(Money);
///@}
///@name 人物逻辑控制
///@{
StringTableEntry GetTSName();
StringTableEntry GetPathTitle();
StringTableEntry GetInstName();
U32 SearchBagGoods (GGoods* pGGoods);
U32 RemoveBagGoods (GGoods* pGGoods);
void RemoveBagGoods (U32 nIndex);
GGoods* GetBagGoods (U32 nIndex);
U32 SearchEquipment (GGoods* pGGoods);
U32 RemoveEquipment (GGoods* pGGoods);
void RemoveEquipment (U32 nIndex);
GGoods* GetEquipment (U32 nIndex);
public:
DECLARE_CHAR_TYPE(GCharacter,Clan,clan);
DECLARE_CHAR_TYPE(GCharacter,Gender,gender);
DECLARE_CHAR_TYPE(GCharacter,Career,career);
///@}
public:
///@name 超类方法重写
///@{
//bool OnNewDataBlock(RPGBaseData* dptr);
//bool OnNewGameBase(GameBase* dptr);
void ProcessTick(const Move *move);
void InterpolateTick(F32 delta);
void AdvanceTime(F32 dt);
//void PreprocessMove(Move *move) {}
U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
void unpackUpdate(NetConnection *conn, BitStream *stream);
//bool onAdd();
//void onRemove();
//void inspectPostApply();
static void initPersistFields();
static void consoleInit();
///@}
public:
DECLARE_CONOBJECT(GCharacter);
};//GCharacter
//////////////////////////////////////////////////////////////////
inline StringTableEntry GCharacter::GetTSName()
{
AssertWarn(g_pRPGSetting,"需要RPGSetting实例");
CSTR pName = avar("%s_%s_%d", GetClanLabel(), GetGenderLabel(), m_dataCharacter.bodyType);
return StringTable->insert(pName);
}
inline StringTableEntry GCharacter::GetPathTitle()
{
AssertWarn(g_pRPGSetting,"需要RPGSetting实例");
CSTR pName = avar("%s%s", GetClanLabel(), m_dataCharacter.gender == GG_FEMALE?GetGenderLabel() : "");
return StringTable->insert(pName);
}
inline StringTableEntry GCharacter::GetInstName()
{
AssertWarn(g_pRPGSetting,"需要RPGSetting实例");
CSTR pName = avar("CharInst_%s_%s_%d", GetClanLabel(), GetGenderLabel(), m_dataCharacter.bodyType);
return StringTable->insert(pName);
}
/////////////////////////////////////
inline U32 GCharacter::SearchBagGoods(GGoods* pGGoods)
{
return m_arBagGoods.SearchCell(pGGoods);
}
inline U32 GCharacter::RemoveBagGoods(GGoods* pGGoods)
{
U32 nIndex= m_arBagGoods.SearchCell(pGGoods);
if(nIndex != -1)
{
m_arBagGoods[nIndex] = NULL;
#ifdef TGE_RPG
UpdateToUI(&m_arBagGoods,nIndex);
#endif
}
return nIndex;
}
inline void GCharacter::RemoveBagGoods(U32 nIndex)
{
if(nIndex < m_arBagGoods.size())
{
m_arBagGoods[nIndex] = NULL;
#ifdef TGE_RPG
UpdateToUI(&m_arBagGoods,nIndex);
#endif
}
}
inline GGoods* GCharacter::GetBagGoods(U32 nIndex)
{
if(nIndex < m_arBagGoods.size())
return m_arBagGoods[nIndex];
return NULL;
}
inline U32 GCharacter::SearchEquipment(GGoods* pGGoods)
{
return m_arEquipments.SearchCell(pGGoods);
}
inline U32 GCharacter::RemoveEquipment(GGoods* pGGoods)
{
U32 nIndex= m_arEquipments.SearchCell(pGGoods);
if(nIndex != -1)
{
m_arEquipments[nIndex] = NULL;
#ifdef TGE_RPG
UpdateToUI(&m_arEquipments,nIndex);
#endif
}
return nIndex;
}
inline void GCharacter::RemoveEquipment(U32 nIndex)
{
if(nIndex < m_arEquipments.size())
{
m_arEquipments[nIndex] = NULL;
#ifdef TGE_RPG
UpdateToUI(&m_arEquipments,nIndex);
#endif
}
}
inline GGoods* GCharacter::GetEquipment(U32 nIndex)
{
if(nIndex < m_arEquipments.size())
return m_arEquipments[nIndex];
return NULL;
}
};//namespace RPG
#endif //_GCHARACTER_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -