EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ItemType.cpp
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: Bloody.Rabbit
24  Rewrite: Allan
25 */
26 
27 #include "eve-server.h"
28 
29 #include "character/Character.h"
30 #include "effects/EffectsDataMgr.h"
31 #include "inventory/ItemType.h"
33 #include "ship/Ship.h"
34 #include "station/Station.h"
35 
36 /*
37  * ItemType
38  */
40 : m_type(_data),
41  m_defaultFxID(0),
42  m_group(Inv::GrpData())
43 {
44  // assert for data consistency
45  assert(m_type.id == _id);
46  sDataMgr.GetGroup(_data.groupID, m_group);
47  assert(_data.groupID == m_group.id);
48  m_AttributeMap.clear();
49 
50  _log(ITEM__TRACE, "Created ItemType object %p for type %s (%u).", this, name().c_str(), id());
51 }
52 
54  return ItemType::Load<ItemType>(typeID);
55 }
56 
57 template<class _Ty>
59  Inv::GrpData gData = Inv::GrpData();
60  sDataMgr.GetGroup(data.groupID, gData);
61 
62  switch (gData.catID) { // not complete list
63  /*
64  * not handled / not needed ?
65  case EVEDB::invCategories::_System:
66  case EVEDB::invCategories::Trading:
67  case EVEDB::invCategories::Bonus:
68  case EVEDB::invCategories::Reaction:
69  */
71  return CharacterType::_LoadType<CharacterType>(typeID, data );
72  }
74  if (gData.id == EVEDB::invGroups::Station)
75  return StationType::_LoadType<StationType>(typeID, data );
76  // i dont think we need anything specific for station services here...
77  //case EVEDB::invGroups::Station_Services:
78  } break;
80  return BlueprintType::_LoadType<BlueprintType>(typeID, data );
81  }
83  case EVEDB::invCategories::Accessories: // clone, voucher, outpost improvement/upgrade, plex
98  // these are called but not sure if they need to be coded specifically
99  } break;
103  // these probably dont need to be coded specifically
104  } break;
105  default:
106  _log(ITEM__MESSAGE, "type %u (group: %u, cat: %u) called _LoadType, but is not handled.", typeID, gData.id, gData.catID);
107  break;
108  }
109 
110  // nothing special, create generic object:
111  return new ItemType(typeID, data);
112 }
113 
115 {
116  // load type attribs
117  std::vector< DmgTypeAttribute > typeAttrVec;
118  sDataMgr.GetDgmTypeAttrVec(m_type.id, typeAttrVec);
119  for (auto cur : typeAttrVec)
120  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(cur.attributeID, cur.value));
121 
122  // load attributes that are needed but NOT in default DgmTypeAttributes set (but found in invTypes)
123  if (m_type.mass)
124  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(AttrMass, m_type.mass));
125  if (m_type.radius)
126  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(AttrRadius, m_type.radius));
127  if (m_type.volume)
128  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(AttrVolume, m_type.volume));
129  if (m_type.capacity)
130  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(AttrCapacity, m_type.capacity));
131  if (m_type.race)
132  m_AttributeMap.insert(std::pair<uint16, EvilNumber>(AttrRaceID, m_type.race));
133 
134  // load required skills and levels into their own map, for later checks
136  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill1).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill1Level).get_uint32()));
138  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill2).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill2Level).get_uint32()));
140  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill3).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill3Level).get_uint32()));
142  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill4).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill4Level).get_uint32()));
144  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill5).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill5Level).get_uint32()));
146  m_reqSkillMap.insert(std::pair<uint16, uint8>((uint16)GetAttribute(AttrRequiredSkill6).get_uint32(), (uint8)GetAttribute(AttrRequiredSkill6Level).get_uint32()));
147 
148  LoadEffects();
149 
150  return true;
151 }
152 
153 const void ItemType::CopyAttributes(InventoryItem& itemRef) const
154 {
155  // set attributes in the item's own attrMap.
156  for (auto cur : m_AttributeMap)
157  itemRef.SetAttribute(cur.first, cur.second, false);
158 }
159 
161 {
162  AttrMapConstItr itr = m_AttributeMap.find(attributeID);
163  if (itr != m_AttributeMap.end())
164  return true;
165  return false;
166 }
167 
169 {
170  AttrMapConstItr itr = m_AttributeMap.find(attributeID);
171  if (itr != m_AttributeMap.end())
172  return itr->second;
173  return 0;
174 }
175 
177 {
178  std::map<uint16, uint8>::const_iterator itr = m_reqSkillMap.find(skillID);
179  if (itr != m_reqSkillMap.end())
180  return true;
181  /* this part will get prequisites for required skills...this isnt right
182  for (auto cur : m_reqSkillMap)
183  if (sItemFactory.GetType(cur.first)->HasReqSkill(skillID))
184  return true;
185  */
186 
187  return false;
188 }
189 
191 {
192  std::vector< TypeEffects > typeEffMap;
193  sFxDataMgr.GetTypeEffect(m_type.id, typeEffMap);
194 
195  for (auto cur : typeEffMap) {
196  Effect mEffect(sFxDataMgr.GetEffect(cur.effectID));
197  m_stateFxMap.emplace(mEffect.effectState, mEffect);
198  if (cur.isDefault) {
199  if (m_defaultFxID) {
200  // error here to show multiple defaults set for this type
201  _log(ITEM__ERROR, "Type %u has multiple default fxID (%u/%u)", m_type.id, m_defaultFxID, cur.effectID);
202  }
203  m_defaultFxID = cur.effectID;
204  }
205  }
206 }
207 
208 bool ItemType::HasEffect(uint16 effectID) const
209 {
210  std::unordered_multimap<int8, Effect>::const_iterator itr = m_stateFxMap.begin();
211  for (; itr != m_stateFxMap.end(); ++itr)
212  if (itr->second.effectID == effectID)
213  return true;
214  return false;
215 }
216 
217 void ItemType::GetEffectMap(const int8 state, std::map<uint16, Effect>& effectMap) const
218 {
219  auto itr = m_stateFxMap.equal_range(state);
220  for (auto it = itr.first; it != itr.second; ++it)
221  effectMap.insert(std::pair<uint16, Effect>(it->second.effectID, it->second));
222 }
223 
224 
225 /*
226  * ItemData
227  */
229  const char *_name/*""*/,
230  uint16 _typeID/*0*/,
231  uint32 _ownerID/*ownerSystem*/,
232  uint32 _locationID/*locTemp*/,
233  EVEItemFlags _flag/*flagNone*/,
234  bool _contraband/*false*/,
235  bool _singleton/*false*/,
236  uint32 _quantity/*0*/,
237  const GPoint &_position/*NULL_ORIGIN*/,
238  const char *_customInfo/*""*/)
239 : name(_name),
240 typeID(_typeID),
241 ownerID(_ownerID),
242 locationID(_locationID),
243 flag(_flag),
244 contraband(_contraband),
245 singleton(_singleton),
246 quantity(_quantity),
247 position(_position),
248 customInfo(_customInfo)
249 {
250 }
251 
253  uint16 _typeID,
254  uint32 _ownerID,
255  uint32 _locationID,
256  EVEItemFlags _flag,
257  uint32 _quantity,
258  const char *_customInfo/*""*/,
259  bool _contraband/*false*/)
260 : name(""),
261 typeID(_typeID),
262 ownerID(_ownerID),
263 locationID(_locationID),
264 flag(_flag),
265 contraband(_contraband),
266 singleton(false),
267 quantity(_quantity),
269 customInfo(_customInfo)
270 {
271 }
272 
274  uint16 _typeID,
275  uint32 _ownerID,
276  uint32 _locationID,
277  EVEItemFlags _flag,
278  const char* _name/*""*/,
279  const GPoint& _position/*NULL_ORIGIN*/,
280  const char* _customInfo/*""*/,
281  bool _contraband/*false*/)
282 : name(_name),
283 typeID(_typeID),
284 ownerID(_ownerID),
285 locationID(_locationID),
286 flag(_flag),
287 contraband(_contraband),
288 singleton(true),
289 quantity(1),
290 position(_position),
291 customInfo(_customInfo)
292 {
293 }
294 
295 
unsigned __int8 uint8
Definition: eve-compat.h:46
void GetEffectMap(const int8 state, std::map< uint16, Effect > &effectMap) const
Definition: ItemType.cpp:217
#define _log(type, fmt,...)
Definition: logsys.h:124
const bool HasAttribute(const uint16 attributeID) const
Definition: ItemType.cpp:160
ItemType m_type
bool HasReqSkill(const uint16 skillID) const
Definition: ItemType.cpp:176
uint32 ownerID() const
Definition: InventoryItem.h:99
const GPoint & position() const
const std::string & customInfo() const
EVEItemFlags
Definition: EVE_Flags.h:13
std::map< uint16, uint8 > m_reqSkillMap
Definition: ItemType.h:161
EvilNumber GetAttribute(const uint16 attributeID) const
Definition: ItemType.cpp:168
bool HasEffect(uint16 effectID) const
Definition: ItemType.cpp:208
this is a class that kinda mimics how python polymorph's numbers.
Definition: EvilNumber.h:59
const char * name()
std::unordered_multimap< int8, Effect > m_stateFxMap
Definition: ItemType.h:154
signed __int8 int8
Definition: eve-compat.h:45
void LoadEffects()
Definition: ItemType.cpp:190
virtual bool _Load()
Definition: ItemType.cpp:114
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
Definition: gpoint.h:33
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type()() itemID() copy() materialLevel()()() itemID() attributeID(value)-Sets attributeID of itemID to value." ) COMMAND( fit
static const GPoint NULL_ORIGIN(0, 0, 0)
#define sFxDataMgr
ItemType(uint16 _id, const Inv::TypeData &_data)
Definition: ItemType.cpp:39
uint32 locationID() const
ItemData(const char *_name="", uint16 _typeID=0, uint32 _ownerID=ownerSystem, uint32 _locationID=locTemp, EVEItemFlags _flag=flagNone, bool _contraband=false, bool _singleton=false, uint32 _quantity=0, const GPoint &_position=NULL_ORIGIN, const char *_customInfo="")
Definition: ItemType.cpp:228
void SetAttribute(uint16 attrID, int num, bool notify=true)
AttrMap::const_iterator AttrMapConstItr
Definition: AttributeMap.h:36
const std::string & name() const
Definition: ItemType.h:74
const void CopyAttributes(InventoryItem &itemRef) const
Definition: ItemType.cpp:153
unsigned __int32 uint32
Definition: eve-compat.h:50
EVEItemFlags flag() const
static ItemType * Load(uint16 typeID)
Definition: ItemType.cpp:53
Inv::TypeData m_type
Definition: ItemType.h:158
uint16 m_defaultFxID
Definition: ItemType.h:159
bool contraband() const
Definition: InventoryItem.h:95
Inv::GrpData m_group
Definition: ItemType.h:157
static _Ty * _LoadType(uint16 typeID, const Inv::TypeData &data)
Definition: ItemType.cpp:58
std::map< uint16, EvilNumber > m_AttributeMap
Definition: ItemType.h:162
unsigned __int16 uint16
Definition: eve-compat.h:48
entityID heal the character with the entityID note giving you detailed ship status information gives a list of all dynamic entities and players and their destinyState in this bubble shows some current destiny variables save all kick all and halt server immediate command list all items in current location s gives list of cargo contents and volumes in all holds list current session values show current ship DNA show current objects in their destiny state
uint16 typeID() const
int32 quantity() const
Definition: InventoryItem.h:97
#define sDataMgr