EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ModuleItem.cpp
Go to the documentation of this file.
1 
10 #include "eve-server.h"
11 
12 #include "Client.h"
13 #include "EntityList.h"
15 
16 ModuleItem::ModuleItem(uint32 _modID, const ItemType& _type, const ItemData& _data)
17 : InventoryItem(_modID, _type, _data)
18 {
19  _log(ITEM__TRACE, "Created ModuleItem for %s(%u).", name(), itemID());
20 }
21 
23 {
24  return InventoryItem::Load<ModuleItem>(modID);
25 }
26 
28 {
29  uint32 modID = InventoryItem::CreateItemID(data);
30  if ( modID == 0 )
31  return ModuleItemRef(nullptr);
32 
33  ModuleItemRef modRef = ModuleItem::Load(modID);
34  if (modRef.get() == nullptr) {
35  // make error msg here for failure to load module?
36  return ModuleItemRef(nullptr);
37  }
38 
39  modRef->SaveItem();
40  return modRef;
41 }
42 
44 {
45  Client* pClient = sItemFactory.GetUsingClient();
46  // test for character creation (which throws errors here and isnt really needed)
47  if ((pClient != nullptr) and pClient->IsCharCreation())
48  return true;
49 
50  // load attributes
51  if (!InventoryItem::_Load())
52  return false;
53 
54  return true;
55 }
56 
57 void ModuleItem::SetOnline(bool online/*false*/, bool isRig/*false*/) {
58  _log(MODULE__DEBUG, "ModuleItem::SetOnline() - set module %s(%u) to %s", \
59  name(), m_itemID, (online ? "Online" : "Offline"));
60 
61  if (!isRig) // rigs DO NOT get isOnline attrib set.
62  SetAttribute(AttrOnline, (online?1:0));
63 
64  Client* pClient = sEntityList.FindClientByCharID(ownerID());
65  if (pClient == nullptr) {
66  _log(MODULE__WARNING, "ModuleItem::SetOnline() - No client object found using m_ownerID (%u) for module %s(%u)", \
67  ownerID(), name(), m_itemID);
68  return;
69  }
70 
71  if (pClient->IsUndock())
72  return;
73 
74  GodmaEnvironment ge;
75  ge.selfID = m_itemID;
76  ge.charID = ownerID();
77  ge.shipID = pClient->GetShipID();
78  ge.target = PyStatic.NewNone();
79  ge.subLoc = PyStatic.NewNone();
80  ge.area = new PyList();
81  ge.effectID = 16;
82  Notify_OnGodmaShipEffect shipEff;
83  shipEff.itemID = ge.selfID;
84  shipEff.effectID = ge.effectID;
85  shipEff.timeNow = GetFileTimeNow();
86  shipEff.start = online;
87  shipEff.active = online;
88  shipEff.environment = ge.Encode();
89  shipEff.startTime = shipEff.timeNow;
91  shipEff.duration = (online ? GetAttribute(AttrDuration).get_float() : 0.0);
92  } else if (HasAttribute(AttrSpeed)) {
93  shipEff.duration = (online ? GetAttribute(AttrSpeed).get_float() : 0.0);
94  } else {
95  shipEff.duration = 0.0;
96  }
97 
98  shipEff.repeat = (online ? 1 : 0);
99  shipEff.error = PyStatic.NewNone();
100  PyList* events = new PyList();
101  events->AddItem(shipEff.Encode());
102  Notify_OnMultiEvent multi;
103  multi.events = events;
104  PyTuple* tmp = multi.Encode();
105  pClient->SendNotification("OnMultiEvent", "clientID", &tmp);
106 }
uint32 GetShipID() const
Definition: Client.h:150
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
ModuleItem(uint32 _modID, const ItemType &_type, const ItemData &_data)
Definition: ModuleItem.cpp:16
RefPtr< ModuleItem > ModuleItemRef
Definition: ItemRef.h:58
#define _log(type, fmt,...)
Definition: logsys.h:124
bool IsCharCreation()
Definition: Client.h:433
bool HasAttribute(const uint16 attrID) const
uint32 ownerID() const
Definition: InventoryItem.h:99
virtual bool _Load()
Definition: ModuleItem.cpp:43
void SetOnline(bool online=false, bool isRig=false)
Definition: ModuleItem.cpp:57
bool IsUndock()
Definition: Client.h:236
virtual bool _Load()
#define sEntityList
Definition: EntityList.h:208
const char * name()
Python tuple.
Definition: PyRep.h:567
void AddItem(PyRep *i)
Definition: PyRep.h:701
static ModuleItemRef Spawn(ItemData &data)
Definition: ModuleItem.cpp:27
void SetAttribute(uint16 attrID, int num, bool notify=true)
#define PyStatic
Definition: PyRep.h:1209
X * get() const
Definition: RefPtr.h:213
Definition: Client.h:66
unsigned __int32 uint32
Definition: eve-compat.h:50
double GetFileTimeNow()
Definition: utils_time.cpp:84
static uint32 CreateItemID(ItemData &data)
EvilNumber GetAttribute(const uint16 attrID) const
#define sItemFactory
Definition: ItemFactory.h:165
float get_float()
Definition: EvilNumber.cpp:184
Python list.
Definition: PyRep.h:639
static ModuleItemRef Load(uint32 modID)
Definition: ModuleItem.cpp:22
uint32 itemID() const
Definition: InventoryItem.h:98