Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
cachedequipmentstoragebase.c
Go to the documentation of this file.
7
8class CachedEquipmentItemAttribute
9{
10 int m_SlotIndex = -1;
11
13
16
18
19 bool HasParent()
20 {
21 return m_Parent != null;
22 }
23
25 {
26 return m_InventoryDepth;
27 }
28
29 string Debug()
30 {
31 if (m_SlotIndex >= 0)
32 {
33 return string.Format("entity:%1(%2 - %3), parent:%4, inventoryDepth:%5",
39 );
40 }
41
42 return string.Format("entity:%1(%2), parent:%3 , inventoryDepth:%4",
47 );
48 }
49}
50
52{
54
59
60 void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent);
61 void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent);
62 void OnItemCargoIn(notnull Entity entity);
63 void OnItemCargoOut(notnull Entity entity);
64
65 // --------------------------------------------------------------------------------
71 {
72 array<Entity> entities = new array<Entity>();
74 {
75 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[query.m_Category])
76 {
77 bool placementMatched = false;
78 bool inventoryDepthMatched = false;
79
80 if (itemAttributes.m_InventoryPlacement == query.m_Placement || query.m_Placement == ECachedEquipmentPlacement.ANY)
81 placementMatched = true;
82
83 if (itemAttributes.m_InventoryDepth <= query.m_MaximumDepth || query.m_MaximumDepth == -1)
84 inventoryDepthMatched = true;
85
86 if (placementMatched && inventoryDepthMatched)
87 entities.Insert(itemAttributes.m_Entity);
88 }
89 }
90
91 return entities;
92 }
93
94 // --------------------------------------------------------------------------------
101 {
102 array<Entity> entities = new array<Entity>();
103 if (m_ItemsCacheByCategory[category])
104 {
105 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
106 {
107 if (itemAttributes.m_InventoryPlacement == placement || placement == ECachedEquipmentPlacement.ANY)
108 entities.Insert(itemAttributes.m_Entity);
109 }
110 }
111
112 return entities;
113 }
114
115 // --------------------------------------------------------------------------------
116
117 protected bool IsStored(Entity entity, ECachedEquipmentItemCategory category)
118 {
119 if (!m_ItemsCacheByCategory.Contains(category))
120 return false;
121
122 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
123 {
124 if (itemAttributes.m_Entity == entity)
125 return true;
126 }
127
128 return false;
129 }
130
131 // --------------------------------------------------------------------------------
132
133 protected void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
134 {
136 if (!m_ItemsCacheByCategory.Contains(category))
137 m_ItemsCacheByCategory.Set(category, attributesArray);
138
139 m_ItemsCacheByCategory[category].Insert(attributes);
140 }
141
142 // --------------------------------------------------------------------------------
143
144 protected void Remove(ECachedEquipmentItemCategory category, Entity entity)
145 {
146 if (!m_ItemsCacheByCategory.Contains(category))
147 return;
148
150 foreach (CachedEquipmentItemAttribute attributeToRemove : m_ItemsCacheByCategory[category])
151 {
152 if (attributeToRemove.m_Entity == entity)
153 toRemove.Insert(attributeToRemove);
154 }
155
156 foreach (CachedEquipmentItemAttribute attribute : toRemove)
157 m_ItemsCacheByCategory[category].RemoveItem(attribute);
158 }
159
160 // --------------------------------------------------------------------------------
161
162 #ifdef DIAG_DEVELOPER
163 void PrintCachedEntitiesByCategory(ECachedEquipmentItemCategory category)
164 {
165 if (m_ItemsCacheByCategory[category])
166 {
167 foreach (CachedEquipmentItemAttribute itemAttributes : m_ItemsCacheByCategory[category])
168 {
169 Print(itemAttributes.Debug());
170 }
171 }
172 }
173
174 // --------------------------------------------------------------------------------
175
176 void DumpCache()
177 {
178 Print("--------------------------");
179 Print("Equipped Items Cache Stats");
180
181 array<ECachedEquipmentItemCategory> categories = m_ItemsCacheByCategory.GetKeyArray();
182 foreach (ECachedEquipmentItemCategory category : categories)
183 {
184 Print(string.Format("[%1]", EnumTools.EnumToString(ECachedEquipmentItemCategory, category)));
185 PrintCachedEntitiesByCategory(category);
186 }
187 Print("--------------------------");
188 }
189 #endif
190}
int InventoryDepth()
string Debug()
bool HasParent()
class CachedEquipmentStorageQuery m_SlotIndex
ECachedEquipmentPlacement m_InventoryPlacement
Entity m_Entity
Entity m_Parent
bool IsStored(Entity entity, ECachedEquipmentItemCategory category)
ref map< ECachedEquipmentItemCategory, ref array< ref CachedEquipmentItemAttribute > > m_ItemsCacheByCategory
void OnItemCargoIn(notnull Entity entity)
void Insert(ECachedEquipmentItemCategory category, CachedEquipmentItemAttribute attributes)
void OnItemAttached(notnull Entity entity, int slotId, notnull Entity parent)
void OnItemCargoOut(notnull Entity entity)
array< Entity > GetEntitiesByCategory(ECachedEquipmentItemCategory category, ECachedEquipmentPlacement placement=ECachedEquipmentPlacement.ANY)
List of entities matching the category and inventory placement.
array< Entity > GetEntitiesByCategory(CachedEquipmentStorageQuery query)
List of entities matching the CachedEquipmentStorageQuery query.
void OnItemDetached(notnull Entity entity, int slotId, notnull Entity parent)
void Remove(ECachedEquipmentItemCategory category, Entity entity)
ECachedEquipmentItemCategory m_Category
ECachedEquipmentPlacement m_Placement
Definition camera.c:2
static string EnumToString(typename e, int enumValue)
Return string name of enum value.
Definition enconvert.c:614
provides access to slot configuration
static proto native owned string GetSlotName(int id)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ECachedEquipmentPlacement
proto void Print(void var)
Prints content of variable to console/log.
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.