]> git.localhorst.tv Git - l2e.git/blob - src/battle/Monster.cpp
8ea79e676d080d4019c812a41581f0a74aee966e
[l2e.git] / src / battle / Monster.cpp
1 /*
2  * Monster.cpp
3  *
4  *  Created on: Aug 3, 2012
5  *      Author: holy
6  */
7
8 #include "Monster.h"
9
10 #include "../common/Stats.h"
11 #include "../graphics/Animation.h"
12 #include "../graphics/Sprite.h"
13 #include "../loader/Interpreter.h"
14 #include "../loader/TypeDescription.h"
15
16 using common::Stats;
17 using graphics::Animation;
18 using graphics::Sprite;
19 using loader::FieldDescription;
20 using loader::Interpreter;
21 using loader::TypeDescription;
22
23 namespace battle {
24
25 Monster::Monster()
26 : name("")
27 , sprite(0)
28 , dropItem(0)
29 , attackScript(0)
30 , defenseScript(0)
31
32 , meleeAnimation(0)
33 , attackAnimation(0)
34 , spellAnimation(0)
35
36 , maxHealth(0)
37 , health(0)
38 , maxMana(0)
39 , mana(0)
40
41 , expReward(0)
42 , goldReward(0)
43
44 , level(0)
45 , dropChance(0) {
46
47 }
48
49 Monster::~Monster() {
50
51 }
52
53
54 void Monster::SubtractHealth(int amount) {
55         if (amount > Health()) {
56                 health = 0;
57         } else {
58                 health -= amount;
59         }
60 }
61
62
63 void Monster::CreateTypeDescription() {
64         Monster m;
65
66         TypeDescription &td(TypeDescription::Create(TYPE_ID, "Monster"));
67         td.SetDescription("All data of a monster.");
68         td.SetConstructor(&Construct);
69         td.SetSize(sizeof(Monster));
70
71         td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), Interpreter::STRING_ID).SetReferenced());
72         td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), Sprite::TYPE_ID).SetReferenced());
73         td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), Interpreter::NUMBER_ID));
74
75         td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), Interpreter::NUMBER_ID));
76         td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), Interpreter::NUMBER_ID));
77         td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), Interpreter::NUMBER_ID));
78         td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), Interpreter::NUMBER_ID));
79         td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), Stats::TYPE_ID));
80
81         td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
82         td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
83         td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
84 }
85
86 void Monster::Construct(void *data) {
87         new (data) Monster;
88 }
89
90 }