]> git.localhorst.tv Git - l2e.git/blob - src/battle/Capsule.cpp
extracted battle logic into a class
[l2e.git] / src / battle / Capsule.cpp
1 #include "Capsule.h"
2
3 #include "../common/Capsule.h"
4 #include "../math/Vector.h"
5
6 #include <cassert>
7
8 using graphics::Animation;
9 using graphics::Sprite;
10
11 namespace battle {
12
13 Capsule::Capsule(common::Capsule *master)
14 : master(master)
15 , health(master ? master->MaxHealth() : 0) {
16         if (master) {
17                 stats = master->GetStats();
18         }
19 }
20
21
22 const char *Capsule::Name() const {
23         assert(master);
24         return master->Name();
25 }
26
27 Uint8 Capsule::Level() const {
28         assert(master);
29         return master->Level();
30 }
31
32 const Sprite *Capsule::Sprite() const {
33         assert(master);
34         return master->BattleSprite();
35 }
36
37 const Animation *Capsule::MeleeAnimation() const {
38         assert(master);
39         return master->MeleeAnimation();
40 }
41
42 const Animation *Capsule::AttackAnimation() const {
43         assert(master);
44         return master->AttackAnimation();
45 }
46
47 const Animation *Capsule::SpellAnimation() const {
48         assert(master);
49         return master->SpellAnimation();
50 }
51
52
53 Uint16 Capsule::MaxHealth() const {
54         assert(master);
55         return master->MaxHealth();
56 }
57
58 Uint16 Capsule::Health() const {
59         return health;
60 }
61
62 int Capsule::RelativeHealth(int max) const {
63         return Health() * max / MaxHealth();
64 }
65
66 void Capsule::SubtractHealth(int amount) {
67         if (amount > health) {
68                 health = 0;
69         } else {
70                 health -= amount;
71         }
72 }
73
74 }