Add infos into target window
[ryzomcore.git] / ryzom / server / src / sabrina / combat_attacker.h
blobdd03eb475d14beadd5241a8610a06084b09ff607
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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
22 // nel misc
23 #include "nel/misc/types_nl.h"
24 // game_share
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;
36 struct CCombatWeapon
38 CCombatWeapon()
40 SpeedInTicks = 0;
41 Damage = 0;
42 Quality = 0;
43 DmgType = DMGTYPE::UNDEFINED;
44 Range = 0;
45 Skill = SKILLS::unknown;
46 SkillValue = 0;
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() );
55 return temp;
58 uint16 SpeedInTicks;
59 uint16 Damage;
60 uint16 Quality;
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
69 /**
70 * Base class for combat attackers
71 * \author David Fleury
72 * \author Nevrax France
73 * \date 2003
75 class CCombatAttacker
77 public:
78 enum TAttackerItem
80 RightHandItem =0,
81 LeftHandItem,
82 Ammo,
84 Unknown,
87 public:
88 CCombatAttacker() {}
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;
115 public:
116 /// row id
117 TDataSetRow _RowId;
122 * Derived class for player attackers
123 * \author David Fleury
124 * \author Nevrax France
125 * \date 2003
127 class CCombatAttackerPlayer : public CCombatAttacker
129 public:
130 CCombatAttackerPlayer(const TDataSetRow &rowId) : CCombatAttacker(rowId)
132 CCharacter *player = PlayerManager.getChar(_RowId);
133 if(!player) return;
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;
172 public:
173 /// right hand item
174 CGameItemPtr _RightHandItem;
176 /// left hand item
177 CGameItemPtr _LeftHandItem;
179 /// current ammos
180 CGameItemPtr _Ammos;
185 * Derived class for AI attackers
186 * \author David Fleury
187 * \author Nevrax France
188 * \date 2003
190 class CCombatAttackerAI : public CCombatAttacker
192 public:
193 CCombatAttackerAI()
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;
216 public:
217 // right hand item
218 CCombatWeapon _RightHandWeapon;
220 // left hand item
221 CCombatWeapon _LeftHandWeapon;
223 // ammo
224 CCombatWeapon _Ammo;
228 #endif // RY_COMBAT_ATTACKER_H
230 /* End of combat_attacker.h */