Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingStartUserAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute(desc: "Action name if supplies are disabled")]
5  protected LocalizedString m_sActionNameNoSupplies;
6 
7  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer;
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;
14  protected DamageManagerComponent m_DamageManager;
15  protected SCR_CompartmentAccessComponent m_CompartmentAccess;
16  protected bool m_bUseRankLimitedAccess;
17  protected bool m_bTemporarilyBlockedAccess;
18  protected bool m_bAccessCanBeBlocked;
19  protected bool m_bRankLimitationCanBeUsed;
20 
21  protected const int PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ = 1;
22  protected const int TEMPORARY_BLOCKED_ACCESS_RESET_TIME = 1000;
23 
24  //------------------------------------------------------------------------------------------------
25  protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
26  {
27  m_RplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
28  InitializeSuppliesComponent();
29 
31 
33  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
34 
35  if (m_ProviderComponent && m_ProviderComponent.ObstrucViewWhenEnemyInRange())
36  m_bAccessCanBeBlocked = true;
37 
38  BaseGameMode gameMode = GetGame().GetGameMode();
39  if (gameMode)
40  m_bRankLimitationCanBeUsed = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  void InitializeSuppliesComponent()
45  {
46  IEntity mainParent = SCR_EntityHelper.GetMainParent(GetOwner(), true);
47  m_ProviderPhysics = mainParent.GetPhysics();
48  m_ProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(GetOwner().FindComponent(SCR_CampaignBuildingProviderComponent));
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
53  {
54  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
55  m_ProviderComponent.RequestBuildingMode(playerID, true);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  override bool CanBePerformedScript(IEntity user)
60  {
61  if (!m_ProviderComponent || m_bTemporarilyBlockedAccess)
62  return false;
63 
64  if (m_bRankLimitationCanBeUsed && m_ProviderComponent.GetAccessRank() > GetUserRank(user))
65  {
66  FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
67  if (!factionAffiliationComp)
68  return false;
69 
70  string rankName;
71  SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComp.GetAffiliatedFaction());
72  if (faction)
73  rankName = faction.GetRankName(m_ProviderComponent.GetAccessRank());
74 
75  SetCannotPerformReason(rankName);
76  return false;
77  }
78 
79  if (m_bAccessCanBeBlocked)
80  {
81  SetTemporaryBlockedAccess();
82 
83  if (m_bTemporarilyBlockedAccess)
84  {
85  SetCannotPerformReason("#AR-Campaign_Action_ShowBuildPreviewEnemyPresence");
86  return false;
87  }
88  }
89 
90  return true;
91  }
92 
93  //------------------------------------------------------------------------------------------------
97  SCR_ECharacterRank GetUserRank(notnull IEntity user)
98  {
99  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
100  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
101  if (!playerController)
102  return SCR_ECharacterRank.INVALID;
103 
104  return SCR_CharacterRankComponent.GetCharacterRank(playerController.GetControlledEntity());
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  override bool CanBeShownScript(IEntity user)
109  {
110  if (!m_ProviderComponent)
111  return false;
112 
113  if (!m_CompartmentAccess)
114  {
115  m_CompartmentAccess = SCR_CompartmentAccessComponent.Cast(user.FindComponent(SCR_CompartmentAccessComponent));
116 
118  if (playerController)
119  playerController.m_OnControlledEntityChanged.Insert(SetNewCompartmentComponent);
120 
121  return false;
122  }
123 
124  if (m_CompartmentAccess.IsGettingIn())
125  return false;
126 
127  // Don't quit if the providerPhysics doesn't exist. The provider might not have one.
128  if (m_ProviderPhysics)
129  {
130  vector velocity = m_ProviderPhysics.GetVelocity();
131  if ((velocity.LengthSq()) > PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ)
132  return false;
133  }
134 
135  // Don't show the action if player is within any vehicle.
136  ChimeraCharacter char = ChimeraCharacter.Cast(user);
137  if (!char || char.IsInVehicle())
138  return false;
139 
140  // No action if the provider is destroyed
141  if (m_DamageManager)
142  {
143  if (m_DamageManager.GetState() == EDamageState.DESTROYED)
144  return false;
145  }
146 
147  return m_ProviderComponent.IsCharacterFactionSame(user);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  override bool GetActionNameScript(out string outName)
152  {
153  if (!m_ResourceComponent)
154  m_ResourceComponent = m_ProviderComponent.GetResourceComponent();
155 
156  if (!m_ResourceComponent.IsResourceTypeEnabled() && !m_sActionNameNoSupplies.IsEmpty())
157  {
158  outName = m_sActionNameNoSupplies;
159  return true;
160  }
161 
164  return false;
165 
166  if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
167  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
168 
171  else
172  m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
173 
174  ActionNameParams[0] = string.ToString(m_ResourceConsumer.GetAggregatedResourceValue());
175 
176  return false;
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  override bool HasLocalEffectOnlyScript()
181  {
182  return true;
183  }
184 
185  //------------------------------------------------------------------------------------------------
187  //\param[in] from Entity from which the ownership is being pased
188  //\param[in] to Entity to which the ownership is passed
189  void SetNewCompartmentComponent(IEntity from, IEntity to)
190  {
191  if (to)
192  m_CompartmentAccess = SCR_CompartmentAccessComponent.Cast(to.FindComponent(SCR_CompartmentAccessComponent));
193  }
194 
195  //------------------------------------------------------------------------------------------------
197  void SetTemporaryBlockedAccess()
198  {
199  IEntity masterProvider = m_ProviderComponent.GetMasterProviderEntity();
200  if (!masterProvider)
201  return;
202 
203  SCR_CampaignBuildingProviderComponent masterProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(masterProvider.FindComponent(SCR_CampaignBuildingProviderComponent));
204  if (!masterProviderComponent)
205  return;
206 
207  GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), masterProviderComponent.GetBuildingRadius(), EvaluateEntity, null, EQueryEntitiesFlags.DYNAMIC);
208  GetGame().GetCallqueue().CallLater(ResetTemporaryBlockedAccess, TEMPORARY_BLOCKED_ACCESS_RESET_TIME, false);
209  }
210 
211  //------------------------------------------------------------------------------------------------
213  void ResetTemporaryBlockedAccess()
214  {
215  m_bTemporarilyBlockedAccess = false;
216  }
217 
218  //------------------------------------------------------------------------------------------------
220  //\param[in] ent Entity to evaluate by this filter.
221  bool EvaluateEntity(IEntity ent)
222  {
223  if (!ent)
224  return true;
225 
226  SCR_ChimeraCharacter char = SCR_ChimeraCharacter.Cast(ent);
227  if (!char)
228  return true;
229 
231  if (!charDamageManager || charDamageManager.GetState() == EDamageState.DESTROYED)
232  return true;
233 
234  if (!m_ProviderComponent.IsEnemyFaction(char))
235  return true;
236 
237  CharacterControllerComponent charControl = char.GetCharacterController();
238  if (!charControl)
239  return true;
240 
241  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
242  if (playerId == 0)
243  {
244  AIControlComponent ctrComp = charControl.GetAIControlComponent();
245  if (!ctrComp)
246  return true;
247 
248  if (ctrComp.IsAIActivated())
249  {
250  m_bTemporarilyBlockedAccess = true;
251  return false;
252  }
253  }
254  else
255  {
256  m_bTemporarilyBlockedAccess = true;
257  return false;
258  }
259 
260  return true;
261  }
262 }
m_ProviderPhysics
protected Physics m_ProviderPhysics
Definition: SCR_CampaignBuildingProviderComponent.c:49
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
SCR_CompartmentAccessComponent
Definition: SCR_CompartmentAccessComponent.c:15
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
SCR_ECharacterRank
SCR_ECharacterRank
Definition: SCR_CharacterRankComponent.c:305
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_CharacterRankComponent
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CharacterRankComponent.c:209
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
m_ResourceSubscriptionHandleConsumer
protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
Definition: SCR_BaseSupportStationComponent.c:125
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_CampaignBuildingStartUserAction
Definition: SCR_CampaignBuildingStartUserAction.c:2
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ
const protected int PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ
Definition: SCR_CampaignBuildingProviderComponent.c:61
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
IsInVehicle
proto external bool IsInVehicle()
Returns true if the character is inside a vehicle.
SCR_ResourceSystemSubscriptionHandleBase
Definition: SCR_ResourceSystemSubscriptionHandleBase.c:1
DamageManagerComponent
Definition: DamageManagerComponent.c:12
m_DamageManager
DamageManagerComponent m_DamageManager
Definition: SCR_AITargetInfo.c:19
LocalizedString
Definition: LocalizedString.c:21
SCR_Faction
Definition: SCR_Faction.c:6
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1