EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Prospector.cpp
Go to the documentation of this file.
1 
10 #include "StaticDataMgr.h"
11 #include "StatisticMgr.h"
13 #include "system/Container.h"
14 #include "system/SystemManager.h"
15 
16 /* this class is for all salvage and data mining types */
17 
19 : ActiveModule(mRef, sRef)
20 {
21  m_success = false;
22  m_firstRun = true;
23  m_salvager = false;
24  m_dataMiner = false;
25 
27  m_salvager = true;
29  m_dataMiner = true;
30  }
31 
32  m_accessChance = 0;
33 
37 
38  if (!m_shipRef->HasPilot())
39  return;
40 
42 
43  // increase scan speed by level of survey skill
44  float cycleTime = GetAttribute(AttrDuration).get_float();
45  cycleTime *= (1 + (0.03f * (pChar->GetSkillLevel(EvESkill::Survey, true))));
46  SetAttribute(AttrDuration, cycleTime);
47 }
48 
50 {
51  if (!m_shipRef->HasPilot())
52  return;
53 
55 
56  // increase scan speed by level of survey skill
57  float cycleTime = GetAttribute(AttrDuration).get_float();
58  cycleTime *= (1 + (0.03f * (pChar->GetSkillLevel(EvESkill::Survey, true))));
59  SetAttribute(AttrDuration, cycleTime);
60 
62 }
63 
64 void Prospector::Activate(uint16 effectID, uint32 targetID, int16 repeat)
65 {
66  // reset for each activation MUST reset BEFORE ActiveModule::Activate() is called.....it calls salvage check.
67  m_success = false;
68  m_firstRun = true;
69 
70  ActiveModule::Activate(effectID, targetID, repeat);
71 
72  if (!m_needsTarget or (m_targetSE == nullptr)) {
74  return;
75  }
77  // are there any modifiers for access here?
78  // are rigs/skills added to module access chance?
79 }
80 
82 {
83  if (m_salvager)
84  if (m_targetSE->IsWreckSE())
86  if (m_dataMiner)
89 
90  throw UserError ("DeniedActivateTargetModuleDisallowed");
91 }
92 
94 {
95  if (m_firstRun) {
96  m_firstRun = false;
97  } else if (!m_success) {
98  SendFailure();
99  CheckSuccess();
100  } else if (m_success) {
101  DropSalvage();
102  AbortCycle();
103  return 0;
104  } else {
105  _log(MODULE__ERROR, "Prospector::DoCycle() hit end of conditional.");
106  }
107 
108  return ActiveModule::DoCycle();
109 }
110 
111 /*
112  [PyTuple 3 items]
113  [PyString "OnRemoteMessage"]
114  [PyString "SalvagingFailure"] (this is also a dungeon trigger)
115  [PyDict 1 kvp]
116  [PyString "type"]
117  [PyTuple 2 items]
118  [PyInt 4] << cacheSolarSystemObjects??? cant find another reference for this. always 4 so far.
119  [PyInt 26513] << wreck type id
120 
121  [PyTuple 2 items] << this goes into effect.error
122  [PyString "SalvagingSuccess"]
123  [PyDict 1 kvp]
124  [PyString "type"]
125  [PyTuple 2 items]
126  [PyInt 4] << cacheSolarSystemObjects???
127  [PyInt 26513]
128  */
130 {
131  if (m_salvager) {
132  PyTuple* type = new PyTuple(2);
133  type->SetItem(0, new PyInt(4));
134  type->SetItem(1, new PyInt(m_targetSE->GetTypeID()));
135  PyDict* dict = new PyDict;
136  dict->SetItemString("type", type);
137  PyTuple* tup = new PyTuple(3);
138  tup->SetItem(0, new PyString("OnRemoteMessage"));
139  tup->SetItem(1, new PyString("SalvagingFailure"));
140  tup->SetItem(2, dict);
142  }
143  if (m_dataMiner) {
144  // not sure what client needs from this
145  }
146 }
147 
149 {
150  int8 chance = m_accessChance;
152 
153  uint8 roll = MakeRandomInt(0,100);
154  if (roll < chance)
155  m_success = true;
156 
157  _log(MODULE__DEBUG, "Prospector::CheckSuccess - chance: %i, roll: %u, success: %s", chance, roll, (m_success ? "true" : "false"));
158 }
159 
161 {
162  if (m_targetSE == nullptr)
163  return;
164 
165  std::vector<uint32> list;
166  list.clear();
167  sDataMgr.GetSalvage(atoi(m_targetSE->GetSelf()->customInfo().c_str()), list);
168 
169  if (!list.empty()) {
170  uint8 drop = 0;
171  switch (m_accessChance) { // drop qty * rate in config
172  case 30: drop = 1; break; // 1 to 3
173  case 20: drop = 2; break; // 2 to 6
174  case 10: drop = 3; break; // 3 to 9
175  case 0: drop = 4; break; // 4 to 12
176  case -10: drop = 5; break; // 5 to 15
177  case -20: drop = 6; break; // 6 to 18
178  }
179 
180  InventoryItemRef iRef(nullptr);
182  uint32 quantity = 0, minDrop = drop, maxDrop = (drop * sConfig.rates.DropSalvage);
183  for (auto cur : list) {
184  // each drop has 50/50 chance. may need to change this later. base on char's salvage skill?
185  if (IsEven(MakeRandomInt(0,10)))
186  continue;
187  quantity = (MakeRandomInt(minDrop, maxDrop));
188  ItemData iLoot(cur, pChar->itemID(), locTemp, flagNone, quantity);
189  iRef = sItemFactory.SpawnItem(iLoot);
190  if (iRef.get() == nullptr) // we'll get over it...continue
191  continue;
192  if (sInv->HasAvailableSpace(m_holdFlag, iRef)) {
193  //iRef->Move(m_shipRef->itemID(), m_holdFlag, true);
194  iRef->MergeTypesInCargo(m_shipRef.get(), m_holdFlag);
195  _log(MODULE__DEBUG, "Prospector::DropSalvage - dropped %u %s of %u/%u", quantity, iRef->name(), minDrop, maxDrop);
196  } else {
197  _log(MODULE__DEBUG, "Prospector::DropSalvage - %s's %s is full.", m_shipRef->name(), sDataMgr.GetFlagName(m_holdFlag));
198  m_shipRef->GetPilot()->SendNotifyMsg("Your %s is full. Remaining salvage is lost.", sDataMgr.GetFlagName(m_holdFlag));
199  break;
200  }
201  }
202  }
203 
204  if (!m_targetSE->GetSelf()->GetMyInventory()->IsEmpty()) {
205 
206  //{'FullPath': u'UI/Messages', 'messageID': 258062, 'label': u'SalvageTooMuchLootBody'}(u'You cannot salvage this wreck because it contains too much loot to fit into a single cargo container. <br>\r\nThe wreck contains <b>{[numeric]volume, useGrouping} m3</b> but can contain no more than <b>{[numeric]maxvolume, useGrouping} m3</b> to be salvageable.', None, {u'{[numeric]maxvolume, useGrouping}': {'conditionalValues': [], 'variableType': 9, 'propertyName': None, 'args': 32, 'kwargs': {}, 'variableName': 'maxvolume'}, u'{[numeric]volume, useGrouping}': {'conditionalValues': [], 'variableType': 9, 'propertyName': None, 'args': 32, 'kwargs': {}, 'variableName': 'volume'}})
207 
208  // tell wreck it's being salvaged, so do not broadcast slim updates...may no longer need this. jetcan set to initial location 0
210 
211  std::map<uint32, InventoryItemRef> shipLoot;
212  shipLoot.clear();
214 
215  // create new container
216  ItemData p_idata(23, // 23 = cargo container
217  m_targetSE->GetSelf()->ownerID(),
218  locTemp,
219  flagNone,
220  "Jettisoned Loot Container",
222 
223  CargoContainerRef jetCanRef = sItemFactory.SpawnCargoContainer(p_idata);
224  if (jetCanRef.get() != nullptr) {
225  for (auto cur : shipLoot)
226  cur.second->Move(jetCanRef->itemID(),flagNone);
227  FactionData data = FactionData();
231  data.ownerID = m_targetSE->GetSelf()->ownerID();
232  ContainerSE* cSE = new ContainerSE(jetCanRef, m_targetSE->GetServices(), m_sysMgr, data);
233  jetCanRef->SetMySE(cSE);
234  m_sysMgr->AddEntity(cSE);
236  }
237  }
238 
239  // add data to StatisticMgr
240  sStatMgr.Increment(Stat::shipsSalvaged);
241 }
242 
244 {
245  // this will be for data miners and hacking/archaeology shit. dunno what all we'll need at this point.
246  // update StaticDataMgr for these items also.
247 }
248 
249 /*
250  * accessDifficultyBonus << salvage tackle(10), salvage tackleII(15), salvage skill : salvagerI +5 per level, salvagerII +7 per level
251  * accessDifficulty (s:30,m:20,l:10,f:0,t2:0,o:-10,s:-20) << in the item to salvage
252  *
253  *
254  * accessDifficultyBonus << civilian analyzer(2), implant(5), analyzerII(7)
255  * accessDifficulty (0.000001) << for analyzing structures ()
256  *
257  *
258  */
virtual void Update()
Definition: Prospector.cpp:49
#define sConfig
A macro for easier access to the singleton.
unsigned __int8 uint8
Definition: eve-compat.h:46
#define sStatMgr
Definition: StatisticMgr.h:68
void AddEntity(SystemEntity *pSE, bool addSignal=true)
Character * pChar
Definition: Prospector.h:52
#define _log(type, fmt,...)
Definition: logsys.h:124
Python string.
Definition: PyRep.h:430
Python's dictionary.
Definition: PyRep.h:719
bool HasAttribute(const uint16 attrID) const
uint32 ownerID() const
Definition: InventoryItem.h:99
void SendJettisonPacket() const
const std::string & customInfo() const
void QueueDestinyEvent(PyTuple **multiEvent)
Definition: Client.cpp:2124
virtual bool HasPilot()
Definition: Ship.h:71
bool m_dataMiner
Definition: Prospector.h:47
SystemManager * m_sysMgr
Definition: ActiveModule.h:80
void CheckSuccess()
Definition: Prospector.cpp:148
const char * name()
void SendNotifyMsg(const char *fmt,...)
Definition: Client.cpp:2776
CharacterRef GetChar() const
Definition: Client.h:164
Python tuple.
Definition: PyRep.h:567
Prospector(ModuleItemRef mRef, ShipItemRef sRef)
Definition: Prospector.cpp:18
void SetAttribute(uint32 attrID, EvilNumber val, bool update=true)
Definition: GenericModule.h:51
virtual WreckSE * GetWreckSE()
Definition: SystemEntity.h:108
signed __int8 int8
Definition: eve-compat.h:45
const GPoint & GetPosition() const
Definition: SystemEntity.h:211
ModuleItemRef m_modRef
uint16 groupID() const
virtual bool CanActivate()
Definition: Prospector.cpp:81
void DropSalvage()
Definition: Prospector.cpp:160
ShipItemRef m_shipRef
SystemEntity * m_targetSE
Definition: ActiveModule.h:78
DestinyManager * DestinyMgr()
Definition: SystemEntity.h:198
bool IsEven(int64 number)
Definition: misc.h:88
bool m_salvager
Definition: Prospector.h:46
InventoryItemRef GetSelf()
Definition: SystemEntity.h:202
void DropItems()
Definition: Prospector.cpp:243
bool m_firstRun
Definition: Prospector.h:45
int64 get_int()
Definition: EvilNumber.cpp:166
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
virtual bool IsContainerSE()
Definition: SystemEntity.h:157
Python integer.
Definition: PyRep.h:231
void Salvaged()
Definition: Container.h:262
int32 GetAllianceID()
Definition: SystemEntity.h:216
X * get() const
Definition: RefPtr.h:213
virtual void AbortCycle()
uint32 DoCycle()
Definition: Prospector.cpp:93
Python object "ccp_exceptions.UserError".
Definition: PyExceptions.h:121
virtual bool CanActivate()
unsigned __int32 uint32
Definition: eve-compat.h:50
virtual bool IsWreckSE()
Definition: SystemEntity.h:188
uint32 corporationID
EVEItemFlags m_holdFlag
Definition: Prospector.h:54
void SendFailure()
Definition: Prospector.cpp:129
void GetInventoryMap(std::map< uint32, InventoryItemRef > &invMap)
Definition: Inventory.cpp:453
virtual void Update()
virtual void Activate(uint16 effectID, uint32 targetID=0, int16 repeat=0)
Definition: Prospector.cpp:64
int64 MakeRandomInt(int64 low, int64 high)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
PyServiceMgr & GetServices()
Definition: SystemEntity.h:194
uint32 GetCorporationID()
Definition: SystemEntity.h:218
virtual Client * GetPilot()
Definition: Ship.h:72
EvilNumber GetAttribute(const uint16 attrID) const
signed __int16 int16
Definition: eve-compat.h:47
int8 GetSkillLevel(uint16 skillTypeID, bool zeroForNotInjected=true) const
Definition: Character.cpp:575
bool m_needsTarget
Definition: ActiveModule.h:107
#define sItemFactory
Definition: ItemFactory.h:165
virtual uint32 DoCycle()
bool IsEmpty()
Definition: Inventory.h:55
float get_float()
Definition: EvilNumber.cpp:184
virtual void Deactivate(std::string effect="")
uint16 GetTypeID()
Definition: SystemEntity.h:203
Inventory * GetMyInventory()
Definition: InventoryItem.h:91
unsigned __int16 uint16
Definition: eve-compat.h:48
EvilNumber GetAttribute(uint32 attrID)
Definition: GenericModule.h:53
int8 m_accessChance
Definition: Prospector.h:49
virtual void Activate(uint16 effectID, uint32 targetID=0, int16 repeat=0)
uint32 itemID() const
Definition: InventoryItem.h:98
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
int32 GetWarFactionID()
Definition: SystemEntity.h:217
bool m_success
Definition: Prospector.h:44
#define sDataMgr