Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingBuildUserAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  protected SCR_CampaignBuildingLayoutComponent m_LayoutComponent;
5  // entity to whom the user action is just shown but is not actively perfroming the action.
6  protected IEntity m_User;
7  // entity who starts performing the action.
8  protected IEntity m_ActiveUser;
9  protected SCR_GadgetManagerComponent m_GadgetManager;
10 
11  //------------------------------------------------------------------------------------------------
12  protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
13  {
14  m_LayoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(pOwnerEntity.FindComponent(SCR_CampaignBuildingLayoutComponent));
15  }
16 
17  //------------------------------------------------------------------------------------------------
18  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
19  {
20  SCR_CampaignBuildingNetworkComponent networkComponent = GetNetworkManager();
21  if (!networkComponent)
22  return;
23 
24  networkComponent.AddBuildingValue(GetBuildingToolValue(pUserEntity), pOwnerEntity);
25  ProcesXPreward();
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override void OnActionStart(IEntity pUserEntity)
30  {
31  m_ActiveUser = pUserEntity;
32 
33  if (!ShouldPerformPerFrame())
34  return;
35 
36  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
37  if (!character)
38  return;
39 
40  CharacterControllerComponent charController = character.GetCharacterController();
41  if (charController)
42  {
43  CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
44  int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
45 
47  params.SetEntity(GetBuildingTool(pUserEntity));
48  params.SetAllowMovementDuringAction(false);
49  params.SetKeepInHandAfterSuccess(true);
50  params.SetCommandID(itemActionId);
51  params.SetCommandIntArg(1);
52 
53  charController.TryUseItemOverrideParams(params);
54  }
55 
56  super.OnActionStart(pUserEntity);
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
61  {
62  m_ActiveUser = null;
63 
64  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
65  if (!character)
66  return;
67 
68  CharacterControllerComponent charController = character.GetCharacterController();
69  if (charController)
70  {
71  CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
72  int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
73  CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
74  if (cmdHandler)
75  cmdHandler.FinishItemUse();
76  }
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override void OnConfirmed(IEntity pUserEntity)
81  {
82  m_ActiveUser = null;
83 
84  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
85  if (!character)
86  return;
87 
88  CharacterControllerComponent charController = character.GetCharacterController();
89  if (charController)
90  {
91  CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
92  CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
93  cmdHandler.FinishItemUse();
94  }
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  //~ If continues action it will only execute everytime the duration is done
99  override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
100  {
101  if (!LoopActionUpdate(timeSlice))
102  return;
103 
104  PerformAction(pOwnerEntity, pUserEntity);
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  // The user action is shown when the preview is visible - means player has a building tool ready (but also when he is running around with building tool hiden)
109  override bool CanBeShownScript(IEntity user)
110  {
111  m_User = user;
112  return m_LayoutComponent && m_LayoutComponent.HasBuildingPreview();
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  // The user action can be performed, when player has a building tool in hands.
117  override bool CanBePerformedScript(IEntity user)
118  {
119  if (!m_GadgetManager)
120  {
121  m_GadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(user);
122 
124  if (playerController)
125  playerController.m_OnControlledEntityChanged.Insert(SetNewGadgetManager);
126 
127  return false;
128  }
129 
130  SCR_GadgetComponent gadgetComponent = m_GadgetManager.GetHeldGadgetComponent();
131  if (!gadgetComponent)
132  return false;
133 
134  ChimeraCharacter character = ChimeraCharacter.Cast(user);
135  CharacterControllerComponent charController = character.GetCharacterController();
136 
137  if (charController && !IsInProgress() && !charController.CanUseItem())
138  return false;
139 
140  return (gadgetComponent.GetMode() == EGadgetMode.IN_HAND);
141  }
142 
143  //------------------------------------------------------------------------------------------------
145  protected void CancelPlayerAnimation(notnull IEntity pUserEntity)
146  {
147  ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
148  if (!character)
149  return;
150 
151  CharacterControllerComponent charController = character.GetCharacterController();
152  if (!charController)
153  return;
154 
155  CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
156  if (!pAnimationComponent)
157  return;
158 
159  CharacterCommandHandlerComponent handlerComponent = pAnimationComponent.GetCommandHandler();
160  if (!handlerComponent)
161  return;
162 
163  handlerComponent.FinishItemUse();
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  override bool GetActionNameScript(out string outName)
168  {
169  if (!m_LayoutComponent || !m_User)
170  return false;
171 
172  float progressPercentage = GetBuildingToolValue(m_User) / (m_LayoutComponent.GetToBuildValue() * 0.01);
173  float buildPercentage = m_LayoutComponent.GetCurrentBuildValue() / (m_LayoutComponent.GetToBuildValue() * 0.01);
174 
175  if (progressPercentage != (int)progressPercentage)
176  ActionNameParams[0] = progressPercentage.ToString(lenDec: 1);
177  else
178  ActionNameParams[0] = progressPercentage.ToString();
179 
180  if (buildPercentage != (int)buildPercentage)
181  ActionNameParams[1] = buildPercentage.ToString(lenDec: 1);
182  else
183  ActionNameParams[1] = buildPercentage.ToString();
184 
185  return super.GetActionNameScript(outName);
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  override bool HasLocalEffectOnlyScript()
190  {
191  return true;
192  }
193 
194  //------------------------------------------------------------------------------------------------
196  void SetNewGadgetManager(IEntity from, IEntity to)
197  {
198  m_GadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(to);
199  }
200 
201  //------------------------------------------------------------------------------------------------
203  IEntity GetBuildingTool(notnull IEntity ent)
204  {
205  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(ent);
206  if (!gadgetManager)
207  return null;
208 
209  return gadgetManager.GetHeldGadget();
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  // Gets the "building tool value" of building tool. It means how many points are added by one usage of the building tool
214  int GetBuildingToolValue(notnull IEntity ent)
215  {
216  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(ent);
217  if (!gadgetManager)
218  return 0;
219 
220  SCR_CampaignBuildingGadgetToolComponent gadgetComponent = SCR_CampaignBuildingGadgetToolComponent.Cast(gadgetManager.GetHeldGadgetComponent());
221  if (!gadgetComponent)
222  return 0;
223 
224  return gadgetComponent.GetToolConstructionValue();
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  void ProcesXPreward()
229  {
230  BaseGameMode gameMode = GetGame().GetGameMode();
231  if (!gameMode)
232  return;
233 
234  SCR_CampaignBuildingManagerComponent campaignBuildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
235  campaignBuildingManagerComponent.ProcesXPreward();
236  }
237 
238  //------------------------------------------------------------------------------------------------
240  protected SCR_CampaignBuildingNetworkComponent GetNetworkManager()
241  {
242  PlayerController playerController = GetGame().GetPlayerController();
243  if (!playerController)
244  return null;
245 
246  return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
247  }
248 
249  //------------------------------------------------------------------------------------------------
250  // Destructor
252  {
253  if (m_ActiveUser)
254  CancelPlayerAnimation(m_ActiveUser);
255  }
256 }
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition: SCR_ScriptedUserAction.c:2
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
ItemUseParameters
Definition: ItemUseParameters.c:15
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
m_GadgetManager
SCR_GadgetManagerComponent m_GadgetManager
Definition: SCR_GadgetManagerComponent.c:2
m_User
private IEntity m_User
Definition: InteractableBoxComponent.c:11
SCR_CampaignBuildingBuildUserAction
Definition: SCR_CampaignBuildingBuildUserAction.c:2
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24