Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingStartUserAction.c
Go to the documentation of this file.
2{
3 [Attribute(desc: "Action name if supplies are disabled")]
5
8 protected SCR_ResourceComponent m_ResourceComponent;
9 protected SCR_ResourceConsumer m_ResourceConsumer;
10 protected SCR_CampaignBuildingProviderComponent m_ProviderComponent;
12 protected RplComponent m_RplComponent;
17 protected bool m_bAccessCanBeBlocked;
18
19 protected const int PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ = 1;
20 protected const int TEMPORARY_BLOCKED_ACCESS_RESET_TIME = 1000;
21
22 //------------------------------------------------------------------------------------------------
23 protected override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
24 {
25 m_RplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
27
29
32
33 if (m_ProviderComponent && m_ProviderComponent.ObstrucViewWhenEnemyInRange())
35 }
36
37 //------------------------------------------------------------------------------------------------
39 {
41 m_ProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(GetOwner().FindComponent(SCR_CampaignBuildingProviderComponent));
42 }
43
44 //------------------------------------------------------------------------------------------------
45 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
46 {
47 int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
48 m_ProviderComponent.RequestEnterBuildingMode(playerID, true);
49 }
50
51 //------------------------------------------------------------------------------------------------
52 override bool CanBePerformedScript(IEntity user)
53 {
55 return false;
56
57 if (SCR_XPHandlerComponent.IsXpSystemEnabled() && m_ProviderComponent.GetAccessRank() > GetUserRank(user))
58 {
59 FactionAffiliationComponent factionAffiliationComp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
60 if (!factionAffiliationComp)
61 return false;
62
63 string rankName;
64 SCR_Faction faction = SCR_Faction.Cast(factionAffiliationComp.GetAffiliatedFaction());
65 if (faction)
66 rankName = faction.GetRanks().GetRankName(m_ProviderComponent.GetAccessRank());
67
68 SetCannotPerformReason(rankName);
69 return false;
70 }
71
73 {
75
77 {
78 SetCannotPerformReason("#AR-Campaign_Action_ShowBuildPreviewEnemyPresence");
79 return false;
80 }
81 }
82
83 return true;
84 }
85
86 //------------------------------------------------------------------------------------------------
90 SCR_ECharacterRank GetUserRank(notnull IEntity user)
91 {
92 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
93 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
94 if (!playerController)
95 return SCR_ECharacterRank.INVALID;
96
97 return SCR_CharacterRankComponent.GetCharacterRank(playerController.GetControlledEntity());
98 }
99
100 //------------------------------------------------------------------------------------------------
101 override bool CanBeShownScript(IEntity user)
102 {
104 return false;
105
107 {
109
111 if (playerController)
113
114 return false;
115 }
116
117 if (m_CompartmentAccess.IsGettingIn())
118 return false;
119
120 Physics providerPhysics = m_MainParent.GetPhysics();
121
122 // Don't quit if the providerPhysics doesn't exist. The provider might not have one.
123 if (providerPhysics)
124 {
125 vector velocity = providerPhysics.GetVelocity();
126 if ((velocity.LengthSq()) > PROVIDER_SPEED_TO_REMOVE_BUILDING_SQ)
127 return false;
128 }
129
130 // Don't show the action if player is within any vehicle.
131 ChimeraCharacter char = ChimeraCharacter.Cast(user);
132 if (!char || char.IsInVehicle())
133 return false;
134
135 // No action if the provider is destroyed
136 if (m_DamageManager)
137 {
138 if (m_DamageManager.GetState() == EDamageState.DESTROYED)
139 return false;
140 }
141
142 if (m_ProviderComponent.CanBeUsedByAnyFaction())
143 {
144 BaseCompartmentManagerComponent comparmentComponent = BaseCompartmentManagerComponent.Cast(GetOwner().GetRootParent().FindComponent(BaseCompartmentManagerComponent));
145 if (comparmentComponent)
146 {
147 array<BaseCompartmentSlot> outCompartments = {};
148 comparmentComponent.GetCompartments(outCompartments);
149
150 foreach (BaseCompartmentSlot compartment : outCompartments)
151 {
152 if (!compartment.IsOccupied())
153 continue;
154
155 if (m_ProviderComponent.IsEntityFactionSame(compartment.GetOccupant(), user))
156 continue;
157
158 DamageManagerComponent occupatDamageManager = DamageManagerComponent.Cast(compartment.GetOccupant().FindComponent(DamageManagerComponent));
159 if (occupatDamageManager && occupatDamageManager.GetState() == EDamageState.DESTROYED)
160 continue;
161
162 return false;
163 }
164
165 return true;
166 }
167 }
168
169 return m_ProviderComponent.IsEntityFactionSame(m_ProviderComponent.GetOwner(), user);
170 }
171
172 //------------------------------------------------------------------------------------------------
173 override bool GetActionNameScript(out string outName)
174 {
176 m_ResourceComponent = m_ProviderComponent.GetResourceComponent();
177
178 if (!m_ResourceComponent.IsResourceTypeEnabled() && !m_sActionNameNoSupplies.IsEmpty())
179 {
180 outName = m_sActionNameNoSupplies;
181 return true;
182 }
183
186 return false;
187
190
193 else
194 m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
195
196 ActionNameParams[0] = string.ToString(m_ResourceConsumer.GetAggregatedResourceValue());
197
198 return false;
199 }
200
201 //------------------------------------------------------------------------------------------------
203 {
204 return true;
205 }
206
207 //------------------------------------------------------------------------------------------------
209 //\param[in] from Entity from which the ownership is being pased
210 //\param[in] to Entity to which the ownership is passed
216
217 //------------------------------------------------------------------------------------------------
220 {
221 IEntity masterProvider = m_ProviderComponent.GetMasterProviderEntity();
222 if (!masterProvider)
223 return;
224
225 SCR_CampaignBuildingProviderComponent masterProviderComponent = SCR_CampaignBuildingProviderComponent.Cast(masterProvider.FindComponent(SCR_CampaignBuildingProviderComponent));
226 if (!masterProviderComponent)
227 return;
228
229 GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), masterProviderComponent.GetBuildingRadius(), EvaluateEntity, null, EQueryEntitiesFlags.DYNAMIC);
231 }
232
233 //------------------------------------------------------------------------------------------------
239
240 //------------------------------------------------------------------------------------------------
242 //\param[in] ent Entity to evaluate by this filter.
244 {
245 if (!ent)
246 return true;
247
248 SCR_ChimeraCharacter char = SCR_ChimeraCharacter.Cast(ent);
249 if (!char)
250 return true;
251
253 if (!charDamageManager || charDamageManager.GetState() == EDamageState.DESTROYED)
254 return true;
255
256 if (!m_ProviderComponent.IsEnemyFaction(char))
257 return true;
258
259 CharacterControllerComponent charControl = char.GetCharacterController();
260 if (!charControl)
261 return true;
262
263 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
264 if (playerId == 0)
265 {
266 AIControlComponent ctrComp = charControl.GetAIControlComponent();
267 if (!ctrComp)
268 return true;
269
270 if (ctrComp.IsAIActivated())
271 {
273 return false;
274 }
275 }
276 else
277 {
279 return false;
280 }
281
282 return true;
283 }
284}
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector GetOrigin()
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external IEntity GetOwner()
Returns the parent entity of this action.
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
void ResetTemporaryBlockedAccess()
Set temporary blocked access back to default false value.
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
bool EvaluateEntity(IEntity ent)
Check if this entity can block player to enter a building mode. If such anentity is found,...
SCR_ECharacterRank GetUserRank(notnull IEntity user)
void SetTemporaryBlockedAccess()
Set temporary blocked access.
void SetNewCompartmentComponent(IEntity from, IEntity to)
Sets a new compartment component. Controlled by an event when the controlled entity has changed.
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_CampaignBuildingProviderComponent m_ProviderComponent
static IEntity GetMainParent(IEntity entity, bool self=false)
SCR_RankContainer GetRanks()
ref OnControlledEntityChangedPlayerControllerInvoker m_OnControlledEntityChanged
string GetRankName(SCR_ECharacterRank rankID)
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
EDamageState
EQueryEntitiesFlags