X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FMonster.cpp;h=498a8c6094ff181d311a334c337f1d9a70cdbf06;hb=4bc70f5311dcbcca4e6b9e852bbcb19602f50eeb;hp=1a52b7911004a7fb4e4d16a0a11a4f28d78bfc25;hpb=6a3e02e15c1626958540626bf2ccf39f8e365ca5;p=l2e.git diff --git a/src/battle/Monster.cpp b/src/battle/Monster.cpp index 1a52b79..498a8c6 100644 --- a/src/battle/Monster.cpp +++ b/src/battle/Monster.cpp @@ -7,16 +7,82 @@ #include "Monster.h" +#include "../loader/TypeDescription.h" + +using loader::FieldDescription; +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; + + 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")); + + TypeDescription &td(TypeDescription::CreateOrGet("Monster")); + td.SetDescription("All data of a monster."); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Monster)); + + td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), stringId).SetReferenced()); + td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), spriteId).SetReferenced()); + td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), numberId)); + + td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), numberId)); + td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), numberId)); + td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), numberId)); + td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), numberId)); + td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), statsId)); + + td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), animationId).SetReferenced()); + td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), animationId).SetReferenced()); + td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), animationId).SetReferenced()); +} + +void Monster::Construct(void *data) { + new (data) Monster; +} + +}