PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TCommon/Combat/States/CombatState_Charging.cpp

http://awoe.googlecode.com/
C++ | 137 lines | 105 code | 21 blank | 11 comment | 15 complexity | 5e6ec4b313d1ef4418748ab38586cc28 MD5 | raw file
  1
  2#include "stdafx.h"
  3#include "CombatState_Charging.h"
  4#include "Combat/EvtCombat.h"
  5#include "Event/EvtImp.h"
  6#include "Combat/CombatSysImp.h"
  7#include "Entity/EntityIf.h"
  8#include "Combat/CombatDefinition.h"
  9#include "Move/EvtMove.h"
 10
 11
 12enum
 13{
 14	time_InCharging		=	15000,
 15};
 16
 17CombatState_Charging::CombatState_Charging(void)
 18
 19{
 20}
 21
 22CombatState_Charging::~CombatState_Charging()
 23{
 24}
 25
 26void
 27CombatState_Charging::enter()
 28{
 29	//
 30	//	if m_nTTL == 0, ICombatSys will keep in Charging states until some one else set me to another state
 31	//	if m_nTTL > 0,  ICombatSys will transfer to casting state when time expired
 32	//
 33
 34	m_nTTL = 0;
 35}
 36
 37void
 38CombatState_Charging::leave()
 39{
 40	//
 41	//	In range
 42	m_wpEntity->setMoveState(Move::mst_Idle);
 43}
 44
 45
 46bool 
 47CombatState_Charging::update(int nElapse)
 48{
 49	m_nTTL-= nElapse;
 50
 51	if (m_nTTL<=0)
 52	{
 53		IEntity* pTarget = m_wpCombat->getTargetCC();
 54		if (pTarget)
 55		{
 56
 57			int  nDstTileX = 0;
 58			int  nDstTileZ = 0;
 59			//pTarget->getTilePosition(nDstTileX, nDstTileZ);
 60
 61			int  nCurTileX = 0;
 62			int  nCurTileZ = 0;
 63			//m_wpEntity->getTilePosition(nCurTileX, nCurTileZ);
 64
 65			nCurTileX -= nDstTileX;
 66			nCurTileZ -= nDstTileZ;
 67			if ((nCurTileX*nCurTileX + nCurTileZ*nCurTileZ)<16)
 68			{
 69				m_wpCombat->setState(Combat::CBS_Casting);
 70			}
 71			else
 72			{
 73				//
 74				//	If target is moving or I am not moving
 75				//
 76				if ( pTarget->getMoveState()==Move::mst_Moving ||
 77					m_wpEntity->getMoveState()!=Move::mst_Moving)
 78				{
 79					EvtImp ge(EVT_Move, int (nDstTileX * 1000),  int (nDstTileZ * 1000), Move::MT_RUN);
 80					m_wpEntity->onEvent(ge);
 81				}
 82
 83				m_nTTL = 1000;
 84			}
 85		}
 86		else
 87		{
 88			m_wpCombat->setState(Combat::CBS_Ready);
 89		}
 90	}
 91	return true;
 92}
 93
 94
 95
 96void 
 97CombatState_Charging::onEvent(IEvt& evt)
 98{
 99	if (evt.getID()==EVT_CastStart)
100	{
101		if (!m_wpCombat->isCalculator())
102		{
103			GECast* pGE = static_cast<GECast*>(&evt);
104			m_wpCombat->onEvent_Cast(evt);
105			m_wpCombat->setState(Combat::CBS_Ready);
106		}
107		else
108		{
109			LOG_ERROR("Failed, calculator should not received cast start when charging!\n");
110		}
111	}
112	else if (evt.getID()==EVT_CastEnd)
113	{
114		if (!m_wpCombat->isCalculator())
115		{
116			m_wpCombat->setState(Combat::CBS_CoolDown);
117		}
118		else
119		{
120			LOG_ERROR_V("Failed to cast end in : %d !\n", m_wpCombat->getStateName());
121		}
122	}
123	else if (evt.getID()==EVT_CastResult)
124	{
125		m_wpCombat->onEvent_CastResult(evt);
126	}
127	else if (evt.getID()==EVT_CastPrep)
128	{
129		m_wpCombat->onEvent_CastPrep(evt);
130	}
131	else if (evt.getID()==EVT_TargetSelected)
132	{
133		m_wpCombat->onEvent_Target(evt);
134	}
135}
136
137