/TGame/TCommon/Combat/CombatSysM.cpp

http://awoe.googlecode.com/ · C++ · 161 lines · 131 code · 18 blank · 12 comment · 14 complexity · 8701ac8bb9124c7a88350c2b426785da MD5 · raw file

  1. #include "stdafx.h"
  2. #include "CombatSysM.h"
  3. #include "Combat/CombatSkill.h"
  4. #include "Entity/EntityIf.h"
  5. #include "States/CombatState_Casting.h"
  6. #include "States/CombatState_Charging.h"
  7. #include "States/CombatState_CoolDown.h"
  8. #include "States/CombatState_Forbidden.h"
  9. #include "States/CombatState_Peace.h"
  10. #include "States/CombatState_Ready.h"
  11. #include "States/CombatState_Standby.h"
  12. bool _g_bisCalculator = false;
  13. //
  14. // Combat Data For Monster
  15. //
  16. CombatSysM::CombatSysM()
  17. :m_wpTheMainSkill(NULL), m_nSkillCnt(0)
  18. {
  19. m_nFaction = Combat::FC_Monster;
  20. #ifdef _DEBUG
  21. MoR = 0;
  22. #endif
  23. for (int i=0; i<cnt_SpecialSkillM; i++)
  24. {
  25. m_wpSkill[i] = NULL;
  26. }
  27. }
  28. void
  29. CombatSysM::updateMP(int nAffectValue)
  30. {
  31. //
  32. // Monster don't need to calculate MP
  33. }
  34. void
  35. CombatSysM::updateMPBottleValue(int nAffectValue)
  36. {
  37. //
  38. // Monster don't need to calculate MP
  39. }
  40. bool
  41. CombatSysM::onInit(IGeneCreateData& createData)
  42. {
  43. if (__super::onInit(createData))
  44. {
  45. return initState(Combat::CBS_Casting, new CombatState_Casting) &&
  46. initState(Combat::CBS_Ready, new CombatState_Ready) &&
  47. initState(Combat::CBS_Forbidden, new CombatState_Forbidden) &&
  48. initState(Combat::CBS_Peace, new CombatState_Peace) &&
  49. initState(Combat::CBS_CoolDown,new CombatState_CoolDown) &&
  50. initState(Combat::CBS_Charging, new CombatState_Charging) &&
  51. initState(Combat::CBS_Standby, new CombatState_Standby);
  52. }
  53. else
  54. {
  55. return false;
  56. }
  57. }
  58. bool
  59. CombatSysM::isCalculator()const
  60. {
  61. return _g_bisCalculator;
  62. }
  63. bool
  64. CombatSysM::TryCastNewSpell()
  65. {
  66. CombatSkill* pSkill = NULL;
  67. //
  68. // Temp code here
  69. if (!hasFlg(Combat::FIdx_Daze) &&
  70. m_nSkillCnt>0)
  71. {
  72. int nRand = rand()%100;
  73. if (nRand<70)
  74. {
  75. pSkill = m_wpSkill[0];
  76. }
  77. else if (nRand<85)
  78. {
  79. pSkill = m_wpSkill[1];
  80. }
  81. else if (nRand<95)
  82. {
  83. pSkill = m_wpSkill[2];
  84. }
  85. else
  86. {
  87. pSkill = m_wpSkill[3];
  88. }
  89. }
  90. if (pSkill==NULL)
  91. {
  92. pSkill = m_wpTheMainSkill;
  93. }
  94. if (pSkill!=NULL)
  95. {
  96. IEntity* pTarget = getTargetCE();
  97. //
  98. // Check whether there is enough energy for casting the next spell
  99. //
  100. if ( pTarget!=NULL &&
  101. getMP()>=pSkill->m_nEnergeCost)
  102. {
  103. return sendMsg_CbtStart(*pTarget, *pSkill);
  104. }
  105. else
  106. {
  107. return false;
  108. }
  109. }
  110. return false;
  111. }
  112. void
  113. CombatSysM::onEvent_CastPrep(IEvt& evt)
  114. {
  115. GECastPrep* pGE = dynamic_cast<GECastPrep*>(&evt);
  116. if (pGE!=NULL)
  117. {
  118. if (pGE->m_nType==GECastPrep::Main)
  119. {
  120. m_wpTheMainSkill = pGE->m_wpSkill;
  121. pGE->setDataY(CombatResult::Succeed);
  122. }
  123. else
  124. {
  125. if (m_nSkillCnt<cnt_SpecialSkillM)
  126. {
  127. m_wpSkill[m_nSkillCnt++] = pGE->m_wpSkill;
  128. pGE->setDataY(CombatResult::Succeed);
  129. }
  130. else
  131. {
  132. pGE->setDataY(CombatResult::Busy);
  133. }
  134. }
  135. }
  136. }
  137. #ifdef _DEBUG
  138. const char*
  139. CombatSysM::getCombatTag()const
  140. {
  141. return "M";
  142. }
  143. #endif