8 protected RplId m_ResourceInventoryPlayerComponentRplId;
9 protected SCR_ResourceComponent m_ResourceComponent;
10 protected SCR_ResourceConsumer m_ResourceConsumer;
11 protected SCR_CampaignBuildingProviderComponent m_ProviderComponent;
12 protected Physics m_ProviderPhysics;
13 protected RplComponent m_RplComponent;
16 protected bool m_bUseRankLimitedAccess;
17 protected bool m_bTemporarilyBlockedAccess;
18 protected bool m_bAccessCanBeBlocked;
19 protected bool m_bRankLimitationCanBeUsed;
21 protected const int PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ = 1;
22 protected const int TEMPORARY_BLOCKED_ACCESS_RESET_TIME = 1000;
25 protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
28 InitializeSuppliesComponent();
35 if (m_ProviderComponent && m_ProviderComponent.ObstrucViewWhenEnemyInRange())
36 m_bAccessCanBeBlocked =
true;
38 BaseGameMode gameMode =
GetGame().GetGameMode();
40 m_bRankLimitationCanBeUsed = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
44 void InitializeSuppliesComponent()
48 m_ProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(
GetOwner().FindComponent(SCR_CampaignBuildingProviderComponent));
52 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
54 int playerID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
55 m_ProviderComponent.RequestBuildingMode(playerID,
true);
59 override bool CanBePerformedScript(IEntity user)
61 if (!m_ProviderComponent || m_bTemporarilyBlockedAccess)
64 if (m_bRankLimitationCanBeUsed && m_ProviderComponent.GetAccessRank() > GetUserRank(user))
66 FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
67 if (!factionAffiliationComp)
73 rankName = faction.GetRankName(m_ProviderComponent.GetAccessRank());
75 SetCannotPerformReason(rankName);
79 if (m_bAccessCanBeBlocked)
81 SetTemporaryBlockedAccess();
83 if (m_bTemporarilyBlockedAccess)
85 SetCannotPerformReason(
"#AR-Campaign_Action_ShowBuildPreviewEnemyPresence");
99 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
100 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
101 if (!playerController)
108 override bool CanBeShownScript(IEntity user)
110 if (!m_ProviderComponent)
113 if (!m_CompartmentAccess)
118 if (playerController)
119 playerController.m_OnControlledEntityChanged.Insert(SetNewCompartmentComponent);
124 if (m_CompartmentAccess.IsGettingIn())
136 ChimeraCharacter
char = ChimeraCharacter.Cast(user);
147 return m_ProviderComponent.IsCharacterFactionSame(user);
151 override bool GetActionNameScript(out
string outName)
158 outName = m_sActionNameNoSupplies;
166 if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
174 ActionNameParams[0] =
string.ToString(
m_ResourceConsumer.GetAggregatedResourceValue());
180 override bool HasLocalEffectOnlyScript()
189 void SetNewCompartmentComponent(IEntity from, IEntity to)
197 void SetTemporaryBlockedAccess()
199 IEntity masterProvider = m_ProviderComponent.GetMasterProviderEntity();
203 SCR_CampaignBuildingProviderComponent masterProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(masterProvider.FindComponent(SCR_CampaignBuildingProviderComponent));
204 if (!masterProviderComponent)
207 GetGame().GetWorld().QueryEntitiesBySphere(
GetOwner().
GetOrigin(), masterProviderComponent.GetBuildingRadius(), EvaluateEntity,
null, EQueryEntitiesFlags.DYNAMIC);
208 GetGame().GetCallqueue().CallLater(ResetTemporaryBlockedAccess, TEMPORARY_BLOCKED_ACCESS_RESET_TIME,
false);
213 void ResetTemporaryBlockedAccess()
215 m_bTemporarilyBlockedAccess =
false;
221 bool EvaluateEntity(IEntity ent)
226 SCR_ChimeraCharacter
char = SCR_ChimeraCharacter.Cast(ent);
231 if (!charDamageManager || charDamageManager.GetState() ==
EDamageState.DESTROYED)
234 if (!m_ProviderComponent.IsEnemyFaction(
char))
237 CharacterControllerComponent charControl =
char.GetCharacterController();
241 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
244 AIControlComponent ctrComp = charControl.GetAIControlComponent();
248 if (ctrComp.IsAIActivated())
250 m_bTemporarilyBlockedAccess =
true;
256 m_bTemporarilyBlockedAccess =
true;