My Project
RpgCharacter.h
1 #pragma once
2 #include "BipedObject.h"
3 #include <vector>
4 namespace ParaEngine
5 {
6 
7  using namespace std;
8  // forward declare
9  //class CDnDCharacterAttribute;
10  struct CNpcDbItem;
11 
14  {
15  public:
18  // implementation of IAttributeFields
19 
21  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_CDndCharacterAttribute;}
23  virtual const char* GetAttributeClassName(){static const char name[] = "Typical DnD Character"; return name;}
25  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
27  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
28 
29  public:
31  float m_fLifePoint;
33  float m_fAge;
35  float m_fHeight;
38  float m_fWeight;
43 
45  float m_fStrength;
47  float m_fDexterity;
52  float m_fDefense, m_fDefenseflat, m_fDefenseMental;
55  float m_fAttackMelee, m_fAttackRanged, m_fAttackMental;
58 
61 
63  vector<int> m_skills;
65  vector<int> m_tools;
66  };
67 
73  class CRpgCharacter : public CBipedObject
74  {
75  public:
76  CRpgCharacter(void);
77  virtual ~CRpgCharacter(void);
78  virtual CBaseObject::_SceneObjectType GetType(){return CBaseObject::RPGBiped;};
79  public:
81  // implementation of IAttributeFields
82 
84  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_CRpgCharacter;}
86  virtual const char* GetAttributeClassName(){static const char name[] = "RPG Character"; return name;}
88  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
90  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
91 
92  ATTRIBUTE_METHOD1(CRpgCharacter, GetCharacterID_s, int*) {*p1 = cls->GetCharacterID(); return S_OK;}
93  ATTRIBUTE_METHOD1(CRpgCharacter, SetCharacterID_s, int) {cls->SetCharacterID(p1); return S_OK;}
94 
95  ATTRIBUTE_METHOD1(CRpgCharacter, GetCharacterType_s, int*) {*p1 = cls->GetCharacterType(); return S_OK;}
96  ATTRIBUTE_METHOD1(CRpgCharacter, SetCharacterType_s, int) {cls->SetCharacterType(p1); return S_OK;}
97 
98  ATTRIBUTE_METHOD1(CRpgCharacter, GetMentalState0_s, int*) {*p1 = cls->GetMentalState(0); return S_OK;}
99  ATTRIBUTE_METHOD1(CRpgCharacter, SetMentalState0_s, int) {cls->SetMentalState(0, (byte)p1); return S_OK;}
100  ATTRIBUTE_METHOD1(CRpgCharacter, GetMentalState1_s, int*) {*p1 = cls->GetMentalState(1); return S_OK;}
101  ATTRIBUTE_METHOD1(CRpgCharacter, SetMentalState1_s, int) {cls->SetMentalState(1, (byte)p1); return S_OK;}
102  ATTRIBUTE_METHOD1(CRpgCharacter, GetMentalState2_s, int*) {*p1 = cls->GetMentalState(2); return S_OK;}
103  ATTRIBUTE_METHOD1(CRpgCharacter, SetMentalState2_s, int) {cls->SetMentalState(2, (byte)p1); return S_OK;}
104  ATTRIBUTE_METHOD1(CRpgCharacter, GetMentalState3_s, int*) {*p1 = cls->GetMentalState(3); return S_OK;}
105  ATTRIBUTE_METHOD1(CRpgCharacter, SetMentalState3_s, int) {cls->SetMentalState(3, (byte)p1); return S_OK;}
106 
107 #ifndef DEFINE_ATTRIBUTE_METHODS_DND
108 #define DEFINE_ATTRIBUTE_METHODS_DND(type, AttriName) \
109  ATTRIBUTE_METHOD1(CRpgCharacter, Get##AttriName##_s, type*) {*p1 = cls->Get##AttriName(); return S_OK;}\
110  ATTRIBUTE_METHOD1(CRpgCharacter, Set##AttriName##_s, type) {cls->Set##AttriName(p1); return S_OK;}
111 #endif
112 
113  DEFINE_ATTRIBUTE_METHODS_DND(float, LifePoint);
114  DEFINE_ATTRIBUTE_METHODS_DND(float, Age);
115  DEFINE_ATTRIBUTE_METHODS_DND(float, BodyHeight);
116  DEFINE_ATTRIBUTE_METHODS_DND(float, Weight);
117  DEFINE_ATTRIBUTE_METHODS_DND(int, Occupation);
118  DEFINE_ATTRIBUTE_METHODS_DND(int, RaceSex);
119  DEFINE_ATTRIBUTE_METHODS_DND(float, Strength);
120  DEFINE_ATTRIBUTE_METHODS_DND(float, Dexterity);
121  DEFINE_ATTRIBUTE_METHODS_DND(float, Intelligence);
122  DEFINE_ATTRIBUTE_METHODS_DND(float, BaseDefense);
123  DEFINE_ATTRIBUTE_METHODS_DND(float, Defense);
124  DEFINE_ATTRIBUTE_METHODS_DND(float, Defenseflat);
125  DEFINE_ATTRIBUTE_METHODS_DND(float, DefenseMental);
126  DEFINE_ATTRIBUTE_METHODS_DND(float, BaseAttack);
127 
128  DEFINE_ATTRIBUTE_METHODS_DND(float, AttackMelee);
129  DEFINE_ATTRIBUTE_METHODS_DND(float, AttackRanged);
130  DEFINE_ATTRIBUTE_METHODS_DND(float, AttackMental);
131  DEFINE_ATTRIBUTE_METHODS_DND(float, MaxLifeLoad);
132  DEFINE_ATTRIBUTE_METHODS_DND(int, HeroPoints);
133  // TODO: define GetSkill and GetTool
134 
135  public:
138  CHAR_NPC,
139  CHAR_BOSS,
140  CHAR_HERO,
141  CHAR_SPAWN,
142  CHAR_NONE, // character without any attributes
143  };
144 
149  int GetCharacterID(){return m_nCharacterID;}
154  void SetCharacterID(int nID){m_nCharacterID = nID;}
155 
160  int GetCharacterType(){return m_nCharacterType;};
165  void SetCharacterType(int nType);
166 
172  DWORD GetMentalState(int nIndex);
178  void SetMentalState(int nIndex, DWORD data);
179 
181  //
182  // define a group of attribute get/set member functions.
183  //
185 #ifndef DEFINE_CLASS_ATTRIBUTE_DND
186  #define DEFINE_CLASS_ATTRIBUTE_DND(type, AttriName, memberName, defaultValue) \
187  type Get##AttriName(){return (m_pDnDAttribute!=0)?m_pDnDAttribute->memberName : defaultValue;} \
188  void Set##AttriName(type p1){if(m_pDnDAttribute!=0) m_pDnDAttribute->memberName = p1;}
189 #endif
190 
191  DEFINE_CLASS_ATTRIBUTE_DND(float, LifePoint, m_fLifePoint, 1);
192  DEFINE_CLASS_ATTRIBUTE_DND(float, Age, m_fAge, 1);
193  DEFINE_CLASS_ATTRIBUTE_DND(float, BodyHeight, m_fHeight, 1);
194  DEFINE_CLASS_ATTRIBUTE_DND(float, Weight, m_fWeight, 1);
195  DEFINE_CLASS_ATTRIBUTE_DND(int, Occupation, m_nOccupation, 1);
196  DEFINE_CLASS_ATTRIBUTE_DND(int, RaceSex, m_nRaceSex, 1);
197  DEFINE_CLASS_ATTRIBUTE_DND(float, Strength, m_fStrength, 1);
198  DEFINE_CLASS_ATTRIBUTE_DND(float, Dexterity, m_fDexterity, 1);
199  DEFINE_CLASS_ATTRIBUTE_DND(float, Intelligence, m_fIntelligence, 1);
200  DEFINE_CLASS_ATTRIBUTE_DND(float, BaseDefense, m_fBaseDefense, 1);
201  DEFINE_CLASS_ATTRIBUTE_DND(float, Defense, m_fDefense, 1);
202  DEFINE_CLASS_ATTRIBUTE_DND(float, Defenseflat, m_fDefenseflat, 1);
203  DEFINE_CLASS_ATTRIBUTE_DND(float, DefenseMental, m_fDefenseMental, 1);
204  DEFINE_CLASS_ATTRIBUTE_DND(float, BaseAttack, m_fBaseAttack, 1);
205  DEFINE_CLASS_ATTRIBUTE_DND(float, AttackMelee, m_fAttackMelee, 1);
206  DEFINE_CLASS_ATTRIBUTE_DND(float, AttackRanged, m_fAttackRanged, 1);
207  DEFINE_CLASS_ATTRIBUTE_DND(float, AttackMental, m_fAttackMental, 1);
208  DEFINE_CLASS_ATTRIBUTE_DND(float, MaxLifeLoad, m_fMaxLifeLoad, 1);
209  DEFINE_CLASS_ATTRIBUTE_DND(int, HeroPoints, m_nHeroPoints, 1);
210 
216  int GetSkill(int nIndex);
222  void SetSkill(int nIndex, int nSkillID);
223 
229  int GetTool(int nIndex);
235  void SetTool(int nIndex, int ntoolID);
236 
237 
243  bool ToNpcDbItem(CNpcDbItem& npc);
244 
252  bool UpdateFromNPCDbItem(const CNpcDbItem& npc, DWORD dwFields);
253  private:
255  int m_nCharacterID;
257  int m_nCharacterType;
258 
260  vector<DWORD> m_MentalStates;
261 
263  union{
264  CDnDCharacterAttribute* m_pDnDAttribute;
265  void* m_pAttributes;
266  };
267  };
268 
269 }
float m_fHeight
the height of the character.
Definition: RpgCharacter.h:35
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: RpgCharacter.h:84
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
int GetCharacterID()
get character ID in the database
Definition: RpgCharacter.h:149
float m_fAge
the age of the character.
Definition: RpgCharacter.h:33
float m_fWeight
the weight of the character.
Definition: RpgCharacter.h:38
A typical character in role playing game.
Definition: RpgCharacter.h:73
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: RpgCharacter.h:86
float m_fStrength
character strength
Definition: RpgCharacter.h:45
float m_fMaxLifeLoad
the maximum load that a character can lift or carry
Definition: RpgCharacter.h:57
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: RpgCharacter.h:88
vector< int > m_tools
character tool ID lists: such as weapons, medicines as in its inventory
Definition: RpgCharacter.h:65
vector< int > m_skills
character skill ID lists: such as magics
Definition: RpgCharacter.h:63
int m_nHeroPoints
levels can be deducted from this value.
Definition: RpgCharacter.h:60
int m_nRaceSex
the race and sex of the character.
Definition: RpgCharacter.h:42
int m_nOccupation
the occupation of the character.
Definition: RpgCharacter.h:40
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: RpgCharacter.h:23
float m_fBaseDefense
character base defense
Definition: RpgCharacter.h:51
CHARACTER_TYPE
character type.
Definition: RpgCharacter.h:137
void SetCharacterID(int nID)
set character ID in the database
Definition: RpgCharacter.h:154
NPC database item (complete)
Definition: NpcDatabase.h:8
float m_fDexterity
character dexterity
Definition: RpgCharacter.h:47
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
Dungeons and Dragons character attributes.
Definition: RpgCharacter.h:13
float m_fIntelligence
character Intelligence
Definition: RpgCharacter.h:49
float m_fBaseAttack
character base attack
Definition: RpgCharacter.h:54
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: RpgCharacter.h:25
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: RpgCharacter.h:21
float m_fLifePoint
the life or hit point of the character.
Definition: RpgCharacter.h:31
int GetCharacterType()
get type
Definition: RpgCharacter.h:160
It can be used to represent biped object(like human, re spawning monsters) in the scene without inher...
Definition: BipedObject.h:60