Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
23  protected ActionVariantManager m_ActionVariantManager;
24  protected ActionVariantManager m_ActionNoToolVariantManager;
25 
26  int m_AttachmentsIndex;
27 
29  {
30  m_BuildParts = new ref array<ConstructionPart>;
31  m_BuildPartsNoTool = new ref array<ConstructionPart>;
32  m_PartIndex = 0;
33 
34  m_Attachments = new ref array<EntityAI>;
35  m_AttachmentsIndex = 0;
36 
37  if ( GetGame().IsClient() || !GetGame().IsMultiplayer() )
38  {
39  m_ActionVariantManager = ActionManagerClient.GetVariantManager( ActionBuildPart );
40  m_ActionVariantManager.GetOnUpdateInvoker().Clear();
41  m_ActionVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActions);
42 
43  m_ActionNoToolVariantManager = ActionManagerClient.GetVariantManager( ActionBuildShelter );
44  m_ActionNoToolVariantManager.GetOnUpdateInvoker().Clear();
45  m_ActionNoToolVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActionsNoTool);
46  }
47  }
48 
49  //************************************************/
50  // Base building
51  //************************************************/
52  string GetMainPartName()
53  {
54  return m_MainPartName;
55  }
56 
57  string GetMainPartNameNoTool()
58  {
59  return m_MainPartNameNoTool;
60  }
61 
62  void SetTarget( Object target )
63  {
64  m_Target = target;
65  }
66 
67  Object GetTarget()
68  {
69  return m_Target;
70  }
71 
72  void SetTargetPart( ConstructionPart target_part )
73  {
74  m_TargetPart = target_part;
75  }
76 
77  ConstructionPart GetTargetPart()
78  {
79  return m_TargetPart;
80  }
81 
82  void SetSlotId( int slot_id )
83  {
84  m_SlotId = slot_id;
85  }
86 
87  int GetSlotId()
88  {
89  return m_SlotId;
90  }
91 
92  void SetActionInitiator( PlayerBase action_initiator )
93  {
94  m_ActionInitiator = action_initiator;
95  }
96 
97  PlayerBase GetActionInitiator()
98  {
99  return m_ActionInitiator;
100  }
101 
102  // deprecated
103  void SetNextIndex()
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 );
123  m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
124  }
125  else
126  {
127  m_BuildParts.Clear();
128  m_ActionVariantManager.Clear();
129  }
130 
131  }
132  else
133  {
134  m_BuildParts.Clear();
135  m_ActionVariantManager.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 );
148  m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
149  }
150  else
151  {
152  m_BuildPartsNoTool.Clear();
153  m_ActionNoToolVariantManager.Clear();
154  }
155  }
156 
157  int GetConstructionPartsCount()
158  {
159  return m_BuildParts.Count();
160  }
161 
162  // deprecated
163  ConstructionPart GetCurrentBuildPart()
164  {
165  return null;
166  }
167 
168  ConstructionPart GetBuildPartAtIndex(int idx)
169  {
170  if( m_BuildParts.Count() > idx )
171  {
172  return m_BuildParts.Get( idx );
173  }
174  return null;
175  }
176 
177  ConstructionPart GetBuildPartNoToolAtIndex(int idx)
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  //************************************************/
189  CombinationLock GetCombinationLock()
190  {
191  return m_CombinationLock;
192  }
193 
194  void SetCombinationLock( CombinationLock combination_lock )
195  {
196  m_CombinationLock = CombinationLock.Cast( combination_lock );
197  }
198 
199  string GetDialNumberText()
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 
340  void SetNextAttachmentIndex()
341  {
342  if ( GetAttachmentsToDetachCount() > 1 )
343  {
344  if ( m_AttachmentsIndex <= GetAttachmentsToDetachCount() - 2 )
345  {
346  m_AttachmentsIndex++;
347  }
348  else if ( m_AttachmentsIndex >= GetAttachmentsToDetachCount() > - 1 )
349  {
350  m_AttachmentsIndex = 0;
351  }
352  }
353  else
354  {
355  m_AttachmentsIndex = 0;
356  }
357  }
358 
359  int GetAttachmentsToDetachCount()
360  {
361  return m_Attachments.Count();
362  }
363 
364  EntityAI GetActualAttachmentToDetach()
365  {
366  if ( GetAttachmentsToDetachCount() > 0 )
367  {
368  m_AttachmentsIndex = Math.Clamp( m_AttachmentsIndex, 0, GetAttachmentsToDetachCount() - 1 );
369 
370  if ( m_Attachments && GetAttachmentsToDetachCount() > ( m_AttachmentsIndex ) )
371  {
372  return m_Attachments.Get( m_AttachmentsIndex );
373  }
374  }
375 
376  return NULL;
377  }
378 
379  //************************************************/
380  // Common
381  //************************************************/
382  void ResetActionIndexes()
383  {
384  m_PartIndex = 0;
385  m_AttachmentsIndex = 0;
386  }
387 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
m_Target
ref ActionTarget m_Target
Definition: actionbase.c:17
ConstructionActionData
Definition: constructionactiondata.c:1
ActionBuildShelter
Definition: actionbuildshelter.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
CombinationLock
Definition: combinationlock4.c:1
ActionBuildPart
Definition: actionbuildpart.c:25
ActionVariantManager
Definition: actionvariantsmanager.c:1
PlayerBase
Definition: playerbaseclient.c:1
BaseBuildingBase
Definition: fence.c:1
Object
Definition: objecttyped.c:1
ActionManagerClient
Definition: actionmanagerclient.c:4
array< ConstructionPart >
ConstructionPart
Definition: constructionpart.c:1
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5