refactor
This commit is contained in:
@@ -1,35 +1,34 @@
|
||||
using System.Drawing;
|
||||
using CommandSystem.Commands.RemoteAdmin.Inventory;
|
||||
using Interactables.Interobjects.DoorUtils;
|
||||
using Interactables.Interobjects.DoorUtils;
|
||||
using InventorySystem.Items;
|
||||
using LabApi.Events.Arguments.PlayerEvents;
|
||||
using LabApi.Events.Arguments.ServerEvents;
|
||||
using LabApi.Events.Handlers;
|
||||
using LabApi.Features;
|
||||
using LabApi.Features.Console;
|
||||
using LabApi.Loader.Features.Plugins;
|
||||
using PlayerRoles;
|
||||
using LabApi.Features.Wrappers;
|
||||
using LabApi.Loader.Features.Plugins;
|
||||
using MapGeneration;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
using MEC;
|
||||
using PlayerRoles;
|
||||
using UnityEngine;
|
||||
using Logger = LabApi.Features.Console.Logger;
|
||||
using Random = System.Random;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
namespace CustomClasses;
|
||||
|
||||
public class CustomClasses : Plugin
|
||||
{
|
||||
private readonly CustomClassManager _classManager = new();
|
||||
public override string Name => "CustomClasses";
|
||||
public override string Author => "Code002Lover";
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override string Description => "Adds custom classes to the game";
|
||||
public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
|
||||
|
||||
|
||||
public JanitorConfig JanitorConfig { get; set; } = new();
|
||||
public ResearchSubjectConfig ResearchSubjectConfig { get; set; } = new();
|
||||
public HeadGuardConfig HeadGuardConfig { get; set; } = new();
|
||||
|
||||
private readonly CustomClassManager _classManager = new();
|
||||
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
PlayerEvents.Spawned += OnPlayerSpawned;
|
||||
@@ -46,21 +45,21 @@ public class CustomClasses : Plugin
|
||||
{
|
||||
_classManager.ResetSpawnStates();
|
||||
}
|
||||
|
||||
|
||||
private void OnPlayerSpawned(PlayerSpawnedEventArgs ev)
|
||||
{
|
||||
if(_classManager.TryHandleSpawn(ev.Player, JanitorConfig, typeof(JanitorConfig))) return;
|
||||
if(_classManager.TryHandleSpawn(ev.Player, ResearchSubjectConfig, typeof(ResearchSubjectConfig))) return;
|
||||
if(_classManager.TryHandleSpawn(ev.Player, HeadGuardConfig, typeof(HeadGuardConfig))) return;
|
||||
if (_classManager.TryHandleSpawn(ev.Player, JanitorConfig, typeof(JanitorConfig))) return;
|
||||
if (_classManager.TryHandleSpawn(ev.Player, ResearchSubjectConfig, typeof(ResearchSubjectConfig))) return;
|
||||
if (_classManager.TryHandleSpawn(ev.Player, HeadGuardConfig, typeof(HeadGuardConfig))) return;
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomClassManager
|
||||
{
|
||||
private readonly Dictionary<Type, ICustomClassHandler> _handlers = new();
|
||||
private readonly object _lock = new();
|
||||
private readonly Random _random = new();
|
||||
private readonly Dictionary<Type, SpawnState> _spawnStates = new();
|
||||
private readonly Dictionary<Type, ICustomClassHandler> _handlers = new();
|
||||
|
||||
public CustomClassManager()
|
||||
{
|
||||
@@ -69,10 +68,10 @@ public class CustomClassManager
|
||||
RegisterHandler<ResearchSubjectConfig>(new ResearchSubjectHandler(this));
|
||||
RegisterHandler<HeadGuardConfig>(new HeadGuardHandler(this));
|
||||
}
|
||||
|
||||
|
||||
public void TeleportPlayerToAround(Player player, Vector3 position)
|
||||
{
|
||||
player.Position = position + new Vector3(0,1,0) + new Vector3((float)(_random.NextDouble() * 2), 0,
|
||||
player.Position = position + new Vector3(0, 1, 0) + new Vector3((float)(_random.NextDouble() * 2), 0,
|
||||
(float)(_random.NextDouble() * 2));
|
||||
}
|
||||
|
||||
@@ -90,10 +89,7 @@ public class CustomClassManager
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var key in _spawnStates.Keys.ToList())
|
||||
{
|
||||
_spawnStates[key] = new SpawnState();
|
||||
}
|
||||
foreach (var key in _spawnStates.Keys.ToList()) _spawnStates[key] = new SpawnState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,13 +114,10 @@ public class CustomClassManager
|
||||
}
|
||||
|
||||
state.Spawns++;
|
||||
|
||||
|
||||
Logger.Debug($"Player spawning {configType} - {player.Nickname} - {state.Spawns} / {config.MaxSpawns}");
|
||||
|
||||
if (_handlers.TryGetValue(configType, out var handler))
|
||||
{
|
||||
return handler.HandleSpawn(player, config, _random);
|
||||
}
|
||||
|
||||
if (_handlers.TryGetValue(configType, out var handler)) return handler.HandleSpawn(player, config, _random);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -144,12 +137,13 @@ public class JanitorHandler(CustomClassManager manager) : ICustomClassHandler
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
{
|
||||
manager.TeleportPlayerToAround(player, scp914.Position);
|
||||
|
||||
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
|
||||
player.SendBroadcast("You're a <color=#A0A0A0>Janitor</color>!", 3);
|
||||
});
|
||||
|
||||
@@ -165,12 +159,13 @@ public class ResearchSubjectHandler(CustomClassManager manager) : ICustomClassHa
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
{
|
||||
manager.TeleportPlayerToAround(player, scientist.Position);
|
||||
|
||||
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
|
||||
player.SendBroadcast("You're a <color=#944710>Research Subject</color>!", 3);
|
||||
});
|
||||
|
||||
@@ -185,20 +180,21 @@ public class HeadGuardHandler(CustomClassManager manager) : ICustomClassHandler
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
{
|
||||
player.RemoveItem(ItemType.KeycardGuard);
|
||||
|
||||
KeycardItem.CreateCustomKeycardTaskForce(player, "Head Guard Keycard", $"HG. {player.Nickname}", new KeycardLevels(1,1,2),UnityEngine.Color.blue,UnityEngine.Color.cyan, "1", 0);
|
||||
|
||||
KeycardItem.CreateCustomKeycardTaskForce(player, "Head Guard Keycard", $"HG. {player.Nickname}",
|
||||
new KeycardLevels(1, 1, 2), Color.blue, Color.cyan, "1", 0);
|
||||
|
||||
player.AddItem(ItemType.Adrenaline, ItemAddReason.StartingItem);
|
||||
|
||||
|
||||
player.RemoveItem(ItemType.ArmorLight);
|
||||
player.AddItem(ItemType.ArmorCombat, ItemAddReason.StartingItem);
|
||||
|
||||
|
||||
player.RemoveItem(ItemType.GunFSP9);
|
||||
|
||||
var pickup = Pickup.Create(ItemType.GunCrossvec, Vector3.one);
|
||||
|
||||
if (pickup != null) player.AddItem(pickup);
|
||||
|
||||
|
||||
player.SetAmmo(ItemType.Ammo9x19, 120);
|
||||
|
||||
player.SendBroadcast("You're a <color=#00B7EB>Head Guard</color>!", 3);
|
||||
|
||||
Reference in New Issue
Block a user