Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace coin_pocket_escape
{
public class Config
{
[Description("Toggle forced coin spawns in the beginning of the Round")]
public bool ForcedCoins { get; set; } = true;

[Description("Changes the number of coins that will spawn at the beginning of the match")]
public int ForcedCoinsNumber { get; set; } = 10;

[Description("Set the waiting time after the coin is flipped in ms")]
public int WaitingTime { get; set; } = 2000;

Expand Down
31 changes: 27 additions & 4 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System;
using System.Threading.Tasks;
using Interactables.Interobjects;
using InventorySystem;
using MapGeneration;
using MapGeneration.Distributors;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Core.Zones;
using PluginAPI.Enums;
using UnityEngine;
using PluginAPI.Core.Items;
using FacilityZone = MapGeneration.FacilityZone;
using Object = UnityEngine.Object;
using Random = System.Random;

namespace coin_pocket_escape
Expand All @@ -19,7 +21,7 @@ public class Plugin

[PluginConfig] public Config Config;

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

[PluginPriority(LoadPriority.Highest)]
[PluginEntryPoint("Coin-Pocket-Escape", Version,
Expand All @@ -31,14 +33,35 @@ void LoadPlugin()
PluginAPI.Events.EventManager.RegisterEvents(this);
}

[PluginEvent(ServerEventType.RoundStart)]
public void OnRoundStart()
{
if (Config.ForcedCoins)
{
Random rand = new Random();
var chamberLenght = Object.FindObjectsOfType<LockerChamber>().Length;
var spawnPosition = Object.FindObjectsOfType<LockerChamber>();
for (int i = 0; i < Config.ForcedCoinsNumber; i++)
{
int temp = rand.Next(chamberLenght);
Vector3 lockerPosition = spawnPosition[temp].transform.position;
//Creates the ItemPickup and Spawns the Coin in a random Locker Chamber
ItemPickup coin = ItemPickup.Create(ItemType.Coin, lockerPosition, Quaternion.identity);
coin.Spawn();
Log.Info($"&rLocker position: &6{spawnPosition[temp].transform.position}&r");
}
Log.Info($"&rAll coins spawned&r");
}
}


[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)
{
Expand Down
1 change: 1 addition & 0 deletions coin-pocket-escape.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Content Include="References\Assembly-CSharp-firstpass.dll" />
<Content Include="References\Assembly-CSharp.dll" />
<Content Include="References\Mirror.dll" />
<Content Include="References\mscorlib.dll" />
<Content Include="References\UnityEngine.CoreModule.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down