-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bring back teleporter commands
- Loading branch information
1 parent
22422e6
commit 9b204e4
Showing
6 changed files
with
148 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GameNetcodeStuff; | ||
|
||
[Command("void")] | ||
class VoidCommand : ITeleporter, ICommand { | ||
public async Task Execute(string[] args, CancellationToken cancellationToken) { | ||
if (args.Length is 0) { | ||
Chat.Print("Usage: /void <player>"); | ||
return; | ||
} | ||
|
||
if (Helper.GetActivePlayer(args[0]) is not PlayerControllerB player) { | ||
Chat.Print("Player not found!"); | ||
return; | ||
} | ||
|
||
this.PrepareToTeleport(this.TeleportPlayerToPositionLater( | ||
player, | ||
player.playersManager.notSpawnedPosition.position | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using UnityEngine; | ||
using GameNetcodeStuff; | ||
|
||
public interface ITeleporter { } | ||
|
||
public static class ITeleporterMixin { | ||
public static ShipTeleporter? GetTeleporter(this ITeleporter _) => | ||
Helper.ShipTeleporters.First(teleporter => teleporter is not null && !teleporter.isInverseTeleporter); | ||
|
||
public static bool TeleporterExists(this ITeleporter self) { | ||
HaxObjects.Instance?.ShipTeleporters?.Renew(); | ||
return self.GetTeleporter(); | ||
} | ||
|
||
public static void PrepareToTeleport(this ITeleporter self, Action action) { | ||
Helper.BuyUnlockable(Unlockable.TELEPORTER); | ||
Helper.ReturnUnlockable(Unlockable.TELEPORTER); | ||
Helper.CreateComponent<WaitForBehaviour>() | ||
.SetPredicate(self.TeleporterExists) | ||
.Init(action); | ||
} | ||
|
||
public static Action PlaceAndTeleport( | ||
this ITeleporter self, | ||
PlayerControllerB player, | ||
Vector3 position | ||
) => () => { | ||
HaxObjects.Instance?.ShipTeleporters?.Renew(); | ||
if (self.GetTeleporter() is not ShipTeleporter teleporter) { | ||
Chat.Print("ShipTeleporter not found!"); | ||
return; | ||
} | ||
Transform newTransform = player.transform.Copy(); | ||
newTransform.transform.position = position; | ||
Vector3 rotationOffset = new(-90.0f, 0.0f, 0.0f); | ||
Vector3 positionOffset = new(0.0f, 1.6f, 0.0f); | ||
ObjectPlacement<Transform, ShipTeleporter> teleporterPlacement = new() { | ||
TargetObject = newTransform, | ||
GameObject = teleporter, | ||
PositionOffset = positionOffset, | ||
RotationOffset = rotationOffset | ||
}; | ||
ObjectPlacement<Transform, ShipTeleporter> previousTeleporterPlacement = new() { | ||
TargetObject = teleporter.transform.Copy(), | ||
GameObject = teleporter, | ||
PositionOffset = positionOffset, | ||
RotationOffset = rotationOffset | ||
}; | ||
Helper.CreateComponent<TransientBehaviour>() | ||
.Init(_ => Helper.PlaceObjectAtPosition(teleporterPlacement), 5.0f) | ||
.Dispose(() => Helper.PlaceObjectAtPosition(previousTeleporterPlacement)); | ||
teleporter.PressTeleportButtonServerRpc(); | ||
}; | ||
|
||
public static Action TeleportPlayerToPositionLater( | ||
this ITeleporter self, | ||
PlayerControllerB player, | ||
Vector3 position | ||
) => () => { | ||
Helper.SwitchRadarTarget(player); | ||
Helper.CreateComponent<WaitForBehaviour>() | ||
.SetPredicate(_ => Helper.IsRadarTarget(player.playerClientId)) | ||
.Init(self.PlaceAndTeleport(player, position)); | ||
}; | ||
} |