/TGame/TCommon/Combat/CombatSysImp.h

http://awoe.googlecode.com/ · C Header · 277 lines · 130 code · 49 blank · 98 comment · 0 complexity · f2ff533f080ee343fa85c83f83c12503 MD5 · raw file

  1. #ifndef __COMBAT_DATA_HH__IMP__
  2. #define __COMBAT_DATA_HH__IMP__
  3. #include "CombatSysIf.h"
  4. #include "CombatDefinition.h"
  5. #include "CombatSkill.h"
  6. #include "Combat/States/CombatState.h"
  7. #include "Combat/EvtCombat.h"
  8. #include "Data/Flags.h"
  9. class IEntity;
  10. class CombatSkill;
  11. #define COMBAT_ONE_BOTTLE_HP_VALUE 100
  12. #define COMBAT_ONE_BOTTLE_ENERGY_VALUE 100
  13. /*
  14. *
  15. * Combat System Implementation
  16. * Spell caster basis, it provide the ability to cast a spell with a progress.
  17. * the spell caster also act as a manager of combat state for its host unit, so most combat state transition
  18. * happened in this class.
  19. *
  20. *
  21. */
  22. class TCOM_API CombatSysImp : public ICombatSys
  23. {
  24. public:
  25. CombatSysImp();
  26. virtual ~CombatSysImp();
  27. //
  28. // Entity Combat Flags : pay attention to all combat flag index
  29. virtual void setFlg(const short& idx);
  30. virtual void clrFlg(const short& idx);
  31. virtual bool hasFlg(const short& idx)const;
  32. //
  33. // Entity Combat State
  34. //
  35. virtual void setState(short);
  36. virtual short getState()const;
  37. virtual const char* getStateName()const;
  38. virtual const char* getStateName(short st)const;
  39. //
  40. // Entity Factions
  41. virtual void setFaction(short f);
  42. virtual short getFaction()const;
  43. virtual const char* getFactionName()const;
  44. //
  45. // set gene host
  46. //
  47. virtual bool setHost(IGeneHost* pHost);
  48. //
  49. // Entity Extension Data for combat
  50. // For setExtData nValue is the value to set
  51. // For getExtData nValue is the default value , when failed to get specific data
  52. //
  53. virtual void setExtData(short nIdx, const int& nValue = 0);
  54. virtual int getExtData(short nIdx, const int& nValue = 0);
  55. //
  56. //
  57. //
  58. virtual void setHP(int val);
  59. virtual void setMaxHP(int val);
  60. virtual void setMP(int val);
  61. virtual void setMaxMP(int val);
  62. virtual int getHP()const;
  63. virtual int getMaxHP()const;
  64. virtual int getMP()const;
  65. virtual int getMaxMP()const;
  66. virtual int getHPPercentage()const;
  67. virtual int getMPPercentage()const;
  68. virtual int getBottleHP()const;
  69. virtual int getBottleMP()const;
  70. virtual int getHpBottleNum() const;
  71. virtual int getMpBottleNum() const;
  72. //
  73. // Entity Combat Data update
  74. //
  75. virtual void updateHPByPercentage(int nPercent);
  76. virtual void updateHP(int nAffectValue);
  77. virtual void updateMP(int nAffectValue);
  78. virtual void updateMaxHP(int nAffectValue);
  79. virtual void updateHPBottleValue(int nAffectValue) ;
  80. virtual void updateMPBottleValue(int nAffectValue) ;
  81. //
  82. // Entity base props
  83. // vit, str, agi, int,
  84. // tohit, tododge,
  85. // critical, resist
  86. // ap, dp
  87. //
  88. virtual void setProps(short nIdx, const int& nValue = 0);
  89. virtual int getProps(short nIdx) const;
  90. virtual void setPropsModifier(short nIdx, const int& nValue = 0);
  91. virtual int getPropsModifier(short nIdx) const;
  92. //
  93. // Entity Immunity
  94. bool addImmunity(int nKey);
  95. bool rmvImmunity(int nKey);
  96. bool hasImmunity(int nKey)const;
  97. public:
  98. //
  99. // Gene ID
  100. //
  101. virtual int getID()const;
  102. //
  103. // Mutex Rule
  104. //
  105. virtual int getMutexRule()const;
  106. //
  107. // Mutex Group
  108. //
  109. virtual int getMutexGroup()const;
  110. //
  111. // Time To Live (Duration)
  112. //
  113. virtual int getDuration()const;
  114. //
  115. // Static Gene Data
  116. virtual IData* getStaticData();
  117. //
  118. // Gene functions
  119. //
  120. virtual bool onInit(IGeneCreateData& createData);
  121. //
  122. // Fire when the gene is attached on a unit. just like unit enter the state.
  123. //
  124. virtual bool onAttach();
  125. //
  126. // Fire when the gene is attached on a unit. just like unit enter the state.
  127. //
  128. virtual bool onDetach();
  129. //
  130. // Periodically update gene logic, normally a gene will be detach when run out of its time to live.
  131. //
  132. virtual bool onUpdate(const int& nElapse);
  133. //
  134. // onEvent callback from hook manager
  135. //
  136. virtual void onEvent(IEvt& evt);
  137. //
  138. // onEvent event handlers
  139. //
  140. virtual void onEvent_CastPrep(IEvt& evt);
  141. virtual void onEvent_Cast(IEvt& evt);
  142. virtual void onEvent_Target(IEvt& evt);
  143. virtual void onEvent_CastResult(IEvt& evt);
  144. //
  145. // Calculator or Demonstrator
  146. virtual bool isCalculator()const = 0;
  147. bool hasSkill(short& nStyle)const;
  148. bool hasSequence(const short& nSeq)const;
  149. //
  150. // UI Effects
  151. //
  152. bool EffectUpdate_CastStart(int& nTTL); // response on server's cast start notification
  153. bool EffectUpdate_CastCancel(); // cast is cancelled, maybe send a cancel message to server
  154. bool EffectUpdate_CastEnding(); // An logic step, calculator will send cast end request to server
  155. bool EffectUpdate_CastEnded(); // response on server's cast end notification
  156. //
  157. // Target of current casting
  158. IEntity* getTarget(const int& nTargetID );
  159. IEntity* getTargetCC();
  160. //
  161. // Target of current enemy
  162. void setTargetCE(int nUIID){ m_nTargetCE = nUIID; }
  163. IEntity* getTargetCE();
  164. int getTargetCE_ID()const { return m_nTargetCE; }
  165. bool hasTargetCE()const { return (m_nTargetCE!=0); }
  166. //
  167. // Spell to cast
  168. virtual bool TryCastNewSpell() = 0;
  169. //
  170. // Send Combat Messages
  171. bool sendMsg_CbtTargt(IEntity& t);
  172. bool sendMsg_CbtStart(IEntity& t, CombatSkill& ab);
  173. bool sendMsg_CbtEnd();
  174. bool sendMsg_CbtCancel();
  175. //
  176. // Combat calculate
  177. // c casting ab on t, result in r
  178. static void calculate(ICombatCalculator* pCalculator);
  179. static bool calculate(CombatSkill& ab, IEntity& c, IEntity& t, CombatResult& r, ICombatCalculator* pOverrideCalculator = NULL);
  180. #ifdef _DEBUG
  181. //
  182. // Debug Helper Function
  183. virtual const char* getCombatTag()const = 0;
  184. short MoR;
  185. #endif
  186. protected:
  187. static ICombatCalculator* s_pCurDefaultCalculator;
  188. short m_theCbtSt;
  189. short m_nFaction;
  190. woe::Flags<32> m_flags;
  191. bool m_bInited; // identify whether current combat data has been initialized
  192. protected:
  193. int sMaxHP;
  194. int sMaxMP;
  195. int sHP;
  196. int sMP;
  197. int sHPBottleValue;
  198. int sMPBottleValue;
  199. int m_nProps[prop_max];
  200. int m_nPropsModifier[prop_max];
  201. typedef std::map<int, short> ImmunityMap;
  202. ImmunityMap m_theImmunityMap;
  203. protected:
  204. bool initState(short nST, ICombatState* pState);
  205. IEntity* m_wpHost;
  206. //
  207. // all data for current casting spell
  208. //
  209. CombatSkill* m_wpCastingSkill;
  210. int m_nTargetCC;
  211. short m_nSequenceCC;
  212. //
  213. // target of current enemy
  214. int m_nTargetCE;
  215. //
  216. // 3D Animation, Effect and Sound
  217. //
  218. int m_nSR_SpellcastingBaseForCls;
  219. int m_nSR_SpellcastedBaseForCls;
  220. int m_nSR_SpellcastingBaseForElement;
  221. int m_nSR_SpellcastingBaseForUnderAttack;
  222. short m_nPrevCbtSt; // previous combat state, try to keep sync with combat state in combat data
  223. // check this state to see if someone change the combat state from other gene
  224. short m_nTimeLine;
  225. ICombatState* m_theStates[Combat::CBS_End];
  226. short m_nSequenceGen;
  227. };
  228. #endif