X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FHero.cpp;h=17ec08a2bbc8316abd84fadb827d02f087d80745;hb=520af5a8ef4fdfd4156377d4fccd93eecd450f0f;hp=3fbd320dc6e308d0e40651e4db1f66f239030f8b;hpb=d7927b645a22776d6e1e1c209365e8f74c4350e9;p=l2e.git diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp index 3fbd320..17ec08a 100644 --- a/src/battle/Hero.cpp +++ b/src/battle/Hero.cpp @@ -7,24 +7,38 @@ #include "Hero.h" +#include "AttackChoice.h" +#include "Resources.h" +#include "../common/Ikari.h" +#include "../common/Item.h" +#include "../common/Spell.h" + +using common::Ikari; +using common::Spell; +using std::vector; + namespace battle { Hero::Hero() : name("") , sprite(0) +, weapon(0) +, armor(0) +, shield(0) +, helmet(0) +, ring(0) +, jewel(0) + +, meleeAnimation(0) +, attackAnimation(0) +, spellAnimation(0) + , maxHealth(0) , health(0) , maxMana(0) , mana(0) -, attack(0) -, defense(0) -, agility(0) -, intelligence(0) -, gut(0) -, magicResistance(0) - , level(0) , ip(0) { @@ -34,4 +48,106 @@ Hero::~Hero() { } + +void Hero::SubtractHealth(int amount) { + if (amount > Health()) { + health = 0; + } else { + health -= amount; + int ipGain(amount * 255 / health); + if (ip + ipGain > 255) { + ip = 255; + } else { + ip += ipGain; + } + } +} + + +void Hero::UpdateSpellMenu() { + SpellMenu().Clear(); + SpellMenu().Reserve(Spells().size()); + for (vector::const_iterator i(Spells().begin()), end(Spells().end()); i != end; ++i) { + bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= Mana()); + SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost()); + } +} + +void Hero::UpdateIkariMenu(const Resources *res) { + IkariMenu().Clear(); + IkariMenu().Reserve(6); + + if (HasWeapon()) { + IkariMenu().Add( + Weapon()->Name(), + Weapon(), + Weapon()->HasIkari() && Weapon()->GetIkari()->Cost() <= IP(), + res->weaponMenuIcon, + 0, + Weapon()->HasIkari() ? Weapon()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon); + } + + if (HasArmor()) { + IkariMenu().Add( + Armor()->Name(), + Armor(), + Armor()->HasIkari() && Armor()->GetIkari()->Cost() <= IP(), + res->armorMenuIcon, + 0, + Armor()->HasIkari() ? Armor()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon); + } + + if (HasShield()) { + IkariMenu().Add( + Shield()->Name(), + Shield(), + Shield()->HasIkari() && Shield()->GetIkari()->Cost() <= IP(), + res->shieldMenuIcon, + 0, + Shield()->HasIkari() ? Shield()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon); + } + + if (HasHelmet()) { + IkariMenu().Add( + Helmet()->Name(), + Helmet(), + Helmet()->HasIkari() && Helmet()->GetIkari()->Cost() <= IP(), + res->helmetMenuIcon, + 0, + Helmet()->HasIkari() ? Helmet()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon); + } + + if (HasRing()) { + IkariMenu().Add( + Ring()->Name(), + Ring(), + Ring()->HasIkari() && Ring()->GetIkari()->Cost() <= IP(), + res->ringMenuIcon, + 0, + Ring()->HasIkari() ? Ring()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon); + } + + if (HasJewel()) { + IkariMenu().Add( + Jewel()->Name(), + Jewel(), + Jewel()->HasIkari() && Jewel()->GetIkari()->Cost() <= IP(), + res->jewelMenuIcon, + 0, + Jewel()->HasIkari() ? Jewel()->GetIkari()->Name() : ""); + } else { + IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon); + } +} + }