X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FHero.cpp;h=d117da078ed072bc8dfa9a00d8f70519ccc91325;hb=8bf720f722ca1b4a95f5a5c340dad39859115de4;hp=ff411137773ee72a21fa20ec54ba5115f3cdd914;hpb=854e5229c3f30bf88aa08d7f0aff56a1411c3367;p=l2e.git diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp index ff41113..d117da0 100644 --- a/src/battle/Hero.cpp +++ b/src/battle/Hero.cpp @@ -7,6 +7,19 @@ #include "Hero.h" +#include "AttackChoice.h" +#include "Resources.h" +#include "../common/Ikari.h" +#include "../common/Item.h" +#include "../common/Spell.h" +#include "../loader/TypeDescription.h" + +using common::Ikari; +using common::Spell; +using loader::FieldDescription; +using loader::TypeDescription; +using std::vector; + namespace battle { Hero::Hero() @@ -20,6 +33,7 @@ Hero::Hero() , ring(0) , jewel(0) +, meleeAnimation(0) , attackAnimation(0) , spellAnimation(0) @@ -28,13 +42,6 @@ Hero::Hero() , maxMana(0) , mana(0) -, attack(0) -, defense(0) -, agility(0) -, intelligence(0) -, gut(0) -, magicResistance(0) - , level(0) , ip(0) { @@ -44,4 +51,135 @@ 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); + } +} + + +void Hero::CreateTypeDescription() { + Hero h; + TypeDescription &td(TypeDescription::CreateOrGet("Hero")); + + td.SetSize(sizeof(Hero)); + + int animationId(TypeDescription::GetTypeId("Animation")); + int numberId(TypeDescription::GetTypeId("Number")); + int spriteId(TypeDescription::GetTypeId("Sprite")); + int statsId(TypeDescription::GetTypeId("Stats")); + int stringId(TypeDescription::GetTypeId("String")); + + td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true)); + td.AddField("sprite", FieldDescription(((char *)&h.sprite) - ((char *)&h), spriteId, true)); + td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId, false)); + + td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId, false)); + td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId, false)); + td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId, false)); + td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId, false)); + td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId, false)); + td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId, false)); + + td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId, true)); + td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId, true)); + td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true)); +} + }