Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayableFactionKillingAttributeDynamicDescription.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), BaseContainerCustomStringTitleField("Players will be killed warning (CUSTOM)")]
6 {
7  protected int m_iPlayersWillBeKilled = 0;
8  protected ref array<int> m_aStartingDisabledFactions = {};
9 
10  protected FactionManager m_FactionManager;
11  protected SCR_ToolboxComponent m_ToolBoxComponent;
12  protected SCR_BaseEditorAttributeFloatStringValues m_ButtonBoxData;
13 
14  protected SCR_RespawnSystemComponent m_RespawnSystemComponent;
15  protected SCR_PlayerDelegateEditorComponent m_PlayerDelegateManager;
16 
17  //------------------------------------------------------------------------------------------------
18  override void InitDynamicDescription(notnull SCR_BaseEditorAttribute attribute, notnull SCR_BaseEditorAttributeUIComponent attributeUi)
19  {
20  super.InitDynamicDescription(attribute);
21 
22  if (!attribute.IsInherited(SCR_PlayableFactionEditorAttribute) && !attribute.IsInherited(SCR_PlayableFactionsEditorAttribute))
23  {
24  Print("'SCR_PlayableFactionDisabledAttributeDynamicDescription' is not attached to the 'SCR_PlayableFactionEditorAttribute' nor 'SCR_PlayableFactionsEditorAttribute'!", LogLevel.ERROR);
25  return;
26  }
27 
28  if (attribute.IsInherited(SCR_PlayableFactionsEditorAttribute))
29  {
31  if (!buttonBoxUI)
32  {
33  Print("'SCR_PlayableFactionDisabledAttributeDynamicDescription' is used for 'SCR_PlayableFactionsEditorAttribute' but attribute UI does not inherent from SCR_ButtonBoxAttributeUIComponent!", LogLevel.ERROR);
34  return;
35  }
36 
37  m_ToolBoxComponent = buttonBoxUI.GetToolboxComponent();
38  if (!m_ToolBoxComponent)
39  {
40  Print("'SCR_PlayableFactionDisabledAttributeDynamicDescription' is used for 'SCR_PlayableFactionsEditorAttribute' but could not find SCR_ToolboxComponent!", LogLevel.ERROR);
41  return;
42  }
43 
44  m_ButtonBoxData = buttonBoxUI.GetButtonBoxData();
45  if (!m_ButtonBoxData)
46  {
47  Print("'SCR_PlayableFactionDisabledAttributeDynamicDescription' is used for 'SCR_PlayableFactionsEditorAttribute' but could not find m_ButtonBoxData!", LogLevel.ERROR);
48  return;
49  }
50  }
51 
52  if (!m_FactionManager)
53  m_FactionManager = GetGame().GetFactionManager();
54 
56  m_RespawnSystemComponent = SCR_RespawnSystemComponent.GetInstance();
57 
58  if (!m_PlayerDelegateManager)
60 
61  //~ Get factions that started out disabled
62  m_aStartingDisabledFactions.Clear();
63  GetDisabledFactions(attribute, m_aStartingDisabledFactions);
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  override bool IsValid(notnull SCR_BaseEditorAttribute attribute, notnull SCR_BaseEditorAttributeUIComponent attributeUi)
68  {
69  if (!super.IsValid(attribute, attributeUi))
70  return false;
71 
72  if (!attribute.IsInherited(SCR_PlayableFactionEditorAttribute) && !attribute.IsInherited(SCR_PlayableFactionsEditorAttribute))
73  return false;
74 
75  if (!m_FactionManager)
76  return false;
77 
78  if (attribute.IsInherited(SCR_PlayableFactionsEditorAttribute))
79  {
80  if (!m_ToolBoxComponent || !m_ButtonBoxData)
81  return false;
82  }
83 
84  if (!m_FactionManager || !m_RespawnSystemComponent || !m_PlayerDelegateManager)
85  return false;
86 
87  UpdateTotalToBeKilledPlayers(attribute);
88 
89  return m_iPlayersWillBeKilled > 0;
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  override void GetDescriptionData(notnull SCR_BaseEditorAttribute attribute, notnull SCR_BaseEditorAttributeUIComponent attributeUi, out SCR_EditorAttributeUIInfo uiInfo, out string param1 = string.Empty, out string param2 = string.Empty, out string param3 = string.Empty)
94  {
95  UpdateTotalToBeKilledPlayers(attribute);
96 
97  uiInfo = m_DescriptionDisplayInfo;
98  param1 = m_iPlayersWillBeKilled.ToString();
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  protected void UpdateTotalToBeKilledPlayers(SCR_BaseEditorAttribute attribute)
103  {
104  array<int> disabledFactions = {};
105  m_iPlayersWillBeKilled = 0;
106 
107  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
108  if (!var)
109  return;
110 
111  //~ Get idisabled factions
112  GetDisabledFactions(attribute, disabledFactions);
113 
114  Faction playerFaction;
115 
116  if (!disabledFactions.IsEmpty())
117  {
119  if (!factionManager) // factions and player factions depend on such faction manager
120  return;
121 
122  array<int> players = new array<int>;
123  GetGame().GetPlayerManager().GetPlayers(players);
124  SCR_EditablePlayerDelegateComponent playerEditorDelegate;
125 
126  foreach (int playerId: players)
127  {
128  //If has player entity
129  if(!SCR_PossessingManagerComponent.GetPlayerMainEntity(playerId))
130  continue;
131 
132  playerFaction = factionManager.GetPlayerFaction(playerId);
133  if (!playerFaction)
134  continue;
135 
136  int factionIndex = factionManager.GetFactionIndex(playerFaction);
137 
138  if (!disabledFactions.Contains(factionIndex) || m_aStartingDisabledFactions.Contains(factionIndex))
139  continue;
140 
141  //Ignore GM
142  /*if (m_PlayerDelegateManager)
143  {
144  playerEditorDelegate = m_PlayerDelegateManager.GetDelegate(playerId);
145 
146  if (playerEditorDelegate)
147  {
148  if (!playerEditorDelegate.HasLimitedEditor())
149  continue;
150  }
151  }*/
152 
153  m_iPlayersWillBeKilled++;
154  }
155  }
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected void GetDisabledFactions(SCR_BaseEditorAttribute attribute, notnull out array<int> disabledFactions)
160  {
161  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
162  if (!var)
163  return;
164 
165  //~ Single faction get if disabled
166  if (attribute.IsInherited(SCR_PlayableFactionEditorAttribute))
167  {
168  vector value = var.GetVector();
169 
170  if (value[0] == 0)
171  disabledFactions.Insert((int)value[1]);
172  }
173  //~ Multiple factions get all disabled faction
174  else
175  {
176  if (!m_ToolBoxComponent || !m_FactionManager || !m_ButtonBoxData)
177  return;
178 
179  //Get all disabled buttonts and the faction associated with it and make sure the system adds a Attribute explanation if any players will die on Accept
180  int count = m_ButtonBoxData.GetValueCount();
181 
182  int factionIndex;
183  Faction faction;
184  SCR_Faction scrFaction;
185 
186  for(int i = 0; i < count; i++)
187  {
188  if (!m_ToolBoxComponent.IsItemSelected(i))
189  {
190  factionIndex = m_ButtonBoxData.GetEntryFloatValue(i);
191 
192  faction = m_FactionManager.GetFactionByIndex(factionIndex);
193 
194  scrFaction = SCR_Faction.Cast(faction);
195 
196  //Check if currently playable
197  if (scrFaction && scrFaction.IsPlayable())
198  disabledFactions.Insert(factionIndex);
199  }
200  }
201  }
202  }
203 };
SCR_PlayableFactionEditorAttribute
Definition: SCR_PlayableFactionEditorAttribute.c:2
m_RespawnSystemComponent
SCR_SpawnHandlerComponentClass m_RespawnSystemComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
BaseContainerCustomStringTitleField
class SCR_HitZoneGroupNameHolder BaseContainerCustomStringTitleField("USE INHERENT VERSION ONLY!")
Definition: SCR_HitZoneGroupNameHolder.c:27
SCR_EditorAttributeUIInfo
UIInfo used by editor attribute system.
Definition: SCR_EditorAttributeUIInfo.c:3
SCR_PlayerDelegateEditorComponent
Definition: SCR_PlayerDelegateEditorComponent.c:9
SCR_PlayableFactionsEditorAttribute
Definition: SCR_PlayableFactionsEditorAttribute.c:3
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
m_FactionManager
protected SCR_FactionManager m_FactionManager
Definition: SCR_NotificationSenderComponent.c:28
SCR_BaseEditorAttributeFloatStringValues
void SCR_BaseEditorAttributeFloatStringValues(array< ref SCR_EditorAttributeFloatStringValueHolder > values)
Definition: SCR_BaseEditorAttribute.c:627
SCR_BaseButtonAttributeDynamicDescription
Definition: SCR_BaseButtonAttributeDynamicDescription.c:5
SCR_BaseEditorAttribute
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
Definition: SCR_BaseEditorAttribute.c:3
SCR_ButtonBoxAttributeUIComponent
Definition: SCR_ButtonBoxAttributeUIComponent.c:3
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3
Faction
Definition: Faction.c:12
SCR_ToolboxComponent
Definition: SCR_ToolboxComponent.c:2
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_Faction
Definition: SCR_Faction.c:6
SCR_PlayableFactionKillingAttributeDynamicDescription
Definition: SCR_PlayableFactionKillingAttributeDynamicDescription.c:5
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468