]> git.localhorst.tv Git - l2e.git/blob - src/common/Hero.h
aa12b2559cdfe69aa1221847aded744bfbd8549e
[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 public:
87         void SetMaxHealth(int h) { maxHealth = h; }
88         void SetHealth(int h) { health = h; }
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         const 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