Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditablePlayerDelegateComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5
7
10class 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 protected RplId m_EntityID = RplId.Invalid();
20
21 protected ref ScriptInvoker m_OnUIReset = new ScriptInvoker();
22 protected ref ScriptInvoker m_OnLimitedEditorChanged = new ScriptInvoker();
23
24 //------------------------------------------------------------------------------------------------
29 void InitPlayerDelegate(SCR_EditorManagerEntity editorManager, int playerID)
30 {
31 if (m_iPlayerID != 0)
32 return;
33
34 m_iPlayerID = playerID;
36
37 m_bHasLimitedEditor = editorManager.IsLimited();
38 editorManager.GetOnLimitedChange().Insert(OnEditorLimitedChange); //--- No Remove() later needed - delegate is removed when the manager is
39
40 Replication.BumpMe();
41 }
42
43 //------------------------------------------------------------------------------------------------
46 override int GetPlayerID()
47 {
48 return m_iPlayerID;
49 }
50
51 //------------------------------------------------------------------------------------------------
55 {
56 return m_OnLimitedEditorChanged;
57 }
58
59 //------------------------------------------------------------------------------------------------
63 {
64 return m_bHasLimitedEditor;
65 }
66
67 //------------------------------------------------------------------------------------------------
70 void SetControlledEntity(IEntity controlledEntity)
71 {
72 RplId entityID = Replication.FindItemId(SCR_EditableEntityComponent.GetEditableEntity(controlledEntity));
75 }
76
77 //------------------------------------------------------------------------------------------------
78 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
79 protected void SetControlledEntityOwner(RplId entityID)
80 {
81 m_EntityID = entityID;
82 m_ControlledEntity = SCR_EditableEntityComponent.Cast(Replication.FindItem(entityID));
83
84 m_OnUIReset.Invoke();
85 }
86
87 //------------------------------------------------------------------------------------------------
91 {
92 return m_ControlledEntity;
93 }
94
95 //--- OnRpl methods
96
97 //------------------------------------------------------------------------------------------------
98 protected void OnRplPlayerID()
99 {
100 if (!SCR_EditorManagerEntity.GetInstance())
101 {
102 //--- Initialized before the editor - wait
104 if (editorManagerCore)
105 {
106 editorManagerCore.Event_OnEditorManagerInitOwner.Insert(OnRplPlayerID);
107 return;
108 }
109 }
110 else
111 {
113 if (editorManagerCore)
114 editorManagerCore.Event_OnEditorManagerInitOwner.Remove(OnRplPlayerID);
115 }
116
118 if (delegateManager)
119 delegateManager.RegisterDelegate(this);
120 }
121
122 //------------------------------------------------------------------------------------------------
123 protected void OnRplLimitedEditor()
124 {
125 m_OnLimitedEditorChanged.Invoke(m_iPlayerID, m_bHasLimitedEditor);
126 }
127
128 //--- Invokers
129
130 //------------------------------------------------------------------------------------------------
131 protected void OnEditorLimitedChange(bool isLimited)
132 {
133 m_bHasLimitedEditor = isLimited;
135 Replication.BumpMe();
136 }
137
138 //------------------------------------------------------------------------------------------------
139 protected bool FetchControlledEntity()
140 {
141 if (!m_ControlledEntity)
142 {
143 if (m_EntityID == RplId.Invalid())
144 return false;
145
146 m_ControlledEntity = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_EntityID));
147 if (!m_ControlledEntity)
148 return false;
149 }
150
151 return true;
152 }
153
154 //--- Overrides
156 {
157 if (m_ControlledEntity)
158 return m_ControlledEntity.GetEntityType(owner);
159 else
160 return super.GetEntityType(owner);
161 }
162
163 //------------------------------------------------------------------------------------------------
164 override SCR_UIInfo GetInfo(IEntity owner = null)
165 {
167 {
168 SCR_UIInfo info = m_ControlledEntity.GetInfo(owner);
169 return info;
170 }
171 else
172 {
173 return super.GetInfo();
174 }
175 }
176
177 //------------------------------------------------------------------------------------------------
179 {
180 return m_OnUIReset;
181 }
182
183 //------------------------------------------------------------------------------------------------
185 {
186 if (m_iPlayerID > 0)
187 {
188 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
189 if (factionManager)
190 return factionManager.GetPlayerFaction(m_iPlayerID);
191 }
192
193 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(m_Owner.FindComponent(FactionAffiliationComponent));
194 if (factionAffiliation)
195 return factionAffiliation.GetAffiliatedFaction();
196
197 return null;
198 }
199
200 //------------------------------------------------------------------------------------------------
202 {
204 return m_ControlledEntity.GetAIGroup();
205 else
206 return null;
207 }
208
209 //------------------------------------------------------------------------------------------------
211 {
213 return m_ControlledEntity.GetVehicle();
214 else
215 return null;
216 }
217
218 //------------------------------------------------------------------------------------------------
219 override float GetHealth()
220 {
222 return m_ControlledEntity.GetHealth();
223 else
224 return 1;
225 }
226
227 //------------------------------------------------------------------------------------------------
228 override bool GetEntityBudgetCost(out notnull array<ref SCR_EntityBudgetValue> outBudgets, IEntity owner = null)
229 {
230 // Return true and empty cost array, avoid fallback entityType cost
231 return true;
232 }
233
234 //------------------------------------------------------------------------------------------------
235 override bool GetPos(out vector pos)
236 {
238 return m_ControlledEntity.GetPos(pos);
239 else
240 return false;
241 }
242
243 //------------------------------------------------------------------------------------------------
244 override string GetLogText(string prefix = "")
245 {
246 return super.GetLogText(prefix) + string.Format(", ctrl: %1", m_ControlledEntity);
247 }
248
249 //--- JIP on server
250
251 //------------------------------------------------------------------------------------------------
252 override bool RplSave(ScriptBitWriter writer)
253 {
254 if (!super.RplSave(writer))
255 return false;
256
257 RplId controlledEntityRplID = Replication.FindItemId(m_ControlledEntity);
258 writer.WriteRplId(controlledEntityRplID);
259
260 return true;
261 }
262
263 //--- JIP on client
264
265 //------------------------------------------------------------------------------------------------
266 override bool RplLoad(ScriptBitReader reader)
267 {
268 if (!super.RplLoad(reader))
269 return false;
270
271 RplId controlledEntityRplID;
272 reader.ReadRplId(controlledEntityRplID);
273
274 SetControlledEntityOwner(controlledEntityRplID);
275 return true;
276 }
277
278 //------------------------------------------------------------------------------------------------
279 override void OnPostInit(IEntity owner)
280 {
281 super.OnPostInit(owner);
282
283 owner.SetFlags(EntityFlags.NO_LINK, true);
284 }
285
286 //------------------------------------------------------------------------------------------------
287 // destructor
294}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
void ~SCR_EditablePlayerDelegateComponent()
ScriptInvoker GetOnLimitedEditorChanged()
void SetControlledEntityOwner(RplId entityID)
void OnEditorLimitedChange(bool isLimited)
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
override SCR_UIInfo GetInfo()
void SCR_FactionManager(IEntitySource src, IEntity parent)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
SCR_EditableEntityComponent GetVehicle()
static SCR_EditableEntityComponent GetEditableEntity(IEntity owner)
EEditableEntityType GetEntityType(IEntity owner=null)
override bool RplLoad(ScriptBitReader reader)
override bool RplSave(ScriptBitWriter writer)
SCR_UIInfo GetInfo(IEntity owner=null)
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets, IEntity owner=null)
SCR_EditableEntityComponent GetAIGroup()
Core component to manage SCR_EditorManagerEntity.
void RegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
void UnegisterDelegate(SCR_EditablePlayerDelegateComponent delegate)
SCR_EditableEntityComponent GetControlledEntity()
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
SCR_EditorManagerCore m_iPlayerID
void SetControlledEntity(IEntity controlledEntity)
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134