]> git.localhorst.tv Git - l2e.git/blob - src/battle/Hero.cpp
added Sort function to Inventory
[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 : master(0) {
24
25 }
26
27 Hero::Hero(common::Hero &h)
28 : master(&h)
29 , stats(h.GetStats()) {
30
31 }
32
33 Hero::~Hero() {
34
35 }
36
37
38 void Hero::UpdateSpellMenu() {
39         SpellMenu().Clear();
40         SpellMenu().Reserve(Spells().size());
41         for (vector<const Spell *>::const_iterator i(Spells().begin()), end(Spells().end()); i != end; ++i) {
42                 bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= Mana());
43                 SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost());
44         }
45 }
46
47 void Hero::UpdateIkariMenu(const Resources *res) {
48         IkariMenu().Clear();
49         IkariMenu().Reserve(6);
50
51         if (HasWeapon()) {
52                 IkariMenu().Add(
53                                 Weapon()->Name(),
54                                 Weapon(),
55                                 Weapon()->HasIkari() && Weapon()->GetIkari()->Cost() <= IP(),
56                                 res->weaponMenuIcon,
57                                 0,
58                                 Weapon()->HasIkari() ? Weapon()->GetIkari()->Name() : "");
59         } else {
60                 IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon);
61         }
62
63         if (HasArmor()) {
64                 IkariMenu().Add(
65                                 Armor()->Name(),
66                                 Armor(),
67                                 Armor()->HasIkari() && Armor()->GetIkari()->Cost() <= IP(),
68                                 res->armorMenuIcon,
69                                 0,
70                                 Armor()->HasIkari() ? Armor()->GetIkari()->Name() : "");
71         } else {
72                 IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon);
73         }
74
75         if (HasShield()) {
76                 IkariMenu().Add(
77                                 Shield()->Name(),
78                                 Shield(),
79                                 Shield()->HasIkari() && Shield()->GetIkari()->Cost() <= IP(),
80                                 res->shieldMenuIcon,
81                                 0,
82                                 Shield()->HasIkari() ? Shield()->GetIkari()->Name() : "");
83         } else {
84                 IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon);
85         }
86
87         if (HasHelmet()) {
88                 IkariMenu().Add(
89                                 Helmet()->Name(),
90                                 Helmet(),
91                                 Helmet()->HasIkari() && Helmet()->GetIkari()->Cost() <= IP(),
92                                 res->helmetMenuIcon,
93                                 0,
94                                 Helmet()->HasIkari() ? Helmet()->GetIkari()->Name() : "");
95         } else {
96                 IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon);
97         }
98
99         if (HasRing()) {
100                 IkariMenu().Add(
101                                 Ring()->Name(),
102                                 Ring(),
103                                 Ring()->HasIkari() && Ring()->GetIkari()->Cost() <= IP(),
104                                 res->ringMenuIcon,
105                                 0,
106                                 Ring()->HasIkari() ? Ring()->GetIkari()->Name() : "");
107         } else {
108                 IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon);
109         }
110
111         if (HasJewel()) {
112                 IkariMenu().Add(
113                                 Jewel()->Name(),
114                                 Jewel(),
115                                 Jewel()->HasIkari() && Jewel()->GetIkari()->Cost() <= IP(),
116                                 res->jewelMenuIcon,
117                                 0,
118                                 Jewel()->HasIkari() ? Jewel()->GetIkari()->Name() : "");
119         } else {
120                 IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon);
121         }
122 }
123
124 }