1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RY_COMBAT_ATTACKER_H
20 #define RY_COMBAT_ATTACKER_H
23 #include "nel/misc/types_nl.h"
25 #include "game_share/tick_event_handler.h"
26 #include "game_share/game_item_manager/game_item.h"
28 #include "entity_base.h"
29 #include "character.h"
30 #include "player_manager.h"
31 #include "entity_manager.h"
33 extern CPlayerManager PlayerManager
;
43 DmgType
= DMGTYPE::UNDEFINED
;
45 Skill
= SKILLS::unknown
;
47 Family
= ITEMFAMILY::UNDEFINED
;
50 CCombatWeapon(CGameItemPtr itemPtr
);
52 std::string
toString() const
54 const std::string temp
= NLMISC::toString("Damage = %u, Quality = %u, SkillValue = %u, dmgType = %s, Family = %s", Damage
, Quality
, SkillValue
,DMGTYPE::toString(DmgType
).c_str(), ITEMFAMILY::toString(Family
).c_str() );
61 DMGTYPE::EDamageType DmgType
;
62 ITEMFAMILY::EItemFamily Family
;
63 float Range
; // if > 0 range weapon or ammo, == 0 melee weapon
64 SKILLS::ESkills Skill
; // no meaning for ammos
65 sint32 SkillValue
; // no meaning for ammos
70 * Base class for combat attackers
71 * \author David Fleury
72 * \author Nevrax France
90 CCombatAttacker( const TDataSetRow
&rowId
) : _RowId(rowId
)
93 virtual ~CCombatAttacker()
96 virtual void lockRightItem() = 0;
97 virtual void lockLeftItem() = 0;
98 virtual void lockAmmos(uint16 nb
= 1) = 0;
99 virtual void unlockRightItem() = 0;
100 virtual void unlockLeftItem() = 0;
101 virtual void unlockAmmos(uint16 nb
= 1) = 0;
103 virtual void damageItem(bool right
= true) = 0;
105 virtual sint32
getSkillValue( SKILLS::ESkills skill
) const = 0;
107 inline CEntityBase
*getEntity() { return CEntityBaseManager::getEntityBasePtr(_RowId
); }
108 inline const TDataSetRow
&getEntityRowId() const { return _RowId
; }
110 virtual bool checkAmmoAmount( uint8 qty
= 1) const = 0;
111 virtual void consumeAmmos( uint8 qty
= 1) = 0;
113 virtual bool getItem( TAttackerItem item
, CCombatWeapon
&weaponItem
) const = 0;
122 * Derived class for player attackers
123 * \author David Fleury
124 * \author Nevrax France
127 class CCombatAttackerPlayer
: public CCombatAttacker
130 CCombatAttackerPlayer(const TDataSetRow
&rowId
) : CCombatAttacker(rowId
)
132 CCharacter
*player
= PlayerManager
.getChar(_RowId
);
135 _RightHandItem
= player
->getRightHandItem();
136 _LeftHandItem
= player
->getLeftHandItem();
137 _Ammos
= player
->getAmmoItem();
140 virtual ~CCombatAttackerPlayer()
143 inline void lockRightItem() { if (_RightHandItem
!= NULL
) _RightHandItem
->setLockState(_RightHandItem
->getLockState() + 1 ); }
144 inline void lockLeftItem() { if (_LeftHandItem
!= NULL
) _LeftHandItem
->setLockState(_LeftHandItem
->getLockState() + 1 ); }
145 inline void lockAmmos(uint16 nb
= 1) { if (_Ammos
!= NULL
) _Ammos
->setLockState(_Ammos
->getLockState() + nb
); }
147 inline void unlockRightItem() { if (_RightHandItem
!= NULL
) _RightHandItem
->setLockState(_RightHandItem
->getLockState() - 1); }
148 inline void unlockLeftItem() { if (_LeftHandItem
!= NULL
) _LeftHandItem
->setLockState(_LeftHandItem
->getLockState() - 1); }
149 inline void unlockAmmos(uint16 nb
= 1) { if (_Ammos
!= NULL
) _Ammos
->setLockState(_Ammos
->getLockState() - nb
); }
151 virtual bool checkAmmoAmount( uint8 qty
= 1) const;
153 virtual void consumeAmmos( uint8 qty
= 1)
155 CCharacter
*character
= PlayerManager
.getChar(_RowId
);
156 if(!character
) return;
157 character
->consumeAmmo(qty
);
160 inline void damageItem(bool right
= true) {}
162 virtual bool getItem( TAttackerItem item
, CCombatWeapon
&weaponItem
) const;
164 inline sint32
getSkillValue( SKILLS::ESkills skill
) const
166 CCharacter
*character
= PlayerManager
.getChar(_RowId
);
167 if (!character
|| skill
>= SKILLS::NUM_SKILLS
) return 0;
168 return character
->getSkills()._Skills
[ skill
].Current
;
174 CGameItemPtr _RightHandItem
;
177 CGameItemPtr _LeftHandItem
;
185 * Derived class for AI attackers
186 * \author David Fleury
187 * \author Nevrax France
190 class CCombatAttackerAI
: public CCombatAttacker
196 CCombatAttackerAI(const TDataSetRow
&rowId
);
198 virtual ~CCombatAttackerAI()
201 inline void consumeAmmos( uint8 qty
= 1) {}
202 inline void damageItem(bool right
= true) {}
203 inline void lockRightItem() {}
204 inline void lockLeftItem() {}
205 inline void lockAmmos(uint16 nb
= 1) {}
206 inline void unlockRightItem() {}
207 inline void unlockLeftItem() {}
208 inline void unlockAmmos(uint16 nb
= 1) {}
210 inline sint32
getSkillValue( SKILLS::ESkills skill
) const { return _RightHandWeapon
.SkillValue
; }
212 inline bool checkAmmoAmount( uint8 qty
= 1) const { return true; }
214 virtual bool getItem( TAttackerItem item
, CCombatWeapon
&weaponItem
) const;
218 CCombatWeapon _RightHandWeapon
;
221 CCombatWeapon _LeftHandWeapon
;
228 #endif // RY_COMBAT_ATTACKER_H
230 /* End of combat_attacker.h */