My Project
NpcDatabase.h
1 #pragma once
2 #include "ic/ParaDatabase.h"
3 #include <vector>
4 namespace ParaEngine
5 {
6  using namespace std;
8  struct CNpcDbItem
9  {
12  {
13  POSITION_FACING = 0x1<<0,
14  APPEARANCE_ATTRIBUTES = 0x1<<1,
15  MENTAL_STATE_0 = 0x1<<2,
16  MENTAL_STATE_1 = 0x1<<3,
17  MENTAL_STATE_2 = 0x1<<4,
18  MENTAL_STATE_3 = 0x1<<5,
19  RPG_ATTRIBUTES = 0x1<<6,
20  DND_ATTRIBUTES = 0x1<<7,
21  ALL_ATTRIBUTES = 0xffffffff
22  };
23 
25  // Biped attributes
26  string m_sName;
27  string m_sAssetName;
28  bool m_bIsGlobal;
29  bool m_bSnapToTerrain;
30  float m_fRadius;
31  float m_fFacing;
32  float m_fScaling;
33  Vector3 m_vPos;
34 
36  // RPG attributes
38  int m_nID;
39 
42 
44  DWORD m_MentalState[4];
45 
47  // DnD attributes
49  float m_fLifePoint;
51  float m_fAge;
53  float m_fHeight;
55  float m_fWeight;
61  float m_fStrength;
63  float m_fDexterity;
68  float m_fDefense, m_fDefenseflat, m_fDefenseMental;
71  float m_fAttackMelee, m_fAttackRanged, m_fAttackMental;
76 
78  // IGameObject attributes
79  float m_fPerceptiveRadius;
80  float m_fSentientRadius;
81  int m_nGroupID;
82  DWORD m_dwSentientField;
83  string m_sOnLoadScript;
84  vector<byte> m_binCustomAppearance;
85  public:
86  CNpcDbItem(){LoadDefaultValues();};
88  void LoadDefaultValues();
89  };
90  typedef vector<CNpcDbItem> NPCDBItemList;
91 
94  {
95  public:
96  CNpcDatabase(void);
97  ~CNpcDatabase(void);
98 
99  public:
101  // common function
102 
104  bool IsValid() {return m_pDataBase.get() !=0;};
105 
107  void Cleanup();
109  DBEntity* GetDBEntity(){return m_pDataBase.get();};
114  void SetDBEntity(const string& sConnectionstring);
115 
117  void ResetDatabase();
118 
120  void ValidateDatabase();
121 #ifdef _DEBUG
122 
123  void TestDB();
124 #endif
125 
126  public:
128  // query functions
129 
135  bool SelectNPCByID(int nNPCID, CNpcDbItem& pOut);
142  bool SelectNPCByName(const string& sName, CNpcDbItem& pOut);
143 
151  bool SelectNPCListByRegion(NPCDBItemList* pOut, const Vector3& vMin, const Vector3& vMax);
152 
157  bool InsertNPC(CNpcDbItem& npc);
158 
164  int GetNPCIDByName(const string& name);
165 
170  int GetNPCCount();
171 
177  bool DeleteNPCByID(int nNPCID);
183  bool DeleteNPCByName(const string& sName);
184 
192  bool UpdateNPC(const CNpcDbItem& npc, DWORD dwFields);
193 
194  private:
196  ParaEngine::asset_ptr<DBEntity> m_pDataBase;
197  CDBRecordSet* m_pProcInsertNPC;
198  CDBRecordSet* m_pProcSelectNPCByID;
199  CDBRecordSet* m_pProcSelectNPCByName;
200  CDBRecordSet* m_pProcSelectNPCListByRegion;
201  CDBRecordSet* m_pProcGetNPCIDByName;
202  CDBRecordSet* m_pProcDeleteNPCByID;
203  CDBRecordSet* m_pProcDeleteNPCByName;
204  CDBRecordSet* m_pProcUpdateNPC;
205  };
206 
207 }
float m_fIntelligence
character Intelligence
Definition: NpcDatabase.h:65
int m_nCharacterType
Definition: NpcDatabase.h:41
float m_fHeight
the height of the character.
Definition: NpcDatabase.h:53
float m_fAge
the age of the character.
Definition: NpcDatabase.h:51
UPDATE_FIELDS
selectively update data fields.
Definition: NpcDatabase.h:11
different physics engine has different winding order.
Definition: EventBinding.h:32
float m_fMaxLifeLoad
the maximum load that a character can lift or carry
Definition: NpcDatabase.h:73
int m_nHeroPoints
levels can be deducted from this value.
Definition: NpcDatabase.h:75
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
float m_fStrength
character strength
Definition: NpcDatabase.h:61
NPC data provider.
Definition: NpcDatabase.h:93
float m_fWeight
the weight of the character.
Definition: NpcDatabase.h:55
float m_fLifePoint
the life or hit point of the character.
Definition: NpcDatabase.h:49
float m_fBaseDefense
character base defense
Definition: NpcDatabase.h:67
NPC database item (complete)
Definition: NpcDatabase.h:8
int m_nID
character ID in database.
Definition: NpcDatabase.h:38
float m_fBaseAttack
character base attack
Definition: NpcDatabase.h:70
DBEntity * GetDBEntity()
get the database object associated with this provider
Definition: NpcDatabase.h:109
a single database file.
Definition: ICDBManager.h:39
bool IsValid()
whether db is opened.
Definition: NpcDatabase.h:104
int m_nOccupation
the occupation of the character.
Definition: NpcDatabase.h:57
float m_fDexterity
character dexterity
Definition: NpcDatabase.h:63
CICRecordSet is both the result and wrapper of a sql statement(procedure).
Definition: ICRecordSet.h:90
int m_nRaceSex
the race and sex of the character.
Definition: NpcDatabase.h:59