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