Skip to content

Commit

Permalink
Merge pull request #6 from leo-ger/4-you-can-still-get-teleported-int…
Browse files Browse the repository at this point in the history
…o-the-void

Fix void teleportation and add result randomization
  • Loading branch information
leo-ger authored Jan 31, 2023
2 parents 3110fda + 8e84b71 commit 88bae9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class Config
{
[Description("Set the waiting time after the coin is flipped in ms")]
public int WaitingTime { get; set; } = 2000;

[Description("Toggle coin success randomization")]
public bool CoinRandom { get; set; } = true;
}
}
36 changes: 26 additions & 10 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Plugin

[PluginConfig] public Config Config;

public const string Version = "1.0.1";
public const string Version = "1.1.0";

[PluginPriority(LoadPriority.Highest)]
[PluginEntryPoint("Coin-Pocket-Escape", Version,
Expand All @@ -44,6 +44,18 @@ public async void OnPlayerCoinFlip(Player player, bool isTails)
{
return;
}

var success = isTails;

// If CoinRandom is enabled, switch up the result randomly
if (Config.CoinRandom)
{
int i = new Random().Next(2);
if (i == 1)
{
success = !isTails;
}
}

player.ReceiveHint("The coin will decide your fate!", 2F);

Expand All @@ -52,41 +64,45 @@ public async void OnPlayerCoinFlip(Player player, bool isTails)

// If isTails and nuke not detonated, the player gets teleported to heavy zone and the coin gets removed
// Only if the player still has a coin in his hand
if (isTails && !AlphaWarheadController.Detonated && player.CurrentItem.ItemTypeId == ItemType.Coin)
if (success && !AlphaWarheadController.Detonated && player.CurrentItem.ItemTypeId == ItemType.Coin)
{
/*
Selecting a room in the HeavyZone to teleport the player.
To prevent teleports to weird rooms, that are way off the map, only rooms with names are possible.
*/
int i = new Random().Next(HeavyZone.Rooms.Count);
while (HeavyZone.Rooms[i].Identifier.Name == RoomName.Unnamed)
while (HeavyZone.Rooms[i].Identifier.Name == RoomName.Unnamed ||
HeavyZone.Rooms[i].Identifier.Name == RoomName.HczTesla ||
HeavyZone.Rooms[i].Identifier.Name == RoomName.HczTestroom)
{
i = new Random().Next(HeavyZone.Rooms.Count);
}
Vector3 vector = HeavyZone.Rooms[i].Position;
vector.y += 1;

Log.Info($"&rPlayer gets teleported to Room &6{i}&r, Position: &6{vector.x}&r, &6{vector.y}&r, " +
$"&6{vector.z}&r.");
Log.Info($"&rPlayer gets teleported to Room &6{HeavyZone.Rooms[i].Identifier.Name}&r, " +
$"Position: &6{vector.x}&r, &6{vector.y}&r, &6{vector.z}&r.");
player.Position = vector;
player.ReceiveHint("You were lucky!", 2F);
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}

// If isTails and nuke detonated, the player gets teleported to surface zone and the coin gets removed
// Only if the player still has a coin in his hand.
else if (isTails && player.CurrentItem.ItemTypeId == ItemType.Coin)
else if (success && player.CurrentItem.ItemTypeId == ItemType.Coin)
{
int i = new Random().Next(SurfaceZone.Rooms.Count);
while (SurfaceZone.Rooms[i].Identifier.Name == RoomName.Unnamed)
while (SurfaceZone.Rooms[i].Identifier.Name == RoomName.Unnamed ||
HeavyZone.Rooms[i].Identifier.Name == RoomName.HczTesla ||
HeavyZone.Rooms[i].Identifier.Name == RoomName.HczTestroom)
{
i = new Random().Next(SurfaceZone.Rooms.Count);
}
Vector3 vector = SurfaceZone.Rooms[i].Position;
vector.y += 1;

Log.Info($"&rPlayer gets teleported to Room &6{i}&r, Position: &6{vector.x}&r, &6{vector.y}&r, " +
$"&6{vector.z}&r.");
Log.Info($"&rPlayer gets teleported to Room &6{HeavyZone.Rooms[i].Identifier.Name}&r, " +
$"Position: &6{vector.x}&r, &6{vector.y}&r, &6{vector.z}&r.");
player.Position = vector;
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}
Expand Down

0 comments on commit 88bae9e

Please sign in to comment.