EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
InventoryItem.h
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------
3  * LICENSE:
4  * ------------------------------------------------------------------------------------
5  * This file is part of EVEmu: EVE Online Server Emulator
6  * Copyright 2006 - 2021 The EVEmu Team
7  * For the latest information visit https://evemu.dev
8  * ------------------------------------------------------------------------------------
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the Free Software
11  * Foundation; either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with
19  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  * http://www.gnu.org/copyleft/lesser.txt.
22  * ------------------------------------------------------------------------------------
23  * Author: Zhur
24  * Rewrite: Allan
25  */
26 #ifndef EVE_INVENTORY_ITEM_H
27 #define EVE_INVENTORY_ITEM_H
28 
29 
30 #include "POD_containers.h"
31 #include "inventory/ItemDB.h"
32 #include "inventory/Inventory.h"
33 #include "inventory/InventoryDB.h"
34 #include "inventory/ItemType.h"
35 #include "inventory/ItemFactory.h"
36 #include "inventory/AttributeMap.h"
37 
38 class PyRep;
39 class PyDict;
40 class PyObject;
41 class ShipItem;
42 class ServiceDB;
43 class ModuleItem;
44 class ItemContainer;
45 class Rsp_CommonGetInfo_Entry;
46 
47 /*
48  * NOTE:
49  * this object system should somehow be merged with the SystemEntity stuff
50  * and class hierarchy built from it (Client, NPC, etc..) in the system manager...
51  * however, the creation and destruction time logic is why it has not been done.
52  *
53  * NOTE:
54  * this system cannot and should not be merged with SE class, as not all Items are SE.
55  * doing so would cause unnecessary SEs to be created for items that are NOT SE.
56  * keeping this as a separate class is cleaner and better for creation and destruction
57  * for both base and derived classes. -allan 23.2.16
58  */
59 
60 /*
61  * Class which maintains generic Inventory item.
62  */
64 : public RefObject
65 {
66 public:
67  InventoryItem(uint32 _itemID, const ItemType &_type, const ItemData &_data);
68 
69  /* begin rewrite and update */
70  // copy c'tor
71  InventoryItem(const InventoryItem& oth);
72  // move c'tor
73  InventoryItem(InventoryItem&& oth) noexcept;
74  // copy assignment
75  InventoryItem& operator= (const InventoryItem& oth) =delete;
76  // move assignment
77  InventoryItem& operator= (InventoryItem&& oth) =delete;
78 
79  virtual ~InventoryItem() noexcept;
80 
81  /* class type pointer querys. */
82  virtual ShipItem* GetShipItem() { return nullptr; }
83  virtual ModuleItem* GetModuleItem() { return nullptr; }
84  /* class type tests. */
85  virtual bool IsShipItem() { return false; }
86  virtual bool IsModuleItem() { return false; }
87 
88  virtual void Rename(std::string name);
89 
90  /* generic access functions handled here */
92 
93  /* common functions for all entities handled here */
94  /* public data queries */
95  bool contraband() const { return m_data.contraband; }
96  bool isSingleton() const { return m_data.singleton != 0; }
97  int32 quantity() const { return m_data.quantity; }
98  uint32 itemID() const { return m_itemID; }
99  uint32 ownerID() const { return m_data.ownerID; }
100  uint32 locationID() const { return m_data.locationID; }
101  EVEItemFlags flag() const { return m_data.flag; }
102  const GPoint & position() const { return m_data.position; }
103  const ItemType & type() const { return m_type; }
104  const std::string & itemName() const { return m_data.name; }
105  const std::string & customInfo() const { return m_data.customInfo; }
106 
107  const char* name() { return m_data.name.c_str(); }
108 
109  /* public type queries */
110  uint16 typeID() const { return m_type.id(); }
111  uint16 groupID() const { return m_type.groupID(); }
112  double radius() const { return (HasAttribute(AttrRadius) ? GetAttribute(AttrRadius).get_double() : 1.0); }
113  uint8 categoryID() const { return m_type.categoryID(); }
114  bool isGlobal() const { return (HasAttribute(AttrIsGlobal) ? GetAttribute(AttrIsGlobal).get_bool() : false); }
115  bool IsOnline() { return GetAttribute(AttrOnline).get_bool(); }
116 
117  /* public-access generic functions handled in base class. */
118  void SetPosition(const GPoint& pos); // change coords of item
119  void SetCustomInfo(const char *ci);
120  void ChangeOwner(uint32 new_owner, bool notify=false);
121  // remove item from old location, add to new location and (optionally) notify client of changes
122  // will bcast to corp for item update (incomplete)
123  void Move(uint32 new_location=locTemp, EVEItemFlags flag=flagNone, bool notify=false);
124  // same as Move() but xfer ownership also
125  // will bcast to corp for item update (incomplete)
126  void Donate(uint32 new_owner=ownerSystem, uint32 new_location=locTemp, EVEItemFlags new_flag=flagNone, bool notify=true);
127  void SendItemChange(uint32 toID, std::map< int32, PyRep* >& changes);
128  // this is for stacking recovered probes, mined ore, and salvage in ship's cargo
129  void MergeTypesInCargo(ShipItem* pShip, EVEItemFlags flag=flagNone); // will test for existing types
130  bool ChangeSingleton(bool singleton, bool notify=false);
131  // this also updates volume of item
132  bool AlterQuantity(int32 qty, bool notify=false); // make sure to use proper sign
133  bool SetQuantity(int32 qty, bool notify=false, bool deleteOnZero=true);
134  // sets new flag, if different, saves update to db, and (optionally) notifies client of change
135  bool SetFlag(EVEItemFlags flag, bool notify=false);
136  // sets owner for player-owned npc types (drone, missile, etc)
138 
139  /* public-access data functions handled in base class. */
140  void SaveItem(); //save the item to the DB.
141  void UpdateLocation(); // save item's location, owner, flag
142  void UpdateLocation(uint32 locID) { m_data.locationID = locID; } // change item's locationID without saving
143 
144  /* virtual functions default to base class and overridden as needed */
145  virtual void Delete(); //totally removes item from game and deletes from the DB.
146  // makes new stack of 'qty', then returns ref of new stack and update client for qty change
147  // notify will update client for the new stack.
148  // silent will not call Move() on new stack (which is loc=0).
149  // failure will return nullptr
150  virtual InventoryItemRef Split(int32 qty=0, bool notify=true, bool silent=false);
151  // combines stacks of identical typeIDs
152  virtual bool Merge(InventoryItemRef to_merge, int32 qty=0, bool notify=true);
153  // same as Move() but doesnt remove item from previous location
154  // used for moving charges to/from ship without calling Remove()
155  virtual void Relocate(uint32 locID=0, EVEItemFlags flag=flagNone);
156 
157  // add itemRef to our inventory.
158  // does not move item
159  virtual void AddItem(InventoryItemRef iRef);
160  // remove itemRef from our inventory.
161  // does not move item
162  virtual void RemoveItem(InventoryItemRef iRef);
163 
164  /* specific functions handled here */
165  /* returns uID for new item. saves item data to db */
166  static uint32 CreateItemID( ItemData &data);
167  /* returns uID for temp item, without saving to db */
168  static uint32 CreateTempItemID( ItemData &data);
169  /* loads attributes for this item */
170  //bool LoadAttributes();
171  double GetPackagedVolume();
172 
173  /* specific functions for ShipItem, virtual here to allow generic class access */
174  virtual void SetPlayer(Client* pClient) { /* do nothing here */ }
175  virtual bool HasPilot() { return false; }
176  virtual Client* GetPilot() { return nullptr; }
177 
178  /* specific function from real item to virtual item for PI commodity xfer */
179  void ToVirtual(uint32 locationID); // this deletes item without updating client with 'this is deleted' data
180 
181  /*********************************************************************************************
182  *
183  * TEMPLATED LOADING INVOKATION EXPLANATION: (written by allan)
184  * Item types and classes (and their children) have special loading.
185  * Every such type has following methods: (with ShipItem being the exception)
186  *
187  * static Load( <identifier>):
188  * Merges static and virtual loading trees.
189  * Call to static _Load()
190  * Call object's virtual _Load()
191  *
192  * static _Load( <identifier>[, <data-argument>, ...]):
193  * retreives specific item data from db for created items, or creates default data for new items.
194  * retrieves type info from static data
195  * Call static _Ty::LoadItem()
196  *
197  * static _Ty::LoadItem():
198  * creates/retrieves additional item data as required
199  * call the item constructor to create object
200  *
201  * virtual _Load():
202  * Performs post-construction loading (container contents) as needed,
203  * Call InventoryItem::_Load() to load the item's attributes
204  * Add the created item to it's location's inventory.
205  *
206  *********************************************************************************************/
207 
208  /* Item Creating and Loading methods */
209  /* calls _Ty::Load<_Ty>. */
211  /* creates new Item and calls item::_Load() */
212  /* does not save to db. does not add item to ItemFactory */
213  static InventoryItemRef SpawnItem( uint32 itemID, const ItemData &data);
214  /* Spawns new Item and saves to db, except missile, sentry, forcefields */
215  static InventoryItemRef Spawn( ItemData &data);
216  /* Spawns new temp Item. not saved to db */
217  static InventoryItemRef SpawnTemp( ItemData &data); // incomplete. returns generic SpawnItem()
218 
219  /* base class _Load() only loads attributes */
220  virtual bool _Load();
221 
222 protected:
223  /* template helper, calls template loader (below) then class loader */
224  template<class _Ty>
226  {
227  // static load
228  RefPtr<_Ty> i = _Ty::template _Load<_Ty>( itemID );
229  if (!i)
230  return RefPtr<_Ty>();
231 
232  // virtual load (load attributes)
233  if (!i->_Load())
234  return RefPtr<_Ty>();
235 
236  return i;
237  }
238 
239  /* template loader, calls class _LoadItem */
240  template<class _Ty>
242  {
243  // pull the specific item info from db
244  ItemData data;
245  if (!ItemDB::GetItem(itemID, data))
246  return RefPtr<_Ty>();
247 
248  // obtain type
249  const ItemType *type = sItemFactory.GetType( data.typeID );
250  if( type == nullptr )
251  return RefPtr<_Ty>();
252 
253  return _Ty::template _LoadItem<_Ty>( itemID, *type, data );
254  }
255 
256  /* template class _LoadItem. defined in derived class. calls class c'tor */
257  template<class _Ty>
258  static RefPtr<_Ty> _LoadItem( uint32 itemID, const ItemType &type, const ItemData &data);
259 
260 
261 public:
262  /* Primary public packet builders */
263  PyRep* GetItem() const { return GetItemRow(); }
264 
265  void GetItemRow( PyPackedRow* into ) const;
266  void GetItemStatusRow( PyPackedRow* into ) const;
267  void GetChargeStatusRow( uint32 shipID, PyPackedRow* into ) const;
268 
269  bool Populate(Rsp_CommonGetInfo_Entry &into);
270 
271  PyList* GetItemInfo() const;
273  PyPackedRow* GetItemRow() const;
274  PyPackedRow* GetItemStatusRow() const;
275  PyPackedRow* GetChargeStatusRow(uint32 shipID) const;
276 
277 protected:
280 
281 private:
282  bool m_delete;
285 
286 /* new effects processing system */
287 public:
288  /* this checks this item's required skills against callers' current skills.
289  * returns true if all pass */
290  bool SkillCheck(InventoryItemRef refItem);
291 
292  // this clears m_modifiers
293  void ClearModifiers();
294  void AddModifier(fxData &data);
295  void RemoveModifier(fxData &data);
296  // this deletes all attributes, reloads default attribs from itemType and
297  void ResetAttributes(); // when called at the wrong time, this will really fuck up ship attributes. ;)
298 
299  // if itemType requires skill(skillID) return true else return false
300  bool HasReqSkill(const uint16 skillID) { return m_type.HasReqSkill(skillID); }
301 
302  // gotta make this public for now...
303  std::multimap<int8, fxData> m_modifiers; // k,v of math, data<math, src, targLoc, targAttr, srcAttr, grpID, typeID>, ordered by key (mathMethod)
304 
305 
306 /* new attribute system */
309 
310  void SetAttribute(uint16 attrID, int num, bool notify=true);
311  void SetAttribute(uint16 attrID, uint32 num, bool notify=true);
312  void SetAttribute(uint16 attrID, int64 num, bool notify=true);
313  void SetAttribute(uint16 attrID, float num, bool notify=true);
314  void SetAttribute(uint16 attrID, double num, bool notify=true);
315  void SetAttribute(uint16 attrID, EvilNumber num, bool notify=true);
316  void MultiplyAttribute(uint16 attrID, EvilNumber num, bool notify=false);
317  bool HasAttribute(const uint16 attrID) const { return pAttributeMap->HasAttribute(attrID); }
318  bool HasAttribute(const uint16 attrID, EvilNumber &value) const { return pAttributeMap->HasAttribute(attrID, value); }
320  void ResetAttribute(uint16 attrID, bool notify=false) { pAttributeMap->ResetAttribute(attrID, notify); }
322 
323  EvilNumber GetAttribute(const uint16 attrID) const { return pAttributeMap->GetAttribute(attrID); }
324  EvilNumber GetDefaultAttribute(const uint16 attrID) const { return m_type.GetAttribute(attrID); }
325 
326 protected:
328 
329 private:
330  // fx timestamp
331  int64 m_timestamp; // not implemented yet
332 
333 };
334 
335 #endif
bool SetQuantity(int32 qty, bool notify=false, bool deleteOnZero=true)
Base Python wire object.
Definition: PyRep.h:66
PyPackedRow * GetItemRow() const
bool HasReqSkill(const uint16 skillID)
unsigned __int8 uint8
Definition: eve-compat.h:46
virtual InventoryItemRef Split(int32 qty=0, bool notify=true, bool silent=false)
void Donate(uint32 new_owner=ownerSystem, uint32 new_location=locTemp, EVEItemFlags new_flag=flagNone, bool notify=true)
double radius() const
void SendItemChange(uint32 toID, std::map< int32, PyRep * > &changes)
InventoryItem & operator=(const InventoryItem &oth)=delete
PyList * GetItemInfo() const
static InventoryItemRef SpawnItem(uint32 itemID, const ItemData &data)
uint16 id() const
Definition: ItemType.h:63
ItemType m_type
uint32 locationID
Definition: ItemType.h:190
virtual bool Merge(InventoryItemRef to_merge, int32 qty=0, bool notify=true)
bool HasReqSkill(const uint16 skillID) const
Definition: ItemType.cpp:176
uint16 groupID() const
Definition: ItemType.h:64
Python's dictionary.
Definition: PyRep.h:719
static RefPtr< _Ty > _LoadItem(uint32 itemID, const ItemType &type, const ItemData &data)
bool HasAttribute(const uint16 attrID) const
bool SetFlag(EVEItemFlags flag, bool notify=false)
virtual void RemoveItem(InventoryItemRef iRef)
bool get_bool()
Definition: EvilNumber.cpp:157
uint32 ownerID() const
Definition: InventoryItem.h:99
virtual void AddItem(InventoryItemRef iRef)
const GPoint & position() const
void ResetAttribute(uint16 attrID, bool notify=false)
const std::string & customInfo() const
EVEItemFlags
Definition: EVE_Flags.h:13
A reference-counted object.
Definition: RefPtr.h:48
GPoint position
Definition: ItemType.h:192
bool isGlobal() const
void UpdateLocation(uint32 locID)
bool SkillCheck(InventoryItemRef refItem)
EvilNumber GetDefaultAttribute(const uint16 attrID) const
EvilNumber GetAttribute(const uint16 attributeID) const
Definition: ItemType.cpp:168
ItemData m_data
virtual bool _Load()
PyRep * GetItem() const
void SetPosition(const GPoint &pos)
this is a class that kinda mimics how python polymorph's numbers.
Definition: EvilNumber.h:59
PyPackedRow * GetItemStatusRow() const
const char * name()
void DeleteAttribute(uint16 attrID)
virtual void Relocate(uint32 locID=0, EVEItemFlags flag=flagNone)
void Move(uint32 new_location=locTemp, EVEItemFlags flag=flagNone, bool notify=false)
AttributeMap * GetAttributeMap()
void GetChargeStatusRow(uint32 shipID, PyPackedRow *into) const
static RefPtr< _Ty > _Load(uint32 itemID)
uint8 categoryID() const
Definition: ItemType.h:66
std::string customInfo
Definition: ItemType.h:194
EvilNumber GetAttribute(const uint16 attrID) const
uint16 groupID() const
signed __int32 int32
Definition: eve-compat.h:49
const ItemType & type() const
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type()() itemID() copy() materialLevel()()() itemID() itemID Fits selected item to active ship() skillID(level)-gives skillID to specified level." ) COMMAND( online
double GetPackagedVolume()
Definition: gpoint.h:33
bool isSingleton() const
Definition: InventoryItem.h:96
bool SaveAttributes()
void SetOwner(uint32 ownerID)
Python object.
Definition: PyRep.h:826
void ResetAttribute(uint16 attrID, bool notify=false)
Inventory * pInventory
std::multimap< int8, fxData > m_modifiers
uint32 locationID() const
bool AlterQuantity(int32 qty, bool notify=false)
static InventoryItemRef SpawnTemp(ItemData &data)
static uint32 CreateTempItemID(ItemData &data)
bool HasAttribute(const uint16 attrID) const
void SetAttribute(uint16 attrID, int num, bool notify=true)
int64 GetTimeStamp()
virtual ShipItem * GetShipItem()
Definition: InventoryItem.h:82
void ChangeOwner(uint32 new_owner, bool notify=false)
uint32 quantity
Definition: ItemType.h:191
bool Populate(Rsp_CommonGetInfo_Entry &into)
Definition: Client.h:66
static InventoryItemRef Load(uint32 itemID)
bool ChangeSingleton(bool singleton, bool notify=false)
static InventoryItemRef Spawn(ItemData &data)
unsigned __int32 uint32
Definition: eve-compat.h:50
uint16 typeID
Definition: ItemType.h:188
virtual ModuleItem * GetModuleItem()
Definition: InventoryItem.h:83
void SetCustomInfo(const char *ci)
void MultiplyAttribute(uint16 attrID, EvilNumber num, bool notify=false)
EVEItemFlags flag() const
InventoryItem(uint32 _itemID, const ItemType &_type, const ItemData &_data)
EVEItemFlags flag
Definition: ItemType.h:187
Definition: Ship.h:46
bool SaveAttributes()
signed __int64 int64
Definition: eve-compat.h:51
const std::string & itemName() const
static uint32 CreateItemID(ItemData &data)
EvilNumber GetAttribute(const uint16 attrID) const
void AddModifier(fxData &data)
virtual void SetPlayer(Client *pClient)
bool HasAttribute(const uint16 attrID, EvilNumber &value) const
virtual void Rename(std::string name)
virtual bool IsModuleItem()
Definition: InventoryItem.h:86
uint32 ownerID
Definition: ItemType.h:189
void DeleteAttribute(uint16 attrID)
bool contraband() const
Definition: InventoryItem.h:95
virtual ~InventoryItem() noexcept
bool contraband
Definition: ItemType.h:185
virtual void Delete()
PyObject * ItemGetInfo()
#define sItemFactory
Definition: ItemFactory.h:165
Packed row.
Definition: PyRep.h:961
AttributeMap * pAttributeMap
void RemoveModifier(fxData &data)
Inventory * GetMyInventory()
Definition: InventoryItem.h:91
unsigned __int16 uint16
Definition: eve-compat.h:48
static bool GetItem(uint32 itemID, ItemData &into)
Definition: ItemDB.cpp:32
static RefPtr< _Ty > Load(uint32 itemID)
void MergeTypesInCargo(ShipItem *pShip, EVEItemFlags flag=flagNone)
std::string name
Definition: ItemType.h:193
uint16 typeID() const
virtual bool IsShipItem()
Definition: InventoryItem.h:85
uint8 categoryID() const
virtual bool HasPilot()
bool singleton
Definition: ItemType.h:186
Python list.
Definition: PyRep.h:639
void ToVirtual(uint32 locationID)
uint32 itemID() const
Definition: InventoryItem.h:98
virtual Client * GetPilot()
int32 quantity() const
Definition: InventoryItem.h:97