Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TaskNetworkComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "Handles client > server communication for tasks. Should be attached to PlayerController.", color: "0 0 255 255")]
2 class SCR_TaskNetworkComponentClass : ScriptComponentClass
3 {
4 }
5 
8 {
9  protected static const int INVALID_PLAYER_ID = -1;
10 
11  // Member variables
13  protected RplComponent m_RplComponent;
14 
15  //*********************//
16  //PUBLIC MEMBER METHODS//
17  //*********************//
18 
19  //------------------------------------------------------------------------------------------------
22  void CancelTask(int taskID)
23  {
24  Rpc(RPC_CancelTask, taskID);
25  }
26 
27  //------------------------------------------------------------------------------------------------
30  void AbandonTask(int taskID)
31  {
32  if (m_RplComponent && m_RplComponent.Role() == RplRole.Authority)
33  {
34  // On server we call this just like any other method
36  }
37  else
38  {
39  // Find local task executor
40  SCR_BaseTaskExecutor taskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
41  if (!taskExecutor)
42  return;
43 
44  // Send RPC to server requesting assignment
45  int playerID = SCR_BaseTaskExecutor.GetTaskExecutorID(taskExecutor);
46  Rpc(RPC_AbandonTask, taskID, playerID);
47  }
48  }
49 
50  //------------------------------------------------------------------------------------------------
53  void RequestAssignment(int taskID)
54  {
55  if (m_RplComponent && m_RplComponent.Role() == RplRole.Authority)
56  {
57  // On server we call this just like any other method
59  }
60  else
61  {
62  // Find local task executor
63  SCR_BaseTaskExecutor taskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
64  if (!taskExecutor)
65  return;
66 
67  // Send RPC to server requesting assignment
68  int playerID = SCR_BaseTaskExecutor.GetTaskExecutorID(taskExecutor);
69  Rpc(RPC_RequestAssignment, taskID, playerID);
70  }
71  }
72 
73  //------------------------------------------------------------------------------------------------
78  void AssignTaskToPlayer(int gmID, int taskID, int playerID)
79  {
80  //Check if the player is game master
81  //This check is here in case someone called it even though they're not GM, prevents unncessary RPC sending
82  if (!SCR_EditorManagerEntity.IsLimitedInstance())
83  Rpc(RPC_AssignTaskToPlayer, gmID, taskID, playerID);
84  }
85 
86  //***********//
87  //RPC METHODS//
88  //***********//
89 
90  //------------------------------------------------------------------------------------------------
91  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
92  protected void RPC_AssignTaskToPlayer(int gmID, int taskID, int playerID)
93  {
95  if (!core)
96  {
97  //Player cannot be GM
98  return;
99  }
100 
101  SCR_EditorManagerEntity manager = core.GetEditorManager(gmID);
102  if (!manager || manager.IsLimited())
103  {
104  //Player isn't GM
105  return;
106  }
107 
108  SCR_BaseTaskExecutor assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
109  if (!assignee)
110  return;
111 
112  if (!GetTaskManager())
113  return;
114 
116  if (!supportEntity)
117  return;
118 
119  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
120  if (!task)
121  return;
122 
123  SCR_BaseTask assigneeTask = assignee.GetAssignedTask();
124  if (assigneeTask)
125  supportEntity.UnassignTask(assigneeTask, assignee, SCR_EUnassignReason.GM_REASSIGN);
126 
127  supportEntity.AssignTask(task, assignee, true);
128  }
129 
130  //------------------------------------------------------------------------------------------------
133  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
134  protected void RPC_CancelTask(int taskID)
135  {
136  if (!GetTaskManager())
137  return;
138 
140  if (supportEntity)
141  supportEntity.CancelTask(taskID);
142  }
143 
144  //------------------------------------------------------------------------------------------------
148  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
149  protected void RPC_AbandonTask(int taskID, int playerID)
150  {
151  SCR_BaseTaskExecutor assignee = null;
152 
153  if (playerID == INVALID_PLAYER_ID)
154  assignee = SCR_BaseTaskExecutor.GetLocalExecutor();
155  else
156  assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
157 
158  if (!assignee)
159  return;
160 
161  GetTaskManager().AbandonTask(taskID, assignee);
162  }
163 
164  //------------------------------------------------------------------------------------------------
168  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
169  protected void RPC_RequestAssignment(int taskID, int playerID)
170  {
171  SCR_BaseTaskExecutor assignee = null;
172 
173  if (playerID == INVALID_PLAYER_ID)
174  assignee = SCR_BaseTaskExecutor.GetLocalExecutor();
175  else
176  assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
177 
178  if (!assignee)
179  return;
180 
181  GetTaskManager().RequestAssignment(taskID, assignee);
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  override void EOnInit(IEntity owner)
186  {
187  m_PlayerController = SCR_PlayerController.Cast(PlayerController.Cast(owner));
188 
189  if (!m_PlayerController)
190  {
191  Print("SCR_TaskNetworkComponent must be attached to SCR_PlayerController!", LogLevel.ERROR);
192  return;
193  }
194 
195  m_RplComponent = RplComponent.Cast(m_PlayerController.FindComponent(RplComponent));
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  override void OnPostInit(IEntity owner)
200  {
201  super.OnPostInit(owner);
202  SetEventMask(owner, EntityEvent.INIT);
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  // constructor
207  void SCR_TaskNetworkComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
208  {
209  }
210 }
AssignTaskToPlayer
void AssignTaskToPlayer(int gmID, int taskID, int playerID)
Definition: SCR_TaskNetworkComponent.c:78
SCR_PlayerController
Definition: SCR_PlayerController.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
CancelTask
void CancelTask(int taskID)
Definition: SCR_TaskNetworkComponent.c:22
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
RPC_CancelTask
protected void RPC_CancelTask(int taskID)
Definition: SCR_TaskNetworkComponent.c:134
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_TaskNetworkComponent
void SCR_TaskNetworkComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_TaskNetworkComponent.c:207
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
AbandonTask
void AbandonTask(int taskID)
Definition: SCR_TaskNetworkComponent.c:30
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_TaskNetworkComponent.c:199
m_PlayerController
protected SCR_PlayerController m_PlayerController
Definition: SCR_TaskNetworkComponent.c:12
RPC_RequestAssignment
protected void RPC_RequestAssignment(int taskID, int playerID)
Definition: SCR_TaskNetworkComponent.c:169
RequestAssignment
void RequestAssignment(int taskID)
Definition: SCR_TaskNetworkComponent.c:53
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_TaskNetworkComponent.c:185
RPC_AssignTaskToPlayer
protected void RPC_AssignTaskToPlayer(int gmID, int taskID, int playerID)
Definition: SCR_TaskNetworkComponent.c:92
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
INVALID_PLAYER_ID
SCR_TaskNetworkComponentClass INVALID_PLAYER_ID
Takes care of tasks-specific server <> client communication and requests.
SCR_TaskNetworkComponentClass
Definition: SCR_TaskNetworkComponent.c:2
RPC_AbandonTask
protected void RPC_AbandonTask(int taskID, int playerID)
Definition: SCR_TaskNetworkComponent.c:149
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_TaskNetworkComponent.c:13
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26