X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FMonster.cpp;h=0088c7935856f817ebdd05015f287635c46c6be7;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=1a52b7911004a7fb4e4d16a0a11a4f28d78bfc25;hpb=6a3e02e15c1626958540626bf2ccf39f8e365ca5;p=l2e.git diff --git a/src/battle/Monster.cpp b/src/battle/Monster.cpp index 1a52b79..0088c79 100644 --- a/src/battle/Monster.cpp +++ b/src/battle/Monster.cpp @@ -1,22 +1,83 @@ -/* - * Monster.cpp - * - * Created on: Aug 3, 2012 - * Author: holy - */ - #include "Monster.h" +#include "../common/Stats.h" +#include "../graphics/Animation.h" +#include "../graphics/Sprite.h" +#include "../loader/Interpreter.h" +#include "../loader/TypeDescription.h" + +using common::Stats; +using graphics::Animation; +using graphics::Sprite; +using loader::FieldDescription; +using loader::Interpreter; +using loader::TypeDescription; + namespace battle { -Monster::Monster() { - // TODO Auto-generated constructor stub +Monster::Monster() +: name("") +, sprite(0) +, dropItem(0) +, attackScript(0) +, defenseScript(0) + +, meleeAnimation(0) +, attackAnimation(0) +, spellAnimation(0) + +, maxHealth(0) +, health(0) +, maxMana(0) +, mana(0) + +, expReward(0) +, goldReward(0) + +, level(0) +, dropChance(0) { } Monster::~Monster() { - // TODO Auto-generated destructor stub } -} /* namespace battle */ + +void Monster::SubtractHealth(int amount) { + if (amount > Health()) { + health = 0; + } else { + health -= amount; + } +} + + +void Monster::CreateTypeDescription() { + Monster m; + + TypeDescription &td(TypeDescription::Create(TYPE_ID, "Monster")); + td.SetDescription("All data of a monster."); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Monster)); + + td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), Interpreter::STRING_ID).SetReferenced()); + td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), Sprite::TYPE_ID).SetReferenced()); + td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), Interpreter::NUMBER_ID)); + + td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), Interpreter::NUMBER_ID)); + td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), Interpreter::NUMBER_ID)); + td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), Interpreter::NUMBER_ID)); + td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), Interpreter::NUMBER_ID)); + td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), Stats::TYPE_ID)); + + td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced()); + td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced()); + td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced()); +} + +void Monster::Construct(void *data) { + new (data) Monster; +} + +}