]> git.localhorst.tv Git - l2e.git/blob - src/battle/Hero.cpp
added interpretation of battle resources
[l2e.git] / src / battle / Hero.cpp
1 /*
2  * Hero.cpp
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #include "Hero.h"
9
10 #include "AttackChoice.h"
11 #include "Resources.h"
12 #include "../common/Ikari.h"
13 #include "../common/Item.h"
14 #include "../common/Spell.h"
15
16 using common::Ikari;
17 using common::Spell;
18 using std::vector;
19
20 namespace battle {
21
22 Hero::Hero()
23 : name("")
24 , sprite(0)
25
26 , weapon(0)
27 , armor(0)
28 , shield(0)
29 , helmet(0)
30 , ring(0)
31 , jewel(0)
32
33 , meleeAnimation(0)
34 , attackAnimation(0)
35 , spellAnimation(0)
36
37 , maxHealth(0)
38 , health(0)
39 , maxMana(0)
40 , mana(0)
41
42 , level(0)
43 , ip(0) {
44
45 }
46
47 Hero::~Hero() {
48
49 }
50
51
52 void Hero::SubtractHealth(int amount) {
53         if (amount > Health()) {
54                 health = 0;
55         } else {
56                 health -= amount;
57                 int ipGain(amount * 255 / health);
58                 if (ip + ipGain > 255) {
59                         ip = 255;
60                 } else {
61                         ip += ipGain;
62                 }
63         }
64 }
65
66
67 void Hero::UpdateSpellMenu() {
68         SpellMenu().Clear();
69         SpellMenu().Reserve(Spells().size());
70         for (vector<const Spell *>::const_iterator i(Spells().begin()), end(Spells().end()); i != end; ++i) {
71                 bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= Mana());
72                 SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
73         }
74 }
75
76 void Hero::UpdateIkariMenu(const Resources *res) {
77         IkariMenu().Clear();
78         IkariMenu().Reserve(6);
79
80         if (HasWeapon()) {
81                 IkariMenu().Add(
82                                 Weapon()->Name(),
83                                 Weapon(),
84                                 Weapon()->HasIkari() && Weapon()->GetIkari()->Cost() <= IP(),
85                                 res->weaponMenuIcon,
86                                 0,
87                                 Weapon()->HasIkari() ? Weapon()->GetIkari()->Name() : "");
88         } else {
89                 IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon);
90         }
91
92         if (HasArmor()) {
93                 IkariMenu().Add(
94                                 Armor()->Name(),
95                                 Armor(),
96                                 Armor()->HasIkari() && Armor()->GetIkari()->Cost() <= IP(),
97                                 res->armorMenuIcon,
98                                 0,
99                                 Armor()->HasIkari() ? Armor()->GetIkari()->Name() : "");
100         } else {
101                 IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon);
102         }
103
104         if (HasShield()) {
105                 IkariMenu().Add(
106                                 Shield()->Name(),
107                                 Shield(),
108                                 Shield()->HasIkari() && Shield()->GetIkari()->Cost() <= IP(),
109                                 res->shieldMenuIcon,
110                                 0,
111                                 Shield()->HasIkari() ? Shield()->GetIkari()->Name() : "");
112         } else {
113                 IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon);
114         }
115
116         if (HasHelmet()) {
117                 IkariMenu().Add(
118                                 Helmet()->Name(),
119                                 Helmet(),
120                                 Helmet()->HasIkari() && Helmet()->GetIkari()->Cost() <= IP(),
121                                 res->helmetMenuIcon,
122                                 0,
123                                 Helmet()->HasIkari() ? Helmet()->GetIkari()->Name() : "");
124         } else {
125                 IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon);
126         }
127
128         if (HasRing()) {
129                 IkariMenu().Add(
130                                 Ring()->Name(),
131                                 Ring(),
132                                 Ring()->HasIkari() && Ring()->GetIkari()->Cost() <= IP(),
133                                 res->ringMenuIcon,
134                                 0,
135                                 Ring()->HasIkari() ? Ring()->GetIkari()->Name() : "");
136         } else {
137                 IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon);
138         }
139
140         if (HasJewel()) {
141                 IkariMenu().Add(
142                                 Jewel()->Name(),
143                                 Jewel(),
144                                 Jewel()->HasIkari() && Jewel()->GetIkari()->Cost() <= IP(),
145                                 res->jewelMenuIcon,
146                                 0,
147                                 Jewel()->HasIkari() ? Jewel()->GetIkari()->Name() : "");
148         } else {
149                 IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon);
150         }
151 }
152
153 }