Otclient  14/8/2020
item.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef ITEM_H
24 #define ITEM_H
25 
26 #include <framework/global.h>
27 
28 #include "thing.h"
29 #include "effect.h"
30 #include "itemtype.h"
31 
33 {
34  ATTR_END = 0,
35  //ATTR_DESCRIPTION = 1,
36  //ATTR_EXT_FILE = 2,
40  ATTR_TEXT = 6,
41  ATTR_DESC = 7,
43  ATTR_ITEM = 9,
45  //ATTR_EXT_SPAWN_FILE = 11,
47  //ATTR_EXT_HOUSE_FILE = 13,
49  ATTR_COUNT = 15,
58  ATTR_NAME = 30,
64  ATTR_ARMOR = 37,
72 };
73 
74 // @bindclass
75 #pragma pack(push,1) // disable memory alignment
76 class Item : public Thing
77 {
78 public:
79  Item();
80  virtual ~Item() { }
81 
82  static ItemPtr create(int id);
83  static ItemPtr createFromOtb(int id);
84 
85  void draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView = nullptr);
86 
87  void setId(uint32 id);
88  void setOtbId(uint16 id);
89  void setCountOrSubType(int value) { m_countOrSubType = value; }
90  void setCount(int count) { m_countOrSubType = count; }
91  void setSubType(int subType) { m_countOrSubType = subType; }
92  void setColor(const Color& c) { m_color = c; }
93 
94  int getCountOrSubType() { return m_countOrSubType; }
95  int getSubType();
96  int getCount();
97  uint32 getId() { return m_clientId; }
98  uint16 getClientId() { return m_clientId; }
99  uint16 getServerId() { return m_serverId; }
100  std::string getName();
101  bool isValid();
102 
103  void unserializeItem(const BinaryTreePtr& in);
104  void serializeItem(const OutputBinaryTreePtr& out);
105 
106  void setDepotId(uint16 depotId) { m_attribs.set(ATTR_DEPOT_ID, depotId); }
107  uint16 getDepotId() { return m_attribs.get<uint16>(ATTR_DEPOT_ID); }
108 
109  void setDoorId(uint8 doorId) { m_attribs.set(ATTR_HOUSEDOORID, doorId); }
110  uint8 getDoorId() { return m_attribs.get<uint8>(ATTR_HOUSEDOORID); }
111 
112  uint16 getUniqueId() { return m_attribs.get<uint16>(ATTR_ACTION_ID); }
113  uint16 getActionId() { return m_attribs.get<uint16>(ATTR_UNIQUE_ID); }
114  void setActionId(uint16 actionId) { m_attribs.set(ATTR_ACTION_ID, actionId); }
115  void setUniqueId(uint16 uniqueId) { m_attribs.set(ATTR_UNIQUE_ID, uniqueId); }
116 
117  std::string getText() { return m_attribs.get<std::string>(ATTR_TEXT); }
118  std::string getDescription() { return m_attribs.get<std::string>(ATTR_DESC); }
119  void setDescription(std::string desc) { m_attribs.set(ATTR_DESC, desc); }
120  void setText(std::string txt) { m_attribs.set(ATTR_TEXT, txt); }
121 
123  void setTeleportDestination(const Position& pos) { m_attribs.set(ATTR_TELE_DEST, pos); }
124 
125  void setAsync(bool enable) { m_async = enable; }
126 
127  bool isHouseDoor() { return m_attribs.has(ATTR_HOUSEDOORID); }
128  bool isDepot() { return m_attribs.has(ATTR_DEPOT_ID); }
129  bool isContainer() { return m_attribs.has(ATTR_CONTAINER_ITEMS); }
130  bool isDoor() { return m_attribs.has(ATTR_HOUSEDOORID); }
131  bool isTeleport() { return m_attribs.has(ATTR_TELE_DEST); }
132  bool isMoveable();
133  bool isGround();
134 
135  ItemPtr clone();
136  ItemPtr asItem() { return static_self_cast<Item>(); }
137  bool isItem() { return true; }
138 
139  ItemVector getContainerItems() { return m_containerItems; }
140  ItemPtr getContainerItem(int slot) { return m_containerItems[slot]; }
141  void addContainerItemIndexed(const ItemPtr& i, int slot) { m_containerItems[slot] = i; }
142  void addContainerItem(const ItemPtr& i) { m_containerItems.push_back(i); }
143  void removeContainerItem(int slot) { m_containerItems[slot] = nullptr; }
144  void clearContainerItems() { m_containerItems.clear(); }
145 
146  void calculatePatterns(int& xPattern, int& yPattern, int& zPattern);
147  int calculateAnimationPhase(bool animate);
148  int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
149 
150  const ThingTypePtr& getThingType();
152 
153 private:
154  uint16 m_clientId;
155  uint16 m_serverId;
156  uint8 m_countOrSubType;
158  ItemVector m_containerItems;
159  Color m_color;
160  bool m_async;
161 
162  uint8 m_phase;
163  ticks_t m_lastPhase;
164 };
165 
166 #pragma pack(pop)
167 
168 #endif
Item::Item
Item()
Definition: item.cpp:40
ATTR_CHARGES
@ ATTR_CHARGES
Definition: item.h:56
Item::setAsync
void setAsync(bool enable)
Definition: item.h:125
Item::asItem
ItemPtr asItem()
Definition: item.h:136
Item::isContainer
bool isContainer()
Definition: item.h:129
Item::serializeItem
void serializeItem(const OutputBinaryTreePtr &out)
Definition: item.cpp:185
Item::isGround
bool isGround()
Definition: item.cpp:261
stdext::packed_storage::get
T get(Key id) const
Definition: packed_storage.h:80
ATTR_ARMOR
@ ATTR_ARMOR
Definition: item.h:64
Color
Definition: color.h:32
ATTR_CONTAINER_ITEMS
@ ATTR_CONTAINER_ITEMS
Definition: item.h:57
Item::getId
uint32 getId()
Definition: item.h:97
ATTR_ARTICLE
@ ATTR_ARTICLE
Definition: item.h:68
ATTR_TEXT
@ ATTR_TEXT
Definition: item.h:40
ATTR_SLEEPSTART
@ ATTR_SLEEPSTART
Definition: item.h:55
Item::setCountOrSubType
void setCountOrSubType(int value)
Definition: item.h:89
Item::setColor
void setColor(const Color &c)
Definition: item.h:92
ATTR_SCRIPTPROTECTED
@ ATTR_SCRIPTPROTECTED
Definition: item.h:69
ATTR_ATTACK
@ ATTR_ATTACK
Definition: item.h:60
uint32
uint32_t uint32
Definition: types.h:35
Item::setSubType
void setSubType(int subType)
Definition: item.h:91
ATTR_COUNT
@ ATTR_COUNT
Definition: item.h:49
ATTR_UNIQUE_ID
@ ATTR_UNIQUE_ID
Definition: item.h:39
ATTR_ACTION_ID
@ ATTR_ACTION_ID
Definition: item.h:38
Item::getContainerItem
ItemPtr getContainerItem(int slot)
Definition: item.h:140
Item::unserializeItem
void unserializeItem(const BinaryTreePtr &in)
Definition: item.cpp:119
Item::clearContainerItems
void clearContainerItems()
Definition: item.h:144
Item::getThingType
const ThingTypePtr & getThingType()
Definition: item.cpp:410
ticks_t
int64 ticks_t
Definition: types.h:43
Item::setDepotId
void setDepotId(uint16 depotId)
Definition: item.h:106
Item::setText
void setText(std::string txt)
Definition: item.h:120
ATTR_DURATION
@ ATTR_DURATION
Definition: item.h:50
ATTR_TELE_DEST
@ ATTR_TELE_DEST
Definition: item.h:42
Item::addContainerItemIndexed
void addContainerItemIndexed(const ItemPtr &i, int slot)
Definition: item.h:141
Item::setId
void setId(uint32 id)
Definition: item.cpp:93
Item::setUniqueId
void setUniqueId(uint16 uniqueId)
Definition: item.h:115
Item::getContainerItems
ItemVector getContainerItems()
Definition: item.h:139
Item::setOtbId
void setOtbId(uint16 id)
Definition: item.cpp:101
Thing
Definition: thing.h:33
Item::getUniqueId
uint16 getUniqueId()
Definition: item.h:112
LightView
Definition: lightview.h:37
ATTR_PLURALNAME
@ ATTR_PLURALNAME
Definition: item.h:59
ATTR_DECAYING_STATE
@ ATTR_DECAYING_STATE
Definition: item.h:51
Item::setDescription
void setDescription(std::string desc)
Definition: item.h:119
ATTR_EXTRAATTACK
@ ATTR_EXTRAATTACK
Definition: item.h:61
uint16
uint16_t uint16
Definition: types.h:36
Item::calculatePatterns
void calculatePatterns(int &xPattern, int &yPattern, int &zPattern)
Definition: item.cpp:273
Item::getName
std::string getName()
Definition: item.cpp:65
Item::getDescription
std::string getDescription()
Definition: item.h:118
Item::getTeleportDestination
Position getTeleportDestination()
Definition: item.h:122
Item::setTeleportDestination
void setTeleportDestination(const Position &pos)
Definition: item.h:123
Item::isValid
bool isValid()
Definition: item.cpp:114
Item::isHouseDoor
bool isHouseDoor()
Definition: item.h:127
ATTR_RUNE_CHARGES
@ ATTR_RUNE_CHARGES
Definition: item.h:46
Item::removeContainerItem
void removeContainerItem(int slot)
Definition: item.h:143
ATTR_ITEM
@ ATTR_ITEM
Definition: item.h:43
Position
Definition: position.h:33
Item::draw
void draw(const Point &dest, float scaleFactor, bool animate, LightView *lightView=nullptr)
Definition: item.cpp:70
Item::createFromOtb
static ItemPtr createFromOtb(int id)
Definition: item.cpp:58
Item::getClientId
uint16 getClientId()
Definition: item.h:98
Item::getActionId
uint16 getActionId()
Definition: item.h:113
Item::getServerId
uint16 getServerId()
Definition: item.h:99
Item::setActionId
void setActionId(uint16 actionId)
Definition: item.h:114
Item::setCount
void setCount(int count)
Definition: item.h:90
stdext::packed_storage< uint8 >
ATTR_ATTRIBUTE_MAP
@ ATTR_ATTRIBUTE_MAP
Definition: item.h:71
Item::clone
ItemPtr clone()
Definition: item.cpp:266
ATTR_WRITTENDATE
@ ATTR_WRITTENDATE
Definition: item.h:52
ATTR_HITCHANCE
@ ATTR_HITCHANCE
Definition: item.h:66
ThingType
Definition: thingtype.h:123
ATTR_DESC
@ ATTR_DESC
Definition: item.h:41
Item::calculateAnimationPhase
int calculateAnimationPhase(bool animate)
Definition: item.cpp:381
Item::getSubType
int getSubType()
Definition: item.cpp:240
Item::setDoorId
void setDoorId(uint8 doorId)
Definition: item.h:109
Item::isDoor
bool isDoor()
Definition: item.h:130
Item::getText
std::string getText()
Definition: item.h:117
ATTR_DUALWIELD
@ ATTR_DUALWIELD
Definition: item.h:70
Item::isMoveable
bool isMoveable()
Definition: item.cpp:256
Item::isDepot
bool isDepot()
Definition: item.h:128
Item::create
static ItemPtr create(int id)
Definition: item.cpp:51
ATTR_EXTRADEFENSE
@ ATTR_EXTRADEFENSE
Definition: item.h:63
ATTR_END
@ ATTR_END
Definition: item.h:34
Item
Definition: item.h:76
Item::~Item
virtual ~Item()
Definition: item.h:80
ATTR_DEPOT_ID
@ ATTR_DEPOT_ID
Definition: item.h:44
ATTR_DEFENSE
@ ATTR_DEFENSE
Definition: item.h:62
Item::isItem
bool isItem()
Definition: item.h:137
stdext::packed_storage::has
bool has(Key id) const
Definition: packed_storage.h:87
effect.h
stdext::shared_object_ptr< Item >
itemtype.h
Item::getExactSize
int getExactSize(int layer=0, int xPattern=0, int yPattern=0, int zPattern=0, int animationPhase=0)
Definition: item.cpp:403
Item::getDoorId
uint8 getDoorId()
Definition: item.h:110
Item::getDepotId
uint16 getDepotId()
Definition: item.h:107
ATTR_SLEEPERGUID
@ ATTR_SLEEPERGUID
Definition: item.h:54
ATTR_WRITTENBY
@ ATTR_WRITTENBY
Definition: item.h:53
ItemVector
std::vector< ItemPtr > ItemVector
Definition: declarations.h:87
ATTR_NAME
@ ATTR_NAME
Definition: item.h:58
ItemAttr
ItemAttr
Definition: item.h:32
thing.h
stdext::packed_storage::set
void set(Key id, const T &value)
Definition: packed_storage.h:47
TPoint< int >
Item::getCount
int getCount()
Definition: item.cpp:249
Item::addContainerItem
void addContainerItem(const ItemPtr &i)
Definition: item.h:142
global.h
ATTR_TILE_FLAGS
@ ATTR_TILE_FLAGS
Definition: item.h:37
Item::isTeleport
bool isTeleport()
Definition: item.h:131
ATTR_HOUSEDOORID
@ ATTR_HOUSEDOORID
Definition: item.h:48
ATTR_SHOOTRANGE
@ ATTR_SHOOTRANGE
Definition: item.h:67
Item::getCountOrSubType
int getCountOrSubType()
Definition: item.h:94
uint8
uint8_t uint8
Definition: types.h:37
ATTR_ATTACKSPEED
@ ATTR_ATTACKSPEED
Definition: item.h:65
Item::rawGetThingType
ThingType * rawGetThingType()
Definition: item.cpp:415