]> git.localhorst.tv Git - l2e.git/blob - src/battle/Monster.cpp
implemented modulo operation for scripts
[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
58         int animationId(TypeDescription::GetTypeId("Animation"));
59         int numberId(TypeDescription::GetTypeId("Number"));
60         int spriteId(TypeDescription::GetTypeId("Sprite"));
61         int statsId(TypeDescription::GetTypeId("Stats"));
62         int stringId(TypeDescription::GetTypeId("String"));
63
64         TypeDescription &td(TypeDescription::CreateOrGet("Monster"));
65         td.SetDescription("All data of a monster.");
66         td.SetConstructor(&Construct);
67         td.SetSize(sizeof(Monster));
68
69         td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), stringId).SetReferenced());
70         td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), spriteId).SetReferenced());
71         td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), numberId));
72
73         td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), numberId));
74         td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), numberId));
75         td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), numberId));
76         td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), numberId));
77         td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), statsId));
78
79         td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), animationId).SetReferenced());
80         td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), animationId).SetReferenced());
81         td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), animationId).SetReferenced());
82 }
83
84 void Monster::Construct(void *data) {
85         new (data) Monster;
86 }
87
88 }