PageRenderTime 19ms CodeModel.GetById 7ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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