Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableFactionComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4  //------------------------------------------------------------------------------------------------
5  static override bool GetEntitySourceBudgetCost(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetValues)
6  {
7  // Avoid fallback entityType cost
8  return true;
9  }
10 }
11 
13 
15 class SCR_EditableFactionComponent : SCR_EditableEntityComponent
16 {
17  [Attribute()]
18  protected ref array<ref SCR_ArsenalItemCountConfig> m_MaxCountPerItemType;
19 
20  [RplProp()]
21  protected int m_iFactionIndex = -1;
22 
23  protected Faction m_Faction;
25  protected ref SCR_UIInfo m_Info;
26 
27  //Faction info
28  protected int m_iSpawnPointCount = -1;
29  protected int m_iTaskCount = -1;
30 
31  //Task Safty
32  protected SCR_BaseTask m_PrevTask = null;
33 
34  //Script invokers
35  protected ref ScriptInvoker Event_OnSpawnPointCountChanged = new ScriptInvoker();
36  protected ref ScriptInvoker Event_OnTaskCountChanged = new ScriptInvoker();
37 
38  //Arsenal
40  protected ref map<SCR_EArsenalItemType, int> m_aCurrentItemTaken = new map<SCR_EArsenalItemType, int>();
41 
42  //------------------------------------------------------------------------------------------------
46  {
47  if (m_iFactionIndex != -1)
48  return;
49 
52  }
53 
54  //------------------------------------------------------------------------------------------------
58  {
59  return m_iFactionIndex;
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
64  protected void SetFactionIndexBroadcast(int index)
65  {
66  FactionManager factionManager = GetGame().GetFactionManager();
67  if (!factionManager)
68  return;
69 
70  //--- Find faction on the manager (factions are local, that's why they're identified by index)
71  m_Faction = factionManager.GetFactionByIndex(index);
72  if (!m_Faction)
73  return;
74 
76  if (!m_ScrFaction)
77  return;
78 
79  //--- Set the value
81 
82  //--- Copy UI info into editable entity
83  m_Info = SCR_UIInfo.CreateInfo(m_Faction.GetUIInfo());
84  SetInfoInstance(m_Info);
85 
86  //--- Register the faction back in the manager on local machine
88  if (delegatesManager)
89  delegatesManager.SetFactionDelegate(m_Faction, this);
90 
91  //--- Hide non-playable faction
92  SetVisible(m_ScrFaction.IsPlayable());
93 
94  //If Workbench or client
95  if (SCR_Global.IsEditMode(GetOwner()) || Replication.IsClient())
96  return;
97 
98  //Init count. Call one frame later to make sure the counts are correct
99  GetGame().GetCallqueue().CallLater(InitSpawnPointCount);
100  GetGame().GetCallqueue().CallLater(InitTaskCount);
101 
102  //Spawnpoints
103  SCR_SpawnPoint.Event_OnSpawnPointCountChanged.Insert(OnSpawnPointsChanged);
104  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Insert(OnSpawnpointFactionChanged);
105 
106  //Tasks
107  SCR_BaseTaskManager.s_OnTaskUpdate.Insert(OnTasksChanged);
108  SCR_BaseTaskManager.s_OnTaskDeleted.Insert(OnTasksChanged);
109  }
110 
111  //======================================== FACTION SPAWNPOINTS ========================================\\
112 
113  //------------------------------------------------------------------------------------------------
114  // Called on server
115  protected void InitSpawnPointCount()
116  {
117  int spawnPointCount = SCR_SpawnPoint.GetSpawnPointCountForFaction(m_Faction.GetFactionKey());
118 
119  InitSpawnPointCountBroadcast(spawnPointCount);
120  Rpc(InitSpawnPointCountBroadcast, spawnPointCount);
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
125  protected void InitSpawnPointCountBroadcast(int spawnPointCount)
126  {
127  m_iSpawnPointCount = spawnPointCount;
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected void OnSpawnpointFactionChanged(SCR_SpawnPoint spawnPoint)
132  {
133  OnSpawnPointsChanged(m_Faction.GetFactionKey());
134  }
135 
136  //---------------------------------------- On Faction Spawnpoints changed ----------------------------------------\\
137 
138  //------------------------------------------------------------------------------------------------
139  // Called on server
140  protected void OnSpawnPointsChanged(string factionKey)
141  {
142  if (factionKey != m_Faction.GetFactionKey())
143  return;
144 
145  int spawnPointCount = SCR_SpawnPoint.GetSpawnPointCountForFaction(m_Faction.GetFactionKey());
146 
147  //No change
148  if (spawnPointCount == m_iSpawnPointCount)
149  return;
150 
151  //Notification no spawns
152  if (spawnPointCount == 0)
153  {
154  int thisRplId = Replication.FindId(this);
155  SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(ENotification.EDITOR_FACTION_NO_SPAWNS, thisRplId);
156  }
157  else if (spawnPointCount == 1 && !m_ScrFaction.IsPlayable())
158  {
159  //SetFactionPlayableServer(true);
160  SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_ATTRIBUTES_FACTION_CHANGED_NO_GM);
161  }
162 
163  //Update Spawn count
164  OnSpawnPointCountChangedBroadcast(spawnPointCount);
165  Rpc(OnSpawnPointCountChangedBroadcast, spawnPointCount);
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
170  protected void OnSpawnPointCountChangedBroadcast(int spawnPointCount)
171  {
172  m_iSpawnPointCount = spawnPointCount;
173  Event_OnSpawnPointCountChanged.Invoke(m_Faction, spawnPointCount);
174  }
175 
176  //======================================== FACTION TASKS ========================================\\
177 
178  //------------------------------------------------------------------------------------------------
179  // Called on server
180  protected void InitTaskCount()
181  {
182  SCR_BaseTaskManager taskManager = GetTaskManager();
183  if (!taskManager)
184  return;
185 
186  array<SCR_BaseTask> tasks = {};
187  int factionTaskCount = taskManager.GetFilteredTasks(tasks, m_Faction);
188 
189  InitTaskCountBroadcast(factionTaskCount);
190  Rpc(InitTaskCountBroadcast, factionTaskCount);
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
195  protected void InitTaskCountBroadcast(int factionTaskCount)
196  {
197  m_iTaskCount = factionTaskCount;
198  }
199 
200  //---------------------------------------- Faction Task Count Changed ----------------------------------------\\
201  //Called on server
202  protected void OnTasksChanged(notnull SCR_BaseTask task)
203  {
204  SCR_BaseTaskManager taskManager = GetTaskManager();
205  if (!taskManager)
206  return;
207 
208  Faction faction = task.GetTargetFaction();
209  if (!faction || faction != m_Faction)
210  return;
211 
212  array<SCR_BaseTask> tasks = {};
213  int factionTaskCount = taskManager.GetFilteredTasks(tasks, m_Faction);
214 
215  //Safty as task Update is called on any change in tasks, but it should catch all the OnTaskUpdates types regardless. So if the same value is given don't do anything
216  if (m_PrevTask == task && m_iTaskCount == factionTaskCount)
217  return;
218 
219  m_PrevTask = task;
220 
221  //Update task count
222  OnTaskCountChangedBroadcast(factionTaskCount);
223  Rpc(OnTaskCountChangedBroadcast, factionTaskCount);
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
228  protected void OnTaskCountChangedBroadcast(int factionTaskCount)
229  {
230  m_iTaskCount = factionTaskCount;
231  Event_OnTaskCountChanged.Invoke(m_Faction, factionTaskCount);
232  }
233 
234  //======================================== FACTION PLAYABLE ========================================\\
235 
236  //------------------------------------------------------------------------------------------------
239  void SetFactionPlayableServer(bool factionPlayable)
240  {
241  //If client cancel
242  if (Replication.IsClient())
243  return;
244 
245  if (m_ScrFaction.IsPlayable() == factionPlayable)
246  return;
247 
248  //Update enabled
249  OnFactionplayableChangedBroadcast(factionPlayable);
250  Rpc(OnFactionplayableChangedBroadcast, factionPlayable);
251  }
252 
253  //------------------------------------------------------------------------------------------------
254  // Broadcast to client
255  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
256  protected void OnFactionplayableChangedBroadcast(bool factionPlayable)
257  {
258  m_ScrFaction.SetIsPlayable(factionPlayable, true);
259 
260  //--- Hide non-playable faction, so it's unselected if it was currently selected
261  SetVisible(factionPlayable);
262  }
263 
264  //======================================== GETTERS ========================================\\
265 
266  //------------------------------------------------------------------------------------------------
270  {
271  return m_iSpawnPointCount;
272  }
273 
274  //------------------------------------------------------------------------------------------------
278  {
279  return m_iTaskCount;
280  }
281 
282  //------------------------------------------------------------------------------------------------
286  {
288  }
289 
290  //------------------------------------------------------------------------------------------------
293  ScriptInvoker GetOnTaskCountChanged()
294  {
296  }
297 
298  //------------------------------------------------------------------------------------------------
301  {
303  }
304 
305  //------------------------------------------------------------------------------------------------
307  void SetAllowedArsenalItemTypes(SCR_EArsenalItemType allowedArsenalItemTypes)
308  {
309  m_AllowedArsenalItemTypes = allowedArsenalItemTypes;
310  }
311 
312  //------------------------------------------------------------------------------------------------
313  override bool CanDuplicate(out notnull set<SCR_EditableEntityComponent> outRecipients)
314  {
315  return false;
316  }
317 
318  //------------------------------------------------------------------------------------------------
319  override Faction GetFaction()
320  {
321  return m_Faction;
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  override bool GetPos(out vector pos)
326  {
327  return false;
328  }
329 
330  //------------------------------------------------------------------------------------------------
331  override bool GetEntityBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
332  {
333  // Return true and empty cost array, avoid fallback entityType cost
334  return true;
335  }
336 
337  //------------------------------------------------------------------------------------------------
338  override void OnPostInit(IEntity owner)
339  {
340  super.OnPostInit(owner);
341 
342  owner.SetFlags(EntityFlags.NO_LINK, true);
343  }
344 
345  //======================================== RPL ========================================\\
346 
347  //------------------------------------------------------------------------------------------------
348  override bool RplSave(ScriptBitWriter writer)
349  {
350  writer.WriteInt(m_iFactionIndex);
351  writer.WriteInt(m_iSpawnPointCount);
352  writer.WriteInt(m_iTaskCount);
353  writer.WriteBool(m_ScrFaction.IsPlayable());
354 
355  return true;
356  }
357 
358  //------------------------------------------------------------------------------------------------
359  override bool RplLoad(ScriptBitReader reader)
360  {
361  int spawnPointCount, taskCount;
362  bool isPlayable;
363 
364  reader.ReadInt(m_iFactionIndex);
365  reader.ReadInt(spawnPointCount);
366  reader.ReadInt(taskCount);
367  reader.ReadBool(isPlayable);
368 
369  m_ScrFaction.InitFactionIsPlayable(isPlayable);
371  InitSpawnPointCountBroadcast(spawnPointCount);
372  InitTaskCountBroadcast(taskCount);
373 
374  return true;
375  }
376 
377  //------------------------------------------------------------------------------------------------
378  // destructor
380  {
381  if (m_Faction && Replication.IsServer())
382  {
383  //Spawnpoints
384  SCR_SpawnPoint.Event_OnSpawnPointCountChanged.Remove(OnSpawnPointsChanged);
385  SCR_SpawnPoint.Event_SpawnPointFactionAssigned.Remove(OnSpawnpointFactionChanged);
386 
387  //Tasks
388  SCR_BaseTaskManager.s_OnTaskUpdate.Remove(OnTasksChanged);
389  SCR_BaseTaskManager.s_OnTaskDeleted.Remove(OnTasksChanged);
390  }
391  }
392 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
GetFaction
override Faction GetFaction()
Definition: SCR_EditableFactionComponent.c:319
InitSpawnPointCountBroadcast
protected void InitSpawnPointCountBroadcast(int spawnPointCount)
Definition: SCR_EditableFactionComponent.c:125
SetAllowedArsenalItemTypes
void SetAllowedArsenalItemTypes(SCR_EArsenalItemType allowedArsenalItemTypes)
Definition: SCR_EditableFactionComponent.c:307
OnSpawnpointFactionChanged
protected void OnSpawnpointFactionChanged(SCR_SpawnPoint spawnPoint)
Definition: SCR_EditableFactionComponent.c:131
Event_OnSpawnPointCountChanged
protected ref ScriptInvoker Event_OnSpawnPointCountChanged
Definition: SCR_EditableFactionComponent.c:35
GetFactionSpawnPointCount
int GetFactionSpawnPointCount()
Definition: SCR_EditableFactionComponent.c:269
SetFactionIndex
void SetFactionIndex(int index)
Definition: SCR_EditableFactionComponent.c:45
m_ScrFaction
protected SCR_Faction m_ScrFaction
Definition: SCR_EditableFactionComponent.c:24
OnFactionplayableChangedBroadcast
protected void OnFactionplayableChangedBroadcast(bool factionPlayable)
Definition: SCR_EditableFactionComponent.c:256
~SCR_EditableFactionComponent
void ~SCR_EditableFactionComponent()
Definition: SCR_EditableFactionComponent.c:379
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iTaskCount
protected int m_iTaskCount
Definition: SCR_EditableFactionComponent.c:29
GetFactionIndex
int GetFactionIndex()
Definition: SCR_EditableFactionComponent.c:57
InitSpawnPointCount
protected void InitSpawnPointCount()
Definition: SCR_EditableFactionComponent.c:115
GetFactionTasksCount
int GetFactionTasksCount()
Definition: SCR_EditableFactionComponent.c:277
InitTaskCount
protected void InitTaskCount()
Definition: SCR_EditableFactionComponent.c:180
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
GetPos
override bool GetPos(out vector pos)
Definition: SCR_EditableFactionComponent.c:325
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
GetEntityBudgetCost
override bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
Definition: SCR_EditableFactionComponent.c:331
m_AllowedArsenalItemTypes
protected SCR_EArsenalItemType m_AllowedArsenalItemTypes
Definition: SCR_EditableFactionComponent.c:39
ENotification
ENotification
Definition: ENotification.c:4
GetOnSpawnPointCountChanged
ScriptInvoker GetOnSpawnPointCountChanged()
Definition: SCR_EditableFactionComponent.c:285
SCR_EArsenalItemType
SCR_EArsenalItemType
Definition: SCR_EArsenalItemType.c:2
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_EditableFactionComponent.c:348
SetVisible
void SetVisible(int layer)
Definition: SCR_ServicePointMapDescriptorComponent.c:95
m_aCurrentItemTaken
protected ref map< SCR_EArsenalItemType, int > m_aCurrentItemTaken
Definition: SCR_EditableFactionComponent.c:40
Attribute
SCR_EditableFactionComponentClass SCR_EditableEntityComponentClass Attribute()] protected ref array< ref SCR_ArsenalItemCountConfig > m_MaxCountPerItemType
Special configuration for editable faction.
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_EditableFactionComponent.c:359
GetAllowedArsenalItemTypes
SCR_EArsenalItemType GetAllowedArsenalItemTypes()
Definition: SCR_EditableFactionComponent.c:300
InitTaskCountBroadcast
protected void InitTaskCountBroadcast(int factionTaskCount)
Definition: SCR_EditableFactionComponent.c:195
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_EditableFactionComponent.c:338
Event_OnTaskCountChanged
protected ref ScriptInvoker Event_OnTaskCountChanged
Definition: SCR_EditableFactionComponent.c:36
SetFactionIndexBroadcast
protected void SetFactionIndexBroadcast(int index)
Definition: SCR_EditableFactionComponent.c:64
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_Info
protected ref SCR_UIInfo m_Info
Definition: SCR_EditableFactionComponent.c:25
SetFactionPlayableServer
void SetFactionPlayableServer(bool factionPlayable)
Definition: SCR_EditableFactionComponent.c:239
SCR_UIInfo
Definition: SCR_UIInfo.c:7
GetOnTaskCountChanged
ScriptInvoker GetOnTaskCountChanged()
Definition: SCR_EditableFactionComponent.c:293
SCR_EditableFactionComponentClass
Definition: SCR_EditableFactionComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
CanDuplicate
override bool CanDuplicate(out notnull set< SCR_EditableEntityComponent > outRecipients)
Definition: SCR_EditableFactionComponent.c:313
Faction
Definition: Faction.c:12
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_Global
Definition: Functions.c:6
OnSpawnPointsChanged
protected void OnSpawnPointsChanged(string factionKey)
Definition: SCR_EditableFactionComponent.c:140
m_PrevTask
protected SCR_BaseTask m_PrevTask
Definition: SCR_EditableFactionComponent.c:32
SCR_DelegateFactionManagerComponent
Definition: SCR_DelegateFactionManagerComponent.c:15
m_iFactionIndex
protected int m_iFactionIndex
Definition: SCR_EditableFactionComponent.c:21
OnTasksChanged
protected void OnTasksChanged(notnull SCR_BaseTask task)
Definition: SCR_EditableFactionComponent.c:202
OnTaskCountChangedBroadcast
protected void OnTaskCountChangedBroadcast(int factionTaskCount)
Definition: SCR_EditableFactionComponent.c:228
m_iSpawnPointCount
protected int m_iSpawnPointCount
Definition: SCR_EditableFactionComponent.c:28
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
OnSpawnPointCountChangedBroadcast
protected void OnSpawnPointCountChangedBroadcast(int spawnPointCount)
Definition: SCR_EditableFactionComponent.c:170
SCR_Faction
Definition: SCR_Faction.c:6
m_Faction
protected Faction m_Faction
Definition: SCR_EditableFactionComponent.c:23
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180