Client LuaCsForBarotrauma
TeleportAction.cs
1 namespace Barotrauma;
2 
6 class TeleportAction : EventAction
7 {
8  public enum TeleportPosition { MainSub, Outpost }
9 
10  [Serialize(TeleportPosition.MainSub, IsPropertySaveable.Yes, description: "Should the entity be teleported to the main submarine or the outpost?")]
11  public TeleportPosition Position { get; set; }
12 
13  [Serialize(SpawnType.Human, IsPropertySaveable.Yes, description: "The type of the spawnpoint to teleport the character to.")]
14  public SpawnType SpawnType { get; set; }
15 
16  [Serialize("", IsPropertySaveable.Yes, description: "Optional tag of the spawnpoint.")]
17  public string SpawnPointTag { get; set; }
18 
19  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the target(s) to teleport.")]
20  public Identifier TargetTag { get; set; }
21 
22  private bool isFinished;
23 
24  public TeleportAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
25 
26  public override void Update(float deltaTime)
27  {
28  if (isFinished) { return; }
29  Submarine sub = Position switch
30  {
31  TeleportPosition.MainSub => Submarine.MainSub,
32  TeleportPosition.Outpost => GameMain.GameSession?.Level?.StartOutpost,
33  _ => null
34  };
35  if (WayPoint.GetRandom(spawnType: SpawnType, sub: sub, spawnPointTag: SpawnPointTag) is WayPoint wp)
36  {
37  foreach (var target in ParentEvent.GetTargets(TargetTag))
38  {
39  if (target is Character c)
40  {
41  c.TeleportTo(wp.WorldPosition);
42  }
43  }
44  }
45  isFinished = true;
46  }
47 
48  public override bool IsFinished(ref string goToLabel) => isFinished;
49 
50  public override void Reset() => isFinished = false;
51 }
Teleports a specific entity to a specific spawn point.
override bool IsFinished(ref string goToLabel)
Identifier TargetTag
override void Update(float deltaTime)
TeleportPosition Position
SpawnType SpawnType
override void Reset()
string SpawnPointTag
TeleportAction(ScriptedEvent parentEvent, ContentXElement element)