Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_CampaignBuildingBuildUserAction.c
Go to the documentation of this file.
1
//------------------------------------------------------------------------------------------------
2
class
SCR_CampaignBuildingBuildUserAction
:
SCR_ScriptedUserAction
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
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);
26
ProcesXPreward
();
27
}
28
29
//------------------------------------------------------------------------------------------------
30
override
void
OnActionStart
(
IEntity
pUserEntity)
31
{
32
m_ActiveUser
= pUserEntity;
33
34
if
(!
ShouldPerformPerFrame
())
35
return
;
36
37
ChimeraCharacter
character
=
ChimeraCharacter
.Cast(pUserEntity);
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
47
ItemUseParameters
params
=
new
ItemUseParameters
();
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
65
ChimeraCharacter
character
=
ChimeraCharacter
.Cast(pUserEntity);
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
85
ChimeraCharacter
character
=
ChimeraCharacter
.Cast(pUserEntity);
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
{
129
m_GadgetManager
=
SCR_GadgetManagerComponent
.
GetGadgetManager
(user);
130
131
SCR_PlayerController
playerController =
SCR_PlayerController
.Cast(
GetGame
().
GetPlayerController
());
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
142
ChimeraCharacter
character
=
ChimeraCharacter
.Cast(user);
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
//------------------------------------------------------------------------------------------------
197
override
bool
HasLocalEffectOnlyScript
()
198
{
199
return
true
;
200
}
201
202
//------------------------------------------------------------------------------------------------
204
void
SetNewGadgetManager
(
IEntity
from,
IEntity
to)
205
{
206
m_GadgetManager
=
SCR_GadgetManagerComponent
.
GetGadgetManager
(to);
207
}
208
209
//------------------------------------------------------------------------------------------------
211
IEntity
GetBuildingTool
(notnull
IEntity
ent)
212
{
213
SCR_GadgetManagerComponent
gadgetManager =
SCR_GadgetManagerComponent
.
GetGadgetManager
(ent);
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
222
int
GetBuildingToolValue
(notnull
IEntity
ent)
223
{
224
SCR_GadgetManagerComponent
gadgetManager =
SCR_GadgetManagerComponent
.
GetGadgetManager
(ent);
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
//------------------------------------------------------------------------------------------------
236
void
ProcesXPreward
()
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
259
void
~SCR_CampaignBuildingBuildUserAction
()
260
{
261
if
(
m_ActiveUser
)
262
CancelPlayerAnimation
(
m_ActiveUser
);
263
}
264
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
BaseUserAction::ShouldPerformPerFrame
proto external bool ShouldPerformPerFrame()
Should this action be performed every frame the input action is triggered?
BaseUserAction::IsInProgress
proto external bool IsInProgress()
Returns true while continuous or timed action is being used.
BaseUserAction::ActionNameParams
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
Definition
BaseUserAction.c:34
CharacterAnimationComponent
Definition
CharacterAnimationComponent.c:13
CharacterCommandHandlerComponent
Definition
CharacterCommandHandlerComponent.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
GenericComponent
Definition
GenericComponent.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
ItemUseParameters
Definition
ItemUseParameters.c:16
SCR_CampaignBuildingBuildUserAction
Definition
SCR_CampaignBuildingBuildUserAction.c:3
SCR_CampaignBuildingBuildUserAction::OnActionCanceled
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
Definition
SCR_CampaignBuildingBuildUserAction.c:61
SCR_CampaignBuildingBuildUserAction::m_bIsShown
bool m_bIsShown
Definition
SCR_CampaignBuildingBuildUserAction.c:10
SCR_CampaignBuildingBuildUserAction::ProcesXPreward
void ProcesXPreward()
Definition
SCR_CampaignBuildingBuildUserAction.c:236
SCR_CampaignBuildingBuildUserAction::GetActionNameScript
override bool GetActionNameScript(out string outName)
Definition
SCR_CampaignBuildingBuildUserAction.c:175
SCR_CampaignBuildingBuildUserAction::GetBuildingToolValue
int GetBuildingToolValue(notnull IEntity ent)
Definition
SCR_CampaignBuildingBuildUserAction.c:222
SCR_CampaignBuildingBuildUserAction::SetNewGadgetManager
void SetNewGadgetManager(IEntity from, IEntity to)
Sets a new gadget manager. Controlled by an event when the controlled entity has changed.
Definition
SCR_CampaignBuildingBuildUserAction.c:204
SCR_CampaignBuildingBuildUserAction::IsShown
bool IsShown()
Definition
SCR_CampaignBuildingBuildUserAction.c:118
SCR_CampaignBuildingBuildUserAction::~SCR_CampaignBuildingBuildUserAction
void ~SCR_CampaignBuildingBuildUserAction()
Definition
SCR_CampaignBuildingBuildUserAction.c:259
SCR_CampaignBuildingBuildUserAction::PerformAction
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
Definition
SCR_CampaignBuildingBuildUserAction.c:19
SCR_CampaignBuildingBuildUserAction::Init
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
Definition
SCR_CampaignBuildingBuildUserAction.c:13
SCR_CampaignBuildingBuildUserAction::m_GadgetManager
SCR_GadgetManagerComponent m_GadgetManager
Definition
SCR_CampaignBuildingBuildUserAction.c:9
SCR_CampaignBuildingBuildUserAction::m_LayoutComponent
SCR_CampaignBuildingLayoutComponent m_LayoutComponent
Definition
SCR_CampaignBuildingBuildUserAction.c:4
SCR_CampaignBuildingBuildUserAction::CanBePerformedScript
override bool CanBePerformedScript(IEntity user)
Definition
SCR_CampaignBuildingBuildUserAction.c:125
SCR_CampaignBuildingBuildUserAction::OnConfirmed
override void OnConfirmed(IEntity pUserEntity)
Definition
SCR_CampaignBuildingBuildUserAction.c:81
SCR_CampaignBuildingBuildUserAction::GetNetworkManager
SCR_CampaignBuildingNetworkComponent GetNetworkManager()
GetNetworkManager.
Definition
SCR_CampaignBuildingBuildUserAction.c:248
SCR_CampaignBuildingBuildUserAction::m_ActiveUser
IEntity m_ActiveUser
Definition
SCR_CampaignBuildingBuildUserAction.c:8
SCR_CampaignBuildingBuildUserAction::PerformContinuousAction
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
Definition
SCR_CampaignBuildingBuildUserAction.c:100
SCR_CampaignBuildingBuildUserAction::CanBeShownScript
override bool CanBeShownScript(IEntity user)
Definition
SCR_CampaignBuildingBuildUserAction.c:110
SCR_CampaignBuildingBuildUserAction::m_User
IEntity m_User
Definition
SCR_CampaignBuildingBuildUserAction.c:6
SCR_CampaignBuildingBuildUserAction::CancelPlayerAnimation
void CancelPlayerAnimation(notnull IEntity pUserEntity)
Stops player animation.
Definition
SCR_CampaignBuildingBuildUserAction.c:153
SCR_CampaignBuildingBuildUserAction::GetBuildingTool
IEntity GetBuildingTool(notnull IEntity ent)
Get building tool entity.
Definition
SCR_CampaignBuildingBuildUserAction.c:211
SCR_CampaignBuildingBuildUserAction::OnActionStart
override void OnActionStart(IEntity pUserEntity)
Definition
SCR_CampaignBuildingBuildUserAction.c:30
SCR_CampaignBuildingBuildUserAction::HasLocalEffectOnlyScript
override bool HasLocalEffectOnlyScript()
Definition
SCR_CampaignBuildingBuildUserAction.c:197
SCR_GadgetManagerComponent
Definition
SCR_GadgetManagerComponent.c:140
SCR_GadgetManagerComponent::GetHeldGadget
IEntity GetHeldGadget()
Definition
SCR_GadgetManagerComponent.c:191
SCR_GadgetManagerComponent::GetGadgetManager
static SCR_GadgetManagerComponent GetGadgetManager(IEntity entity)
Definition
SCR_GadgetManagerComponent.c:177
SCR_GadgetManagerComponent::GetHeldGadgetComponent
SCR_GadgetComponent GetHeldGadgetComponent()
Definition
SCR_GadgetManagerComponent.c:212
SCR_PlayerController
Definition
SCR_PlayerController.c:31
SCR_PlayerController::m_OnControlledEntityChanged
ref OnControlledEntityChangedPlayerControllerInvoker m_OnControlledEntityChanged
Definition
SCR_PlayerController.c:64
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition
SCR_ScriptedUserAction.c:6
SCR_ScriptedUserAction::LoopActionUpdate
bool LoopActionUpdate(float timeSlice)
Definition
SCR_ScriptedUserAction.c:175
SCR_ScriptedUserAction::character
ChimeraCharacter character
Definition
SCR_ScriptedUserAction.c:35
GetPlayerController
proto external PlayerController GetPlayerController()
Definition
SCR_PlayerDeployMenuHandlerComponent.c:307
PerformAction
@ PerformAction
Definition
EUserActionEvent.c:15
scripts
Game
UserActions
SCR_CampaignBuildingBuildUserAction.c
Generated by
1.17.0