Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
constructionactiondata.c
Go to the documentation of this file.
2{
3 Object m_Target;
4
5 //base building
6 ref array<ConstructionPart> m_BuildParts;
7 ref array<ConstructionPart> m_BuildPartsNoTool;
8
9 int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
10 string m_MainPartName;
11 string m_MainPartNameNoTool;
12 ref ConstructionPart m_TargetPart;
13
14 //combination lock
15 CombinationLock m_CombinationLock;
16
17 //attaching
18 int m_SlotId;
19 PlayerBase m_ActionInitiator;
20 //detaching
21 ref array<EntityAI> m_Attachments;
22
25
27
48
50 {
51 if (GetGame() && (GetGame().IsClient() || !GetGame().IsMultiplayer()))
52 {
54 {
56 }
57
59 {
61 }
62 }
63 }
64
65 //************************************************/
66 // Base building
67 //************************************************/
69 {
70 return m_MainPartName;
71 }
72
74 {
75 return m_MainPartNameNoTool;
76 }
77
78 void SetTarget( Object target )
79 {
80 m_Target = target;
81 }
82
84 {
85 return m_Target;
86 }
87
88 void SetTargetPart( ConstructionPart target_part )
89 {
90 m_TargetPart = target_part;
91 }
92
94 {
95 return m_TargetPart;
96 }
97
98 void SetSlotId( int slot_id )
99 {
100 m_SlotId = slot_id;
101 }
102
104 {
105 return m_SlotId;
106 }
107
108 void SetActionInitiator( PlayerBase action_initiator )
109 {
110 m_ActionInitiator = action_initiator;
111 }
112
114 {
115 return m_ActionInitiator;
116 }
117
118 // deprecated
120 {
121 }
122
123 // deprecated
124 void RefreshPartsToBuild( string main_part_name, ItemBase tool, bool use_tool = true )
125 {
126
127 }
128
129 void OnUpdateActions( Object item, Object target, int component_index )
130 {
131 ItemBase tool = ItemBase.Cast( item );
132 if ( tool )
133 {
134 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
135 if ( base_building_object )
136 {
137 string main_part_name = target.GetActionComponentName( component_index );
138 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildParts, tool, m_MainPartName, true );
139 m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
140 }
141 else
142 {
143 m_BuildParts.Clear();
145 }
146
147 }
148 else
149 {
150 m_BuildParts.Clear();
152 }
153 //not needed
154 //m_Target = target;
155 }
156
157 void OnUpdateActionsNoTool( Object item, Object target, int component_index )
158 {
159 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
160 if ( base_building_object )
161 {
162 string main_part_name = target.GetActionComponentName( component_index );
163 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildPartsNoTool, null, m_MainPartNameNoTool, false );
164 m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
165 }
166 else
167 {
168 m_BuildPartsNoTool.Clear();
170 }
171 }
172
174 {
175 return m_BuildParts.Count();
176 }
177
178 // deprecated
180 {
181 return null;
182 }
183
185 {
186 if( m_BuildParts.Count() > idx )
187 {
188 return m_BuildParts.Get( idx );
189 }
190 return null;
191 }
192
194 {
195 if( m_BuildPartsNoTool.Count() > idx )
196 {
197 return m_BuildPartsNoTool.Get( idx );
198 }
199 return null;
200 }
201
202 //************************************************/
203 // Combination lock
204 //************************************************/
206 {
207 return m_CombinationLock;
208 }
209
210 void SetCombinationLock( CombinationLock combination_lock )
211 {
212 m_CombinationLock = CombinationLock.Cast( combination_lock );
213 }
214
216 {
217 string dial_text;
218
219 if ( m_CombinationLock )
220 {
221 string combination_text = m_CombinationLock.GetCombination().ToString();
222
223 //insert zeros to dials with 0 value
224 int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
225 for ( int i = 0; i < length_diff; ++i )
226 {
227 combination_text = "0" + combination_text;
228 }
229
230 //assemble the whole combination with selected part
231 for ( int j = 0; j < m_CombinationLock.GetLockDigits(); ++j )
232 {
233 if ( j == m_CombinationLock.GetDialIndex() )
234 {
235 dial_text += string.Format( "[%1]", combination_text.Get( j ) );
236 }
237 else
238 {
239 dial_text += string.Format( " %1 ", combination_text.Get( j ) );
240 }
241 }
242 }
243
244 return dial_text;
245 }
246
247 //************************************************/
248 // Attach/Detach actions
249 //************************************************/
250 int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
251 {
252 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
253
254 if ( GetGame().ConfigIsExisting( cfg_path ) )
255 {
256 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
257
258 for ( int i = 0; i < child_count; i++ )
259 {
260 string child_name;
261 GetGame().ConfigGetChildName( cfg_path, i, child_name );
262
263 string child_selection;
264 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
265
266 if ( selection == child_selection )
267 {
268 ref array<string> attachment_slots = new array<string>;
269 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
270
271 for ( int j = 0; j < attachment_slots.Count(); ++j )
272 {
273 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
274 int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
275
276 for ( int k = 0; k < item_slot_count; ++k )
277 {
278 int item_slot_id = item_to_attach.GetInventory().GetSlotId( k );
279 ItemBase attachment_item = ItemBase.Cast( target.GetInventory().FindAttachment( item_slot_id ) );
280
281 if ( target_slot_id == item_slot_id )
282 {
283 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 ) )
284 {
285 if(target.CanDisplayAttachmentSlot(target_slot_id))
286 return item_slot_id;
287 else
288 return -1;
289 }
290 }
291 }
292 }
293 }
294 }
295 }
296
297 return -1;
298 }
299
300 void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
301 {
302 attachments.Clear(); //clear output
303
304 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
305 if ( GetGame().ConfigIsExisting( cfg_path ) )
306 {
307 int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
308
309 for ( int i = 0; i < child_count; i++ )
310 {
311 string child_name;
312 GetGame().ConfigGetChildName( cfg_path, i, child_name );
313
314 string child_selection;
315 GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
316
317 if ( selection == child_selection )
318 {
319 ref array<string> attachment_slots = new array<string>;
320 GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
321
322 for ( int j = 0; j < attachment_slots.Count(); ++j )
323 {
324 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
325
326 //is attached and can be detached
327 EntityAI attachment = target.GetInventory().FindAttachment( target_slot_id );
328 if ( attachment && target.GetInventory().CanRemoveAttachmentEx( attachment, target_slot_id ) && !target.GetInventory().GetSlotLock( target_slot_id ) )
329 {
330 attachments.Insert( attachment );
331 }
332 }
333 }
334 }
335 }
336 }
337
338 void CombineItems( ItemBase target, ItemBase item )
339 {
340 if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
341 {
342 int quantity_used = target.ComputeQuantityUsed( item, true );
343 if( quantity_used != 0 )
344 {
345 target.AddQuantity( quantity_used );
346 item.AddQuantity( -quantity_used );
347 }
348 }
349 }
350
351 void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
352 {
353 GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
354 }
355
357 {
358 if ( GetAttachmentsToDetachCount() > 1 )
359 {
361 {
363 }
365 {
367 }
368 }
369 else
370 {
372 }
373 }
374
376 {
377 return m_Attachments.Count();
378 }
379
381 {
382 if ( GetAttachmentsToDetachCount() > 0 )
383 {
385
386 if ( m_Attachments && GetAttachmentsToDetachCount() > ( m_AttachmentsIndex ) )
387 {
388 return m_Attachments.Get( m_AttachmentsIndex );
389 }
390 }
391
392 return NULL;
393 }
394
395 //************************************************/
396 // Common
397 //************************************************/
399 {
400 m_PartIndex = 0;
402 }
403}
ref ActionTarget m_Target
Definition actionbase.c:18
static ActionVariantManager GetVariantManager(typename actionName)
ScriptInvoker GetOnUpdateInvoker()
void SetActionVariantCount(int count)
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)
void OnUpdateActions(Object item, Object target, int component_index)
void SetTargetPart(ConstructionPart target_part)
provides access to slot configuration
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()