DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CachedEquipmentStorage.c
См. документацию.
1//#define CACHED_EQUIPMENT_STORAGE_LOGGING
2
3class CachedEquipmentStorageInventoryEntry
4{
5 int m_SlotId = -1;
6
10
13}
14
16
18{
20
22 {
23 m_Player = player;
24 }
25
26 // --------------------------------------------------------------------------------
27
28 override void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
29 {
30 EntityAI item = EntityAI.Cast(entity);
31 ECachedEquipmentItemCategory category = item.GetCachedEquipmentCategory();
32 if (category != ECachedEquipmentItemCategory.NONE && !IsStored(entity, category))
33 {
34 CachedEquipmentItemAttribute newItemAttributes = new CachedEquipmentItemAttribute();
35 newItemAttributes.m_Entity = entity;
36 newItemAttributes.m_Parent = parent;
37 newItemAttributes.m_InventoryDepth = item.GetHierarchyLevel();
38 newItemAttributes.m_SlotIndex = slotId;
39 newItemAttributes.m_InventoryPlacement = ECachedEquipmentPlacement.ATTACHMENT;
40
41 #ifdef ENABLE_LOGGING
42 LogMessage(string.Format("parent:%1 entity:%2 (slot:%3)", parent, entity, InventorySlots.GetSlotName(slotId)), "OnItemAttached");
43 #endif
44
45 Insert(category, newItemAttributes);
46 }
47
48 CachedEquipmentStorageInventoryEntry params = new CachedEquipmentStorageInventoryEntry();
49 params.m_Entity = item;
50 params.m_GameInventory = item.GetInventory();
51 params.m_SlotId = slotId;
52 params.m_CallerMethod = "OnItemAttached";
53 params.m_OperationMode = ECachedEquipmentOperationMode.INSERT;
54
57 }
58
59 // --------------------------------------------------------------------------------
60
61 override void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
62 {
63 EntityAI item = EntityAI.Cast(entity);
64 ECachedEquipmentItemCategory category = item.GetCachedEquipmentCategory();
65 if (category != ECachedEquipmentItemCategory.NONE)
66 {
67 #ifdef ENABLE_LOGGING
68 LogMessage(string.Format("parent:%1 entity:%2 (slot:%3)", parent, entity, InventorySlots.GetSlotName(slotId)), "OnItemDetached");
69 #endif
70
71 Remove(category, entity);
72 }
73
74 CachedEquipmentStorageInventoryEntry params = new CachedEquipmentStorageInventoryEntry();
75 params.m_Entity = item;
76 params.m_GameInventory = item.GetInventory();
77 params.m_SlotId = slotId;
78 params.m_CallerMethod = "OnItemDetached";
79 params.m_OperationMode = ECachedEquipmentOperationMode.REMOVE;
80
82 }
83
84 // --------------------------------------------------------------------------------
85
86 override void OnItemCargoIn(notnull Entity entity)
87 {
88 EntityAI item = EntityAI.Cast(entity);
89 if (!item.GetHierarchyParent())
90 return;
91
92 ECachedEquipmentItemCategory category = item.GetCachedEquipmentCategory();
93 if (category != ECachedEquipmentItemCategory.NONE && !IsStored(entity, category))
94 {
95 CachedEquipmentItemAttribute newItemAttributes = new CachedEquipmentItemAttribute();
96 newItemAttributes.m_Entity = entity;
97 newItemAttributes.m_Parent = item.GetHierarchyParent();
98 newItemAttributes.m_InventoryDepth = item.GetHierarchyLevel();
99 newItemAttributes.m_InventoryPlacement = ECachedEquipmentPlacement.CARGO;
100
101 #ifdef ENABLE_LOGGING
102 LogMessage(string.Format("parent:%1 entity:%2", item.GetHierarchyParent(), entity), "OnItemCargoIn");
103 #endif
104
105 Insert(category, newItemAttributes);
106 }
107
108 CachedEquipmentStorageInventoryEntry params = new CachedEquipmentStorageInventoryEntry();
109 params.m_Entity = item;
110 params.m_GameInventory = item.GetInventory();
111 params.m_CallerMethod = "OnItemCargoIn";
112 params.m_OperationMode = ECachedEquipmentOperationMode.INSERT;
113
114 ProcessItemInventory(params);
115 }
116
117 // --------------------------------------------------------------------------------
118
119 override void OnItemCargoOut(notnull Entity entity)
120 {
121 EntityAI item = EntityAI.Cast(entity);
122 ECachedEquipmentItemCategory category = item.GetCachedEquipmentCategory();
123 if (category != ECachedEquipmentItemCategory.NONE)
124 {
125 #ifdef ENABLE_LOGGING
126 LogMessage(string.Format("parent:%1 entity:%2", item.GetHierarchyParent(), entity), "OnItemCargoOut");
127 #endif
128
129 Remove(category, entity);
130 }
131
132 CachedEquipmentStorageInventoryEntry params = new CachedEquipmentStorageInventoryEntry();
133 params.m_Entity = item;
134 params.m_GameInventory = item.GetInventory();
135 params.m_CallerMethod = "OnItemCargoOut";
136 params.m_OperationMode = ECachedEquipmentOperationMode.REMOVE;
137
138 ProcessItemInventory(params);
139 }
140
141 // --------------------------------------------------------------------------------
142
143 protected void ProcessItemInventory(CachedEquipmentStorageInventoryEntry params)
144 {
145 CachedItemAttributesPerCategory attachmentAttributesPerCategory = ProcessAttachments(params);
146 foreach (ECachedEquipmentItemCategory attachmentCategory, array<ref CachedEquipmentItemAttribute> attachmentAttributes : attachmentAttributesPerCategory)
147 {
148 foreach (CachedEquipmentItemAttribute attachmentAttribute : attachmentAttributes)
149 {
150 if (params.m_OperationMode == ECachedEquipmentOperationMode.INSERT)
151 Insert(attachmentCategory, attachmentAttribute);
152 else
153 Remove(attachmentCategory, attachmentAttribute.m_Entity);
154 }
155 }
156
157 CachedItemAttributesPerCategory cargoAttributesPerCategory = ProcessCargo(params);
158 foreach (ECachedEquipmentItemCategory cargoCategory, array<ref CachedEquipmentItemAttribute> cargoAttributes : cargoAttributesPerCategory)
159 {
160 foreach (CachedEquipmentItemAttribute cargoAttribute : cargoAttributes)
161 {
162 if (params.m_OperationMode == ECachedEquipmentOperationMode.INSERT)
163 Insert(cargoCategory, cargoAttribute);
164 else
165 Remove(cargoCategory, cargoAttribute.m_Entity);
166 }
167 }
168 }
169
170 // --------------------------------------------------------------------------------
177 {
178 CachedItemAttributesPerCategory attachmentAttributesPerCategory = new CachedItemAttributesPerCategory();
179
180 int attachments = params.m_GameInventory.AttachmentCount();
181 for (int attachmentIndex = 0; attachmentIndex < attachments; ++attachmentIndex)
182 {
183 EntityAI attachment = params.m_GameInventory.GetAttachmentFromIndex(attachmentIndex);
184 ECachedEquipmentItemCategory category = attachment.GetCachedEquipmentCategory();
185 if (category == ECachedEquipmentItemCategory.NONE)
186 continue;
187
188 if (params.m_OperationMode == ECachedEquipmentOperationMode.INSERT && IsStored(attachment, category))
189 continue;
190
191 InventoryLocation parentInventoryLocation = new InventoryLocation();
192 params.m_GameInventory.GetCurrentInventoryLocation(parentInventoryLocation);
193
194 CachedEquipmentItemAttribute newItemAttributes = new CachedEquipmentItemAttribute();
195 newItemAttributes.m_Entity = attachment;
196 newItemAttributes.m_Parent = attachment.GetHierarchyParent();
197 newItemAttributes.m_ParentInventoryPlacement = parentInventoryLocation.GetSlot();
198 newItemAttributes.m_InventoryDepth = attachment.GetHierarchyLevel();
199 newItemAttributes.m_SlotIndex = params.m_SlotId;
200 newItemAttributes.m_InventoryPlacement = ECachedEquipmentPlacement.ATTACHMENT;
201
203 if (!attachmentAttributesPerCategory.Find(category, arr))
204 {
206 attachmentAttributesPerCategory.Set(category, arr);
207 }
208
209 #ifdef ENABLE_LOGGING
210 LogMessage(string.Format("parent:%1 entity:%2", newItemAttributes.m_Parent, attachment), string.Format("%1:ProcessAttachments", params.m_CallerMethod));
211 #endif
212
213 arr.Insert(newItemAttributes);
214 }
215
216 return attachmentAttributesPerCategory;
217 }
218
219 // --------------------------------------------------------------------------------
226 {
227 CachedItemAttributesPerCategory cargoAttributesPerCategory = new CachedItemAttributesPerCategory();
228 if (params.m_GameInventory.GetCargo())
229 {
230 int cargoCount = params.m_GameInventory.GetCargo().GetItemCount();
231 for (int cargoIndex = 0; cargoIndex < cargoCount; ++cargoIndex)
232 {
233 EntityAI cargo = params.m_GameInventory.GetCargo().GetItem(cargoIndex);
234 ECachedEquipmentItemCategory category = cargo.GetCachedEquipmentCategory();
235 if (category == ECachedEquipmentItemCategory.NONE)
236 continue;
237
238 if (params.m_OperationMode == ECachedEquipmentOperationMode.INSERT && IsStored(cargo, category))
239 continue;
240
241 InventoryLocation parentInventoryLocation = new InventoryLocation();
242 params.m_GameInventory.GetCurrentInventoryLocation(parentInventoryLocation);
243
244 CachedEquipmentItemAttribute newItemAttributes = new CachedEquipmentItemAttribute();
245
246 newItemAttributes.m_Entity = cargo;
247 newItemAttributes.m_Parent = cargo.GetHierarchyParent();
248 newItemAttributes.m_ParentInventoryPlacement = parentInventoryLocation.GetSlot();
249 newItemAttributes.m_InventoryDepth = cargo.GetHierarchyLevel();
250 newItemAttributes.m_InventoryPlacement = ECachedEquipmentPlacement.CARGO;
251
252
254 if (!cargoAttributesPerCategory.Find(category, arr))
255 {
257 cargoAttributesPerCategory.Set(category, arr);
258 }
259
260 #ifdef ENABLE_LOGGING
261 LogMessage(string.Format("parent:%1 entity:%2", newItemAttributes.m_Parent, cargo), string.Format("%1:ProcessCargo", params.m_CallerMethod));
262 #endif
263
264 arr.Insert(newItemAttributes);
265 }
266 }
267
268 return cargoAttributesPerCategory;
269 }
270
271 // --------------------------------------------------------------------------------
272
273 #ifdef ENABLE_LOGGING
274 private void LogMessage(string message, string method)
275 {
276 #ifdef CACHED_EQUIPMENT_STORAGE_LOGGING
277 Debug.Log(message, this.ClassName(), "", string.Format("%1(%2)", m_Player.ToString(), Debug.GetDebugName(m_Player)), method);
278 #endif
279 }
280 #endif
281}
map CachedItemAttributesPerCategory
ECachedEquipmentItemCategory
Определения ECachedEquipmentItemCategory.c:2
ECachedEquipmentOperationMode
Определения ECachedEquipmentOperationMode.c:2
ECachedEquipmentPlacement
Определения ECachedEquipmentPlacement.c:2
DayZPlayer m_Player
Определения Hand_Events.c:42
void ProcessItemInventory(CachedEquipmentStorageInventoryEntry params)
Определения CachedEquipmentStorage.c:143
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessAttachments(CachedEquipmentStorageInventoryEntry params)
Processes attachments of item given through params.
Определения CachedEquipmentStorage.c:176
map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > ProcessCargo(CachedEquipmentStorageInventoryEntry params)
Processes cargo of item given through params.
Определения CachedEquipmentStorage.c:225
void CachedEquipmentStorage(DayZPlayerImplement player)
Определения CachedEquipmentStorage.c:21
override void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
Определения CachedEquipmentStorage.c:61
DayZPlayerImplement m_Player
Определения CachedEquipmentStorage.c:19
override void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
Определения CachedEquipmentStorage.c:28
override void OnItemCargoOut(notnull Entity entity)
Определения CachedEquipmentStorage.c:119
override void OnItemCargoIn(notnull Entity entity)
Определения CachedEquipmentStorage.c:86
bool IsStored(Entity entity, ECachedEquipmentItemCategory category)
Определения CachedEquipmentStorageBase.c:129
void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
Определения CachedEquipmentStorageBase.c:145
void Remove(ECachedEquipmentItemCategory category, Entity entity)
Определения CachedEquipmentStorageBase.c:156
Определения ManBase.c:2
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Определения 3_Game/DayZ/tools/Debug.c:183
static string GetDebugName(Managed entity)
Определения 3_Game/DayZ/tools/Debug.c:32
Определения 3_Game/DayZ/tools/Debug.c:2
Определения Camera.c:2
script counterpart to engine's class Inventory
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation.
Определения InventoryLocation.c:30
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
ECachedEquipmentPlacement m_InventoryPlacement
Определения CachedEquipmentStorage.c:12
Определения Transport.c:70