Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
cachedequipmentstorage.c
Go to the documentation of this file.
1
//#define CACHED_EQUIPMENT_STORAGE_LOGGING
2
3
class
CachedEquipmentStorageInventoryEntry
4
{
5
int
m_SlotId
= -1;
6
7
string
m_CallerMethod
;
8
EntityAI
m_Entity
;
9
GameInventory
m_GameInventory
;
10
11
ECachedEquipmentOperationMode
m_OperationMode
;
12
}
13
14
typedef
map<ECachedEquipmentItemCategory, ref array<ref CachedEquipmentItemAttribute>
> CachedItemAttributesPerCategory
15
16
class
CachedEquipmentStorage
:
CachedEquipmentStorageBase
17
{
18
private
DayZPlayerImplement
m_Player
;
19
20
void
CachedEquipmentStorage
(
DayZPlayerImplement
player)
21
{
22
m_Player
= player;
23
}
24
25
// --------------------------------------------------------------------------------
26
27
override
void
OnItemAttached
(notnull
Entity
entity,
int
slotId, notnull
Entity
parent)
28
{
29
EntityAI
item =
EntityAI
.Cast(entity);
30
ECachedEquipmentItemCategory
category = item.GetCachedEquipmentCategory();
31
if
(category !=
ECachedEquipmentItemCategory
.NONE && !IsStored(entity, category))
32
{
33
CachedEquipmentItemAttribute newItemAttributes =
new
CachedEquipmentItemAttribute();
34
newItemAttributes.m_Entity = entity;
35
newItemAttributes.m_Parent = parent;
36
newItemAttributes.m_InventoryDepth = item.GetHierarchyLevel();
37
newItemAttributes.m_SlotIndex = slotId;
38
newItemAttributes.m_InventoryPlacement =
ECachedEquipmentPlacement
.ATTACHMENT;
39
40
#ifdef ENABLE_LOGGING
41
LogMessage(
string
.Format(
"parent:%1 entity:%2 (slot:%3)"
, parent, entity,
InventorySlots
.
GetSlotName
(slotId)),
"OnItemAttached"
);
42
#endif
43
44
Insert
(category, newItemAttributes);
45
}
46
47
CachedEquipmentStorageInventoryEntry params =
new
CachedEquipmentStorageInventoryEntry();
48
params.m_Entity = item;
49
params.m_GameInventory = item.GetInventory();
50
params.m_SlotId = slotId;
51
params.m_CallerMethod =
"OnItemAttached"
;
52
params.m_OperationMode =
ECachedEquipmentOperationMode
.INSERT;
53
54
ProcessItemInventory
(params);
55
}
56
57
// --------------------------------------------------------------------------------
58
59
override
void
OnItemDetached
(notnull
Entity
entity,
int
slotId, notnull
Entity
parent)
60
{
61
EntityAI
item =
EntityAI
.Cast(entity);
62
ECachedEquipmentItemCategory
category = item.GetCachedEquipmentCategory();
63
if
(category !=
ECachedEquipmentItemCategory
.NONE)
64
{
65
#ifdef ENABLE_LOGGING
66
LogMessage(
string
.Format(
"parent:%1 entity:%2 (slot:%3)"
, parent, entity,
InventorySlots
.
GetSlotName
(slotId)),
"OnItemDetached"
);
67
#endif
68
69
Remove
(category, entity);
70
}
71
72
CachedEquipmentStorageInventoryEntry params =
new
CachedEquipmentStorageInventoryEntry();
73
params.m_Entity = item;
74
params.m_GameInventory = item.GetInventory();
75
params.m_SlotId = slotId;
76
params.m_CallerMethod =
"OnItemDetached"
;
77
params.m_OperationMode =
ECachedEquipmentOperationMode
.REMOVE;
78
79
ProcessItemInventory
(params);
80
}
81
82
// --------------------------------------------------------------------------------
83
84
override
void
OnItemCargoIn
(notnull
Entity
entity)
85
{
86
EntityAI
item =
EntityAI
.Cast(entity);
87
if
(!item.GetHierarchyParent())
88
return
;
89
90
ECachedEquipmentItemCategory
category = item.GetCachedEquipmentCategory();
91
if
(category !=
ECachedEquipmentItemCategory
.NONE && !IsStored(entity, category))
92
{
93
CachedEquipmentItemAttribute newItemAttributes =
new
CachedEquipmentItemAttribute();
94
newItemAttributes.m_Entity = entity;
95
newItemAttributes.m_Parent = item.GetHierarchyParent();
96
newItemAttributes.m_InventoryDepth = item.GetHierarchyLevel();
97
newItemAttributes.m_InventoryPlacement =
ECachedEquipmentPlacement
.CARGO;
98
99
#ifdef ENABLE_LOGGING
100
LogMessage(
string
.Format(
"parent:%1 entity:%2"
, item.GetHierarchyParent(), entity),
"OnItemCargoIn"
);
101
#endif
102
103
Insert
(category, newItemAttributes);
104
}
105
106
CachedEquipmentStorageInventoryEntry params =
new
CachedEquipmentStorageInventoryEntry();
107
params.m_Entity = item;
108
params.m_GameInventory = item.GetInventory();
109
params.m_CallerMethod =
"OnItemCargoIn"
;
110
params.m_OperationMode =
ECachedEquipmentOperationMode
.INSERT;
111
112
ProcessItemInventory
(params);
113
}
114
115
// --------------------------------------------------------------------------------
116
117
override
void
OnItemCargoOut
(notnull
Entity
entity)
118
{
119
EntityAI
item =
EntityAI
.Cast(entity);
120
ECachedEquipmentItemCategory
category = item.GetCachedEquipmentCategory();
121
if
(category !=
ECachedEquipmentItemCategory
.NONE)
122
{
123
#ifdef ENABLE_LOGGING
124
LogMessage(
string
.Format(
"parent:%1 entity:%2"
, item.GetHierarchyParent(), entity),
"OnItemCargoOut"
);
125
#endif
126
127
Remove
(category, entity);
128
}
129
130
CachedEquipmentStorageInventoryEntry params =
new
CachedEquipmentStorageInventoryEntry();
131
params.m_Entity = item;
132
params.m_GameInventory = item.GetInventory();
133
params.m_CallerMethod =
"OnItemCargoOut"
;
134
params.m_OperationMode =
ECachedEquipmentOperationMode
.REMOVE;
135
136
ProcessItemInventory
(params);
137
}
138
139
// --------------------------------------------------------------------------------
140
141
protected
void
ProcessItemInventory
(CachedEquipmentStorageInventoryEntry params)
142
{
143
CachedItemAttributesPerCategory attachmentAttributesPerCategory =
ProcessAttachments
(params);
144
foreach
(
ECachedEquipmentItemCategory
attachmentCategory,
array<ref CachedEquipmentItemAttribute>
attachmentAttributes : attachmentAttributesPerCategory)
145
{
146
foreach
(CachedEquipmentItemAttribute attachmentAttribute : attachmentAttributes)
147
{
148
if
(params.m_OperationMode ==
ECachedEquipmentOperationMode
.INSERT)
149
Insert
(attachmentCategory, attachmentAttribute);
150
else
151
Remove
(attachmentCategory, attachmentAttribute.m_Entity);
152
}
153
}
154
155
CachedItemAttributesPerCategory cargoAttributesPerCategory =
ProcessCargo
(params);
156
foreach
(
ECachedEquipmentItemCategory
cargoCategory,
array<ref CachedEquipmentItemAttribute>
cargoAttributes : cargoAttributesPerCategory)
157
{
158
foreach
(CachedEquipmentItemAttribute cargoAttribute : cargoAttributes)
159
{
160
if
(params.m_OperationMode ==
ECachedEquipmentOperationMode
.INSERT)
161
Insert
(cargoCategory, cargoAttribute);
162
else
163
Remove
(cargoCategory, cargoAttribute.m_Entity);
164
}
165
}
166
}
167
168
// --------------------------------------------------------------------------------
174
private
map<ECachedEquipmentItemCategory, ref array<ref CachedEquipmentItemAttribute>
>
ProcessAttachments
(CachedEquipmentStorageInventoryEntry params)
175
{
176
CachedItemAttributesPerCategory attachmentAttributesPerCategory =
new
CachedItemAttributesPerCategory();
177
178
int
attachments = params.m_GameInventory.AttachmentCount();
179
for
(
int
attachmentIndex = 0; attachmentIndex < attachments; ++attachmentIndex)
180
{
181
EntityAI
attachment = params.m_GameInventory.GetAttachmentFromIndex(attachmentIndex);
182
ECachedEquipmentItemCategory
category = attachment.GetCachedEquipmentCategory();
183
if
(category ==
ECachedEquipmentItemCategory
.NONE)
184
continue
;
185
186
if
(params.m_OperationMode ==
ECachedEquipmentOperationMode
.INSERT && IsStored(attachment, category))
187
continue
;
188
189
CachedEquipmentItemAttribute newItemAttributes =
new
CachedEquipmentItemAttribute();
190
newItemAttributes.m_Entity = attachment;
191
newItemAttributes.m_Parent = attachment.GetHierarchyParent();
192
newItemAttributes.m_InventoryDepth = attachment.GetHierarchyLevel();
193
newItemAttributes.m_SlotIndex = params.m_SlotId;
194
newItemAttributes.m_InventoryPlacement =
ECachedEquipmentPlacement
.ATTACHMENT;
195
196
array<ref CachedEquipmentItemAttribute>
arr;
197
if
(!attachmentAttributesPerCategory.Find(category, arr))
198
{
199
arr =
new
array<ref CachedEquipmentItemAttribute>
();
200
attachmentAttributesPerCategory.Set(category, arr);
201
}
202
203
#ifdef ENABLE_LOGGING
204
LogMessage(
string
.Format(
"parent:%1 entity:%2"
, newItemAttributes.m_Parent, attachment),
string
.Format(
"%1:ProcessAttachments"
, params.m_CallerMethod));
205
#endif
206
207
arr.Insert(newItemAttributes);
208
}
209
210
return
attachmentAttributesPerCategory;
211
}
212
213
// --------------------------------------------------------------------------------
219
private
map<ECachedEquipmentItemCategory, ref array<ref CachedEquipmentItemAttribute>
>
ProcessCargo
(CachedEquipmentStorageInventoryEntry params)
220
{
221
CachedItemAttributesPerCategory cargoAttributesPerCategory =
new
CachedItemAttributesPerCategory();
222
if
(params.m_GameInventory.GetCargo())
223
{
224
int
cargoCount = params.m_GameInventory.GetCargo().GetItemCount();
225
for
(
int
cargoIndex = 0; cargoIndex < cargoCount; ++cargoIndex)
226
{
227
EntityAI
cargo = params.m_GameInventory.GetCargo().GetItem(cargoIndex);
228
ECachedEquipmentItemCategory
category = cargo.GetCachedEquipmentCategory();
229
if
(category ==
ECachedEquipmentItemCategory
.NONE)
230
continue
;
231
232
if
(params.m_OperationMode ==
ECachedEquipmentOperationMode
.INSERT && IsStored(cargo, category))
233
continue
;
234
235
CachedEquipmentItemAttribute newItemAttributes =
new
CachedEquipmentItemAttribute();
236
237
newItemAttributes.m_Entity = cargo;
238
newItemAttributes.m_Parent = cargo.GetHierarchyParent();
239
newItemAttributes.m_InventoryDepth = cargo.GetHierarchyLevel();
240
newItemAttributes.m_InventoryPlacement =
ECachedEquipmentPlacement
.CARGO;
241
242
array<ref CachedEquipmentItemAttribute>
arr;
243
if
(!cargoAttributesPerCategory.Find(category, arr))
244
{
245
arr =
new
array<ref CachedEquipmentItemAttribute>
();
246
cargoAttributesPerCategory.Set(category, arr);
247
}
248
249
#ifdef ENABLE_LOGGING
250
LogMessage(
string
.Format(
"parent:%1 entity:%2"
, newItemAttributes.m_Parent, cargo),
string
.Format(
"%1:ProcessCargo"
, params.m_CallerMethod));
251
#endif
252
253
arr.Insert(newItemAttributes);
254
}
255
}
256
257
return
cargoAttributesPerCategory;
258
}
259
260
// --------------------------------------------------------------------------------
261
262
#ifdef ENABLE_LOGGING
263
private
void
LogMessage(
string
message,
string
method)
264
{
265
#ifdef CACHED_EQUIPMENT_STORAGE_LOGGING
266
Debug
.Log(message, this.ClassName(),
""
,
string
.Format(
"%1(%2)"
,
m_Player
.ToString(),
Debug
.GetDebugName(
m_Player
)), method);
267
#endif
268
}
269
#endif
270
}
m_Player
map m_Player
ProcessCargo
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessCargo(CachedEquipmentStorageInventoryEntry params)
Processes cargo of item given through params.
Definition
cachedequipmentstorage.c:219
ProcessAttachments
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessAttachments(CachedEquipmentStorageInventoryEntry params)
Processes attachments of item given through params.
Definition
cachedequipmentstorage.c:174
CachedEquipmentStorage
void CachedEquipmentStorage(DayZPlayerImplement player)
Definition
cachedequipmentstorage.c:20
ProcessItemInventory
void ProcessItemInventory(CachedEquipmentStorageInventoryEntry params)
Definition
cachedequipmentstorage.c:141
Debug
string Debug()
Definition
cachedequipmentstoragebase.c:29
CachedEquipmentStorageBase
Definition
cachedequipmentstoragebase.c:52
CachedEquipmentStorageBase::OnItemCargoIn
void OnItemCargoIn(notnull Entity entity)
CachedEquipmentStorageBase::Insert
void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
Definition
cachedequipmentstoragebase.c:133
CachedEquipmentStorageBase::OnItemAttached
void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
CachedEquipmentStorageBase::OnItemCargoOut
void OnItemCargoOut(notnull Entity entity)
CachedEquipmentStorageBase::OnItemDetached
void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
CachedEquipmentStorageBase::Remove
void Remove(ECachedEquipmentItemCategory category, Entity entity)
Definition
cachedequipmentstoragebase.c:144
DayZPlayerImplement
Definition
manbase.c:2
EntityAI
Definition
inventoryitem.c:2
Entity
Definition
camera.c:2
GameInventory
script counterpart to engine's class Inventory
Definition
inventory.c:81
InventorySlots
provides access to slot configuration
Definition
inventoryslots.c:6
InventorySlots::GetSlotName
static proto native owned string GetSlotName(int id)
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
map
Definition
cachedequipmentstorage.c:4
map< int, float >::m_SlotId
int m_SlotId
Definition
cachedequipmentstorage.c:5
map< int, float >::m_OperationMode
ECachedEquipmentOperationMode m_OperationMode
Definition
cachedequipmentstorage.c:11
map< int, float >::m_CallerMethod
string m_CallerMethod
Definition
cachedequipmentstorage.c:7
map< int, float >::m_Entity
EntityAI m_Entity
Definition
cachedequipmentstorage.c:8
map< int, float >::m_GameInventory
GameInventory m_GameInventory
Definition
cachedequipmentstorage.c:9
ECachedEquipmentItemCategory
ECachedEquipmentItemCategory
Definition
ecachedequipmentitemcategory.c:2
ECachedEquipmentOperationMode
ECachedEquipmentOperationMode
Definition
ecachedequipmentoperationmode.c:2
ECachedEquipmentPlacement
ECachedEquipmentPlacement
Definition
ecachedequipmentplacement.c:2
Games
Dayz
scripts
4_world
entities
cachedequipmentstorage.c
Generated by
1.17.0