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