Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignReconfigureRelayUserAction.c
Go to the documentation of this file.
1
3{
4 // Member variables
6 protected bool m_bCanBeShownResult = false;
7
8 //------------------------------------------------------------------------------------------------
12 {
13 if (!player)
14 return null;
15
16 if (!ChimeraCharacter.Cast(player))
17 return null;
18
19 auto foundComponent = ChimeraCharacter.Cast(player).FindComponent(FactionAffiliationComponent);
20 Faction faction;
21
22 if (foundComponent)
23 {
24 auto castedComponent = FactionAffiliationComponent.Cast(foundComponent);
25 faction = castedComponent.GetAffiliatedFaction();
26 };
27
28 return faction;
29 }
30
31 //------------------------------------------------------------------------------------------------
32 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
33 {
34 if (!pOwnerEntity || !GetGame().InPlayMode())
35 return;
36
37 IEntity parent = pOwnerEntity.GetParent();
38
39 // Register parent base
42 }
43
44 //------------------------------------------------------------------------------------------------
45 override void OnActionStart(IEntity pUserEntity)
46 {
47 if (!m_Base)
48 return;
49
50 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(pUserEntity);
51 if (!character)
52 return;
53
54 ToggleBaseCapture(character, m_Base, true);
55 }
56
57 //------------------------------------------------------------------------------------------------
58 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
59 {
60 if (!m_Base)
61 return;
62
63 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(pUserEntity);
64 if (!character)
65 return;
66
67 ToggleBaseCapture(character, m_Base, false);
68 }
69
70 //------------------------------------------------------------------------------------------------
71 protected void ToggleBaseCapture(notnull SCR_ChimeraCharacter character, notnull SCR_CampaignMilitaryBaseComponent base, bool isBeingCaptured)
72 {
73 if (character.GetRplComponent().Role() != RplRole.Authority)
74 return;
75
76 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
77 if (!faction)
78 return;
79
80 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(character);
81
82 if (isBeingCaptured)
83 base.BeginCapture(faction, playerId);
84 else
85 base.EndCapture();
86 }
87
88 //------------------------------------------------------------------------------------------------
89 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
90 {
91 if (!m_Base)
92 return;
93
94 if (!CanBePerformedScript(pUserEntity))
95 return; // authority needs to make sure that user is able to actually do this
96
97 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
98 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(pUserEntity);
99 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
100
101 m_Base.CaptureRelay(faction, playerId);
102 }
103
104 //------------------------------------------------------------------------------------------------
105 override bool CanBePerformedScript(IEntity user)
106 {
107 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(user);
108 if (!character)
109 return false;
110
111 SCR_CampaignFaction faction = SCR_CampaignFaction.Cast(character.GetFaction());
112 if (!faction)
113 return false;
114
115 // Already ours
116 if (m_Base.GetFaction() == faction)
117 {
118 SetCannotPerformReason("#AR-Campaign_Action_Done");
119 return false;
120 }
121
122 // No radio signal
123 if (m_Base != faction.GetMainBase() && !m_Base.IsHQRadioTrafficPossible(faction))
124 {
125 SetCannotPerformReason("#AR-Campaign_Action_NoSignal");
126 return false;
127 }
128
129 return true;
130 }
131
132 //------------------------------------------------------------------------------------------------
133 override bool CanBeShownScript(IEntity user)
134 {
135 return m_Base != null;
136 }
137
138 //------------------------------------------------------------------------------------------------
139 override bool CanBroadcastScript()
140 {
141 return false;
142 }
143}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SetCannotPerformReason(string reason)
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
SCR_CampaignMilitaryBaseComponent GetMainBase()
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
void ToggleBaseCapture(notnull SCR_ChimeraCharacter character, notnull SCR_CampaignMilitaryBaseComponent base, bool isBeingCaptured)
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14