Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignFastTravelComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/FastTravel", description: "Handles client > server communication for Fast travel in Conflict. Should be attached to PlayerController.")]
3{
4 [Attribute("50", params: "0 inf 1")]
5 protected int m_iSupplyCost;
6
7 [Attribute("100", desc: "Tolerance when player identifies their location in the map (meters)", params: "0 inf 1")]
8 protected int m_iPickupRadius;
9
10 [Attribute("200", desc: "If there are enemies closer that this distance to the player, the request will fail", params: "0 inf 1")]
11 protected int m_iNoEnemyRadius;
12
13 //------------------------------------------------------------------------------------------------
16 {
17 return m_iSupplyCost;
18 }
19
20 //------------------------------------------------------------------------------------------------
23 {
24 return m_iPickupRadius;
25 }
26
27 //------------------------------------------------------------------------------------------------
30 {
31 return m_iNoEnemyRadius;
32 }
33}
34
35class SCR_CampaignFastTravelComponent : SCR_FastTravelComponent
36{
37 protected bool m_bSelectionInProgress;
38 protected bool m_bEnemiesNearby;
39
41
43
45
47
48 //------------------------------------------------------------------------------------------------
49 override protected bool ServerSanityCheck(notnull IEntity target)
50 {
51 if (!super.ServerSanityCheck(target))
52 return false;
53
54 SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
55
56 if (!player)
57 return false;
58
59 if (!m_PlayerFaction)
60 m_PlayerFaction = SCR_CampaignFaction.Cast(player.GetFaction());
61
63
64 if (!componentData)
65 return false;
66
67 m_bEnemiesNearby = false;
68 GetGame().GetWorld().QueryEntitiesBySphere(player.GetOrigin(), componentData.GetNoEnemyRadius(), ProcessEntity, FilterEntity, EQueryEntitiesFlags.DYNAMIC | EQueryEntitiesFlags.WITH_OBJECT);
69
71 SCR_NotificationsComponent.SendToPlayer(m_PlayerController.GetPlayerId(), ENotification.FASTTRAVEL_ENEMIES_NEARBY);
72
73 return !m_bEnemiesNearby;
74 }
75
76
77 //------------------------------------------------------------------------------------------------
78 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
79 protected void RpcAsk_CheckSpawnpointAvailability(RplId spawnpointId)
80 {
82
83 if (!spawnpoint)
84 return;
85
86 if (spawnpoint.GetRespawnCount() >= spawnpoint.GetMaxRespawns())
87 return;
88
89 Rpc(RpcDo_EnableDestination, spawnpointId);
90 }
91
92 //------------------------------------------------------------------------------------------------
93 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
94 protected void RpcDo_EnableDestination(RplId spawnpointId)
95 {
97
98 if (!spawnpoint)
99 return;
100
101 SCR_SelectionMenuEntry entry = SCR_MapHelper<SCR_SelectionMenuEntry, SCR_DeployableSpawnPoint>.GetKeyByValue(m_mMenuEntries,spawnpoint);
102
103 if (!entry)
104 return;
105
106 entry.SetName("#AR-MapMarker_DeployedRadio");
107 entry.Enable(true);
108 }
109
110 //------------------------------------------------------------------------------------------------
112 override protected int GetCooldown()
113 {
114 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
115
116 if (!fManager)
117 return m_iCooldown;
118
119 IEntity player = m_PlayerController.GetControlledEntity();
120
121 if (!player)
122 return m_iCooldown;
123
124 return fManager.GetRankFastTravelCooldown(SCR_CharacterRankComponent.GetCharacterRank(player), m_PlayerController.GetPlayerId());
125 }
126
127 //------------------------------------------------------------------------------------------------
128 protected bool FilterEntity(IEntity ent)
129 {
130 return SCR_ChimeraCharacter.Cast(ent) != null;
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected bool ProcessEntity(IEntity ent)
135 {
136 SCR_ChimeraCharacter char = SCR_ChimeraCharacter.Cast(ent);
137 Faction entityFaction = char.GetFaction();
138
139 if (!entityFaction.IsFactionEnemy(m_PlayerFaction))
140 return true;
141
142 if (char.GetCharacterController().IsDead())
143 return true;
144
145 m_bEnemiesNearby = true;
146 return false;
147 }
148
149 //------------------------------------------------------------------------------------------------
152 {
155
157 return;
158
159 m_MapContextualMenu.GetOnMenuInitInvoker().Insert(SetupMapRadialMenuEntries);
160 m_MapContextualMenu.GetOnEntryPerformedInvoker().Insert(OnMapFastTravelRequested);
161 m_MapContextualMenu.GetOnEntrySelectedInvoker().Insert(CenterMapOnDestination);
162
164 }
165
166 //------------------------------------------------------------------------------------------------
169 {
170 SCR_SpawnPoint.Event_SpawnPointAdded.Remove(OnSpawnpointAdded);
171 SCR_SpawnPoint.Event_SpawnPointRemoved.Remove(OnSpawnpointRemoved);
172
175
176 GetGame().GetCallqueue().Remove(RefreshShownCooldown);
177
178 SCR_HintManagerComponent.HideHint();
179
181 SCR_NotificationsComponent.SendLocal(ENotification.FASTTRAVEL_PLAYER_LOCATION_CANCELLED);
182
184
186 return;
187
188 m_MapContextualMenu.GetOnMenuInitInvoker().Remove(SetupMapRadialMenuEntries);
189 m_MapContextualMenu.GetOnEntryPerformedInvoker().Remove(OnMapFastTravelRequested);
190 m_MapContextualMenu.GetOnEntrySelectedInvoker().Remove(CenterMapOnDestination);
191 }
192
193 //------------------------------------------------------------------------------------------------
194 protected void OnMapFastTravelRequested(SCR_SelectionMenuEntry element, float[] worldPos)
195 {
196 SCR_DeployableSpawnPoint spawnpoint = m_mMenuEntries.Get(element);
197
198 if (!spawnpoint)
199 return;
200
201 SCR_CampaignFeedbackComponent feedbackComp = SCR_CampaignFeedbackComponent.GetInstance();
202
203 if (feedbackComp)
204 feedbackComp.ShowHint(EHint.CONFLICT_TRANSPORT_PICKUP, true, true);
205
207 SetDestination(FindDestinationId(spawnpoint), string.Empty);
208
211 }
212
213 //------------------------------------------------------------------------------------------------
215 {
217 SCR_HintManagerComponent.HideHint();
218
220
222 return;
223
224 IEntity player = m_PlayerController.GetControlledEntity();
225
226 if (!player)
227 return;
228
230
231 if (!mapEntity)
232 return;
233
235
236 if (!componentData)
237 return;
238
239 if (player && mapEntity.IsOpen())
240 {
242
243 if (comp)
244 comp.RemoveHeldGadget();
245 }
246
247 float x, y;
248 mapEntity.ScreenToWorld(coords[0], coords[2], x, y);
249 coords[0] = x;
250 coords[2] = y;
251
252 if (vector.DistanceXZ(player.GetOrigin(), coords) > componentData.GetPickupRadius())
253 {
254 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.ACTION_FAILED);
255 SCR_NotificationsComponent.SendLocal(ENotification.FASTTRAVEL_PLAYER_LOCATION_WRONG);
256 return;
257 }
258
259 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_MAP_CLICK_POINT_ON);
260 FastTravel();
261 }
262
263 //------------------------------------------------------------------------------------------------
265 {
266 m_mMenuEntries.Clear();
267
269 return;
270
271 // Parent for fast travel radial menu entries
272 m_MainEntry = m_MapContextualMenu.AddRadialCategory("#AR-Tasks_TitleTransport");
273 m_MainEntry.SetIconFromDeafaultImageSet("terrainIcon");
275 bool available = RefreshMainEntry();
276
277 if (!available)
278 return;
279
280 SCR_SpawnPoint.Event_SpawnPointAdded.Insert(OnSpawnpointAdded);
281 SCR_SpawnPoint.Event_SpawnPointRemoved.Insert(OnSpawnpointRemoved);
282
283 if (m_mMenuEntries.IsEmpty())
284 {
285 m_MainEntry.Enable(false);
286 return;
287 }
288
290 }
291
292 //------------------------------------------------------------------------------------------------
293 protected bool RefreshMainEntry()
294 {
295 ChimeraWorld world = GetGame().GetWorld();
296 WorldTimestamp timestamp = world.GetServerTimestamp();
297
298 // Disable fast travel entry if its cooldown is still in progress
299 bool cooldownDone = !m_fNextTravelAvailableAt || timestamp.GreaterEqual(m_fNextTravelAvailableAt);
300 m_MainEntry.SetName("#AR-Tasks_TitleTransport");
301 m_MainEntry.Enable(cooldownDone);
302
303 SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
304
305 if (!player)
306 return false;
307
308 SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
309 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
310
311 if (player.IsInVehicle())
312 {
313 m_MainEntry.Enable(false);
314 m_MainEntry.SetName(string.Empty);
315 return false;
316 }
317
318 // Disable fast travel entry if player is renegade
319 if (fManager && fManager.GetFactionRanks(m_PlayerController.GetPlayerId()).IsRankRenegade(SCR_CharacterRankComponent.GetCharacterRank(player)))
320 {
321 m_MainEntry.Enable(false);
322 m_MainEntry.SetName("#AR-Rank_Renegade");
323 return false;
324 }
325
326 // Disable fast travel entry if player is carrying a radio backpack
327 EquipedLoadoutStorageComponent loadoutStorage = EquipedLoadoutStorageComponent.Cast(player.FindComponent(EquipedLoadoutStorageComponent));
328
329 if (loadoutStorage)
330 {
331 IEntity backpack = loadoutStorage.GetClothFromArea(LoadoutBackpackArea);
332
333 if (backpack && BaseRadioComponent.Cast(backpack.FindComponent(BaseRadioComponent)))
334 {
335 m_MainEntry.Enable(false);
336 m_MainEntry.SetName("#AR-ArsenalItemType_RadioBackpack_Name");
337 return false;
338 }
339 }
340
341 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(player);
342
343 if (resourceComponent)
344 {
345 SCR_ResourceConsumer consumer = resourceComponent.GetConsumer(EResourceGeneratorID.SELF, EResourceType.SUPPLIES);
346
347 if (consumer)
348 {
349 //Print(consumer.GetAggregatedResourceValue());
350 }
351 }
352
353 if (campaign && !campaign.GetBaseManager().IsEntityInFactionRadioSignal(player, player.GetFaction()))
354 {
355 m_MainEntry.Enable(false);
356 m_MainEntry.SetName("#AR-Campaign_NoRadioSignal");
357 return false;
358 }
359
360 if (!cooldownDone)
361 GetGame().GetCallqueue().CallLater(RefreshShownCooldown, SCR_GameModeCampaign.UI_UPDATE_DELAY, true);
362
363 return cooldownDone;
364 }
365
366 //------------------------------------------------------------------------------------------------
367 protected void CenterMapOnDestination(SCR_SelectionMenuEntry entry, int id)
368 {
369 if (!entry)
370 return;
371
372 SCR_DeployableSpawnPoint spawnpoint = m_mMenuEntries.Get(entry);
373
374 if (!spawnpoint)
375 return;
376
378
379 if (!mapEntity || !mapEntity.IsOpen())
380 return;
381
382 vector spawnpointPos = spawnpoint.GetOrigin();
383 float x, y;
384 mapEntity.WorldToScreen(spawnpointPos[0], spawnpointPos[2], x, y);
385 mapEntity.PanSmooth(x, y);
386 }
387
388 //------------------------------------------------------------------------------------------------
389 protected void ComposeDestinationList()
390 {
391 array<SCR_SpawnPoint> spawnpoints = SCR_SpawnPoint.GetSpawnPoints();
393 int playerId = m_PlayerController.GetPlayerId();
394
395 foreach (SCR_SpawnPoint spawnpoint : spawnpoints)
396 {
397 radioSpawnpoint = SCR_RestrictedDeployableSpawnPoint.Cast(spawnpoint);
398
399 if (!radioSpawnpoint || !radioSpawnpoint.IsSpawnPointVisibleForPlayer(playerId))
400 continue;
401
402 SCR_SelectionMenuEntry newEntry = m_MapContextualMenu.AddRadialEntry("#AR-DeployableSpawnPoints_MapIconName", m_MainEntry);
403 m_mMenuEntries.Set(newEntry, radioSpawnpoint);
404 newEntry.SetIconFromDeafaultImageSet("VON_radio");
405 newEntry.SetName("#AR-DeployMenu_DisabledSpawnPointReason_OutOfRespawns");
406 newEntry.Enable(false);
407 }
408 }
409
410 //------------------------------------------------------------------------------------------------
411 protected void RefreshDestinationList()
412 {
413 SCR_DeployableSpawnPoint radioSpawnpoint;
414
415 for (int i = 0, count = m_mMenuEntries.Count(); i < count; i++)
416 {
417 radioSpawnpoint = m_mMenuEntries.GetElement(i);
418
419 if (!radioSpawnpoint)
420 continue;
421
423 }
424 }
425
426 //------------------------------------------------------------------------------------------------
427 protected void RefreshShownCooldown()
428 {
429 ChimeraWorld world = GetGame().GetWorld();
430 WorldTimestamp timestamp = world.GetServerTimestamp();
431 Widget radialRoot = m_MapContextualMenu.GetRadialDisplay().GetRootWidget();
432 SCR_SelectionMenuEntry currentEntry = m_MapContextualMenu.GetRadialController().GetRadialMenu().GetSelectionEntry();
433
434 if (!m_fNextTravelAvailableAt || timestamp.GreaterEqual(m_fNextTravelAvailableAt))
435 {
436 // Cooldown finished, re-enable fast travel
437 GetGame().GetCallqueue().Remove(RefreshShownCooldown);
440 }
441 else
442 {
443 // Update timer
444 m_MainEntry.Enable(false);
445 m_MainEntry.SetName(SCR_FormatHelper.GetTimeFormatting(m_fNextTravelAvailableAt.DiffMilliseconds(timestamp) * 0.001, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS));
446
447 if (currentEntry == m_MainEntry)
448 m_MainEntry.SetNameTo(TextWidget.Cast(radialRoot.FindAnyWidget("InfoName")));
449 }
450 }
451
452 //------------------------------------------------------------------------------------------------
453 protected void OnSpawnpointRemoved(SCR_SpawnPoint spawnpoint)
454 {
455 }
456
457 //------------------------------------------------------------------------------------------------
458 protected void OnSpawnpointAdded(SCR_SpawnPoint spawnpoint)
459 {
460 }
461
462 //------------------------------------------------------------------------------------------------
463 protected void ToggleDestinationSelection(bool enable)
464 {
465 bool updateCursor = (m_bSelectionInProgress != enable);
466 m_bSelectionInProgress = enable;
467
468 if (!updateCursor)
469 return;
470
472
473 if (!mapEntity)
474 return;
475
476 SCR_MapCursorModule module = SCR_MapCursorModule.Cast(mapEntity.GetMapModule(SCR_MapCursorModule));
477
478 if (!module)
479 return;
480
481 module.ToggleFastTravelDestinationSelection(enable);
482 }
483
484 //------------------------------------------------------------------------------------------------
488 {
489 IEntity destination = GetEntityByDestinationId(id);
490
491 if (!destination)
492 return false;
493
494 return !ChimeraWorldUtils.TryGetWaterSurfaceSimple(GetGame().GetWorld(), CalculateDestinationVector(destination));
495 }
496
497 //------------------------------------------------------------------------------------------------
501 {
502 if (destination == vector.Zero)
503 return false;
504
505 return !ChimeraWorldUtils.TryGetWaterSurfaceSimple(GetGame().GetWorld(), CalculateDestinationVector(destination));
506 }
507
508 //------------------------------------------------------------------------------------------------
509 override void EOnInit(IEntity owner)
510 {
511 super.EOnInit(owner);
512
514 return;
515
517 }
518}
EHint
Definition EHint.c:11
ENotification
ETimeFormatParam
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref array< string > coords
SCR_CharacterControllerComponent GetCharacterController()
void ComposeDestinationList()
int GetCooldown()
Reads the cooldown value from player's rank.
bool FilterEntity(IEntity ent)
void SendPlayerCoords(vector coords)
void ToggleDestinationSelection(bool enable)
ref map< SCR_SelectionMenuEntry, SCR_DeployableSpawnPoint > m_mMenuEntries
void RefreshDestinationList()
bool IsDestinationReachable(RplId id)
void CenterMapOnDestination(SCR_SelectionMenuEntry entry, int id)
void RpcAsk_CheckSpawnpointAvailability(RplId spawnpointId)
void OnSpawnpointAdded(SCR_SpawnPoint spawnpoint)
SCR_CampaignFastTravelComponentClass m_bSelectionInProgress
void RpcDo_EnableDestination(RplId spawnpointId)
void RefreshShownCooldown()
void OnSpawnpointRemoved(SCR_SpawnPoint spawnpoint)
SCR_CampaignFaction m_PlayerFaction
SCR_SelectionMenuCategoryEntry m_MainEntry
bool ProcessEntity(IEntity ent)
void SetupMapRadialMenuEntries()
void OnMapFastTravelRequested(SCR_SelectionMenuEntry element, float[] worldPos)
bool ServerSanityCheck(notnull IEntity target)
void OnMapClose(MapConfiguration config)
void OnMapOpen(MapConfiguration config)
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void SetDestination(RplId id, string name)
Destination must be a replicated item with valid RplId.
vector CalculateDestinationVector(notnull IEntity destination)
RplId FindDestinationId(IEntity entity)
void FastTravel()
SCR_FastTravelComponentClass m_PlayerController
IEntity GetEntityByDestinationId(RplId id)
WorldTimestamp m_fNextTravelAvailableAt
int m_iCooldown
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
SCR_MapRadialUI m_MapContextualMenu
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
Replication item identifier.
Definition RplId.c:14
static SCR_GadgetManagerComponent GetGadgetManager(IEntity entity)
void RemoveHeldGadget()
Remove gadget held in hand.
SCR_MapModuleBase GetMapModule(typename moduleType)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapClose()
Get on map close invoker.
static ScriptInvokerVector GetOnSelection()
Get on selection invoker.
void ScreenToWorld(int screenPosX, int screenPosY, out float worldX, out float worldY)
Use scaled screen coords to get canvas world coords, flips the y-axis.
void WorldToScreen(float worldX, float worldY, out int screenPosX, out int screenPosY, bool withPan=false)
Use canvas world coords to get DPIscaled screen coords, flips the y-axis.
void PanSmooth(float panX, float panY, float panTime=0.25)
bool IsOpen()
Check if the map is opened.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
static SCR_MapEntity GetMapInstance()
Get map entity instance.
2D map radial menu UI
static SCR_MapRadialUI GetInstance()
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
Basically SCR_SpawnPoint with the ability to limit respawn amount.
void SetName(string name)
void Enable(bool enable)
void SetIconFromDeafaultImageSet(string imageSetName="")
Spawn point entity defines positions on which players can possibly spawn.
Definition Types.c:486
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
proto external bool IsDead()
SCR_FieldOfViewSettings Attribute
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
EQueryEntitiesFlags