]> git.localhorst.tv Git - l2e.git/blob - src/common/Hero.h
f61d0ee95507b5ae009e25ea31ccd28d3469de63
[l2e.git] / src / common / Hero.h
1 /*
2  * Hero.h
3  *
4  *  Created on: Oct 7, 2012
5  *      Author: holy
6  */
7
8 #ifndef COMMON_HERO_H_
9 #define COMMON_HERO_H_
10
11 #include "fwd.h"
12 #include "Stats.h"
13 #include "../graphics/fwd.h"
14 #include "../map/Entity.h"
15
16 #include <vector>
17
18 namespace common {
19
20 class Hero {
21
22 public:
23         static const int TYPE_ID = 301;
24
25 public:
26         Hero();
27         ~Hero() { }
28
29 public:
30         enum EquipSlot {
31                 EQUIP_WEAPON,
32                 EQUIP_ARMOR,
33                 EQUIP_SHIELD,
34                 EQUIP_HELMET,
35                 EQUIP_RING,
36                 EQUIP_JEWEL,
37                 EQUIP_COUNT,
38         };
39
40         const char *Name() const { return name; }
41
42         Uint16 MaxHealth() const { return maxHealth; }
43         Uint16 Health() const { return health; }
44         int RelativeHealth(int max) const { return Health() * max / MaxHealth(); }
45         void SubtractHealth(int amount);
46
47         Uint16 MaxMana() const { return maxMana; }
48         Uint16 Mana() const { return mana; }
49         int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); }
50         bool CanUseMagic() const { return MaxMana() > 0; }
51
52         Uint8 MaxIP() const { return 255; }
53         Uint8 IP() const { return ip; }
54         int RelativeIP(int max) const { return IP() * max / MaxIP(); }
55
56         Stats &GetStats() { return stats; }
57         const Stats &GetStats() const { return stats; }
58
59         Uint8 Level() const { return level; }
60         int Experience() const { return experience; }
61         int NextLevel() const;
62
63         bool CanEquip(const Item &) const;
64         bool CanInvoke(const Spell &) const;
65
66         Item *Equipment(EquipSlot i) { return equipment[i]; }
67         const Item *Equipment(EquipSlot i) const { return equipment[i]; }
68         bool Equipped(EquipSlot i) const { return equipment[i]; }
69         void RemoveEquipment(EquipSlot i) { equipment[i] = 0; }
70         void SetEquipment(EquipSlot i, Item *item) { equipment[i] = item; }
71
72         std::vector<const Spell *> &Spells() { return spells; }
73         const std::vector<const Spell *> &Spells() const { return spells; }
74
75         graphics::Sprite *BattleSprite() { return battleSprite; }
76         const graphics::Sprite *BattleSprite() const { return battleSprite; }
77         graphics::Animation *MeleeAnimation() { return meleeAnimation; }
78         graphics::Animation *AttackAnimation() { return attackAnimation; }
79         graphics::Animation *SpellAnimation() { return spellAnimation; }
80
81         map::Entity &MapEntity() { return mapEntity; }
82         const map::Entity &MapEntity() const { return mapEntity; }
83
84         static void CreateTypeDescription();
85         static void Construct(void *);
86
87 // temporary setters
88 public:
89         void AddSpell(Spell *s) { spells.push_back(s); }
90
91 private:
92         const char *name;
93
94         int maxHealth, health;
95         int maxMana, mana;
96         int ip;
97
98         Stats stats;
99
100         int level;
101         int experience;
102
103         int *levelLadder;
104         int numLevels;
105
106         int useMask;
107
108         Item *equipment[EQUIP_COUNT];
109
110         // TODO: vector does not seem to be a good choice
111         std::vector<const Spell *> spells;
112
113         graphics::Sprite *battleSprite;
114         graphics::Animation *meleeAnimation;
115         graphics::Animation *attackAnimation;
116         graphics::Animation *spellAnimation;
117
118         map::Entity mapEntity;
119
120 };
121
122 }
123
124 #endif /* COMMON_HERO_H_ */