3 protected SCR_CampaignBuildingCompositionComponent m_CompositionComponent;
6 protected FactionAffiliationComponent m_FactionComponent;
7 protected ref array<SCR_EditableVehicleComponent> m_EditableVehicle = {};
8 protected bool m_bCompositionSpawned;
9 protected bool m_bTurretCollected;
11 protected bool m_DoNotDisassemble;
12 protected IEntity m_RootEntity;
13 protected IEntity m_User;
18 protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
20 m_RootEntity = pOwnerEntity.GetRootParent();
22 m_CompositionComponent = SCR_CampaignBuildingCompositionComponent.Cast(m_RootEntity.FindComponent(SCR_CampaignBuildingCompositionComponent));
29 m_CompositionComponent.GetOnCompositionSpawned().Insert(OnCompositionSpawned);
31 BaseGameMode gameMode =
GetGame().GetGameMode();
35 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
36 if (!buildingManagerComponent)
39 if (buildingManagerComponent.CanDisassembleSameFactionOnly())
40 m_CompositionComponent.GetOnBuilderSet().Insert(CacheFactionAffiliationComponent);
45 if (!campaignGameMode || !m_EditableEntity)
49 if (!editableEntityUIInfo)
52 array<EEditableEntityLabel> entityLabels = {};
53 editableEntityUIInfo.GetEntityLabels(entityLabels);
55 m_DoNotDisassemble =
true;
59 override void OnActionStart(IEntity pUserEntity)
61 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
65 CharacterControllerComponent charController = character.GetCharacterController();
69 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
70 int itemActionId = pAnimationComponent.BindCommand(
"CMD_Item_Action");
73 params.SetEntity(GetBuildingTool(pUserEntity));
74 params.SetAllowMovementDuringAction(
false);
75 params.SetKeepInHandAfterSuccess(
true);
76 params.SetCommandID(itemActionId);
77 params.SetCommandIntArg(2);
79 charController.TryUseItemOverrideParams(
params);
84 super.OnActionStart(pUserEntity);
88 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
92 ChimeraCharacter character = ChimeraCharacter.Cast(pUserEntity);
96 CharacterControllerComponent charController = character.GetCharacterController();
99 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
100 int itemActionId = pAnimationComponent.BindCommand(
"CMD_Item_Action");
101 CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
103 cmdHandler.FinishItemUse();
108 void CancelPlayerAnimation(notnull IEntity entity)
110 ChimeraCharacter character = ChimeraCharacter.Cast(entity);
114 CharacterControllerComponent charController = character.GetCharacterController();
117 CharacterAnimationComponent pAnimationComponent = charController.GetAnimationComponent();
118 CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(pAnimationComponent.GetCommandHandler());
119 cmdHandler.FinishItemUse();
124 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
126 SCR_CampaignBuildingNetworkComponent networkComponent = GetNetworkManager();
127 if (!networkComponent || !m_RootEntity)
130 if (HasCompositionService())
131 TryToSendNotification(pOwnerEntity, pUserEntity, networkComponent);
133 networkComponent.DeleteCompositionByUserAction(m_RootEntity);
137 void TryToSendNotification(IEntity pOwnerEntity, IEntity pUserEntity, notnull SCR_CampaignBuildingNetworkComponent networkComponent)
139 if (!m_CompositionComponent)
142 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
144 IEntity provider = m_CompositionComponent.GetProviderEntity();
148 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(provider.FindComponent(SCR_CampaignBuildingProviderComponent));
149 if (!providerComponent)
152 array<SCR_MilitaryBaseComponent> bases = {};
153 providerComponent.GetBases(bases);
157 int callsign = bases[0].GetCallsign();
158 if (callsign == SCR_MilitaryBaseComponent.INVALID_BASE_CALLSIGN)
161 Faction baseFaction = bases[0].GetFaction();
163 if (playerFaction != baseFaction)
166 networkComponent.SendDeleteNotification(m_EditableEntity.GetOwner(), playerId, callsign);
171 bool HasCompositionService()
173 if (!m_EditableEntity)
177 return editableEntityUIInfo && editableEntityUIInfo.HasEntityLabel(
EEditableEntityLabel.TRAIT_SERVICE);
182 override bool CanBeShownScript(IEntity user)
184 if (m_DoNotDisassemble)
187 if (!IsPlayerFactionSame(user))
195 if (playerController)
196 playerController.m_OnControlledEntityChanged.Insert(SetNewGadgetManager);
201 if (!SCR_CampaignBuildingGadgetToolComponent.Cast(
m_GadgetManager.GetHeldGadgetComponent()))
206 return m_bCompositionSpawned;
208 return GetOwner().FindComponent(SCR_CampaignBuildingLayoutComponent);
213 void SetNewGadgetManager(IEntity from, IEntity to)
219 override bool CanBePerformedScript(IEntity user)
221 if (m_bCompositionSpawned && !m_bTurretCollected)
222 GetAllTurretsInComposition();
231 array<CompartmentAccessComponent> crewCompartmentAccess = {};
233 foreach (SCR_EditableVehicleComponent editableVehicle : m_EditableVehicle)
235 if (editableVehicle.GetCrew(crewCompartmentAccess,
false) != 0)
243 SCR_GadgetComponent gadgetComponent = gadgetManager.GetHeldGadgetComponent();
244 if (!gadgetComponent)
247 return (gadgetComponent.GetMode() == EGadgetMode.IN_HAND);
251 override bool HasLocalEffectOnlyScript()
257 void SetEditorManager()
268 void GetAllTurretsInComposition()
270 m_bTurretCollected =
true;
271 set<SCR_EditableEntityComponent> editableEntities =
new set<SCR_EditableEntityComponent>();
272 m_EditableEntity.GetChildren(editableEntities);
276 SCR_EditableVehicleComponent editableVehicle = SCR_EditableVehicleComponent.Cast(ent);
278 m_EditableVehicle.Insert(editableVehicle);
284 void OnCompositionSpawned(
bool compositionSpawned)
286 m_bCompositionSpawned = compositionSpawned;
287 if (m_CompositionComponent)
288 m_CompositionComponent.GetOnCompositionSpawned().Remove(OnCompositionSpawned);
293 void CacheFactionAffiliationComponent()
295 IEntity provider = m_CompositionComponent.GetProviderEntity();
299 m_FactionComponent = FactionAffiliationComponent.Cast(provider.FindComponent(FactionAffiliationComponent));
304 IEntity GetBuildingTool(notnull IEntity ent)
310 return gadgetManager.GetHeldGadget();
315 bool IsPlayerFactionSame(notnull IEntity user)
320 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
328 protected SCR_CampaignBuildingNetworkComponent GetNetworkManager()
330 PlayerController playerController =
GetGame().GetPlayerController();
331 if (!playerController)
334 return SCR_CampaignBuildingNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignBuildingNetworkComponent));
342 CancelPlayerAnimation(
m_User);