]> git.localhorst.tv Git - l2e.git/blob - src/common/Item.cpp
955f48c9e6204954e08c3faef26a8a7d75346e2e
[l2e.git] / src / common / Item.cpp
1 /*
2  * Item.cpp
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #include "Item.h"
9
10 #include "Ikari.h"
11 #include "TargetingMode.h"
12 #include "../graphics/Animation.h"
13 #include "../graphics/Sprite.h"
14 #include "../loader/Interpreter.h"
15 #include "../loader/TypeDescription.h"
16
17 using graphics::Animation;
18 using graphics::Sprite;
19 using loader::FieldDescription;
20 using loader::Interpreter;
21 using loader::TypeDescription;
22
23 namespace common {
24
25 Item::Item()
26 : name("")
27 , menuIcon(0)
28 , chestIcon(0)
29 , ikari(0)
30 , attackAnimation(0)
31
32 , value(0)
33 , properties(0)
34
35 , equipability(0)
36 , heroMask(0)
37
38 , mostUseful(false)
39 , cursed(false)
40 , fruit(false)
41 , scenario(false)
42 , status(false)
43 , battle(false) {
44
45 }
46
47
48 void Item::CreateTypeDescription() {
49         Item i;
50
51         TypeDescription &td(TypeDescription::Create(TYPE_ID, "Item"));
52         td.SetDescription("All data of an item (soon).");
53         td.SetConstructor(&Construct);
54         td.SetSize(sizeof(Item));
55
56         td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), Interpreter::STRING_ID).SetReferenced().SetDescription("the item's name"));
57         td.AddField("menuicon", FieldDescription(((char *)&i.menuIcon) - ((char *)&i), Sprite::TYPE_ID).SetReferenced().SetDescription("icon that is displayed in menus"));
58
59         td.AddField("mostUseful", FieldDescription(((char *)&i.mostUseful) - ((char *)&i), Interpreter::BOOLEAN_ID));
60         td.AddField("cursed", FieldDescription(((char *)&i.cursed) - ((char *)&i), Interpreter::BOOLEAN_ID));
61         td.AddField("fruit", FieldDescription(((char *)&i.fruit) - ((char *)&i), Interpreter::BOOLEAN_ID));
62         td.AddField("scenario", FieldDescription(((char *)&i.scenario) - ((char *)&i), Interpreter::BOOLEAN_ID));
63         td.AddField("status", FieldDescription(((char *)&i.status) - ((char *)&i), Interpreter::BOOLEAN_ID));
64         td.AddField("battle", FieldDescription(((char *)&i.battle) - ((char *)&i), Interpreter::BOOLEAN_ID).SetDescription("if the item can be used in battle"));
65
66         td.AddField("targets", FieldDescription(((char *)&i.targettingMode) - ((char *)&i), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed"));
67         td.AddField("ikari", FieldDescription(((char *)&i.ikari) - ((char *)&i), Ikari::TYPE_ID).SetReferenced().SetDescription("ikari attack of the item (sensible only for equipment)"));
68         td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), Animation::TYPE_ID).SetReferenced().SetDescription("animation that is run when the item is used for attacking"));
69         td.AddField("equipability", FieldDescription(((char *)&i.equipability) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("how this item can be equipped"));
70         td.AddField("heroMask", FieldDescription(((char *)&i.heroMask) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("which heroes may equip this item"));
71 }
72
73 void Item::Construct(void *data) {
74         new (data) Item;
75 }
76
77
78 bool Item::Less(const Item &lhs, const Item &rhs) {
79         if (lhs.IsMostUseful()) {
80                 return !rhs.IsMostUseful();
81         }
82         if (lhs.IsEquipable()) {
83                 if (rhs.IsMostUseful()) {
84                         return false;
85                 }
86                 if (!rhs.IsEquipable()) {
87                         return true;
88                 }
89                 return lhs.equipability < rhs.equipability;
90         }
91         if (lhs.IsFruit()) {
92                 if (rhs.IsMostUseful() || rhs.IsEquipable()) {
93                         return true;
94                 }
95                 return !rhs.IsFruit();
96         }
97         return false;
98 }
99
100 }