]> git.localhorst.tv Git - l2e.git/blob - src/common/Hero.h
7014331b844b6cad7586edf7cc9bc1c5c7b08464
[l2e.git] / src / common / Hero.h
1 #ifndef COMMON_HERO_H_
2 #define COMMON_HERO_H_
3
4 namespace common {
5         class Item;
6         class Spell;
7 }
8 namespace graphics {
9         class Animation;
10         class Sprite;
11 }
12
13 #include "Stats.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         const Item *Equipment(EquipSlot i) const { return equipment[i]; }
67         bool Equipped(EquipSlot i) const { return equipment[i]; }
68         void RemoveEquipment(EquipSlot i) { equipment[i] = 0; }
69         void SetEquipment(EquipSlot i, const Item *item) { equipment[i] = item; }
70
71         std::vector<const Spell *> &Spells() { return spells; }
72         const std::vector<const Spell *> &Spells() const { return spells; }
73
74         graphics::Sprite *BattleSprite() { return battleSprite; }
75         const graphics::Sprite *BattleSprite() const { return battleSprite; }
76         graphics::Animation *MeleeAnimation() { return meleeAnimation; }
77         graphics::Animation *AttackAnimation() { return attackAnimation; }
78         graphics::Animation *SpellAnimation() { return spellAnimation; }
79
80         map::Entity &MapEntity() { return mapEntity; }
81         const map::Entity &MapEntity() const { return mapEntity; }
82
83         static void CreateTypeDescription();
84         static void Construct(void *);
85
86 // temporary setters
87 public:
88         void AddSpell(Spell *s) { spells.push_back(s); }
89
90 private:
91         const char *name;
92
93         int maxHealth, health;
94         int maxMana, mana;
95         int ip;
96
97         Stats stats;
98
99         int level;
100         int experience;
101
102         int *levelLadder;
103         int numLevels;
104
105         int useMask;
106
107         const Item *equipment[EQUIP_COUNT];
108
109         // TODO: vector does not seem to be a good choice
110         std::vector<const Spell *> spells;
111
112         graphics::Sprite *battleSprite;
113         graphics::Animation *meleeAnimation;
114         graphics::Animation *attackAnimation;
115         graphics::Animation *spellAnimation;
116
117         map::Entity mapEntity;
118
119 };
120
121 }
122
123 #endif /* COMMON_HERO_H_ */