3 [
Attribute(
"#AR-SupportStation_ActionInvalid_NotInRange",
desc:
"No support stations of type in range", uiwidget: UIWidgets.LocaleEditBox)]
6 [
Attribute(
"#AR-SupportStation_ActionInvalid_Destroyed",
desc:
"Support station in range but the only one is destroyed", uiwidget: UIWidgets.LocaleEditBox)]
9 [
Attribute(
"#AR-SupportStation_ActionInvalid_HostileFaction",
desc:
"There are support stations in range but user is an invalid faction (Generally means faction is hostile)", uiwidget: UIWidgets.LocaleEditBox)]
12 [
Attribute(
"#AR-SupportStation_ActionInvalid_Supplies",
desc:
"There are support stations in range but non of them have enough supplies", uiwidget: UIWidgets.LocaleEditBox)]
15 [
Attribute(
"#AR-SupportStation_ActionInvalid_IsMoving",
desc:
"There are support stations in range but all of them are moving", uiwidget: UIWidgets.LocaleEditBox)]
18 [
Attribute(
"#AR-SupportStation_ActionInvalid_Disabled",
desc:
"There are support stations use range and are in range but all of them are disabled (by the game master)", uiwidget: UIWidgets.LocaleEditBox)]
21 [
Attribute(
"1",
desc:
"Show supplies in action if there is a supply cost")]
22 protected bool m_bShowSupplyCostOnAction;
24 [
Attribute(
"0",
desc:
"If true will check if support station component can be found on children. Only enable if support station is on Vehicle part and support station does not have range")]
25 protected bool m_bAllowCheckChildrenSupportStation;
27 [
Attribute(
"-1",
desc:
"What animation the player should play if using the support station with a gadget. Leave -1 to not play any animation")]
28 protected int m_iGadgetAnimationCommand;
30 [
Attribute(
"1",
desc:
"If an animation is assigned, does the animation loop?")]
31 protected bool m_bDoesGadgetAnimationLoop;
33 [
Attribute(
"0",
desc:
"If an animation is assigned, does the animation play while the character is in a vehicle?")]
34 protected bool m_bAnimateGadgetInVehicle;
36 protected bool m_bIsMaster;
37 protected bool m_bActionActive;
39 protected IEntity m_ActionUser;
40 protected SCR_BaseSupportStationComponent m_ActionOwnerSupportStationComponent;
41 protected SCR_BaseSupportStationComponent m_SupportStationComponent;
44 protected BaseWorld m_World;
45 protected float m_fLastCheckedCanPerform = 0;
46 protected bool m_bSupportStationWasNull =
false;
47 protected const int DELAY_CAN_PERFORM = 500;
49 protected int m_iSuppliesOnUse;
50 protected int m_iAvailableSupplies;
51 protected bool m_bCanPerform;
54 protected SCR_SupportStationGadgetComponent m_SupportStationGadget;
55 protected bool m_bOnActionAnimationInDone;
57 protected const LocalizedString ACTION_WITH_SUPPLYCOST_FORMATTING =
"#AR-ActionFormat_SupplyCost";
58 protected const LocalizedString ACTION_WITH_PARAM_FORMATTING =
"#AR-SupportStation_ActionFormat_WithParam";
59 protected const LocalizedString ACTION_PERCENTAGE_FORMATTING =
"#AR-SupportStation_ActionFormat_Percentage";
64 Print(
"Do not use 'SCR_BaseUseSupportStationAction' as action, inherit from it and override ' SupportStationActionType' function to the correct type!", LogLevel.ERROR);
70 protected SCR_BaseSupportStationComponent GetClosestValidSupportStation(IEntity actionOwner, IEntity actionUser, out
ESupportStationReasonInvalid reasonInvalid = 0)
72 SCR_BaseSupportStationComponent supportStationComponent;
73 vector actionWorldPosition = GetWorldPositionAction();
76 if (m_SupportStationGadget && PrioritizeHeldGadget() && AllowGetSupportStationFromGadget())
78 supportStationComponent = m_SupportStationGadget.GetSupportStation(GetSupportStationType());
79 if (supportStationComponent)
82 if (supportStationComponent.IsValid(actionOwner, actionUser,
this, actionWorldPosition, reasonInvalid, m_iSuppliesOnUse))
83 return supportStationComponent;
87 m_iAvailableSupplies = supportStationComponent.GetMaxAvailableSupplies();
95 if (m_ActionOwnerSupportStationComponent && !m_ActionOwnerSupportStationComponent.UsesRange() && !m_ActionOwnerSupportStationComponent.IgnoreSelf())
97 if (m_ActionOwnerSupportStationComponent.IsValid(actionOwner, actionUser,
this, actionWorldPosition, reasonInvalid, m_iSuppliesOnUse))
98 return m_ActionOwnerSupportStationComponent;
100 m_iAvailableSupplies = m_ActionOwnerSupportStationComponent.GetMaxAvailableSupplies();
106 if (supportStationManager)
109 supportStationComponent = supportStationManager.GetClosestValidSupportStation(GetSupportStationType(), actionUser, actionOwner,
this, actionWorldPosition, reasonInvalid, m_iSuppliesOnUse);
110 if (supportStationComponent)
111 return supportStationComponent;
118 if (m_SupportStationGadget && !PrioritizeHeldGadget() && AllowGetSupportStationFromGadget())
120 supportStationComponent = m_SupportStationGadget.GetSupportStation(GetSupportStationType());
121 if (supportStationComponent)
124 if (supportStationComponent.IsValid(actionOwner, actionUser,
this, actionWorldPosition, reasonInvalid, m_iSuppliesOnUse))
125 return supportStationComponent;
128 m_iAvailableSupplies = supportStationComponent.GetMaxAvailableSupplies();
135 if (supportStationComponent)
136 m_iAvailableSupplies = supportStationComponent.GetMaxAvailableSupplies();
138 m_iAvailableSupplies = 0;
144 override bool CanBeShownScript(IEntity user)
146 if (!super.CanBeShownScript(user))
149 m_SupportStationGadget = SCR_SupportStationGadgetComponent.GetHeldSupportStationGadget(GetSupportStationType(), user);
150 if (RequiresGadget() && !m_SupportStationGadget)
154 SCR_BaseSupportStationComponent supportStationComponent = SCR_BaseSupportStationComponent.Cast(
GetOwner().FindComponent(SCR_BaseSupportStationComponent));
155 if (supportStationComponent && !supportStationComponent.UsesRange() && !supportStationComponent.IsEnabled())
159 if (!CanShowDestroyed())
167 protected bool CanShowDestroyed()
170 SCR_DamageManagerComponent damageComponent = SCR_DamageManagerComponent.Cast(
GetOwner().FindComponent(SCR_DamageManagerComponent));
172 return damageComponent.GetState() !=
EDamageState.DESTROYED;
176 if (hitZoneContainer)
178 HitZone defaultHitZone = hitZoneContainer.GetDefaultHitZone();
181 return defaultHitZone.GetDamageState() !=
EDamageState.DESTROYED;
188 override bool CanBePerformedScript(IEntity user)
195 if (!CanHaveMultipleUsers() && m_ActionUser && m_ActionUser != user)
203 if (
m_World.GetWorldTime() < (m_fLastCheckedCanPerform + DELAY_CAN_PERFORM))
208 SetCanPerform(
true, -1);
212 else if (m_bSupportStationWasNull)
214 SetCanPerform(
false, -1);
225 CanBePerformedUpdate(user);
238 m_bCanPerform = canPerform;
240 if (reasonInvalid >= 0)
242 m_eCannotPerformReason = reasonInvalid;
243 m_sCannotPerformReason = GetInvalidPerformReasonString(reasonInvalid);
250 cannotPerformReason = m_eCannotPerformReason;
251 return m_bCanPerform;
256 protected void CanBePerformedUpdate(IEntity user)
259 m_fLastCheckedCanPerform =
m_World.GetWorldTime();
268 return m_sInvalidRangeActionReason;
270 return m_sInvalidDestroyedActionReason;
273 return m_sInvalidDisabledActionReason;
276 return m_sInvalidFactionActionReason;
279 return m_sInvalidSuppliesActionReason;
282 return m_sInvalidMovingActionReason;
289 protected void ResetReferencesOnServer()
291 m_fLastCheckedCanPerform = 0;
293 m_bSupportStationWasNull =
false;
298 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity,
float timeSlice)
303 if (!LoopActionUpdate(timeSlice))
307 if (m_SupportStationGadget && m_iGadgetAnimationCommand > 0 && m_bDoesGadgetAnimationLoop)
310 if (m_bAnimateGadgetInVehicle || !IsUserInVehicle(pUserEntity))
313 if (!m_SupportStationGadget.InUseAnimationLoop(pUserEntity))
319 m_bLoopAction =
true;
321 PerformAction(pOwnerEntity, pUserEntity);
325 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
332 ResetReferencesOnServer();
334 if (!CanBeShownScript(pUserEntity))
337 if (!CanBePerformedScript(pUserEntity))
348 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
350 super.Init(pOwnerEntity, pManagerComponent);
353 if ((gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer()))
359 GetSupportStationType();
361 if (ShouldPerformPerFrame() && GetActionDuration() > 0)
362 Print(
"'SCR_BaseUseSupportStationAction' Support Station action type: '" +
typename.EnumToString(
ESupportStationType, GetSupportStationType()) +
"' has PerformPerFrame true but the duraction is greater than 0. Set it to less that 0, eg: 1 sec == -1", LogLevel.ERROR);
365 GetGame().GetCallqueue().CallLater(DelayedInit, param1: pOwnerEntity);
369 protected void DelayedInit(IEntity owner)
374 m_ActionOwnerSupportStationComponent = SCR_BaseSupportStationComponent.FindSupportStation(owner, GetSupportStationType(), queryFlags:
SCR_EComponentFinderQueryFlags.ENTITY);
377 if (!m_ActionOwnerSupportStationComponent && m_bAllowCheckChildrenSupportStation)
379 if (Vehicle.Cast(owner))
380 m_ActionOwnerSupportStationComponent = SCR_BaseSupportStationComponent.FindSupportStation(owner, GetSupportStationType(), queryFlags:
SCR_EComponentFinderQueryFlags.SLOTS);
382 m_ActionOwnerSupportStationComponent = SCR_BaseSupportStationComponent.FindSupportStation(owner, GetSupportStationType(), queryFlags:
SCR_EComponentFinderQueryFlags.CHILDREN);
387 override bool CanBroadcastScript()
393 protected bool CanHaveMultipleUsers()
400 protected float GetActionPercentage()
406 protected int GetActionDecimalCount()
413 protected bool RequiresGadget()
420 protected bool PrioritizeHeldGadget()
427 protected bool AllowGetSupportStationFromGadget()
434 protected IEntity GetCurrentActionUser()
440 override void OnActionStart(IEntity pUserEntity)
442 m_ActionUser = pUserEntity;
444 super.OnActionStart(pUserEntity);
447 if (!ShouldPerformPerFrame())
450 m_SupportStationGadget = SCR_SupportStationGadgetComponent.GetHeldSupportStationGadget(GetSupportStationType(), pUserEntity);
451 if (!m_SupportStationGadget)
453 m_bLoopAction =
true;
456 else if (!m_bDoesGadgetAnimationLoop)
458 m_bLoopAction =
true;
460 if (m_iGadgetAnimationCommand > 0 && (m_bAnimateGadgetInVehicle || !IsUserInVehicle(pUserEntity)))
461 m_SupportStationGadget.StartGadgetAnimation(pUserEntity, m_iGadgetAnimationCommand,
this);
466 m_bLoopAction =
false;
468 if (m_iGadgetAnimationCommand > 0 && (m_bAnimateGadgetInVehicle || !IsUserInVehicle(pUserEntity)))
469 m_SupportStationGadget.StartGadgetAnimation(pUserEntity, m_iGadgetAnimationCommand,
this);
473 protected bool IsUserInVehicle(notnull IEntity user)
475 ChimeraCharacter chimeraCharacter = ChimeraCharacter.Cast(user);
476 return chimeraCharacter && chimeraCharacter.IsInVehicle();
480 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
482 super.OnActionCanceled(pUserEntity);
487 if (!m_SupportStationGadget)
490 if (m_bDoesGadgetAnimationLoop && m_iGadgetAnimationCommand > 0 && (m_bAnimateGadgetInVehicle || !IsUserInVehicle(pUserEntity)))
491 m_SupportStationGadget.StopGadgetAnimation(pUserEntity, m_iGadgetAnimationCommand);
495 protected string GetActionStringParam()
501 protected override void OnActionSelected()
503 super.OnActionSelected();
504 m_fLastCheckedCanPerform = 0;
505 m_bActionActive =
true;
510 protected override void OnActionDeselected()
512 super.OnActionSelected();
513 m_bActionActive =
false;
517 override bool GetActionNameScript(out
string outName)
520 if (outName.IsEmpty())
525 if (outName.IsEmpty())
529 outName = uiInfo.GetName();
536 string actionParam = GetActionStringParam();
537 float actionPercentage =
int.MIN;
539 if (actionParam.IsEmpty())
540 actionPercentage = GetActionPercentage();
543 if (actionPercentage !=
int.MIN)
544 actionParam =
SCR_FormatHelper.FloatToStringNoZeroDecimalEndings(actionPercentage, GetActionDecimalCount());
547 if (!actionParam.IsEmpty())
549 if (actionPercentage !=
int.MIN)
550 outName = WidgetManager.Translate(ACTION_PERCENTAGE_FORMATTING, outName, actionParam);
552 outName = WidgetManager.Translate(ACTION_WITH_PARAM_FORMATTING, outName, actionParam);
556 if (m_bShowSupplyCostOnAction && m_iSuppliesOnUse > 0)
560 outName = WidgetManager.Translate(ACTION_WITH_SUPPLYCOST_FORMATTING, outName, m_iSuppliesOnUse, m_iAvailableSupplies);
564 return !outName.IsEmpty();
571 if (m_ActionUser && m_SupportStationGadget)
573 if (m_bDoesGadgetAnimationLoop && m_iGadgetAnimationCommand > 0 && (m_bAnimateGadgetInVehicle || !IsUserInVehicle(m_ActionUser)))
574 m_SupportStationGadget.StopGadgetAnimation(m_ActionUser, m_iGadgetAnimationCommand);