DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CachedEquipmentStorageBase.c
См. документацию.
8
9class CachedEquipmentItemAttribute
10{
11 int m_SlotIndex = -1;
12
15
18
20
22 {
23 return m_InventoryDepth;
24 }
25
26 string Debug()
27 {
28 if (m_SlotIndex >= 0)
29 {
30 return string.Format("entity:%1(%2 - %3), parent:%4(%5), inventoryDepth:%6",
37 );
38 }
39
40 return string.Format("entity:%1(%2), parent:%3(%4) , inventoryDepth:%5",
46 );
47 }
48}
49
51{
53
58
59 void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent);
60 void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent);
61 void OnItemCargoIn(notnull Entity entity);
62 void OnItemCargoOut(notnull Entity entity);
63
64 // --------------------------------------------------------------------------------
70 {
71 TIntArray categoriesAll = m_ItemsCacheByCategory.GetKeyArray();
72 TIntArray matchedCategories = new TIntArray();
73
74 foreach (int category: categoriesAll)
75 {
76 if (category & query.m_Category)
77 matchedCategories.Insert(category);
78 }
79
80 array<Entity> entities = new array<Entity>();
81
82 if (matchedCategories.Count() > 0)
83 {
84 foreach (int matchedCategory : matchedCategories)
85 {
86 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[matchedCategory])
87 {
88 bool placementMatched = false;
89 bool parentPlacementMatched = false;
90 bool inventoryDepthMatched = false;
91
92 if (itemAttributes.m_InventoryPlacement == query.m_Placement || query.m_Placement == ECachedEquipmentPlacement.ANY)
93 placementMatched = true;
94
95 if (query.m_ParentPlacement.Count() == 0 || query.m_ParentPlacement.Find(itemAttributes.m_ParentInventoryPlacement) > INDEX_NOT_FOUND)
96 parentPlacementMatched = true;
97
98 if (itemAttributes.m_InventoryDepth <= query.m_MaximumDepth || query.m_MaximumDepth == -1)
99 inventoryDepthMatched = true;
100
101 if (placementMatched && parentPlacementMatched && inventoryDepthMatched)
102 entities.Insert(itemAttributes.m_Entity);
103 }
104 }
105 }
106
107 return entities;
108 }
109
110 // --------------------------------------------------------------------------------
117 {
119 query.m_Category = category;
120 query.m_Placement = placement;
121 query.m_MaximumDepth = 2;
122 array<Entity> entities = GetEntitiesByCategory(query);
123
124 return entities;
125 }
126
127 // --------------------------------------------------------------------------------
128
129 protected bool IsStored(Entity entity, ECachedEquipmentItemCategory category)
130 {
131 if (!m_ItemsCacheByCategory.Contains(category))
132 return false;
133
134 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
135 {
136 if (itemAttributes.m_Entity == entity)
137 return true;
138 }
139
140 return false;
141 }
142
143 // --------------------------------------------------------------------------------
144
145 protected void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
146 {
148 if (!m_ItemsCacheByCategory.Contains(category))
149 m_ItemsCacheByCategory.Set(category, attributesArray);
150
151 m_ItemsCacheByCategory[category].Insert(attributes);
152 }
153
154 // --------------------------------------------------------------------------------
155
156 protected void Remove(ECachedEquipmentItemCategory category, Entity entity)
157 {
158 if (!m_ItemsCacheByCategory.Contains(category))
159 return;
160
162 foreach (CachedEquipmentItemAttribute attributeToRemove : m_ItemsCacheByCategory[category])
163 {
164 if (attributeToRemove.m_Entity == entity)
165 toRemove.Insert(attributeToRemove);
166 }
167
168 foreach (CachedEquipmentItemAttribute attribute : toRemove)
169 m_ItemsCacheByCategory[category].RemoveItem(attribute);
170 }
171
172 // --------------------------------------------------------------------------------
173
175 {
177 if (!categories)
178 return;
179
180 InventoryLocation parentInventoryLocation = new InventoryLocation();
181
182 foreach (ECachedEquipmentItemCategory category : categories)
183 {
184 if (!m_ItemsCacheByCategory[category])
185 continue;
186
187 foreach (int index, CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
188 {
189 if (!itemAttributes || !itemAttributes.m_Parent)
190 continue;
191
192 EntityAI parent;
193 if (!Class.CastTo(parent, itemAttributes.m_Parent))
194 continue;
195
196 GameInventory parentInventory = parent.GetInventory();
197 if (!parentInventory)
198 continue;
199
200 parentInventory.GetCurrentInventoryLocation(parentInventoryLocation);
201 itemAttributes.m_ParentInventoryPlacement = parentInventoryLocation.GetSlot();
202 }
203 }
204 }
205
206 // --------------------------------------------------------------------------------
207
208 #ifdef DIAG_DEVELOPER
209 void PrintCachedEntitiesByCategory(ECachedEquipmentItemCategory category)
210 {
211 if (m_ItemsCacheByCategory[category])
212 {
213 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
214 {
215 Print(itemAttributes.Debug());
216 }
217 }
218 }
219
220 // --------------------------------------------------------------------------------
221
222 void DumpCache()
223 {
224 Print("--------------------------");
225 Print("Equipped Items Cache Stats");
226
227 array<ECachedEquipmentItemCategory> categories = m_ItemsCacheByCategory.GetKeyArray();
228 foreach (ECachedEquipmentItemCategory category : categories)
229 {
230 Print(string.Format("[%1]", EnumTools.EnumFlagsToString(ECachedEquipmentItemCategory, category)));
231 PrintCachedEntitiesByCategory(category);
232 }
233 Print("--------------------------");
234 }
235 #endif
236}
int InventoryDepth()
Определения CachedEquipmentStorageBase.c:21
string Debug()
Определения CachedEquipmentStorageBase.c:26
int m_ParentInventoryPlacement
Определения CachedEquipmentStorageBase.c:14
int m_InventoryDepth
Определения CachedEquipmentStorageBase.c:13
class CachedEquipmentStorageQuery m_SlotIndex
ECachedEquipmentPlacement m_InventoryPlacement
Определения CachedEquipmentStorageBase.c:19
Entity m_Entity
Определения CachedEquipmentStorageBase.c:16
Entity m_Parent
Определения CachedEquipmentStorageBase.c:17
ECachedEquipmentItemCategory
Определения ECachedEquipmentItemCategory.c:2
ECachedEquipmentPlacement
Определения ECachedEquipmentPlacement.c:2
void OnItemCargoOut(notnull Entity entity)
bool IsStored(Entity entity, ECachedEquipmentItemCategory category)
Определения CachedEquipmentStorageBase.c:129
void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
array< Entity > GetEntitiesByCategory(CachedEquipmentStorageQuery query)
List of entities matching the CachedEquipmentStorageQuery query.
Определения CachedEquipmentStorageBase.c:69
ref map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > m_ItemsCacheByCategory
Определения CachedEquipmentStorageBase.c:52
void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
Определения CachedEquipmentStorageBase.c:145
void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
void OnItemCargoIn(notnull Entity entity)
void Remove(ECachedEquipmentItemCategory category, Entity entity)
Определения CachedEquipmentStorageBase.c:156
array< Entity > GetEntitiesByCategory(ECachedEquipmentItemCategory category, ECachedEquipmentPlacement placement=ECachedEquipmentPlacement.ANY)
List of entities matching the category and inventory placement.
Определения CachedEquipmentStorageBase.c:116
ECachedEquipmentItemCategory m_Category
Определения CachedEquipmentStorageBase.c:5
ref TIntArray m_ParentPlacement
Определения CachedEquipmentStorageBase.c:4
ECachedEquipmentPlacement m_Placement
Определения CachedEquipmentStorageBase.c:6
Super root of all classes in Enforce script.
Определения EnScript.c:11
Определения Camera.c:2
static string EnumToString(typename e, int enumValue)
Return string name of enum value.
Определения EnConvert.c:699
Определения EnConvert.c:688
proto native bool GetCurrentInventoryLocation(out notnull InventoryLocation loc)
returns information about current item location
script counterpart to engine's class Inventory
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation.
Определения InventoryLocation.c:30
const int INVALID
Invalid slot (-1)
Определения InventorySlots.c:17
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.
Определения Transport.c:70
const int INDEX_NOT_FOUND
Определения gameplay.c:13
proto void Print(void var)
Prints content of variable to console/log.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
array< int > TIntArray
Определения EnScript.c:733
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.