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