Add infos into target window
[ryzomcore.git] / ryzom / server / src / sabrina / combat_defender.h
blob50b170e7218bfdbc20bad2335adf8da22bdbadf5
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_DEFENDER_H
20 #define RY_COMBAT_DEFENDER_H
22 // misc
23 #include "nel/misc/types_nl.h"
24 // game_share
25 #include "game_share/skills.h"
26 #include "game_share/damage_types.h"
27 #include "game_share/armor_types.h"
28 #include "game_share/game_item_manager/game_item.h"
31 #include "entity_base.h"
32 #include "character.h"
33 #include "player_manager.h"
34 #include "entity_manager.h"
36 extern CPlayerManager PlayerManager;
38 struct CCombatArmor
40 CCombatArmor()
42 Quality = 0;
43 MaxBluntProtection = 0;
44 MaxPiercingProtection = 0;
45 MaxSlashingProtection = 0;
46 BluntProtectionFactor = 0.0f;
47 PiercingProtectionFactor = 0.0f;
48 SlashingProtectionFactor = 0.0f;
50 MaxRotProtection = 0;
51 RotProtectionFactor = 0.0f;
52 MaxAcidProtection = 0;
53 AcidProtectionFactor = 0.0f;
54 MaxColdProtection = 0;
55 ColdProtectionFactor = 0.0f;
56 MaxFireProtection = 0;
57 FireProtectionFactor = 0.0f;
58 MaxPoisonProtection = 0;
59 PoisonProtectionFactor = 0.0f;
60 MaxElectricityProtection = 0;
61 ElectricityProtectionFactor = 0.0f;
62 MaxShockProtection = 0;
63 ShockProtectionFactor = 0.0f;
65 Skill = SKILLS::unknown;
66 SkillValue = 0;
67 ArmorType = ARMORTYPE::UNKNOWN;
70 CCombatArmor( const CStaticItem *item, uint16 quality);
72 std::string toString() const
74 const std::string temp = NLMISC::toString("Quality= %u, SkillValue= %u, MaxB =%u,FactorB =%f, MaxP=%u,FactorP=%f, MaxS=%u, FactorS=%f", Quality, SkillValue, MaxBluntProtection, BluntProtectionFactor, MaxPiercingProtection, PiercingProtectionFactor, MaxSlashingProtection, SlashingProtectionFactor);
75 return temp;
78 uint16 Quality;
79 uint16 MaxBluntProtection;
80 uint16 MaxPiercingProtection;
81 uint16 MaxSlashingProtection;
82 float BluntProtectionFactor;
83 float PiercingProtectionFactor;
84 float SlashingProtectionFactor;
86 uint16 MaxRotProtection;
87 float RotProtectionFactor;
88 uint16 MaxAcidProtection;
89 float AcidProtectionFactor;
90 uint16 MaxColdProtection;
91 float ColdProtectionFactor;
92 uint16 MaxFireProtection;
93 float FireProtectionFactor;
94 uint16 MaxPoisonProtection;
95 float PoisonProtectionFactor;
96 uint16 MaxElectricityProtection;
97 float ElectricityProtectionFactor;
98 uint16 MaxShockProtection;
99 float ShockProtectionFactor;
101 SKILLS::ESkills Skill;
102 sint32 SkillValue;
103 ARMORTYPE::EArmorType ArmorType;
106 struct CCombatShield : public CCombatArmor
108 CCombatShield() : CCombatArmor()
110 ShieldType = SHIELDTYPE::NONE;
113 SHIELDTYPE::EShieldType ShieldType;
118 * Base class for combat defenders
119 * \author David Fleury
120 * \author Nevrax France
121 * \date 2003
123 class CCombatDefender
125 public:
126 CCombatDefender() {}
128 CCombatDefender(const TDataSetRow &rowId) : _RowId(rowId)
132 virtual ~CCombatDefender()
135 virtual sint32 getSkillValue( SKILLS::ESkills skill) const = 0;
137 inline CEntityBase *getEntity() { return CEntityBaseManager::getEntityBasePtr(_RowId); }
138 inline const TDataSetRow &getEntityRowId() const { return _RowId; }
140 virtual bool getArmor( SLOT_EQUIPMENT::TSlotEquipment slot, CCombatArmor &armor ) const = 0;
141 virtual bool getShield(CCombatShield &shield) const = 0;
143 virtual void damageOnShield(uint32 dmg) = 0;
144 virtual void damageOnArmor(SLOT_EQUIPMENT::TSlotEquipment slot, uint32 dmg) = 0;
146 virtual sint32 getDefenseValue() = 0;
148 public:
149 /// row id
150 TDataSetRow _RowId;
155 * Base class for combat player defenders
156 * \author David Fleury
157 * \author Nevrax France
158 * \date 2003
160 class CCombatDefenderPlayer : public CCombatDefender
162 public:
163 CCombatDefenderPlayer()
166 CCombatDefenderPlayer(const TDataSetRow &rowId) : CCombatDefender(rowId)
169 virtual ~CCombatDefenderPlayer()
172 inline sint32 getSkillValue( SKILLS::ESkills skill) const
174 CCharacter *character = PlayerManager.getChar(_RowId);
175 if (!character || skill >= SKILLS::NUM_SKILLS) return 0;
176 return character->getSkills()._Skills[ skill ].Current;
179 virtual bool getArmor( SLOT_EQUIPMENT::TSlotEquipment slot, CCombatArmor &armor ) const ;
181 virtual bool getShield(CCombatShield &shield) const;
183 virtual sint32 getDefenseValue()
185 CCharacter *character = PlayerManager.getChar(_RowId);
186 if ( !character)
188 return 0;
191 if (character->dodgeAsDefense())
193 return character->getSkills()._Skills[ SKILLS::SDD ].Current;
195 else
197 // get right weapon skill
198 CGameItemPtr item = character->getRightHandItem();
199 if (item != NULL && item->getStaticForm() != NULL && item->getStaticForm()->Family == ITEMFAMILY::MELEE_WEAPON && item->getStaticForm()->Skill < SKILLS::NUM_SKILLS)
200 return character->getSkills()._Skills[ item->getStaticForm()->Skill ].Current;
201 else
202 // return character->getSkills()._Skills[ SKILLS::BareHandCombat ].Current; TODO; skill missing
203 return 0;
207 virtual void damageOnShield(uint32 dmg)
209 CCharacter *character = PlayerManager.getChar(_RowId);
210 if ( !character)
212 return;
215 CGameItemPtr shieldPtr = character->getLeftHandItem();
216 if (shieldPtr == NULL || shieldPtr->getStaticForm() == NULL || shieldPtr->getStaticForm()->Family != ITEMFAMILY::SHIELD )
217 return;
219 shieldPtr->removeHp(dmg);
222 virtual void damageOnArmor(SLOT_EQUIPMENT::TSlotEquipment slot, uint32 dmg)
224 CCharacter *character = PlayerManager.getChar(_RowId);
225 if ( !character)
227 return;
230 CGameItemPtr armorPtr = character->getItem(INVENTORIES::equipment, slot);
231 if (armorPtr == NULL || armorPtr->getStaticForm() == NULL || armorPtr->getStaticForm()->Family != ITEMFAMILY::ARMOR)
232 return;
234 armorPtr->removeHp(dmg);
240 * Base class for combat AI defenders
241 * \author David Fleury
242 * \author Nevrax France
243 * \date 2003
245 class CCombatDefenderAI : public CCombatDefender
247 public:
248 CCombatDefenderAI() : CreatureForm(0)
251 CCombatDefenderAI(const TDataSetRow &rowId);
253 virtual ~CCombatDefenderAI()
256 inline sint32 getSkillValue( SKILLS::ESkills skill) const { return _DefenseValue; }
257 inline sint32 getDefenseValue() { return _DefenseValue; }
259 virtual bool getArmor( SLOT_EQUIPMENT::TSlotEquipment slot, CCombatArmor &armor ) const;
261 virtual bool getShield(CCombatShield &shield) const;
263 inline void damageOnShield(uint32 dmg) {}
264 inline void damageOnArmor(SLOT_EQUIPMENT::TSlotEquipment slot, uint32 dmg) {}
266 std::pair<const CStaticItem *, uint16> getArmorOnSlot( SLOT_EQUIPMENT::TSlotEquipment slot );
268 public:
269 /// creature form
270 const CStaticCreatures *CreatureForm;
272 /// defense value (parry or dodge)
273 sint32 _DefenseValue;
275 /// Global armor
276 CCombatShield _GlobalArmor;
279 /// shield
280 CCombatShield _Shield;
282 /// head armor
283 CCombatArmor _HeadArmor;
284 /// legs armor
285 CCombatArmor _LegsArmor;
286 /// arms armor
287 CCombatArmor _ArmsArmor;
288 /// chest armor
289 CCombatArmor _ChestArmor;
290 /// feet armor
291 CCombatArmor _FeetArmor;
292 /// hands armor
293 CCombatArmor _HandsArmor;
297 #endif // RY_COMBAT_DEFENDER_H
299 /* End of combat_defender.h */