DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
29 {
32 m_PartIndex = 0;
33
36
37 if ( GetGame().IsClient() || !GetGame().IsMultiplayer() )
38 {
42
46 }
47 }
48
49 //************************************************/
50 // Base building
51 //************************************************/
53 {
54 return m_MainPartName;
55 }
56
58 {
60 }
61
62 void SetTarget( Object target )
63 {
64 m_Target = target;
65 }
66
68 {
69 return m_Target;
70 }
71
72 void SetTargetPart( ConstructionPart target_part )
73 {
74 m_TargetPart = target_part;
75 }
76
78 {
79 return m_TargetPart;
80 }
81
82 void SetSlotId( int slot_id )
83 {
84 m_SlotId = slot_id;
85 }
86
88 {
89 return m_SlotId;
90 }
91
92 void SetActionInitiator( PlayerBase action_initiator )
93 {
94 m_ActionInitiator = action_initiator;
95 }
96
98 {
99 return m_ActionInitiator;
100 }
101
102 // deprecated
104 {
105 }
106
107 // deprecated
108 void RefreshPartsToBuild( string main_part_name, ItemBase tool, bool use_tool = true )
109 {
110
111 }
112
113 void OnUpdateActions( Object item, Object target, int component_index )
114 {
115 ItemBase tool = ItemBase.Cast( item );
116 if ( tool )
117 {
118 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
119 if ( base_building_object )
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
141 void OnUpdateActionsNoTool( Object item, Object target, int component_index )
142 {
143 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
144 if ( base_building_object )
145 {
146 string main_part_name = target.GetActionComponentName( component_index );
147 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildPartsNoTool, null, m_MainPartNameNoTool, false );
149 }
150 else
151 {
152 m_BuildPartsNoTool.Clear();
154 }
155 }
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 {
172 return m_BuildParts.Get( idx );
173 }
174 return null;
175 }
176
178 {
179 if( m_BuildPartsNoTool.Count() > idx )
180 {
181 return m_BuildPartsNoTool.Get( idx );
182 }
183 return null;
184 }
185
186 //************************************************/
187 // Combination lock
188 //************************************************/
190 {
191 return m_CombinationLock;
192 }
193
194 void SetCombinationLock( CombinationLock combination_lock )
195 {
196 m_CombinationLock = CombinationLock.Cast( combination_lock );
197 }
198
200 {
201 string dial_text;
202
203 if ( m_CombinationLock )
204 {
205 string combination_text = m_CombinationLock.GetCombination().ToString();
206
207 //insert zeros to dials with 0 value
208 int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
209 for ( int i = 0; i < length_diff; ++i )
210 {
211 combination_text = "0" + combination_text;
212 }
213
214 //assemble the whole combination with selected part
215 for ( int j = 0; j < m_CombinationLock.GetLockDigits(); ++j )
216 {
217 if ( j == m_CombinationLock.GetDialIndex() )
218 {
219 dial_text += string.Format( "[%1]", combination_text.Get( j ) );
220 }
221 else
222 {
223 dial_text += string.Format( " %1 ", combination_text.Get( j ) );
224 }
225 }
226 }
227
228 return dial_text;
229 }
230
231 //************************************************/
232 // Attach/Detach actions
233 //************************************************/
234 int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
235 {
236 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
237
238 if ( GetGame().ConfigIsExisting( cfg_path ) )
239 {
240 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
241
242 for ( int i = 0; i < child_count; i++ )
243 {
244 string child_name;
245 GetGame().ConfigGetChildName( cfg_path, i, child_name );
246
247 string child_selection;
248 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
249
250 if ( selection == child_selection )
251 {
252 ref array<string> attachment_slots = new array<string>;
253 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
254
255 for ( int j = 0; j < attachment_slots.Count(); ++j )
256 {
257 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
258 int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
259
260 for ( int k = 0; k < item_slot_count; ++k )
261 {
262 int item_slot_id = item_to_attach.GetInventory().GetSlotId( k );
263 ItemBase attachment_item = ItemBase.Cast( target.GetInventory().FindAttachment( item_slot_id ) );
264
265 if ( target_slot_id == item_slot_id )
266 {
267 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 ) )
268 {
269 if(target.CanDisplayAttachmentSlot(target_slot_id))
270 return item_slot_id;
271 else
272 return -1;
273 }
274 }
275 }
276 }
277 }
278 }
279 }
280
281 return -1;
282 }
283
284 void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
285 {
286 attachments.Clear(); //clear output
287
288 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
289 if ( GetGame().ConfigIsExisting( cfg_path ) )
290 {
291 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
292
293 for ( int i = 0; i < child_count; i++ )
294 {
295 string child_name;
296 GetGame().ConfigGetChildName( cfg_path, i, child_name );
297
298 string child_selection;
299 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
300
301 if ( selection == child_selection )
302 {
303 ref array<string> attachment_slots = new array<string>;
304 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
305
306 for ( int j = 0; j < attachment_slots.Count(); ++j )
307 {
308 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
309
310 //is attached and can be detached
311 EntityAI attachment = target.GetInventory().FindAttachment( target_slot_id );
312 if ( attachment && target.GetInventory().CanRemoveAttachmentEx( attachment, target_slot_id ) && !target.GetInventory().GetSlotLock( target_slot_id ) )
313 {
314 attachments.Insert( attachment );
315 }
316 }
317 }
318 }
319 }
320 }
321
322 void CombineItems( ItemBase target, ItemBase item )
323 {
324 if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
325 {
326 int quantity_used = target.ComputeQuantityUsed( item, true );
327 if( quantity_used != 0 )
328 {
329 target.AddQuantity( quantity_used );
330 item.AddQuantity( -quantity_used );
331 }
332 }
333 }
334
335 void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
336 {
337 GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
338 }
339
341 {
342 if ( GetAttachmentsToDetachCount() > 1 )
343 {
345 {
347 }
349 {
351 }
352 }
353 else
354 {
356 }
357 }
358
360 {
361 return m_Attachments.Count();
362 }
363
365 {
366 if ( GetAttachmentsToDetachCount() > 0 )
367 {
369
371 {
372 return m_Attachments.Get( m_AttachmentsIndex );
373 }
374 }
375
376 return NULL;
377 }
378
379 //************************************************/
380 // Common
381 //************************************************/
383 {
384 m_PartIndex = 0;
386 }
387}
static ActionVariantManager GetVariantManager(typename actionName)
void SetActionVariantCount(int count)
ScriptInvoker GetOnUpdateInvoker()
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
void CombineItems(ItemBase target, ItemBase item)
void GetAttachmentsFromSelection(EntityAI target, string selection, out array< EntityAI > attachments)
ref array< ConstructionPart > m_BuildPartsNoTool
ref array< EntityAI > m_Attachments
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
ConstructionPart GetTargetPart()
ref array< ConstructionPart > m_BuildParts
void RefreshAttachmentsToDetach(EntityAI target, string main_part_name)
void OnUpdateActionsNoTool(Object item, Object target, int component_index)
CombinationLock GetCombinationLock()
void SetCombinationLock(CombinationLock combination_lock)
void SetActionInitiator(PlayerBase action_initiator)
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
ref ConstructionPart m_TargetPart
void SetTargetPart(ConstructionPart target_part)
protected ActionVariantManager m_ActionNoToolVariantManager
void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool=true)
void OnUpdateActions(Object item, Object target, int component_index)
ConstructionPart GetBuildPartAtIndex(int idx)
ConstructionPart GetCurrentBuildPart()
void SetTarget(Object target)
protected ActionVariantManager m_ActionVariantManager
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition Rag.c:52
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
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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'.
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.
string Get(int index)
Gets n-th character from string.
Definition EnString.c:434
proto native int Length()
Returns length of string.