Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingNetworkComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Building", description: "Handles client > server communication in Building. Should be attached to PlayerController.")]
5
6class SCR_CampaignBuildingNetworkComponent : ScriptComponent
7{
8 //------------------------------------------------------------------------------------------------
12 void AddBuildingValue(int buildingValue, notnull IEntity compositionOutline)
13 {
14 RplComponent comp = RplComponent.Cast(compositionOutline.FindComponent(RplComponent));
15 if (!comp)
16 return;
17
18 Rpc(RpcAsk_AddBuildingValue, buildingValue, comp.Id());
19 }
20
21 //------------------------------------------------------------------------------------------------
25 void RemoveEditorMode(int playerID, IEntity provider)
26 {
27 RplComponent comp = RplComponent.Cast(provider.FindComponent(RplComponent));
28 if (!comp)
29 return;
30
31 Rpc(RpcAsk_RemoveEditorMode, playerID, comp.Id());
32 }
33
34 //------------------------------------------------------------------------------------------------
41 void RequestEnterBuildingMode(IEntity provider, int playerID, bool UserActionActivationOnly, bool UserActionUsed, bool useAllAvailableProviders = false)
42 {
43 RplComponent providerRplComp = RplComponent.Cast(provider.FindComponent(RplComponent));
44 if (!providerRplComp)
45 return;
46
48 if (!owner || playerID != owner.GetPlayerId())
49 return; // requesting building mode for someone esle is not allowed!
50
51 Rpc(RpcAsk_RequestEnterBuildingMode, providerRplComp.Id(), playerID, UserActionActivationOnly, UserActionUsed, useAllAvailableProviders);
52 }
53
54 //------------------------------------------------------------------------------------------------
55 void SetClientLock(bool lock, IEntity provider)
56 {
57 RplComponent comp = RplComponent.Cast(provider.FindComponent(RplComponent));
58 if (!comp)
59 return;
60
61 Rpc(RpcDo_SetClientLock, lock, comp.Id());
62 }
63
64 //------------------------------------------------------------------------------------------------
66 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
67 protected void RpcDo_SetClientLock(bool lock, RplId compId)
68 {
69 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(compId));
70 if (!rplComp)
71 return;
72
73 IEntity provider = rplComp.GetEntity();
74 if (!provider)
75 return;
76
77 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(provider.FindComponent(SCR_CampaignBuildingProviderComponent));
78 if (providerComponent)
79 providerComponent.SetCooldownClientLock(lock);
80 }
81
82 //------------------------------------------------------------------------------------------------
86 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
87 protected void RpcAsk_AddBuildingValue(int buildingValue, RplId compId)
88 {
89 IEntity compositionOutline = GetProviderFormRplId(compId);
90 if (!compositionOutline)
91 return;
92
93 SCR_CampaignBuildingLayoutComponent layoutComponent = SCR_CampaignBuildingLayoutComponent.Cast(compositionOutline.FindComponent(SCR_CampaignBuildingLayoutComponent));
94 if (!layoutComponent)
95 return;
96
97 layoutComponent.AddBuildingValue(buildingValue);
98 }
99
100 //------------------------------------------------------------------------------------------------
104 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
105 protected void RpcAsk_RemoveEditorMode(int playerID, RplId compId)
106 {
107 IEntity provider = GetProviderFormRplId(compId);
108 if (!provider)
109 return;
110
111 BaseGameMode gameMode = GetGame().GetGameMode();
112
113 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
114 if (!buildingManagerComponent)
115 return;
116
117 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(provider.FindComponent(SCR_CampaignBuildingProviderComponent));
118 if (!providerComponent)
119 return;
120
121 bool isActiveUser = buildingManagerComponent.RemovePlayerIdFromProvider(playerID, providerComponent);
122 buildingManagerComponent.RemoveProvider(playerID, providerComponent, isActiveUser);
123 }
124
125 //------------------------------------------------------------------------------------------------
132 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
133 protected void RpcAsk_RequestEnterBuildingMode(RplId rplProviderId, int playerID, bool UserActionActivationOnly, bool UserActionUsed, bool useAllAvailableProviders)
134 {
136 if (!owner || playerID != owner.GetPlayerId())
137 return;
138
139 IEntity provider = GetProviderFormRplId(rplProviderId);
140 if (!provider)
141 return;
142
143 BaseGameMode gameMode = GetGame().GetGameMode();
144 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
145 if (!buildingManagerComponent)
146 return;
147
148 buildingManagerComponent.EnterEditorMode(playerID, provider, UserActionActivationOnly, UserActionUsed, useAllAvailableProviders);
149 }
150
151 //------------------------------------------------------------------------------------------------
157
158 //------------------------------------------------------------------------------------------------
159 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
161 {
163 if (!core)
164 return;
165
166 PlayerController playerController = PlayerController.Cast(GetOwner());
167 SCR_EditorManagerEntity editorManager = core.GetEditorManager(playerController.GetPlayerId());
168 if (!editorManager)
169 return;
170
171 SCR_EditorModeEntity modeEntity = editorManager.FindModeEntity(EEditorMode.BUILDING);
172 if (!modeEntity)
173 {
174 editorManager.Close();
175 return;
176 }
177
178 SCR_CampaignBuildingEditorComponent buildingComp = SCR_CampaignBuildingEditorComponent.Cast(modeEntity.FindComponent(SCR_CampaignBuildingEditorComponent));
179 if (buildingComp)
180 {
181 buildingComp.SendProviders_S();
182 }
183 else
184 {
185 editorManager.Close();
186 return;
187 }
188 }
189
190 //------------------------------------------------------------------------------------------------
193 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
194 protected void RpcAsk_AddXPReward(int playerId)
195 {
196 BaseGameMode gameMode = GetGame().GetGameMode();
197 if (!gameMode)
198 return;
199
200 SCR_XPHandlerComponent compXP = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
201 if (!compXP)
202 return;
203
204 compXP.AwardXP(playerId, SCR_EXPRewards.FREE_ROAM_BUILDING_BUILT);
205 }
206
207 //------------------------------------------------------------------------------------------------
210 void AddXPReward(int playerId)
211 {
212 Rpc(RpcAsk_AddXPReward, playerId);
213 }
214
215 //------------------------------------------------------------------------------------------------
219 {
220 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(rplProviderId));
221 if (!rplComp)
222 return null;
223
224 return rplComp.GetEntity();
225 }
226}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void AddBuildingValue(int value)
void RpcAsk_AddXPReward(int playerId)
void RpcAsk_RequestEnterBuildingMode(RplId rplProviderId, int playerID, bool UserActionActivationOnly, bool UserActionUsed, bool useAllAvailableProviders)
void RpcDo_SetClientLock(bool lock, RplId compId)
Set a cooldown lock on client.
void RpcAsk_RemoveEditorMode(int playerID, RplId compId)
void RpcAsk_RequestBuildModeProvider()
void RemoveEditorMode(int playerID, IEntity provider)
void RequestEnterBuildingMode(IEntity provider, int playerID, bool UserActionActivationOnly, bool UserActionUsed, bool useAllAvailableProviders=false)
IEntity GetProviderFormRplId(RplId rplProviderId)
void RequestBuildModeProvider()
Client method which asks the server for the information about providers used for by current build mod...
void RpcAsk_AddBuildingValue(int buildingValue, RplId compId)
void SetClientLock(bool lock, IEntity provider)
void AddXPReward()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SCR_EditorManagerEntity(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 Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
Core component to manage SCR_EditorManagerEntity.
SCR_EditorManagerEntity GetEditorManager()
proto external GenericEntity GetOwner()
Get owner entity.
EEditorMode
Editor mode that defines overall functionality.
Definition EEditorMode.c:6
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