Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EnableDefendersAction.c
Go to the documentation of this file.
2 {
3 
4  protected SCR_DefenderSpawnerComponent m_DefenderSpawner;
5  protected SCR_SpawnerAIGroupManagerComponent m_GroupSpawningManager;
6 
7  //------------------------------------------------------------------------------------------------
8  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
9  {
10  if (!m_DefenderSpawner)
11  return;
12 
13  PlayerController playerController = GetGame().GetPlayerController();
14  if (!playerController)
15  return;
16 
17  SCR_SpawnerRequestComponent playerReqComponent = SCR_SpawnerRequestComponent.Cast(playerController.FindComponent(SCR_SpawnerRequestComponent));
18  if (!playerReqComponent)
19  return;
20 
21  playerReqComponent.EnableSpawning(m_DefenderSpawner, !m_DefenderSpawner.IsSpawningEnabled(), playerController.GetPlayerId());
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  override bool CanBePerformedScript(IEntity user)
26  {
27  if (m_GroupSpawningManager.IsAtAILimit())
28  {
29  SetCannotPerformReason("#AR-Campaign_Action_BuildBlocked-UC");
30  return false;
31  }
32 
33  if (!m_DefenderSpawner.UserRankCheck(user))
34  {
35  string rankName;
36  FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
37  if (!factionAffiliationComp)
38  return false;
39 
40  SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComp.GetAffiliatedFaction());
41  if (!faction)
42  return false;
43 
44  rankName = faction.GetRankName(m_DefenderSpawner.GetMinimumRank());
45 
46  SetCannotPerformReason(rankName);
47  return false;
48  }
49 
50  return true;
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  override bool CanBeShownScript(IEntity user)
55  {
56  if (!m_DefenderSpawner)
57  return false;
58 
60  if (!playerController)
61  return false;
62 
63  SCR_ChimeraCharacter chimeraCharacter = SCR_ChimeraCharacter.Cast(playerController.GetControlledEntity());
64  if (!chimeraCharacter || chimeraCharacter.GetFaction() != m_DefenderSpawner.GetFaction())
65  return false;
66 
67  return true;
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected override bool HasLocalEffectOnlyScript()
72  {
73  return true;
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  override bool GetActionNameScript(out string outName)
78  {
79  if (m_DefenderSpawner.IsSpawningEnabled())
80  outName = "#AR-DefenderSpawner_DisableSpawning";
81  else
82  outName = "#AR-DefenderSpawner_EnableSpawning";
83 
84  return true;
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
89  {
90  m_DefenderSpawner = SCR_DefenderSpawnerComponent.Cast(pOwnerEntity.FindComponent(SCR_DefenderSpawnerComponent));
91 
92  BaseGameMode gameMode = GetGame().GetGameMode();
93  if (!gameMode)
94  return;
95 
96  m_GroupSpawningManager = SCR_SpawnerAIGroupManagerComponent.Cast(gameMode.FindComponent(SCR_SpawnerAIGroupManagerComponent));
97  if (!m_GroupSpawningManager)
98  {
99  Print("SCR_DefenderSpawnerComponent requires SCR_SpawnerAIGroupManagerComponent attached to gamemode to work properly!", LogLevel.ERROR);
100  return;
101  }
102  }
103 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_DefenderSpawnerComponent
Service providing group of defenders defined in faction. Requires SCR_EnableDefenderAction on ActionM...
Definition: SCR_DefenderSpawnerComponent.c:40
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_EnableDefendersAction
Definition: SCR_EnableDefendersAction.c:1
SCR_Faction
Definition: SCR_Faction.c:6