PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TCommon/Gene/Status/GEConfuse.cpp

http://awoe.googlecode.com/
C++ | 147 lines | 114 code | 26 blank | 7 comment | 18 complexity | f3cf3634c6bdaff3dc20df958409275e MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////////////////////
  2// GEConfuse.cpp
  3// 2010?1?20?
  4// Copyright ?2007, 2010, 8DWorld, Inc. All rights reserved.
  5//
  6// 
  7///////////////////////////////////////////////////////////////////////////////////////////////////
  8
  9
 10
 11#include "stdafx.h"
 12#include "GEConfuse.h"
 13#include "Entity/EntityIf.h"
 14#include "Combat/CombatSysIf.h"
 15#include "Gene/GeneCreateDataIf.h"
 16#include "GEFear.h"
 17#include "GEDaze.h"
 18
 19static short ___style2stage2state_[3][3] =
 20{
 21	{GEConfuse::St_Fear,GEConfuse::St_Daze,GEConfuse::St_Daze},
 22	{GEConfuse::St_Daze,GEConfuse::St_Daze,GEConfuse::St_Fear},
 23	{GEConfuse::St_Daze,GEConfuse::St_Fear,GEConfuse::St_Daze}
 24};
 25
 26GEConfuse::GEConfuse() 
 27:m_nCurState(St_Null), m_pGene(NULL)
 28{
 29}
 30
 31GEConfuse::~GEConfuse()
 32{
 33	if (m_pGene)
 34	{
 35		delete m_pGene;
 36	}
 37}
 38
 39bool
 40GEConfuse::onInit(IGeneCreateData& createData)
 41{
 42	if (!__super::onInit(createData))
 43	{
 44		return false;
 45	}
 46
 47	m_nTIStage = m_wpSData->getDataZ()/3;
 48	m_nTimeLineNextStage = m_wpSData->getDataZ();
 49
 50	m_nStyle = createData.getDataX() % 3;
 51	return true;
 52}
 53
 54bool
 55GEConfuse::onAttach()
 56{
 57	m_nCurStage = -1;
 58	while (m_nTTL<=m_nTimeLineNextStage)
 59	{
 60		m_nCurStage++;
 61		m_nTimeLineNextStage -= m_nTIStage;
 62	}
 63
 64	if (m_nCurStage<0 || m_nCurStage>2)
 65	{
 66		m_nCurStage = 0;
 67	}
 68
 69	
 70	setState(m_nStyle, m_nCurStage);
 71	
 72	return true;
 73}
 74
 75bool
 76GEConfuse::onDetach()
 77{
 78	setState(-1, -1);
 79	return true;
 80}
 81
 82
 83
 84bool
 85GEConfuse::onUpdate(int nElapse)
 86{
 87	__super::onUpdate(nElapse);
 88
 89	if (m_nTTL<=0)
 90	{
 91		return false;
 92	}
 93
 94	if (m_nTTL<=m_nTimeLineNextStage)
 95	{
 96		m_nCurStage++;
 97		if (m_nCurStage>2)
 98		{
 99			m_nCurStage = 2;
100		}
101
102		setState(m_nStyle, m_nCurStage);
103	}
104
105	return true;
106}
107
108void 
109GEConfuse::setState(short nStyle, short nStage)
110{
111	int nNewState = St_Null;
112	if (nStyle>=0 && nStyle<3 &&
113		nStage>=0 && nStage<3)
114	{
115		nNewState = ___style2stage2state_[nStyle][nStage];
116	}
117	if (m_nCurState!=nNewState)
118	{
119		m_nCurState = nNewState;
120
121		if (m_pGene)
122		{
123			if (m_pGene)
124			{
125				m_pGene->onDetach();
126				m_pGene->setHost(NULL);
127				delete m_pGene;
128				m_pGene = NULL;
129			}
130
131			if (m_nCurState==St_Daze)
132			{
133				m_pGene = new GEDaze; 
134			}
135			else if (m_nCurState==St_Fear)
136			{
137				m_pGene = new GEFear;
138			}
139
140			if (m_pGene)
141			{
142				m_pGene->setHost(m_wpHost);
143				m_pGene->onAttach();
144			}
145		}
146	}
147}