4 protected SCR_CampaignBuildingLayoutComponent m_LayoutComponent;
6 protected IEntity m_User;
8 protected IEntity m_ActiveUser;
12 protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
14 m_LayoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(pOwnerEntity.FindComponent(SCR_CampaignBuildingLayoutComponent));
18 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
20 SCR_CampaignBuildingNetworkComponent networkComponent = GetNetworkManager();
21 if (!networkComponent)
24 networkComponent.AddBuildingValue(GetBuildingToolValue(pUserEntity), pOwnerEntity);
29 override void OnActionStart(IEntity pUserEntity)
31 m_ActiveUser = pUserEntity;
33 if (!ShouldPerformPerFrame())
36 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
40 CharacterControllerComponent charController = character.GetCharacterController();
43 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
44 int itemActionId = pAnimationComponent.BindCommand(
"CMD_Item_Action");
47 params.SetEntity(GetBuildingTool(pUserEntity));
48 params.SetAllowMovementDuringAction(
false);
49 params.SetKeepInHandAfterSuccess(
true);
50 params.SetCommandID(itemActionId);
51 params.SetCommandIntArg(1);
53 charController.TryUseItemOverrideParams(
params);
56 super.OnActionStart(pUserEntity);
60 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
64 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
68 CharacterControllerComponent charController = character.GetCharacterController();
71 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
72 int itemActionId = pAnimationComponent.BindCommand(
"CMD_Item_Action");
73 CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
75 cmdHandler.FinishItemUse();
80 override void OnConfirmed(IEntity pUserEntity)
84 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
88 CharacterControllerComponent charController = character.GetCharacterController();
91 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
92 CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
93 cmdHandler.FinishItemUse();
99 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity,
float timeSlice)
101 if (!LoopActionUpdate(timeSlice))
104 PerformAction(pOwnerEntity, pUserEntity);
109 override bool CanBeShownScript(IEntity user)
112 return m_LayoutComponent && m_LayoutComponent.HasBuildingPreview();
117 override bool CanBePerformedScript(IEntity user)
124 if (playerController)
125 playerController.m_OnControlledEntityChanged.Insert(SetNewGadgetManager);
130 SCR_GadgetComponent gadgetComponent =
m_GadgetManager.GetHeldGadgetComponent();
131 if (!gadgetComponent)
134 ChimeraCharacter character = ChimeraCharacter.Cast(user);
135 CharacterControllerComponent charController = character.GetCharacterController();
137 if (charController && !IsInProgress() && !charController.CanUseItem())
140 return (gadgetComponent.GetMode() == EGadgetMode.IN_HAND);
145 protected void CancelPlayerAnimation(notnull IEntity pUserEntity)
147 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
151 CharacterControllerComponent charController = character.GetCharacterController();
155 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
156 if (!pAnimationComponent)
159 CharacterCommandHandlerComponent handlerComponent = pAnimationComponent.GetCommandHandler();
160 if (!handlerComponent)
163 handlerComponent.FinishItemUse();
167 override bool GetActionNameScript(out
string outName)
169 if (!m_LayoutComponent || !
m_User)
172 float progressPercentage = GetBuildingToolValue(
m_User) / (m_LayoutComponent.GetToBuildValue() * 0.01);
173 float buildPercentage = m_LayoutComponent.GetCurrentBuildValue() / (m_LayoutComponent.GetToBuildValue() * 0.01);
175 if (progressPercentage != (
int)progressPercentage)
176 ActionNameParams[0] = progressPercentage.ToString(lenDec: 1);
178 ActionNameParams[0] = progressPercentage.ToString();
180 if (buildPercentage != (
int)buildPercentage)
181 ActionNameParams[1] = buildPercentage.ToString(lenDec: 1);
183 ActionNameParams[1] = buildPercentage.ToString();
185 return super.GetActionNameScript(outName);
189 override bool HasLocalEffectOnlyScript()
196 void SetNewGadgetManager(IEntity from, IEntity to)
203 IEntity GetBuildingTool(notnull IEntity ent)
209 return gadgetManager.GetHeldGadget();
214 int GetBuildingToolValue(notnull IEntity ent)
220 SCR_CampaignBuildingGadgetToolComponent gadgetComponent = SCR_CampaignBuildingGadgetToolComponent.Cast(gadgetManager.GetHeldGadgetComponent());
221 if (!gadgetComponent)
224 return gadgetComponent.GetToolConstructionValue();
228 void ProcesXPreward()
230 BaseGameMode gameMode =
GetGame().GetGameMode();
234 SCR_CampaignBuildingManagerComponent campaignBuildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
235 campaignBuildingManagerComponent.ProcesXPreward();
240 protected SCR_CampaignBuildingNetworkComponent GetNetworkManager()
242 PlayerController playerController =
GetGame().GetPlayerController();
243 if (!playerController)
246 return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
254 CancelPlayerAnimation(m_ActiveUser);