Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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.
10 protected bool m_bIsShown;
11
12 //------------------------------------------------------------------------------------------------
13 protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
14 {
15 m_LayoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(pOwnerEntity.FindComponent(SCR_CampaignBuildingLayoutComponent));
16 }
17
18 //------------------------------------------------------------------------------------------------
19 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
20 {
21 SCR_CampaignBuildingNetworkComponent networkComponent = GetNetworkManager();
22 if (!networkComponent)
23 return;
24
25 networkComponent.AddBuildingValue(GetBuildingToolValue(pUserEntity), pOwnerEntity);
27 }
28
29 //------------------------------------------------------------------------------------------------
30 override void OnActionStart(IEntity pUserEntity)
31 {
32 m_ActiveUser = pUserEntity;
33
35 return;
36
38 if (!character)
39 return;
40
41 CharacterControllerComponent charController = character.GetCharacterController();
42 if (charController)
43 {
44 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
45 int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
46
48 params.SetEntity(GetBuildingTool(pUserEntity));
49 params.SetAllowMovementDuringAction(false);
50 params.SetKeepInHandAfterSuccess(true);
51 params.SetCommandID(itemActionId);
52 params.SetCommandIntArg(1);
53
54 charController.TryUseItemOverrideParams(params);
55 }
56
57 super.OnActionStart(pUserEntity);
58 }
59
60 //------------------------------------------------------------------------------------------------
61 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
62 {
63 m_ActiveUser = null;
64
66 if (!character)
67 return;
68
69 CharacterControllerComponent charController = character.GetCharacterController();
70 if (charController)
71 {
72 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
73 int itemActionId = pAnimationComponent.BindCommand("CMD_Item_Action");
74 CharacterCommandHandlerComponent cmdHandler = pAnimationComponent.GetCommandHandler();
75 if (cmdHandler)
76 cmdHandler.FinishItemUse(true);
77 }
78 }
79
80 //------------------------------------------------------------------------------------------------
81 override void OnConfirmed(IEntity pUserEntity)
82 {
83 m_ActiveUser = null;
84
86 if (!character)
87 return;
88
89 CharacterControllerComponent charController = character.GetCharacterController();
90 if (charController)
91 {
92 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
93 CharacterCommandHandlerComponent cmdHandler = pAnimationComponent.GetCommandHandler();
94 cmdHandler.FinishItemUse(true);
95 }
96 }
97
98 //------------------------------------------------------------------------------------------------
99 //~ If continues action it will only execute everytime the duration is done
100 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
101 {
102 if (!LoopActionUpdate(timeSlice))
103 return;
104
105 PerformAction(pOwnerEntity, pUserEntity);
106 }
107
108 //------------------------------------------------------------------------------------------------
109 // 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)
110 override bool CanBeShownScript(IEntity user)
111 {
112 m_User = user;
113 m_bIsShown = m_LayoutComponent && m_LayoutComponent.HasBuildingPreview();
114 return m_bIsShown;
115 }
116
117 //------------------------------------------------------------------------------------------------
118 bool IsShown()
119 {
120 return m_bIsShown;
121 }
122
123 //------------------------------------------------------------------------------------------------
124 // The user action can be performed, when player has a building tool in hands.
125 override bool CanBePerformedScript(IEntity user)
126 {
127 if (!m_GadgetManager)
128 {
130
132 if (playerController)
133 playerController.m_OnControlledEntityChanged.Insert(SetNewGadgetManager);
134
135 return false;
136 }
137
138 SCR_GadgetComponent gadgetComponent = m_GadgetManager.GetHeldGadgetComponent();
139 if (!gadgetComponent)
140 return false;
141
143 CharacterControllerComponent charController = character.GetCharacterController();
144
145 if (charController && !IsInProgress() && !charController.CanUseItem())
146 return false;
147
148 return (gadgetComponent.GetMode() == EGadgetMode.IN_HAND);
149 }
150
151 //------------------------------------------------------------------------------------------------
153 protected void CancelPlayerAnimation(notnull IEntity pUserEntity)
154 {
155 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
156 if (!character)
157 return;
158
159 CharacterControllerComponent charController = character.GetCharacterController();
160 if (!charController)
161 return;
162
163 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
164 if (!pAnimationComponent)
165 return;
166
167 CharacterCommandHandlerComponent handlerComponent = pAnimationComponent.GetCommandHandler();
168 if (!handlerComponent)
169 return;
170
171 handlerComponent.FinishItemUse(true);
172 }
173
174 //------------------------------------------------------------------------------------------------
175 override bool GetActionNameScript(out string outName)
176 {
177 if (!m_LayoutComponent || !m_User)
178 return false;
179
180 float progressPercentage = GetBuildingToolValue(m_User) / (m_LayoutComponent.GetToBuildValue() * 0.01);
181 float buildPercentage = m_LayoutComponent.GetCurrentBuildValue() / (m_LayoutComponent.GetToBuildValue() * 0.01);
182
183 if (progressPercentage != (int)progressPercentage)
184 ActionNameParams[0] = progressPercentage.ToString(lenDec: 1);
185 else
186 ActionNameParams[0] = progressPercentage.ToString();
187
188 if (buildPercentage != (int)buildPercentage)
189 ActionNameParams[1] = buildPercentage.ToString(lenDec: 1);
190 else
191 ActionNameParams[1] = buildPercentage.ToString();
192
193 return super.GetActionNameScript(outName);
194 }
195
196 //------------------------------------------------------------------------------------------------
198 {
199 return true;
200 }
201
202 //------------------------------------------------------------------------------------------------
208
209 //------------------------------------------------------------------------------------------------
212 {
214 if (!gadgetManager)
215 return null;
216
217 return gadgetManager.GetHeldGadget();
218 }
219
220 //------------------------------------------------------------------------------------------------
221 // Gets the "building tool value" of building tool. It means how many points are added by one usage of the building tool
223 {
225 if (!gadgetManager)
226 return 0;
227
228 SCR_CampaignBuildingGadgetToolComponent gadgetComponent = SCR_CampaignBuildingGadgetToolComponent.Cast(gadgetManager.GetHeldGadgetComponent());
229 if (!gadgetComponent)
230 return 0;
231
232 return gadgetComponent.GetToolConstructionValue();
233 }
234
235 //------------------------------------------------------------------------------------------------
237 {
238 BaseGameMode gameMode = GetGame().GetGameMode();
239 if (!gameMode)
240 return;
241
242 SCR_CampaignBuildingManagerComponent campaignBuildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
243 campaignBuildingManagerComponent.ProcesXPreward();
244 }
245
246 //------------------------------------------------------------------------------------------------
248 protected SCR_CampaignBuildingNetworkComponent GetNetworkManager()
249 {
250 PlayerController playerController = GetGame().GetPlayerController();
251 if (!playerController)
252 return null;
253
254 return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
255 }
256
257 //------------------------------------------------------------------------------------------------
258 // Destructor
264}
ArmaReforgerScripted GetGame()
Definition game.c:1398
proto external bool ShouldPerformPerFrame()
Should this action be performed every frame the input action is triggered?
proto external bool IsInProgress()
Returns true while continuous or timed action is being used.
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
proto external Managed FindComponent(typename typeName)
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
void SetNewGadgetManager(IEntity from, IEntity to)
Sets a new gadget manager. Controlled by an event when the controlled entity has changed.
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
SCR_CampaignBuildingLayoutComponent m_LayoutComponent
SCR_CampaignBuildingNetworkComponent GetNetworkManager()
GetNetworkManager.
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
void CancelPlayerAnimation(notnull IEntity pUserEntity)
Stops player animation.
IEntity GetBuildingTool(notnull IEntity ent)
Get building tool entity.
static SCR_GadgetManagerComponent GetGadgetManager(IEntity entity)
SCR_GadgetComponent GetHeldGadgetComponent()
ref OnControlledEntityChangedPlayerControllerInvoker m_OnControlledEntityChanged
A scripted action class having optional logic to check if vehicle is valid.
bool LoopActionUpdate(float timeSlice)
proto external PlayerController GetPlayerController()
@ PerformAction