1 [
EntityEditorProps(
category:
"GameScripted/FastTravel", description:
"Handles client > server communication for Fast travel. Should be attached to PlayerController.")]
22 [
Attribute(
"250",
desc:
"How far away from the target destination will player get teleported.",
params:
"0 inf 1")];
25 [
Attribute(
"IEntity",
desc:
"Allowed class name of destination entity (inherited classes are also allowed).")];
28 [
RplProp(condition: RplCondition.OwnerOnly)]
31 static const int SPAWNING_RADIUS = 10;
33 static const float FADE_DURATION = 1.5;
34 static const float BLACKSCREEN_DURATION = 1.0;
35 static const float CLOSE_MAP_DELAY = 0.75;
39 static SCR_FastTravelComponent GetLocalInstance()
41 PlayerController pc =
GetGame().GetPlayerController();
46 return SCR_FastTravelComponent.Cast(pc.FindComponent(SCR_FastTravelComponent));
83 static void ToggleMapDestinationSelection(
bool enable,
bool disableAfterUse =
true)
85 SCR_FastTravelComponent comp = GetLocalInstance();
91 SCR_NotificationsComponent.SendLocal(
ENotification.FASTTRAVEL_AVAILABLE);
93 SCR_NotificationsComponent.SendLocal(
ENotification.FASTTRAVEL_UNAVAILABLE);
95 SCR_MapEntity.GetOnSelectionChanged().Remove(comp.OnSelectionChanged);
101 comp.DisableAfterUse();
103 SCR_MapEntity.GetOnSelectionChanged().Insert(comp.OnSelectionChanged);
118 selectedItem = mapEntity.GetHoveredItem();
123 IEntity entity = selectedItem.Entity();
135 if (player && mapEntity.IsOpen())
140 comp.RemoveHeldGadget();
153 RplId
id = Replication.FindId(entity);
158 RplComponent rpl = RplComponent.Cast(entity.FindComponent(RplComponent));
161 return RplId.Invalid();
177 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
199 Replication.BumpMe();
208 Managed destination = Replication.FindItem(
id);
216 if (destination.IsInherited(IEntity))
217 target = IEntity.Cast(destination);
220 else if (destination.IsInherited(BaseRplComponent))
221 target = BaseRplComponent.Cast(destination).GetEntity();
241 Replication.BumpMe();
245 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
249 ToggleMapDestinationSelection(
false);
254 GetGame().GetCallqueue().CallLater(
FadeOut, CLOSE_MAP_DELAY * 1000);
261 fade.FadeOutEffect(
true, FADE_DURATION);
264 GetGame().GetCallqueue().CallLater(
Teleport, (FADE_DURATION + BLACKSCREEN_DURATION) * 1000);
270 SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(
m_PlayerController.GetControlledEntity());
272 if (player && !player.IsInVehicle() && !player.GetCharacterController().IsDead())
275 SCR_NotificationsComponent.SendLocal(
ENotification.FASTTRAVEL_DONE);
279 fade.FadeOutEffect(
false, FADE_DURATION);
299 vector newPlayerOrigin;
301 newPlayerOrigin[1] = playerOrigin[1];
303 float angle = Math.Atan2(playerOrigin[2] - targetOrigin[2], playerOrigin[0] - targetOrigin[0]);
308 SCR_WorldTools.FindEmptyTerrainPosition(newPlayerOrigin, newPlayerOrigin, SPAWNING_RADIUS);
310 return newPlayerOrigin;
316 super.OnPostInit(owner);
317 SetEventMask(owner, EntityEvent.INIT);
326 Print(
"SCR_FastTravelComponent must be attached to PlayerController!", LogLevel.ERROR);