PageRenderTime 32ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/TGame/TCommon/Gene/Status/GEDOT.cpp

http://awoe.googlecode.com/
C++ | 172 lines | 132 code | 33 blank | 7 comment | 21 complexity | 0bb9b9b00a06540c6669b16eb6a1e8f8 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////////////////////
  2// GEDOT.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 "GEDOT.h"
 13#include "Entity/EntityIf.h"
 14#include "Combat/CombatSysIf.h"
 15#include "Gene/GeneCreateDataIf.h"
 16
 17GEDOT::GEDOT() 
 18{
 19}
 20
 21
 22bool
 23GEDOT::onAttach()
 24{
 25	if (! __super::onAttach())
 26	{
 27		return false;
 28	}
 29
 30	if (m_nTTL<=0 || m_wpSData->getDataZ()<=0)
 31	{
 32		return false;
 33	}
 34
 35	m_nTimeInterval = m_wpSData->getData(ArgIdx_IntervalTime);
 36	if (m_nTimeInterval<0)
 37	{
 38		m_nTimeInterval = 1000;
 39	}
 40
 41	m_nDamageRemain = m_wpSData->getData(ArgIdx_FullBaseDamage);
 42
 43	CalculateDamage(m_nDamageRemain);
 44
 45	m_nDamagePerTime = m_nDamageRemain * m_nTimeInterval / m_wpSData->getDataZ();
 46
 47	if (m_nDamagePerTime==0)
 48	{
 49		LOG_WARN("Wain, Damage Per Time is zeo in Dot\n");
 50	}
 51
 52	m_nTimeNextDamage = m_wpSData->getDataZ() - m_nTimeInterval;
 53
 54	if (m_wpSData->getDataZ()>0 && m_wpSData->getDataZ()!=m_nTTL)
 55	{
 56		while(m_nTimeNextDamage>=m_nTTL)
 57		{
 58			m_nTimeNextDamage -= m_nTimeInterval;
 59			m_nDamageRemain  -= m_nDamagePerTime;
 60		}
 61	}
 62
 63	return true;
 64}
 65
 66
 67bool 
 68GEDOT::onUpdate(int nElapse)
 69{
 70	__super::onUpdate(nElapse);
 71
 72	if (m_nTTL<=0)
 73	{
 74		m_wpCombat->updateHP(m_nDamageRemain);
 75		return false;
 76	}
 77	else if (m_nTTL<=m_nTimeNextDamage)
 78	{
 79		m_nDamageRemain -= m_nDamagePerTime;
 80		m_nTimeNextDamage -= m_nTimeInterval;
 81		m_wpCombat->updateHP(m_nDamagePerTime);
 82	}
 83	return true;
 84}
 85
 86bool
 87GEDOT::CalculateDamage(int& nD)
 88{
 89	if (nD<0)
 90	{
 91		return true;
 92	}
 93	else if (nD>0)
 94	{
 95		nD = -nD;
 96	}
 97	else
 98	{
 99		nD = -1;
100	}
101	return false;
102}
103
104
105GEDOT_Element::GEDOT_Element(short nElemID)
106:m_nWhichElement(nElemID), m_nTheElementValue(0), m_nTheCaster(0)
107{
108
109}
110
111bool 
112GEDOT_Element::onInit(IGeneCreateData& createData)
113{
114	if (m_nWhichElement<Combat::CBP_Start || m_nWhichElement>=Combat::CBP_End)
115	{
116		m_nWhichElement = Combat::CBP_Fire;
117	}
118
119
120	m_nTheCaster = createData.getSrcEntityID();
121	IEntity* pCaster = createData.getSrcEntity();
122	if (pCaster && pCaster->getCombatSys())
123	{
124		m_nTheElementValue = 0;
125	}
126	else
127	{
128		m_nTheElementValue = 0;
129	}
130	return true;
131}
132
133
134
135bool GEDOT_Element::onAttach()
136{
137	if (__super::onAttach())
138	{
139		m_nDamageRatioOnElement = m_wpSData->getData(ArgIdx_DamageRatio_OnElement);
140
141		if (m_nDamageRatioOnElement<=0)
142		{
143			m_nDamageRatioOnElement = 1;
144		}
145		return true;
146	}
147	else
148	{
149		return false;
150	}
151}
152
153
154bool GEDOT_Element::CalculateDamage(int& nD)
155{
156	int nDamage = m_nDamageRatioOnElement * m_nTheElementValue / 1000;
157
158	if (nD<=0)
159	{
160		nD = nD - nDamage;
161	}
162	else
163	{
164		nD = -nD - nDamage;
165	}
166
167	if (nD>=0)
168	{
169		nD = -1;
170	}
171	return true;
172}