DayZ 1.24
Loading...
Searching...
No Matches
ConstructionActionData.c
Go to the documentation of this file.
2{
4
5 //base building
8
9 int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
13
14 //combination lock
16
17 //attaching
20 //detaching
22
25
27
48
49 //************************************************/
50 // Base building
51 //************************************************/
53 {
54 return m_MainPartName;
55 }
56
58 {
60 }
61
63 {
65 }
66
68 {
69 return m_Target;
70 }
71
76
81
83 {
85 }
86
88 {
89 return m_SlotId;
90 }
91
96
101
102 // deprecated
104 {
105 }
106
107 // deprecated
109 {
110
111 }
112
114 {
115 ItemBase tool = ItemBase.Cast(item);
116 if (tool)
117 {
120 {
121 string main_part_name = target.GetActionComponentName(component_index);
122 base_building_object.GetConstruction().GetConstructionPartsToBuild(main_part_name, m_BuildParts, tool, m_MainPartName, true);
124 }
125 else
126 {
127 m_BuildParts.Clear();
129 }
130
131 }
132 else
133 {
134 m_BuildParts.Clear();
136 }
137 //not needed
138 //m_Target = target;
139 }
140
156
158 {
159 return m_BuildParts.Count();
160 }
161
162 // deprecated
164 {
165 return null;
166 }
167
169 {
170 if (m_BuildParts.Count() > idx)
171 return m_BuildParts.Get(idx);
172 return null;
173 }
174
176 {
177 if (m_BuildPartsNoTool.Count() > idx)
178 return m_BuildPartsNoTool.Get(idx);
179 return null;
180 }
181
182 //************************************************/
183 // Combination lock
184 //************************************************/
189
194
196 {
197 string dial_text;
198
200 {
201 string combination_text = m_CombinationLock.GetCombination().ToString();
202
203 //insert zeros to dials with 0 value
204 int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
205 for (int i = 0; i < length_diff; ++i)
207
208 //assemble the whole combination with selected part
209 for (int j = 0; j < m_CombinationLock.GetLockDigits(); ++j)
210 {
211 if (j == m_CombinationLock.GetDialIndex())
212 dial_text += string.Format("[%1]", combination_text.Get(j));
213 else
214 dial_text += string.Format(" %1 ", combination_text.Get(j));
215 }
216 }
217
218 return dial_text;
219 }
220
221 //************************************************/
222 // Attach/Detach actions
223 //************************************************/
225 {
226 string cfg_path = "cfgVehicles" + " " + target.GetType() + " " + "GUIInventoryAttachmentsProps";
227
228 if (GetGame().ConfigIsExisting(cfg_path))
229 {
230 int child_count = GetGame().ConfigGetChildrenCount(cfg_path);
231
232 for (int i = 0; i < child_count; i++)
233 {
234 string child_name;
235 GetGame().ConfigGetChildName(cfg_path, i, child_name);
236
237 string child_selection;
238 GetGame().ConfigGetText(cfg_path + " " + child_name + " " + "selection", child_selection);
239
240 if (selection == child_selection)
241 {
243 GetGame().ConfigGetTextArray(cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots);
244
245 for (int j = 0; j < attachment_slots.Count(); ++j)
246 {
248 int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
249
250 for (int k = 0; k < item_slot_count; ++k)
251 {
252 int item_slot_id = item_to_attach.GetInventory().GetSlotId(k);
253 ItemBase attachment_item = ItemBase.Cast(target.GetInventory().FindAttachment(item_slot_id));
254
256 {
257 if (target.GetInventory().CanAddAttachmentEx(item_to_attach, item_slot_id) && target.CanReceiveAttachment(item_to_attach, item_slot_id) || attachment_item && attachment_item.CanBeCombined(item_to_attach))
258 {
259 if (target.CanDisplayAttachmentSlot(target_slot_id))
260 return item_slot_id;
261 else
262 return -1;
263 }
264 }
265 }
266 }
267 }
268 }
269 }
270
271 return -1;
272 }
273
275 {
276 attachments.Clear(); //clear output
277
278 string cfg_path = "cfgVehicles" + " " + target.GetType() + " " + "GUIInventoryAttachmentsProps";
279 if (GetGame().ConfigIsExisting(cfg_path))
280 {
281 int child_count = GetGame().ConfigGetChildrenCount(cfg_path);
282
283 for (int i = 0; i < child_count; i++)
284 {
285 string child_name;
286 GetGame().ConfigGetChildName(cfg_path, i, child_name);
287
288 string child_selection;
289 GetGame().ConfigGetText(cfg_path + " " + child_name + " " + "selection", child_selection);
290
291 if (selection == child_selection)
292 {
294 GetGame().ConfigGetTextArray(cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots);
295
296 for (int j = 0; j < attachment_slots.Count(); ++j)
297 {
299
300 //is attached and can be detached
301 EntityAI attachment = target.GetInventory().FindAttachment(target_slot_id);
302 if (attachment && target.GetInventory().CanRemoveAttachmentEx(attachment, target_slot_id) && !target.GetInventory().GetSlotLock(target_slot_id))
303 attachments.Insert(attachment);
304 }
305 }
306 }
307 }
308 }
309
311 {
312 if (target.ConfigGetBool("canBeSplit") && item && !target.IsFullQuantity())
313 {
314 int quantity_used = target.ComputeQuantityUsed(item, true);
315 if (quantity_used != 0)
316 {
317 target.AddQuantity(quantity_used);
318 item.AddQuantity(-quantity_used);
319 }
320 }
321 }
322
327
329 {
331 {
336 }
337 else
339 }
340
342 {
343 return m_Attachments.Count();
344 }
345
358
359 //************************************************/
360 // Common
361 //************************************************/
363 {
364 m_PartIndex = 0;
366 }
367}
static ActionVariantManager GetVariantManager(typename actionName)
ScriptInvoker GetOnUpdateInvoker()
void SetActionVariantCount(int count)
ref array< EntityAI > m_Attachments
ref array< ConstructionPart > m_BuildParts
void SetCombinationLock(CombinationLock combination_lock)
ConstructionPart GetCurrentBuildPart()
CombinationLock GetCombinationLock()
ActionVariantManager m_ActionNoToolVariantManager
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
void CombineItems(ItemBase target, ItemBase item)
void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool=true)
void SetTarget(Object target)
void OnUpdateActionsNoTool(Object item, Object target, int component_index)
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
ActionVariantManager m_ActionVariantManager
ConstructionPart GetBuildPartAtIndex(int idx)
ConstructionPart GetTargetPart()
void GetAttachmentsFromSelection(EntityAI target, string selection, out array< EntityAI > attachments)
void SetActionInitiator(PlayerBase action_initiator)
void RefreshAttachmentsToDetach(EntityAI target, string main_part_name)
ref ConstructionPart m_TargetPart
void OnUpdateActions(Object item, Object target, int component_index)
ref array< ConstructionPart > m_BuildPartsNoTool
void SetTargetPart(ConstructionPart target_part)
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
Definition EnMath.c:7
proto native void Clear()
remove all calls from list
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
proto native CGame GetGame()
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.