DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CachedEquipmentStorage.c
См. документацию.
1//#define CACHED_EQUIPMENT_STORAGE_LOGGING
2
15
17{
19
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
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
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 // --------------------------------------------------------------------------------
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
197 if (!attachmentAttributesPerCategory.Find(category, arr))
198 {
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 // --------------------------------------------------------------------------------
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
243 if (!cargoAttributesPerCategory.Find(category, arr))
244 {
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}
map m_Player
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessCargo(CachedEquipmentStorageInventoryEntry params)
Processes cargo of item given through params.
Определения CachedEquipmentStorage.c:219
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessAttachments(CachedEquipmentStorageInventoryEntry params)
Processes attachments of item given through params.
Определения CachedEquipmentStorage.c:174
void CachedEquipmentStorage(DayZPlayerImplement player)
Определения CachedEquipmentStorage.c:20
void ProcessItemInventory(CachedEquipmentStorageInventoryEntry params)
Определения CachedEquipmentStorage.c:141
string Debug()
Определения CachedEquipmentStorageBase.c:29
ECachedEquipmentItemCategory
Определения ECachedEquipmentItemCategory.c:2
ECachedEquipmentOperationMode
Определения ECachedEquipmentOperationMode.c:2
ECachedEquipmentPlacement
Определения ECachedEquipmentPlacement.c:2
void OnItemCargoOut(notnull Entity entity)
void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
Определения CachedEquipmentStorageBase.c:133
void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
void OnItemCargoIn(notnull Entity entity)
void Remove(ECachedEquipmentItemCategory category, Entity entity)
Определения CachedEquipmentStorageBase.c:144
Определения ManBase.c:2
Определения Camera.c:2
script counterpart to engine's class Inventory
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
Определения InventorySlots.c:6
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ECachedEquipmentOperationMode m_OperationMode
Определения CachedEquipmentStorage.c:11
EntityAI m_Entity
Определения CachedEquipmentStorage.c:8
string m_CallerMethod
Определения CachedEquipmentStorage.c:7
GameInventory m_GameInventory
Определения CachedEquipmentStorage.c:9
Определения CachedEquipmentStorage.c:4