-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
125 lines (108 loc) · 5.27 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Threading.Tasks;
using Interactables.Interobjects;
using InventorySystem;
using MapGeneration;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Core.Zones;
using PluginAPI.Enums;
using UnityEngine;
using FacilityZone = MapGeneration.FacilityZone;
using Random = System.Random;
namespace coin_pocket_escape
{
public class Plugin
{
public static Plugin Singleton;
[PluginConfig] public Config Config;
public const string Version = "1.1.0";
[PluginPriority(LoadPriority.Highest)]
[PluginEntryPoint("Coin-Pocket-Escape", Version,
"Players have a chance of escaping the pocket dimension when flipping a coin.", "David-Floy,"+
" josqu-john, leo-ger")]
void LoadPlugin()
{
Singleton = this;
PluginAPI.Events.EventManager.RegisterEvents(this);
}
[PluginEvent(ServerEventType.PlayerCoinFlip)]
public async void OnPlayerCoinFlip(Player player, bool isTails)
{
var playerInPocket = (player.Zone == FacilityZone.Other);
Log.Info($"&rPlayer &6{player.Nickname}&r (&6{player.UserId}&r) flipped the coin. Flip result: " +
$"{(isTails ? "tails" : "heads")}. Player is {(playerInPocket ? "in" : "not in")} pocket.");
// If the player is not in the pocket, do nothing
if (!playerInPocket)
{
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);
// Wait to let the coin-flip animation play
await Task.Delay(TimeSpan.FromMilliseconds(Config.WaitingTime));
// 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 (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 ||
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{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 (success && player.CurrentItem.ItemTypeId == ItemType.Coin)
{
int i = new Random().Next(SurfaceZone.Rooms.Count);
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{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);
}
// If the coin is heads, the coin just gets removed and the player stays in the pocket.
// Only if the player still has a coin in his hand.
else if (player.CurrentItem.ItemTypeId == ItemType.Coin)
{
player.ReceiveHint("Looks like you didn't have luck.", 1F);
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}
// If the player doesn't have a coin in his hand anymore, the event is cancelled.
else
{
player.ReceiveHint("Coin flip cancelled!", 1F);
}
}
}
}