]> git.localhorst.tv Git - l2e.git/blob - src/battle/Hero.h
added animation runners to Hero and Monster
[l2e.git] / src / battle / Hero.h
1 /*
2  * Hero.h
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #ifndef BATTLE_HERO_H_
9 #define BATTLE_HERO_H_
10
11 #include "Stats.h"
12 #include "../graphics/Animation.h"
13
14 #include <vector>
15 #include <SDL.h>
16
17 namespace common {
18         class Item;
19         class Spell;
20 }
21 namespace graphics {
22         class Sprite;
23 }
24
25 namespace battle {
26
27 class Hero {
28
29 public:
30         Hero();
31         ~Hero();
32
33 public:
34         const char *Name() const { return name; }
35         Uint8 Level() const { return level; }
36         const graphics::Sprite *Sprite() const { return sprite; }
37
38         const std::vector<const common::Spell *> &Spells() const { return spells; }
39
40         Uint16 MaxHealth() const { return maxHealth; }
41         Uint16 Health() const { return health; }
42         int RelativeHealth(int max) const { return Health() * max / MaxHealth(); }
43         void SubtractHealth(int amount);
44
45         Uint16 MaxMana() const { return maxMana; }
46         Uint16 Mana() const { return mana; }
47         int RelativeMana(int max) const { return MaxMana() == 0 ? 0 : Mana() * max / MaxMana(); }
48         bool CanUseMagic() const { return MaxMana() > 0; }
49
50         Uint8 MaxIP() const { return 255; }
51         Uint8 IP() const { return ip; }
52         int RelativeIP(int max) const { return IP() * max / MaxIP(); }
53
54         Stats &GetStats() { return stats; }
55         const Stats &GetStats() const { return stats; }
56
57         common::Item *Weapon() { return weapon; }
58         common::Item *Armor() { return armor; }
59         common::Item *Shield() { return shield; }
60         common::Item *Helmet() { return helmet; }
61         common::Item *Ring() { return ring; }
62         common::Item *Jewel() { return jewel; }
63
64         const common::Item *Weapon() const { return weapon; }
65         const common::Item *Armor() const { return armor; }
66         const common::Item *Shield() const { return shield; }
67         const common::Item *Helmet() const { return helmet; }
68         const common::Item *Ring() const { return ring; }
69         const common::Item *Jewel() const { return jewel; }
70
71         bool HasWeapon() const { return weapon; }
72         bool HasArmor() const { return armor; }
73         bool HasShield() const { return shield; }
74         bool HasHelmet() const { return helmet; }
75         bool HasRing() const { return ring; }
76         bool HasJewel() const { return jewel; }
77
78         graphics::AnimationRunner &GetAnimation() { return animation; }
79         const graphics::AnimationRunner &GetAnimation() const { return animation; }
80         void SetAnimation(const graphics::AnimationRunner &a) { animation = a; }
81
82         const graphics::Animation *MeleeAnimation() const { return meleeAnimation; }
83         const graphics::Animation *AttackAnimation() const { return attackAnimation; }
84         const graphics::Animation *SpellAnimation() const { return spellAnimation; }
85
86 // temporary setters until loader is implemented
87 public:
88         void SetName(const char *n) { name = n; }
89         void SetLevel(Uint8 l) { level = l; }
90         void SetSprite(graphics::Sprite *s) { sprite = s; }
91
92         void SetMaxHealth(Uint16 h) { maxHealth = h; }
93         void SetHealth(Uint16 h) { health = h; }
94         void SetMaxMana(Uint16 m) { maxMana = m; }
95         void SetMana(Uint16 m) { mana = m; }
96         void SetIP(Uint8 i) { ip = i; }
97
98         void SetStats(const Stats &s) { stats = s; }
99
100         void SetWeapon(common::Item *i) { weapon = i; }
101         void SetArmor(common::Item *i) { armor = i; }
102         void SetShield(common::Item *i) { shield = i; }
103         void SetHelmet(common::Item *i) { helmet = i; }
104         void SetRing(common::Item *i) { ring = i; }
105         void SetJewel(common::Item *i) { jewel = i; }
106
107         void AddSpell(const common::Spell *s) { spells.push_back(s); }
108
109         void SetMeleeAnimation(const graphics::Animation *a) { meleeAnimation = a; }
110         void SetAttackAnimation(const graphics::Animation *a) { attackAnimation = a; }
111         void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; }
112
113 private:
114         const char *name;
115         graphics::Sprite *sprite;
116
117         common::Item *weapon;
118         common::Item *armor;
119         common::Item *shield;
120         common::Item *helmet;
121         common::Item *ring;
122         common::Item *jewel;
123
124         const graphics::Animation *meleeAnimation;
125         const graphics::Animation *attackAnimation;
126         const graphics::Animation *spellAnimation;
127
128         graphics::AnimationRunner animation;
129
130         // TODO: vector does not seem to be a good choice
131         std::vector<const common::Spell *> spells;
132
133         Uint16 maxHealth, health;
134         Uint16 maxMana, mana;
135
136         Stats stats;
137
138         Uint8 level;
139         Uint8 ip;
140
141 };
142
143 }
144
145 #endif /* BATTLE_HERO_H_ */