Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditablePlayerDelegateComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 }
5 
7 
10 class SCR_EditablePlayerDelegateComponent : SCR_EditableEntityComponent
11 {
12  [RplProp(onRplName: "OnRplPlayerID")]
13  protected int m_iPlayerID = 0;
14 
15  [RplProp(onRplName: "OnRplLimitedEditor")]
16  protected bool m_bHasLimitedEditor;
17 
18  protected SCR_EditableEntityComponent m_ControlledEntity; //--- Don't use RplProp(), controlled entity cannot be found on client using Replication.FindItem() right after being spawned
19 
20  protected ref ScriptInvoker m_OnUIReset = new ScriptInvoker();
21  protected ref ScriptInvoker m_OnLimitedEditorChanged = new ScriptInvoker();
22 
23  //------------------------------------------------------------------------------------------------
28  void InitPlayerDelegate(SCR_EditorManagerEntity editorManager, int playerID)
29  {
30  if (m_iPlayerID != 0) return;
31 
32  m_iPlayerID = playerID;
33  OnRplPlayerID();
34 
35  m_bHasLimitedEditor = editorManager.IsLimited();
36  editorManager.GetOnLimitedChange().Insert(OnEditorLimitedChange); //--- No Remove() later needed - delegate is removed when the manager is
37 
38  Replication.BumpMe();
39  }
40 
41  //------------------------------------------------------------------------------------------------
44  override int GetPlayerID()
45  {
46  return m_iPlayerID;
47  }
48 
49  //------------------------------------------------------------------------------------------------
52  ScriptInvoker GetOnLimitedEditorChanged()
53  {
54  return m_OnLimitedEditorChanged;
55  }
56 
57  //------------------------------------------------------------------------------------------------
61  {
62  return m_bHasLimitedEditor;
63  }
64 
65  //------------------------------------------------------------------------------------------------
68  void SetControlledEntity(IEntity controlledEntity)
69  {
70  RplId entityID = Replication.FindId(SCR_EditableEntityComponent.GetEditableEntity(controlledEntity));
71  SetControlledEntityOwner(entityID);
72  Rpc(SetControlledEntityOwner, entityID);
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
77  protected void SetControlledEntityOwner(RplId entityID)
78  {
79  m_ControlledEntity = SCR_EditableEntityComponent.Cast(Replication.FindItem(entityID));
80  m_OnUIReset.Invoke();
81  }
82 
83  //------------------------------------------------------------------------------------------------
87  {
88  return m_ControlledEntity;
89  }
90 
91  //--- OnRpl methods
92 
93  //------------------------------------------------------------------------------------------------
94  protected void OnRplPlayerID()
95  {
96  if (!SCR_EditorManagerEntity.GetInstance())
97  {
98  //--- Initialized before the editor - wait
100  if (editorManagerCore) editorManagerCore.Event_OnEditorManagerInitOwner.Insert(OnRplPlayerID);
101  return;
102  }
103  else
104  {
106  if (editorManagerCore) editorManagerCore.Event_OnEditorManagerInitOwner.Remove(OnRplPlayerID);
107  }
108 
110  if (delegateManager)
111  delegateManager.RegisterDelegate(this);
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  protected void OnRplLimitedEditor()
116  {
117  m_OnLimitedEditorChanged.Invoke(m_iPlayerID, m_bHasLimitedEditor);
118  }
119 
120  //--- Invokers
121 
122  //------------------------------------------------------------------------------------------------
123  protected void OnEditorLimitedChange(bool isLimited)
124  {
125  m_bHasLimitedEditor = isLimited;
127  Replication.BumpMe();
128  }
129 
130  //--- Overrides
131  override EEditableEntityType GetEntityType(IEntity owner = null)
132  {
133  if (m_ControlledEntity)
134  return m_ControlledEntity.GetEntityType(owner);
135  else
136  return super.GetEntityType(owner);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  override SCR_UIInfo GetInfo(IEntity owner = null)
141  {
142  if (m_ControlledEntity)
143  {
144  SCR_UIInfo info = m_ControlledEntity.GetInfo(owner);
145  return info;
146  }
147  else
148  {
149  return super.GetInfo();
150  }
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  override ScriptInvoker GetOnUIReset()
155  {
156  return m_OnUIReset;
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  override Faction GetFaction()
161  {
162  if (m_ControlledEntity)
163  {
164  Faction faction = m_ControlledEntity.GetFaction();
165  return faction;
166  }
167  else
168  {
169  return null;
170  }
171  }
172 
173  //------------------------------------------------------------------------------------------------
175  {
176  if (m_ControlledEntity)
177  return m_ControlledEntity.GetAIGroup();
178  else
179  return null;
180  }
181 
182  //------------------------------------------------------------------------------------------------
184  {
185  if (m_ControlledEntity)
186  return m_ControlledEntity.GetVehicle();
187  else
188  return null;
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  override float GetHealth()
193  {
194  if (m_ControlledEntity)
195  return m_ControlledEntity.GetHealth();
196  else
197  return 1;
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  override bool GetEntityBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
202  {
203  // Return true and empty cost array, avoid fallback entityType cost
204  return true;
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  override bool GetPos(out vector pos)
209  {
210  if (m_ControlledEntity)
211  return m_ControlledEntity.GetPos(pos);
212  else
213  return false;
214  }
215 
216  //------------------------------------------------------------------------------------------------
217  override string GetLogText(string prefix = "")
218  {
219  return super.GetLogText(prefix) + string.Format(", ctrl: %1", m_ControlledEntity);
220  }
221 
222  //--- JIP on server
223 
224  //------------------------------------------------------------------------------------------------
225  override bool RplSave(ScriptBitWriter writer)
226  {
227  if (!super.RplSave(writer))
228  return false;
229 
230  RplId controlledEntityRplID = Replication.FindId(m_ControlledEntity);
231  writer.WriteRplId(controlledEntityRplID);
232 
233  return true;
234  }
235 
236  //--- JIP on client
237 
238  //------------------------------------------------------------------------------------------------
239  override bool RplLoad(ScriptBitReader reader)
240  {
241  if (!super.RplLoad(reader))
242  return false;
243 
244  RplId controlledEntityRplID;
245  reader.ReadRplId(controlledEntityRplID);
246 
247  SetControlledEntityOwner(controlledEntityRplID);
248  return true;
249  }
250 
251  //------------------------------------------------------------------------------------------------
252  override void OnPostInit(IEntity owner)
253  {
254  super.OnPostInit(owner);
255 
256  owner.SetFlags(EntityFlags.NO_LINK, true);
257  }
258 
259  //------------------------------------------------------------------------------------------------
260  // destructor
262  {
264  if (delegateManager)
265  delegateManager.UnegisterDelegate(this);
266  }
267 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_EditablePlayerDelegateComponent.c:239
GetFaction
override Faction GetFaction()
Definition: SCR_EditablePlayerDelegateComponent.c:160
GetHealth
override float GetHealth()
Definition: SCR_EditablePlayerDelegateComponent.c:192
GetLogText
override string GetLogText(string prefix="")
Definition: SCR_EditablePlayerDelegateComponent.c:217
SCR_EditablePlayerDelegateComponentClass
Definition: SCR_EditablePlayerDelegateComponent.c:2
OnRplLimitedEditor
protected void OnRplLimitedEditor()
Definition: SCR_EditablePlayerDelegateComponent.c:115
GetInfo
override SCR_UIInfo GetInfo(IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:140
HasLimitedEditor
bool HasLimitedEditor()
Definition: SCR_EditablePlayerDelegateComponent.c:60
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetOnUIReset
override ScriptInvoker GetOnUIReset()
Definition: SCR_EditablePlayerDelegateComponent.c:154
OnRplPlayerID
protected void OnRplPlayerID()
Definition: SCR_EditablePlayerDelegateComponent.c:94
SCR_PlayerDelegateEditorComponent
Definition: SCR_PlayerDelegateEditorComponent.c:9
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_EditablePlayerDelegateComponent.c:252
GetPlayerID
override int GetPlayerID()
Definition: SCR_EditablePlayerDelegateComponent.c:44
~SCR_EditablePlayerDelegateComponent
void ~SCR_EditablePlayerDelegateComponent()
Definition: SCR_EditablePlayerDelegateComponent.c:261
GetControlledEntity
SCR_EditableEntityComponent GetControlledEntity()
Returns the controlled entity or null if none.
Definition: SCR_EditablePlayerDelegateComponent.c:86
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SetControlledEntityOwner
protected void SetControlledEntityOwner(RplId entityID)
Definition: SCR_EditablePlayerDelegateComponent.c:77
GetVehicle
override SCR_EditableEntityComponent GetVehicle()
Definition: SCR_EditablePlayerDelegateComponent.c:183
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
GetEntityType
override EEditableEntityType GetEntityType(IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:131
Faction
Definition: Faction.c:12
OnEditorLimitedChange
protected void OnEditorLimitedChange(bool isLimited)
Definition: SCR_EditablePlayerDelegateComponent.c:123
GetPos
override bool GetPos(out vector pos)
Definition: SCR_EditablePlayerDelegateComponent.c:208
GetEntityBudgetCost
override bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:201
m_iPlayerID
SCR_EditorManagerCore m_iPlayerID
RplProp
SCR_EditablePlayerDelegateComponentClass SCR_EditableEntityComponentClass RplProp(onRplName:"OnRplPlayerID")
Definition: SCR_EditablePlayerDelegateComponent.c:12
GetAIGroup
override SCR_EditableEntityComponent GetAIGroup()
Definition: SCR_EditablePlayerDelegateComponent.c:174
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
SetControlledEntity
void SetControlledEntity(IEntity controlledEntity)
Definition: SCR_EditablePlayerDelegateComponent.c:68
GetOnLimitedEditorChanged
ScriptInvoker GetOnLimitedEditorChanged()
Definition: SCR_EditablePlayerDelegateComponent.c:52
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_EditablePlayerDelegateComponent.c:225