Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingGadgetToolComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_CampaignBuildingGadgetToolComponent : SCR_GadgetComponent
6 {
7  [Attribute(defvalue: "25", desc: "Max distance at which the ghost preview is shown.")]
8  protected float m_fDistanceToShowPreview;
9 
10  [Attribute(defvalue: "10", desc: "Max distance from which the composition can be build.")]
11  protected float m_fDistanceToBuildComposition;
12 
13  [Attribute(defvalue: "10", desc: "How much of construction value this tool adds to composition per one action")]
14  protected int m_iConstructionValue;
15 
16  protected const static float TRACE_DELAY_VALUE = 0.5;
17 
18  protected float m_fTraceDelay;
19 
20  protected ref array<SCR_CampaignBuildingLayoutComponent> m_aShownPreview = {};
21  protected ref array<SCR_CampaignBuildingLayoutComponent> m_aShownPreviewOld = {};
22 
24 
25 // protected SCR_CampaignBuildingLayoutComponent m_LayoutComponent;
26 
27  //------------------------------------------------------------------------------------------------
28  override void Update(float timeSlice)
29  {
30  m_fTraceDelay += timeSlice;
31 
32  if (m_fTraceDelay < TRACE_DELAY_VALUE)
33  return;
34 
36 
37  m_fTraceDelay = 0.0;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override void OnToggleActive(bool state)
42  {
43  m_fTraceDelay = 0.0;
44 
45  if (state)
46  ToolToHand();
47  else
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  override EGadgetType GetType()
53  {
54  return EGadgetType.BUILDING_TOOL;
55  }
56 
57 // //------------------------------------------------------------------------------------------------
58 // // Perform one build step - add a given build value to a composition player is building.
59 // protected void Build(notnull SCR_CampaignBuildingLayoutComponent layoutComponent)
60 // {
61 // layoutComponent.AddBuildingValue(m_iConstructionValue);
62 // }
63 
64  //------------------------------------------------------------------------------------------------
68  override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
69  {
70  if (!charOwner || charOwner != EntityUtils.GetPlayer())
71  {
72  super.ModeSwitch(mode, charOwner);
73  return;
74  }
75 
76  if (SCR_GadgetManagerComponent.GetGadgetManager(charOwner).GetHeldGadgetComponent() == this)
77  ToolToHand();
78  else
80 
81  super.ModeSwitch(mode, charOwner);
82  }
83 
84  //------------------------------------------------------------------------------------------------
86  void ToolToHand()
87  {
88  // Disabled for future
89 // EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(m_CharacterOwner.FindComponent(EventHandlerManagerComponent));
90 // if (eventHandlerManager)
91 // eventHandlerManager.RegisterScriptHandler("OnADSChanged", this, TraceCompositionToBuild);
92 
93  //ToDo: Later the frame has to run on server too because of tracing the composition to build
94  if (!System.IsConsoleApp())
96 
98  if (!characterController)
99  return;
100 
101  characterController.GetOnPlayerDeath().Insert(ToolToInventory);
102 
103  SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.GetInstance();
104  if (!editorManagerEntity)
105  return;
106 
107  editorManagerEntity.GetOnOpened().Insert(OnEditorOpened);
108  editorManagerEntity.GetOnClosed().Insert(OnEditorClosed);
109  }
110 
111  //------------------------------------------------------------------------------------------------
115  void OnPossessed(int playerID, bool isPossessing, RplId mainEntityID)
116  {
118 
120  if (!characterController)
121  return;
122 
123  characterController.GetOnPlayerDeath().Remove(ToolToInventory);
124 
125  if (isPossessing)
126  return;
127 
128  SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.GetInstance();
129  if (!editorManagerEntity)
130  return;
131 
132  editorManagerEntity.GetOnOpened().Remove(OnEditorOpened);
133  editorManagerEntity.GetOnClosed().Remove(OnEditorClosed);
134 
135  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(SCR_PlayerController.GetLocalControlledEntity());
136  if (!gadgetManager)
137  return;
138 
139  SCR_GadgetComponent gadgetComponent = SCR_GadgetComponent.Cast(gadgetManager.GetHeldGadgetComponent());
140  if (!gadgetComponent)
141  return;
142 
143  ToolToInventory();
144  if (gadgetComponent.GetType() == EGadgetType.BUILDING_TOOL)
145  gadgetManager.SetGadgetMode(gadgetManager.GetGadgetByType(EGadgetType.BUILDING_TOOL), EGadgetMode.IN_SLOT);
146  }
147 
148  //------------------------------------------------------------------------------------------------
151  {
152  //ToDo: Later the frame has to run on server too because of tracing the composition to build
153  if (!System.IsConsoleApp())
154  {
155  if (!GetBuildingModeEntity())
156  RemovePreviews();
157 
159 
161  }
162  }
163 
164  //------------------------------------------------------------------------------------------------
168  {
170  if (!core)
171  return null;
172 
173  SCR_EditorManagerEntity editorManager = core.GetEditorManager();
174  if (!editorManager)
175  return null;
176 
177  return editorManager.FindModeEntity(EEditorMode.BUILDING);
178  }
179 
180  //------------------------------------------------------------------------------------------------
181  protected void RemovePreviews()
182  {
183  foreach (SCR_CampaignBuildingLayoutComponent layoutComponent : m_aShownPreviewOld)
184  {
185  if (layoutComponent)
186  layoutComponent.DeletePreview();
187  }
188 
189  m_aShownPreviewOld.Clear();
190  }
191 
192  //------------------------------------------------------------------------------------------------
194  protected void OnEditorOpened()
195  {
196  ChimeraCharacter char = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
197  if (!char)
198  return;
199 
201  ToolToInventory();
202 
204  if (!controllerComponent)
205  return;
206 
207  controllerComponent.m_OnLifeStateChanged.Insert(OnConsciousnessChanged);
208 
209  SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
210  if (!possessingManager)
211  return;
212 
213  possessingManager.GetOnPossessedProxy().Insert(OnPossessed);
214  }
215 
216  //------------------------------------------------------------------------------------------------
218  protected void OnEditorClosed()
219  {
221 
222  SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
223  if (!possessingManager)
224  return;
225 
226  possessingManager.GetOnPossessedProxy().Remove(OnPossessed);
227 
228  // If the editor is closed, because player possessed entity, don't continue and keep this event hooked for another call.
229  if (possessingManager.IsPossessing(SCR_PlayerController.GetLocalPlayerId()))
230  {
232  return;
233  }
234 
237  GetGame().GetCallqueue().CallLater(ToolToHand, 0, false);
238  }
239 
240  //------------------------------------------------------------------------------------------------
241  void OnConsciousnessChanged(bool conscious)
242  {
243  if (conscious)
244  return;
245 
248  }
249 
250  //------------------------------------------------------------------------------------------------
252  {
253  ChimeraCharacter char = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
254  if (!char)
255  return;
256 
258  if (!controllerComponent)
259  return;
260 
261  controllerComponent.m_OnLifeStateChanged.Remove(OnConsciousnessChanged);
262  }
263 // //------------------------------------------------------------------------------------------------
264 // // Trace a composition to build commented out for future
265 // void TraceCompositionToBuild()
266 // {
267 // if (!m_CharacterOwner)
268 // return;
269 //
270 // ChimeraCharacter character = ChimeraCharacter.Cast(m_CharacterOwner);
271 //
272 // TraceParam param = new TraceParam();
273 // param.Start = character.EyePosition();
274 // param.End = param.Start + GetPlayersDirection() * m_fDistanceToBuildComposition;
275 //
276 // param.Flags =TraceFlags.ENTS;
277 // param.Exclude = character;
278 // param.LayerMask = EPhysicsLayerPresets.Interaction;
279 // BaseWorld world = GetOwner().GetWorld();
280 // float traceDistance = world.TraceMove(param, EvaluateBuildEntity);
281 //
282 // // This has to be done after the trace finished, because spawning / deleting or moving with the entity while trace is running can cause an issues.
283 // if (m_LayoutComponent)
284 // {
285 // Build(m_LayoutComponent);
286 // m_LayoutComponent = null;
287 // }
288 //
289 // }
290 
291  //------------------------------------------------------------------------------------------------
295  {
296  BaseWorld world = GetOwner().GetWorld();
297  if (!world)
298  return false;
299 
300  world.QueryEntitiesBySphere(GetOwner().GetOrigin(), m_fDistanceToShowPreview, EvaluatePreviewEntity);
301 
302  // Delete those preview which are no more on the list of traced one and then copy the array for next iteration cycle.
303  for (int i = m_aShownPreviewOld.Count() - 1; i >= 0; i--)
304  {
306  {
307  m_aShownPreviewOld.Remove(i);
308  continue;
309  }
310 
311  if (!m_aShownPreview.Contains(m_aShownPreviewOld[i]))
312  m_aShownPreviewOld[i].DeletePreview();
313  }
314 
315  foreach (SCR_CampaignBuildingLayoutComponent component : m_aShownPreview)
316  {
317  if (component && !m_aShownPreviewOld.Contains(component))
318  component.SpawnPreview();
319  }
320 
321  m_aShownPreviewOld.Copy(m_aShownPreview);
322  m_aShownPreview.Clear();
323 
324  return true;
325  }
326 
327  //------------------------------------------------------------------------------------------------
328  protected bool EvaluatePreviewEntity(IEntity ent)
329  {
330  if (!ent)
331  return true;
332 
333  SCR_CampaignBuildingLayoutComponent layoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(ent.FindComponent(SCR_CampaignBuildingLayoutComponent));
334  if (!layoutComponent)
335  return true;
336 
337  m_aShownPreview.Insert(layoutComponent);
338 
339  return true;
340  }
341 
342  //------------------------------------------------------------------------------------------------
345  {
346  return m_iConstructionValue;
347  }
348 
349  //------------------------------------------------------------------------------------------------
352  {
353  IEntity playerEntity = SCR_PlayerController.GetLocalMainEntity();
354  if (!playerEntity)
355  return null;
356 
357  return SCR_CharacterControllerComponent.Cast(playerEntity.FindComponent(SCR_CharacterControllerComponent));
358  }
359 
360 // //------------------------------------------------------------------------------------------------
361 // // Disabled for future
362 // bool EvaluateBuildEntity(IEntity ent, vector start = "0 0 0", vector dir = "0 0 0")
363 // {
364 // IEntity parent = ent.GetParent();
365 // if (!parent)
366 // return true;
367 //
368 // SCR_CampaignBuildingLayoutComponent layoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(parent.FindComponent(SCR_CampaignBuildingLayoutComponent));
369 // if (!layoutComponent)
370 // return true;
371 //
372 // m_LayoutComponent = layoutComponent;
373 // return false;
374 // }
375 
376 // //------------------------------------------------------------------------------------------------
377 // //! Returns the direction the player is looking Disabled debug
378 // private vector GetPlayersDirection()
379 // {
380 // vector aimMat[4];
381 // ChimeraCharacter character = ChimeraCharacter.Cast(m_CharacterOwner);
382 // Math3D.AnglesToMatrix(CharacterControllerComponent.Cast(character.FindComponent(CharacterControllerComponent)).GetInputContext().GetAimingAngles() * Math.RAD2DEG, aimMat);
383 // return aimMat[2];
384 // }
385 
386  //------------------------------------------------------------------------------------------------
389  {
391  if (characterController)
392  characterController.GetOnPlayerDeath().Remove(ToolToInventory);
393 
394  SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.GetInstance();
395  if (editorManagerEntity)
396  {
397  editorManagerEntity.GetOnOpened().Remove(OnEditorOpened);
398 
400  editorManagerEntity.GetOnClosed().Remove(OnEditorClosed);
401  }
402  }
403 }
404 
SCR_CampaignBuildingGadgetToolComponentClass
Definition: SCR_CampaignBuildingGadgetToolComponent.c:1
ToolToInventory
void ToolToInventory()
Building tool out of hands - show preview.
Definition: SCR_CampaignBuildingGadgetToolComponent.c:150
GetBuildingModeEntity
SCR_EditorModeEntity GetBuildingModeEntity()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:167
OnConsciousnessChanged
void OnConsciousnessChanged(bool conscious)
Will be called when the consciousness of the character changes.
Definition: SCR_CampaignBuildingGadgetToolComponent.c:241
GetCharacterController
protected SCR_CharacterControllerComponent GetCharacterController(IEntity from)
Definition: SCR_ItemPlacementComponent.c:50
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetType
override EGadgetType GetType()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:52
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
m_bToolActiveWhenEditorOpen
protected bool m_bToolActiveWhenEditorOpen
Definition: SCR_CampaignBuildingGadgetToolComponent.c:23
SCR_GadgetComponentClass
Definition: SCR_GadgetComponent.c:2
ModeSwitch
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:68
OnPossessed
void OnPossessed(int playerID, bool isPossessing, RplId mainEntityID)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:115
GetToolConstructionValue
int GetToolConstructionValue()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:344
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
DeactivateGadgetUpdate
override void DeactivateGadgetUpdate()
Definition: SCR_WristwatchComponent.c:161
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
OnEditorClosed
protected void OnEditorClosed()
Method called when character has a shovel in hands and any editor mode is closed.
Definition: SCR_CampaignBuildingGadgetToolComponent.c:218
ActivateGadgetUpdate
override void ActivateGadgetUpdate()
Definition: SCR_WristwatchComponent.c:151
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
Update
override void Update(float timeSlice)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:28
m_aShownPreviewOld
protected ref array< SCR_CampaignBuildingLayoutComponent > m_aShownPreviewOld
Definition: SCR_CampaignBuildingGadgetToolComponent.c:21
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
OnEditorOpened
protected void OnEditorOpened()
Method called when character has a shovel in hands and any editor mode is opned.
Definition: SCR_CampaignBuildingGadgetToolComponent.c:194
ToolToHand
void ToolToHand()
Building tool taken to hand - show preview etc.
Definition: SCR_CampaignBuildingGadgetToolComponent.c:86
HasBuildingPreview
bool HasBuildingPreview()
Definition: SCR_CampaignBuildingLayoutComponent.c:119
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
Attribute
SCR_CampaignBuildingGadgetToolComponentClass SCR_GadgetComponentClass Attribute(defvalue:"25", desc:"Max distance at which the ghost preview is shown.")
Definition: SCR_CampaignBuildingGadgetToolComponent.c:7
OnToggleActive
override void OnToggleActive(bool state)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:41
RemovePreviews
protected void RemovePreviews()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:181
EntityUtils
Definition: EntityUtils.c:12
RemoveOnConsciousnessChanged
void RemoveOnConsciousnessChanged()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:251
TraceCompositionToShowPreview
protected bool TraceCompositionToShowPreview()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:294
GetCharacterControllerComponent
SCR_CharacterControllerComponent GetCharacterControllerComponent()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:351
EvaluatePreviewEntity
protected bool EvaluatePreviewEntity(IEntity ent)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:328
RemoveEventHandlers
void RemoveEventHandlers()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:388
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26