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