PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/TGame/TCommon/Combat/CombatSysImp.h

http://awoe.googlecode.com/
C++ Header | 277 lines | 130 code | 49 blank | 98 comment | 0 complexity | f2ff533f080ee343fa85c83f83c12503 MD5 | raw file
  1#ifndef  __COMBAT_DATA_HH__IMP__
  2#define  __COMBAT_DATA_HH__IMP__
  3
  4
  5#include "CombatSysIf.h"
  6#include "CombatDefinition.h"
  7#include "CombatSkill.h"
  8#include "Combat/States/CombatState.h"
  9#include "Combat/EvtCombat.h"
 10#include "Data/Flags.h"
 11
 12
 13class IEntity;
 14class CombatSkill;
 15
 16
 17#define		COMBAT_ONE_BOTTLE_HP_VALUE		100
 18#define		COMBAT_ONE_BOTTLE_ENERGY_VALUE	100
 19
 20/*
 21*
 22*	Combat System Implementation
 23*	Spell caster basis, it provide the ability to cast a spell with a progress.
 24*	the spell caster also act as a manager of combat state for its host unit, so most combat state transition 
 25*	happened in this class.
 26*	
 27*
 28*/
 29class TCOM_API  CombatSysImp : public ICombatSys
 30{
 31public:
 32	CombatSysImp();
 33	virtual ~CombatSysImp();
 34
 35	//
 36	//	Entity Combat Flags : pay attention to all combat flag index
 37	virtual	void setFlg(const short& idx);
 38	virtual	void clrFlg(const short& idx);
 39	virtual	bool hasFlg(const short& idx)const;
 40
 41	//
 42	//	Entity Combat State
 43	//
 44	virtual	void		setState(short);
 45	virtual	short		getState()const;
 46	virtual	const char*	getStateName()const;
 47	virtual	const char* getStateName(short st)const;
 48
 49	//
 50	//	Entity Factions
 51	virtual	void		setFaction(short f);
 52	virtual	short		getFaction()const;
 53	virtual	const char*	getFactionName()const;
 54
 55	//
 56	//	set gene host
 57	//
 58	virtual bool setHost(IGeneHost* pHost);
 59
 60	//
 61	//	Entity Extension Data for combat
 62	//	For setExtData nValue is the value to set
 63	//	For getExtData nValue is the default value , when failed to get specific data
 64	//
 65	virtual void	setExtData(short nIdx, const int& nValue = 0);
 66	virtual int		getExtData(short nIdx, const int& nValue = 0);
 67
 68	//
 69	//	
 70	//
 71	virtual	void		setHP(int val);
 72	virtual	void		setMaxHP(int val);
 73	virtual	void		setMP(int val);
 74	virtual void		setMaxMP(int val);
 75	virtual	int			getHP()const;
 76	virtual	int			getMaxHP()const;
 77	virtual	int			getMP()const;
 78	virtual	int			getMaxMP()const;
 79	virtual	int			getHPPercentage()const;
 80	virtual	int			getMPPercentage()const;
 81
 82	virtual	int			getBottleHP()const;
 83	virtual	int			getBottleMP()const;
 84	virtual	int			getHpBottleNum() const;
 85	virtual	int			getMpBottleNum() const;
 86
 87
 88	//
 89	//	Entity Combat Data update
 90	//
 91	virtual	void	updateHPByPercentage(int nPercent);
 92	virtual	void	updateHP(int nAffectValue);
 93	virtual	void	updateMP(int nAffectValue);
 94	virtual	void	updateMaxHP(int nAffectValue);
 95	virtual	void	updateHPBottleValue(int nAffectValue) ;
 96	virtual	void    updateMPBottleValue(int nAffectValue) ;
 97
 98	//
 99	//	Entity base props
100	//	vit, str, agi, int, 
101	//	tohit, tododge,  
102	//	critical, resist
103	//	ap, dp
104	//
105	virtual void	setProps(short nIdx, const int& nValue = 0);
106	virtual int		getProps(short nIdx) const;
107	virtual void	setPropsModifier(short nIdx, const int& nValue = 0);
108	virtual int		getPropsModifier(short nIdx) const;
109
110	//
111	//	Entity Immunity
112	bool	addImmunity(int nKey);
113	bool	rmvImmunity(int nKey);
114	bool	hasImmunity(int nKey)const;
115public:
116	//	
117	//	Gene ID
118	//
119	virtual int		getID()const;	
120
121	//
122	//	Mutex Rule
123	//
124	virtual int		getMutexRule()const;	
125
126	//
127	//	Mutex Group
128	//
129	virtual int		getMutexGroup()const;
130
131	//
132	//	Time To Live (Duration)
133	//
134	virtual int		getDuration()const;	
135	//
136	//	Static Gene Data
137	virtual IData*	getStaticData();
138
139	//
140	//	Gene functions
141	//
142	virtual bool onInit(IGeneCreateData& createData);
143	// 
144	//	Fire when the gene is attached on a unit. just like unit enter the state.
145	//
146	virtual bool onAttach();
147
148	// 
149	//	Fire when the gene is attached on a unit. just like unit enter the state.
150	//
151	virtual bool onDetach();
152
153	// 
154	//	Periodically update gene logic, normally a gene will be detach when run out of its time to live.
155	//
156	virtual bool onUpdate(const int& nElapse);
157
158	// 
159	//	onEvent callback from hook manager
160	//
161	virtual void onEvent(IEvt& evt);
162
163	//
164	//	onEvent event handlers
165	//
166	virtual void onEvent_CastPrep(IEvt& evt);
167	virtual void onEvent_Cast(IEvt& evt);
168	virtual void onEvent_Target(IEvt& evt);
169	virtual void onEvent_CastResult(IEvt& evt);
170
171	//
172	//	Calculator or Demonstrator
173	virtual	bool isCalculator()const = 0;
174
175	bool	hasSkill(short& nStyle)const;
176	bool	hasSequence(const short& nSeq)const;
177
178	//
179	//	UI Effects
180	//
181	bool	EffectUpdate_CastStart(int& nTTL);		//	response on server's cast start notification
182	bool	EffectUpdate_CastCancel();				//	cast is cancelled, maybe send a cancel message to server
183	bool	EffectUpdate_CastEnding();				//	An logic step, calculator will send cast end request to server
184	bool	EffectUpdate_CastEnded();				//	response on server's cast end notification
185	//
186	//	Target of current casting
187	IEntity*	getTarget(const int& nTargetID ); 
188	IEntity*	getTargetCC();
189	//
190	//	Target of current enemy
191	void				setTargetCE(int nUIID){	m_nTargetCE = nUIID;	}
192	IEntity*			getTargetCE();
193	int					getTargetCE_ID()const			{	return m_nTargetCE;	}
194	bool				hasTargetCE()const				{	return (m_nTargetCE!=0);	}
195
196	//
197	//	Spell to cast
198	virtual bool TryCastNewSpell() = 0;
199
200	//
201	//	Send Combat Messages
202	bool sendMsg_CbtTargt(IEntity& t);
203	bool sendMsg_CbtStart(IEntity& t, CombatSkill& ab);
204	bool sendMsg_CbtEnd();
205	bool sendMsg_CbtCancel();
206
207	//
208	//	Combat calculate
209	//	c casting ab on t, result in r
210	static void calculate(ICombatCalculator* pCalculator);
211	static bool calculate(CombatSkill& ab, IEntity& c, IEntity& t, CombatResult& r, ICombatCalculator* pOverrideCalculator = NULL);
212#ifdef _DEBUG
213	//
214	//	Debug Helper Function
215	virtual	const char*		getCombatTag()const = 0;
216
217	short		MoR;
218#endif
219
220protected:
221	static ICombatCalculator*	s_pCurDefaultCalculator;
222
223	short	m_theCbtSt;
224	short	m_nFaction;
225
226	woe::Flags<32>	m_flags;
227	bool	m_bInited;	//	identify whether current combat data has been initialized
228
229protected:
230	int	sMaxHP;
231	int	sMaxMP;
232	int	sHP;
233	int	sMP;
234	int	sHPBottleValue;
235	int	sMPBottleValue;
236
237	int	m_nProps[prop_max];
238	int	m_nPropsModifier[prop_max];
239
240	typedef	std::map<int, short>	ImmunityMap;
241
242	ImmunityMap	m_theImmunityMap;
243
244protected:
245	bool		initState(short nST, ICombatState* pState);
246
247	IEntity*	m_wpHost;
248
249	//
250	//	all data for current casting spell
251	//
252	CombatSkill*	m_wpCastingSkill;
253	int	m_nTargetCC;
254	short			m_nSequenceCC;
255
256	//
257	//	target of current enemy
258	int	m_nTargetCE;
259
260	//
261	//	3D Animation, Effect and Sound
262	//
263	int m_nSR_SpellcastingBaseForCls;
264	int m_nSR_SpellcastedBaseForCls;
265	int	m_nSR_SpellcastingBaseForElement;
266	int m_nSR_SpellcastingBaseForUnderAttack;
267
268	short m_nPrevCbtSt;			//	previous combat state, try to keep sync with combat state in combat data
269	//	check this state to see if someone change the combat state from other gene
270
271	short m_nTimeLine;
272
273	ICombatState*	m_theStates[Combat::CBS_End];
274	short m_nSequenceGen;
275};
276
277#endif