]> git.localhorst.tv Git - l2e.git/blob - src/common/Item.cpp
259c4b55c449b8b92c6fae38ffed078af0956e83
[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
37 , mostUseful(false)
38 , cursed(false)
39 , fruit(false)
40 , scenario(false)
41 , status(false)
42 , battle(false) {
43
44 }
45
46
47 void Item::CreateTypeDescription() {
48         Item i;
49
50         TypeDescription &td(TypeDescription::Create(TYPE_ID, "Item"));
51         td.SetDescription("All data of an item (soon).");
52         td.SetConstructor(&Construct);
53         td.SetSize(sizeof(Item));
54
55         td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), Interpreter::STRING_ID).SetReferenced().SetDescription("the item's name"));
56         td.AddField("menuicon", FieldDescription(((char *)&i.menuIcon) - ((char *)&i), Sprite::TYPE_ID).SetReferenced().SetDescription("icon that is displayed in menus"));
57
58         td.AddField("mostUseful", FieldDescription(((char *)&i.mostUseful) - ((char *)&i), Interpreter::BOOLEAN_ID));
59         td.AddField("cursed", FieldDescription(((char *)&i.cursed) - ((char *)&i), Interpreter::BOOLEAN_ID));
60         td.AddField("fruit", FieldDescription(((char *)&i.fruit) - ((char *)&i), Interpreter::BOOLEAN_ID));
61         td.AddField("scenario", FieldDescription(((char *)&i.scenario) - ((char *)&i), Interpreter::BOOLEAN_ID));
62         td.AddField("status", FieldDescription(((char *)&i.status) - ((char *)&i), Interpreter::BOOLEAN_ID));
63         td.AddField("battle", FieldDescription(((char *)&i.battle) - ((char *)&i), Interpreter::BOOLEAN_ID).SetDescription("if the item can be used in battle"));
64
65         td.AddField("targets", FieldDescription(((char *)&i.targettingMode) - ((char *)&i), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed"));
66         td.AddField("ikari", FieldDescription(((char *)&i.ikari) - ((char *)&i), Ikari::TYPE_ID).SetReferenced().SetDescription("ikari attack of the item (sensible only for equipment)"));
67         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"));
68         td.AddField("equipability", FieldDescription(((char *)&i.equipability) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("how this item can be equipped"));
69 }
70
71 void Item::Construct(void *data) {
72         new (data) Item;
73 }
74
75
76 bool Item::Less(const Item &lhs, const Item &rhs) {
77         if (lhs.IsMostUseful()) {
78                 return !rhs.IsMostUseful();
79         }
80         if (lhs.IsEquipable()) {
81                 if (rhs.IsMostUseful()) {
82                         return false;
83                 }
84                 if (!rhs.IsEquipable()) {
85                         return true;
86                 }
87                 return lhs.equipability < rhs.equipability;
88         }
89         if (lhs.IsFruit()) {
90                 if (rhs.IsMostUseful() || rhs.IsEquipable()) {
91                         return true;
92                 }
93                 return !rhs.IsFruit();
94         }
95         return false;
96 }
97
98 }