DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ConstructionActionData.c
См. документацию.
2{
4
5 //base building
7 ref array<ConstructionPart> m_BuildPartsNoTool; //used only for ShelterSite building (legacy)
8 ref array<ConstructionPart> m_BuildPartsHandsGeneric; //used for generic construction, EXCEPT for ShelterSites
10 #ifdef DIAG_DEVELOPER
11 ref array<ConstructionPart> m_BuildPartsInstant;
12 #endif
13 protected bool m_IsValid; //validated from main update method on each simulation step
14
15 int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
16 string m_MainPartName; //unused?
19
20 //combination lock
23
24 //attaching
26 //detaching
28
33 #ifdef DIAG_DEVELOPER
34 protected ActionVariantManager m_ActionVariantManagerInstant;
35 #endif
36 //protected ActionVariantManager m_ActionInfoInteractVariantManager;
37
39 #ifdef DIAG_DEVELOPER
40 private int m_FastConstructionMode;
41 #endif
43 {
48 #ifdef DIAG_DEVELOPER
49 m_BuildPartsInstant = new array<ConstructionPart>();
50 #endif
51 m_PartIndex = 0;
52
55
56 if ( g_Game.IsClient() || !g_Game.IsMultiplayer() )
57 {
58 m_IsValid = false;
59
61 m_ActionVariantManager.GetOnUpdateInvoker().Clear();
62 m_ActionVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActions);
63
65 m_ActionHandsGenericVariantManager.GetOnUpdateInvoker().Clear();
67
69 m_ActionInfoContinuousVariantManager.GetOnUpdateInvoker().Clear();
71
72 #ifdef DIAG_DEVELOPER
73 m_ActionVariantManagerInstant = ActionManagerClient.GetVariantManager(ActionBuildPartInstantDebug);
74 m_ActionVariantManagerInstant.GetOnUpdateInvoker().Clear();
75 m_ActionVariantManagerInstant.GetOnUpdateInvoker().Insert(OnUpdateActionsInstant);
76 #endif
77 /*m_ActionInfoInteractVariantManager = ActionManagerClient.GetVariantManager(ActionConstructionPartInfoInteract);
78 m_ActionInfoInteractVariantManager.GetOnUpdateInvoker().Clear();
79 m_ActionInfoInteractVariantManager.GetOnUpdateInvoker().Insert(OnUpdateInfoActions);*/
80 }
81 }
82
84 {
85 if (g_Game && (g_Game.IsClient() || !g_Game.IsMultiplayer()))
86 {
88 m_ActionVariantManager.GetOnUpdateInvoker().Remove(OnUpdateActions);
93 /*if (m_ActionInfoInteractVariantManager)
94 m_ActionInfoInteractVariantManager.GetOnUpdateInvoker().Remove(OnUpdateInfoActions);*/
95 }
96 }
97
98 //************************************************/
99 // Base building
100 //************************************************/
102 {
103 return m_MainPartName;
104 }
105
107 {
109 }
110
111 void SetTarget( Object target )
112 {
113 m_Target = target;
114 }
115
117 {
118 return m_Target;
119 }
120
121 void SetTargetPart( ConstructionPart target_part )
122 {
123 m_TargetPart = target_part;
124 }
125
127 {
128 return m_TargetPart;
129 }
130
131 void SetActionInitiator( PlayerBase action_initiator )
132 {
133 m_ActionInitiator = action_initiator;
134 }
135
140
143 {
144 m_IsValid = false;
145 }
146
147 protected void Validate()
148 {
149 m_IsValid = true;
150 }
151
153 protected void ValidateConstructionData(Object item, Object target, int component_index)
154 {
155 if (!m_IsValid)
156 {
157 //TODO
158 Validate();
159 }
160 }
161
163 void OnUpdateActions( Object item, Object target, int component_index )
164 {
165 ValidateConstructionData(item,target,component_index);
166
167 ItemBase tool = ItemBase.Cast(item);
168 EntityAI ent = EntityAI.Cast(target);
169 if (ent)
170 {
171 ConstructionBase con = ConstructionBase.Cast(ent.GetConstructionBasic());
172 if (con)
173 {
174 array<string> compNames = new array<string>;
175 target.GetActionComponentNameList(component_index, compNames, LOD.NAME_VIEW); //in case component is part of more than one named selection
176 m_BuildParts.Clear();
177 foreach (string compName : compNames)
178 {
180 con.GetConstructionPartsToBuild(compName, tmp, tool, m_MainPartName, true); //m_MainPartName unused?
181 foreach (ConstructionPart part : tmp)
182 {
183 if (m_BuildParts.Find(part) == -1)
184 m_BuildParts.Insert(part);
185 }
186 }
187 m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
188 }
189 else
190 {
191 m_BuildParts.Clear();
193 }
194 }
195 else
196 {
197 m_BuildParts.Clear();
199 }
200 //not needed
201 //m_Target = target;
202 }
203
205 void OnUpdateActionsNoTool( Object item, Object target, int component_index )
206 {
207 ValidateConstructionData(item,target,component_index);
208
209 ItemBase tool = ItemBase.Cast(item);
210 ShelterSite shelter = ShelterSite.Cast(target);
212 if (!tool && shelter && Class.CastTo(con,shelter.GetConstructionBasic()))
213 {
214 array<string> compNames = new array<string>;
215 target.GetActionComponentNameList(component_index, compNames, LOD.NAME_VIEW); //in case component is part of more than one named selection
216 m_BuildPartsNoTool.Clear();
217 foreach (string compName : compNames)
218 {
220 con.GetConstructionPartsToBuild(compName, tmp, null, m_MainPartNameNoTool, false); //m_MainPartNameNoTool unused?
221 foreach (ConstructionPart part : tmp)
222 {
223 if (m_BuildPartsNoTool.Find(part) == -1)
224 m_BuildPartsNoTool.Insert(part);
225 }
226 }
227 m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
228 }
229 else
230 {
231 m_BuildPartsNoTool.Clear();
233 }
234 }
235
236 void OnUpdateActionsHandsGeneric(Object item, Object target, int componentIndex)
237 {
238 ValidateConstructionData(item,target,componentIndex);
239
240 ItemBase tool = ItemBase.Cast(item);
241 EntityAI ent = EntityAI.Cast(target);
243 if (!tool && ent && Class.CastTo(con,ent.GetConstructionBasic()))
244 {
245 array<string> compNames = new array<string>;
246 target.GetActionComponentNameList(componentIndex, compNames, LOD.NAME_VIEW); //in case component is part of more than one named selection
248 foreach (string compName : compNames)
249 {
251 con.GetConstructionPartsToBuild(compName, tmp, null, m_MainPartNameNoTool, false); //m_MainPartNameNoTool unused?
252 foreach (ConstructionPart part : tmp)
253 {
254 if (m_BuildPartsHandsGeneric.Find(part) == -1)
255 m_BuildPartsHandsGeneric.Insert(part);
256 }
257 }
259 }
260 else
261 {
264 }
265 }
266
267 void OnUpdateInfoActions( Object item, Object target, int component_index )
268 {
269 ValidateConstructionData(item,target,component_index);
270
271 ItemBase tool = ItemBase.Cast(item);
272 EntityAI ent = EntityAI.Cast(target);
273 if (ent)
274 {
275 ConstructionBase con = ConstructionBase.Cast(ent.GetConstructionBasic());
276 if (con)
277 {
278 array<string> compNames = new array<string>;
279 target.GetActionComponentNameList(component_index, compNames, LOD.NAME_VIEW); //in case component is part of more than one named selection
280 m_BuildPartsJustInfos.Clear();
281 foreach (string compName : compNames)
282 {
284 con.GetConstructionPartsUnableToBuild(compName, tmp, tool, m_MainPartName, tool != null); //m_MainPartName unused?
285 foreach (ConstructionPart part : tmp)
286 {
287 if (m_BuildPartsJustInfos.Find(part) == -1)
288 m_BuildPartsJustInfos.Insert(part);
289 }
290 }
291 m_ActionInfoContinuousVariantManager.SetActionVariantCount(m_BuildPartsJustInfos.Count());
292 //m_ActionInfoInteractVariantManager.SetActionVariantCount(m_BuildPartsJustInfos.Count());
293 }
294 else
295 {
296 m_BuildPartsJustInfos.Clear();
298 //m_ActionInfoInteractVariantManager.Clear();
299 }
300 }
301 else
302 {
303 m_BuildPartsJustInfos.Clear();
305 //m_ActionInfoInteractVariantManager.Clear();
306 }
307 }
308
309 #ifdef DIAG_DEVELOPER
310 void OnUpdateActionsInstant(Object item, Object target, int componentIndex)
311 {
312 ValidateConstructionData(item,target,componentIndex);
313
314 EntityAI ent;
316 if (Class.CastTo(ent, EntityAI.Cast(target)) && Class.CastTo(con, ent.GetConstructionBasic()))
317 {
318 array<string> compNames = new array<string>;
319 target.GetActionComponentNameList(componentIndex, compNames, LOD.NAME_VIEW); //in case component is part of more than one named selection
320 m_BuildPartsInstant.Clear();
321 foreach (string compName : compNames)
322 {
324 con.GetConstructionPartsToBuild(compName, tmp, null, m_MainPartNameNoTool, false); //m_MainPartNameNoTool unused?
325 foreach (ConstructionPart part : tmp)
326 {
327 if (m_BuildPartsInstant.Find(part) == -1)
328 m_BuildPartsInstant.Insert(part);
329 }
330 }
331 m_ActionVariantManagerInstant.SetActionVariantCount(m_BuildPartsInstant.Count());
332 }
333 else
334 {
335 m_BuildPartsInstant.Clear();
336 m_ActionVariantManagerInstant.Clear();
337 }
338 }
339 #endif
340
342 {
343 return m_BuildParts.Count();
344 }
345
347 {
348 if( m_BuildParts.Count() > idx )
349 {
350 return m_BuildParts[idx];
351 }
352 return null;
353 }
354
356 {
357 if( m_BuildPartsNoTool.Count() > idx )
358 {
359 return m_BuildPartsNoTool[idx];
360 }
361 return null;
362 }
363
365 {
366 if( m_BuildPartsHandsGeneric.Count() > idx )
367 {
368 return m_BuildPartsHandsGeneric[idx];
369 }
370 return null;
371 }
372
374 {
375 if( m_BuildPartsJustInfos.Count() > idx )
376 {
377 return m_BuildPartsJustInfos[idx];
378 }
379 return null;
380 }
381
382 #ifdef DIAG_DEVELOPER
383 ConstructionPart GetBuildPartInstantAtIndex(int idx)
384 {
385 if (m_BuildPartsInstant.Count() > idx)
386 {
387 return m_BuildPartsInstant[idx];
388 }
389 return null;
390 }
391 #endif
392
393 //************************************************/
394 // Combination lock
395 //************************************************/
400
401 void SetCombinationLock( CombinationLock combination_lock )
402 {
403 m_CombinationLock = CombinationLock.Cast( combination_lock );
404 }
405
407 {
408 string dialText;
409
411 {
412 string combinationText;
413 if (m_CombinationLockSide == 0)
414 {
415 combinationText = m_CombinationLock.GetCombination().ToString();
416 }
417 else if (m_CombinationLockSide == 1)
418 {
419 combinationText = m_CombinationLock.GetCombinationInside().ToString();
420 }
421
422 //insert zeros to dials with 0 value
423 int lengthDiff = m_CombinationLock.GetLockDigits() - combinationText.Length();
424 for (int i = 0; i < lengthDiff; ++i)
425 {
426 combinationText = "0" + combinationText;
427 }
428
429 int dialIndex;
430 if (m_CombinationLockSide == 0)
431 {
432 dialIndex = m_CombinationLock.GetDialIndex();
433 }
434 else if (m_CombinationLockSide == 1)
435 {
436 dialIndex = m_CombinationLock.GetDialIndexInside();
437 }
438
439 //assemble the whole combination with selected part
440 for (int j = 0; j < m_CombinationLock.GetLockDigits(); ++j)
441 {
442 if (j == dialIndex)
443 {
444 dialText += string.Format("[%1]", combinationText.Get(j));
445 }
446 else
447 {
448 dialText += string.Format(" %1 ", combinationText.Get(j));
449 }
450 }
451 }
452
453 return dialText;
454 }
455
456 void SetCombinationLockSide(int lockSide)
457 {
458 m_CombinationLockSide = lockSide;
459 }
460
462 {
464 }
465
466 //************************************************/
467 // Attach/Detach actions
468 //************************************************/
469 int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
470 {
471 TypeAttachmentGroupsDataHolder holder = target.GetTypeAttachmentGroupInfoHolder();
473 if (!dataArray) //no valid slot paired to the selection
474 return InventorySlots.INVALID;
475
476 foreach (TypeAttachmentGroupData data : dataArray)
477 {
478 if (data)
479 {
480 int slotId;
481 foreach (string slotName : data.m_AttSlots)
482 {
484 GameInventory inventory = target.GetInventory();
485 EntityAI attachment = inventory.FindAttachment(slotId);
486
487 if ((inventory.CanAddAttachmentEx(item_to_attach, slotId)) || (attachment && attachment.CanBeCombined(item_to_attach)))
488 {
489 if(target.CanDisplayAttachmentSlot(slotId) && target.CanDisplayAttachmentCategory(data.GetAttachmentGroupClassName()))
490 return slotId;
491 }
492 }
493 }
494 }
495
496 return InventorySlots.INVALID;
497 }
498
499 void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
500 {
501 attachments.Clear(); //clear output
502 TypeAttachmentGroupsDataHolder holder = target.GetTypeAttachmentGroupInfoHolder();
504 foreach (TypeAttachmentGroupData data : dataArray)
505 {
506 if (data)
507 {
508 int slotId;
509 EntityAI attachment;
510 GameInventory inventory = target.GetInventory();
511 foreach (string slotName : data.m_AttSlots)
512 {
514 attachment = inventory.FindAttachment(slotId);
515 if (attachment && inventory.CanRemoveAttachmentEx(attachment, slotId) && !inventory.GetSlotLock(slotId))
516 {
517 attachments.Insert(attachment);
518 }
519 }
520 }
521 }
522 }
523
524 void CombineItems( ItemBase target, ItemBase item )
525 {
526 if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
527 {
528 int quantity_used = target.ComputeQuantityUsed( item, true );
529 if( quantity_used != 0 )
530 {
531 target.AddQuantity( quantity_used );
532 item.AddQuantity( -quantity_used );
533 }
534 }
535 }
536
537 void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
538 {
539 GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
540 }
541
543 {
544 if ( GetAttachmentsToDetachCount() > 1 )
545 {
547 {
549 }
551 {
553 }
554 }
555 else
556 {
558 }
559 }
560
562 {
563 return m_Attachments.Count();
564 }
565
567 {
568 if ( GetAttachmentsToDetachCount() > 0 )
569 {
571
573 {
574 return m_Attachments.Get( m_AttachmentsIndex );
575 }
576 }
577
578 return NULL;
579 }
580
581 //************************************************/
582 // Common
583 //************************************************/
585 {
586 m_PartIndex = 0;
588 }
589
590 //************************************************/
591 // Debugs
592 //************************************************/
593#ifdef DIAG_DEVELOPER
594 void SetFastConstructionMode(int mode)
595 {
596 m_FastConstructionMode = mode;
597 }
598
599 int GetFastConstructionMode()
600 {
601 return m_FastConstructionMode;
602 }
603#endif
604
606 // Deprecated below
610 {
611 return null;
612 }
613
615 void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool = true);
616
617 [Obsolete("1.30: Unsafe, overridden ActionData used in-system instead")]
618 void SetSlotId( int slot_id )
619 {
620 m_SlotId = slot_id;
621 }
622
623 [Obsolete("1.30: Unsafe, overridden ActionData used in-system instead")]
625 {
626 return m_SlotId;
627 }
628}
ActionBuildPart ActionContinuousBase ActionBuildPartHandsGeneric()
Определения ActionBuildPart.c:379
PlayerSpawnPreset slotName
void ConstructionBase(EntityAI parent)
Определения ConstructionBase.c:58
DayZGame g_Game
Определения DayZGame.c:4074
static ActionVariantManager GetVariantManager(typename actionName)
Определения ActionManagerClient.c:267
ScriptInvoker GetOnUpdateInvoker()
Определения ActionVariantsManager.c:14
void SetActionVariantCount(int count)
Определения ActionVariantsManager.c:24
Super root of all classes in Enforce script.
Определения EnScript.c:11
string m_MainPartName
Определения ConstructionActionData.c:16
ref array< EntityAI > m_Attachments
Определения ConstructionActionData.c:27
void Invalidate()
to be called from outside
Определения ConstructionActionData.c:142
void ResetActionIndexes()
Определения ConstructionActionData.c:584
ref array< ConstructionPart > m_BuildParts
Определения ConstructionActionData.c:6
EntityAI GetActualAttachmentToDetach()
Определения ConstructionActionData.c:566
string GetMainPartName()
Определения ConstructionActionData.c:101
void SetCombinationLock(CombinationLock combination_lock)
Определения ConstructionActionData.c:401
void ConstructionActionData()
Определения ConstructionActionData.c:42
ConstructionPart GetCurrentBuildPart()
Определения ConstructionActionData.c:609
CombinationLock m_CombinationLock
Определения ConstructionActionData.c:21
string GetDialNumberText()
Определения ConstructionActionData.c:406
ActionVariantManager m_ActionHandsGenericVariantManager
Определения ConstructionActionData.c:31
CombinationLock GetCombinationLock()
Определения ConstructionActionData.c:396
Object GetTarget()
Определения ConstructionActionData.c:116
void OnUpdateInfoActions(Object item, Object target, int component_index)
Определения ConstructionActionData.c:267
int GetAttachmentsToDetachCount()
Определения ConstructionActionData.c:561
ref array< ConstructionPart > m_BuildPartsHandsGeneric
Определения ConstructionActionData.c:8
int GetCombinationLockSide()
Определения ConstructionActionData.c:461
void SetCombinationLockSide(int lockSide)
Определения ConstructionActionData.c:456
string GetMainPartNameNoTool()
Определения ConstructionActionData.c:106
string m_MainPartNameNoTool
Определения ConstructionActionData.c:17
ActionVariantManager m_ActionNoToolVariantManager
Определения ConstructionActionData.c:30
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
Определения ConstructionActionData.c:355
void ~ConstructionActionData()
Определения ConstructionActionData.c:83
int GetConstructionPartsCount()
Определения ConstructionActionData.c:341
void CombineItems(ItemBase target, ItemBase item)
Определения ConstructionActionData.c:524
ConstructionPart GetBuildPartHandsGenericAtIndex(int idx)
Определения ConstructionActionData.c:364
ActionVariantManager m_ActionInfoContinuousVariantManager
Определения ConstructionActionData.c:32
ConstructionPart GetBuildPartInfoAtIndex(int idx)
Определения ConstructionActionData.c:373
void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool=true)
void SetTarget(Object target)
Определения ConstructionActionData.c:111
void OnUpdateActionsNoTool(Object item, Object target, int component_index)
used for ShelterSite only (legacy)
Определения ConstructionActionData.c:205
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
Определения ConstructionActionData.c:469
ActionVariantManager m_ActionVariantManager
Определения ConstructionActionData.c:29
void SetSlotId(int slot_id)
Определения ConstructionActionData.c:618
ConstructionPart GetBuildPartAtIndex(int idx)
Определения ConstructionActionData.c:346
void ValidateConstructionData(Object item, Object target, int component_index)
Single update method to prepare and validate all construction data for the update,...
Определения ConstructionActionData.c:153
void OnUpdateActionsHandsGeneric(Object item, Object target, int componentIndex)
Определения ConstructionActionData.c:236
void SetNextAttachmentIndex()
Определения ConstructionActionData.c:542
PlayerBase GetActionInitiator()
Определения ConstructionActionData.c:136
ConstructionPart GetTargetPart()
Определения ConstructionActionData.c:126
int m_CombinationLockSide
Определения ConstructionActionData.c:22
void GetAttachmentsFromSelection(EntityAI target, string selection, out array< EntityAI > attachments)
Определения ConstructionActionData.c:499
ref array< ConstructionPart > m_BuildPartsJustInfos
Определения ConstructionActionData.c:9
void SetActionInitiator(PlayerBase action_initiator)
Определения ConstructionActionData.c:131
PlayerBase m_ActionInitiator
Определения ConstructionActionData.c:25
void RefreshAttachmentsToDetach(EntityAI target, string main_part_name)
Определения ConstructionActionData.c:537
ref ConstructionPart m_TargetPart
Определения ConstructionActionData.c:18
void OnUpdateActions(Object item, Object target, int component_index)
regular tool actions
Определения ConstructionActionData.c:163
ref array< ConstructionPart > m_BuildPartsNoTool
Определения ConstructionActionData.c:7
void SetTargetPart(ConstructionPart target_part)
Определения ConstructionActionData.c:121
Instanced construction part data classes for dynamic data, statics now stored on EntityType level in ...
Определения ConstructionPart.c:4
proto native bool CanRemoveAttachmentEx(EntityAI attachment, int slot)
proto native bool GetSlotLock(int slot)
proto native bool CanAddAttachmentEx(notnull EntityAI e, int slot)
Check if attachment can be added to slot @NOTE: Note that slot index IS NOT slot ID!...
proto native EntityAI FindAttachment(int slot)
Returns attached entity in slot (you can use InventorySlots.GetSlotIdFromString(name) to get slot id)
script counterpart to engine's class Inventory
const int INVALID
Invalid slot (-1)
Определения InventorySlots.c:17
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
provides access to slot configuration
Определения InventorySlots.c:6
static const string NAME_VIEW
Определения gameplay.c:207
LOD class.
Определения gameplay.c:204
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
proto native void Clear()
remove all calls from list
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
Data for one attachment group.
Определения TypeAttachmentGroupData.c:4
array< TypeAttachmentGroupData > GetAttGroupsDataBySelectionParam(string selectionName)
Returns an array of 'GUIInventoryAttachmentsProps' subclasses that use the same 'selection'.
Data holder for attachment group classes.
Определения TypeAttachmentGroupDataHolders.c:5
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
void Obsolete(string msg="")
Определения EnScript.c:371
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'.
proto native int Length()
Returns length of string.
proto string Get(int index)
Gets n-th character from string.
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.