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