X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcommon%2FHero.cpp;h=7150af0a35b8c0528058d5c845794875c4483c18;hb=350055a7ff27c74882aff8a4d6af2014782f830b;hp=373f63d01d2744c373c39f7dad7e655df9953bec;hpb=ec0841bce8db9b1419dfbbb03ceff9c8502ab755;p=l2e.git diff --git a/src/common/Hero.cpp b/src/common/Hero.cpp index 373f63d..7150af0 100644 --- a/src/common/Hero.cpp +++ b/src/common/Hero.cpp @@ -7,18 +7,24 @@ #include "Hero.h" +#include "Item.h" +#include "Spell.h" #include "../graphics/Animation.h" #include "../graphics/Sprite.h" #include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" #include "../map/Entity.h" +#include + using graphics::Animation; using graphics::Sprite; using loader::FieldDescription; using loader::Interpreter; using loader::TypeDescription; using map::Entity; +using std::memset; + namespace common { @@ -33,19 +39,16 @@ Hero::Hero() , level(0) , experience(0) +, levelLadder(0) +, numLevels(0) -, weapon(0) -, armor(0) -, shield(0) -, helmet(0) -, ring(0) -, jewel(0) +, useMask(0) , battleSprite(0) , meleeAnimation(0) , attackAnimation(0) , spellAnimation(0) { - + memset(equipment, 0, sizeof(equipment)); } @@ -64,6 +67,25 @@ void Hero::SubtractHealth(int amount) { } +int Hero::NextLevel() const { + int levelOffset(Level() - 1); + if (levelOffset < numLevels) { + return levelLadder[levelOffset] - Experience(); + } else { + return 0; + } +} + + +bool Hero::CanEquip(const Item &item) const { + return useMask & item.HeroMask(); +} + +bool Hero::CanInvoke(const Spell &spell) const { + return useMask & spell.HeroMask(); +} + + void Hero::CreateTypeDescription() { Hero h; @@ -82,6 +104,9 @@ void Hero::CreateTypeDescription() { td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID)); td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID)); + td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetReferenced().SetAggregate()); + + td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID)); td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes")); td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));