Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseFactionCheckUserAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute("3", desc: "Set faction of user that can use the action, will be ignored if non are selected. Requires a 'FactionAffiliationComponent' on the Owner or parent. It will always allow interaction if user does not have 'FactionAffiliationComponent'. Default faction is the faction associated with the Initial Owner faction. Flags are checked in order. DISALLOW ON NULL is only checked when Default faction check is not set.", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EActionFactionUsage), category: "Faction Settings")]
5  protected EActionFactionUsage m_eFactionUsageCheck;
6 
7  [Attribute("#AR-ActionInvalid_HostileFaction", desc: "Faction invalid faction for the user that tries to use the action (By default this means faction is hostile, replace if there is a diffrent meaning)")]
8  protected LocalizedString m_sInvalidFactionCannotPerform;
9 
10  [Attribute("0", desc: "If entity itself does not have faction affiliation component then it will try to get the parents faction affiliation component if this is true")]
11  protected bool m_bAllowGetFactionOfParent;
12 
13  protected FactionAffiliationComponent m_OwnerFactionAffiliation;
14 
15  //------------------------------------------------------------------------------------------------
16  override protected bool CanBePerformedScript(IEntity user)
17  {
18  //~ Action is invalid. Set cannnot perform reason
19  if (!IsFactionValid(user))
20  {
21  m_sCannotPerformReason = m_sInvalidFactionCannotPerform;
22  return false;
23  }
24  //~ Action can be performed
25  else
26  {
27  m_sCannotPerformReason = string.Empty;
28  return true;
29  }
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  protected bool IsFactionValid(IEntity user)
34  {
35  //~ No flags set so ignore
36  if (m_eFactionUsageCheck == 0 || !user || !m_OwnerFactionAffiliation)
37  return true;
38 
39  FactionAffiliationComponent userFactionAffiliation = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
40 
41  //~ None have a faction so both return true
42  if (!userFactionAffiliation)
43  return true;
44 
45  //~ User is faction less so allow interaction
46  Faction userFaction = userFactionAffiliation.GetAffiliatedFaction();
47  if (!userFaction)
48  return true;
49 
50  Faction ownerFaction;
51 
52  //~ Checks current faction
53  if (m_eFactionUsageCheck & (EActionFactionUsage.SAME_CURRENT_FACTION | EActionFactionUsage.FRIENDLY_CURRENT_FACTION))
54  {
55  //~ Only check if has current faction
56  ownerFaction = m_OwnerFactionAffiliation.GetAffiliatedFaction();
57  if (ownerFaction)
58  {
59  //~ If faction is the same
60  if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.SAME_CURRENT_FACTION) && ownerFaction.GetFactionKey() == userFaction.GetFactionKey())
61  return true;
62 
63  //~ If faction is friendly
64  if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.FRIENDLY_CURRENT_FACTION) && ownerFaction.IsFactionFriendly(userFaction))
65  return true;
66 
67  //~ Current faction exists but is not the same (or if friendly is checked and is not friendly)
68  return false;
69  }
70  }
71 
72  //~ Checks default faction
73  if (m_eFactionUsageCheck & (EActionFactionUsage.SAME_DEFAULT_FACTION | EActionFactionUsage.FRIENDLY_DEFAULT_FACTION))
74  {
75  //~ No default faction so return true
76  ownerFaction = m_OwnerFactionAffiliation.GetDefaultAffiliatedFaction();
77  if (!ownerFaction)
78  return true;
79 
80  //~ If default faction is the same
81  if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.SAME_DEFAULT_FACTION) && ownerFaction.GetFactionKey() == userFaction.GetFactionKey())
82  return true;
83 
84  //~ If default faction is friendly
85  if (SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.FRIENDLY_DEFAULT_FACTION) && ownerFaction.IsFactionFriendly(userFaction))
86  return true;
87 
88  //~ Default faction exists but is not the same (or if friendly is checked and is not friendly)
89  return false;
90  }
91 
92  //~ Has no current faction and did not check Default faction. So check if it is allowed to be used neutral
93  return !SCR_Enum.HasFlag(m_eFactionUsageCheck, EActionFactionUsage.DISALLOW_USE_ON_CURRENT_FACTION_NULL);
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
98  {
99  m_OwnerFactionAffiliation = FactionAffiliationComponent.Cast(GetOwner().FindComponent(FactionAffiliationComponent));
100 
101  if (!m_OwnerFactionAffiliation && m_bAllowGetFactionOfParent && GetOwner().GetParent())
102  m_OwnerFactionAffiliation = FactionAffiliationComponent.Cast(GetOwner().GetParent().FindComponent(FactionAffiliationComponent));
103  }
104 };
105 
107 {
113 };
FRIENDLY_CURRENT_FACTION
@ FRIENDLY_CURRENT_FACTION
The user with a faction that is a friendly faction as the current faction can interact with the actio...
Definition: SCR_BaseFactionCheckUserAction.c:109
SCR_Enum
Definition: SCR_Enum.c:1
SAME_DEFAULT_FACTION
@ SAME_DEFAULT_FACTION
The user with the same faction as the default faction of the action can interact with the action.
Definition: SCR_BaseFactionCheckUserAction.c:110
m_eFactionUsageCheck
protected ESupportStationFactionUsage m_eFactionUsageCheck
Definition: SCR_BaseSupportStationComponent.c:109
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
DISALLOW_USE_ON_CURRENT_FACTION_NULL
@ DISALLOW_USE_ON_CURRENT_FACTION_NULL
If set it disallows the action to be used if the faction of the owner is not set. Only valid if Defau...
Definition: SCR_BaseFactionCheckUserAction.c:112
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseAudioScriptedUserAction
A scripted action class having optional logic for playing audio as well as checking if the faction is...
Definition: SCR_BaseAudioScriptedUserAction.c:2
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Faction
Definition: Faction.c:12
EActionFactionUsage
EActionFactionUsage
Definition: SCR_BaseFactionCheckUserAction.c:106
SCR_BaseFactionCheckUserAction
Definition: SCR_BaseFactionCheckUserAction.c:2
FRIENDLY_DEFAULT_FACTION
@ FRIENDLY_DEFAULT_FACTION
he user with a faction that is a friendly faction to the default faction of the action can interact w...
Definition: SCR_BaseFactionCheckUserAction.c:111
LocalizedString
Definition: LocalizedString.c:21
SAME_CURRENT_FACTION
@ SAME_CURRENT_FACTION
The user with the same faction as the current faction can interact with the action.
Definition: SCR_BaseFactionCheckUserAction.c:108
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180