Add Template, more custom classes & fix issues
This commit is contained in:
+120
-49
@@ -1,5 +1,6 @@
|
||||
using Interactables.Interobjects.DoorUtils;
|
||||
using InventorySystem.Items;
|
||||
using InventorySystem.Items.Firearms.Modules;
|
||||
using LabApi.Events.Arguments.PlayerEvents;
|
||||
using LabApi.Events.Arguments.ServerEvents;
|
||||
using LabApi.Events.Handlers;
|
||||
@@ -28,11 +29,30 @@ public class CustomClasses : Plugin
|
||||
public JanitorConfig JanitorConfig { get; set; } = new();
|
||||
public ResearchSubjectConfig ResearchSubjectConfig { get; set; } = new();
|
||||
public HeadGuardConfig HeadGuardConfig { get; set; } = new();
|
||||
public MedicConfig MedicConfig { get; set; } = new();
|
||||
public GamblerConfig GamblerConfig { get; set; } = new();
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
PlayerEvents.Spawned += OnPlayerSpawned;
|
||||
ServerEvents.RoundEnded += OnRoundEnded;
|
||||
Scp914Events.ProcessingPickup += ev =>
|
||||
{
|
||||
if (ev.Pickup.Type < ItemType.KeycardCustomTaskForce) return;
|
||||
//process custom upgrade
|
||||
var keycard = (KeycardPickup)ev.Pickup;
|
||||
var pickup = Pickup.Create(ItemType.KeycardMTFCaptain, keycard.Position);
|
||||
keycard.Destroy();
|
||||
pickup!.Spawn();
|
||||
};
|
||||
Scp914Events.ProcessingInventoryItem += ev =>
|
||||
{
|
||||
if (ev.Item.Type < ItemType.KeycardCustomTaskForce) return;
|
||||
//process custom upgrade
|
||||
var keycard = (KeycardItem)ev.Item;
|
||||
ev.Player.RemoveItem(keycard);
|
||||
ev.Player.AddItem(ItemType.KeycardMTFCaptain, ItemAddReason.Scp914Upgrade);
|
||||
};
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
@@ -51,6 +71,8 @@ public class CustomClasses : Plugin
|
||||
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, MedicConfig, typeof(MedicConfig))) return;
|
||||
if (_classManager.TryHandleSpawn(ev.Player, GamblerConfig, typeof(GamblerConfig))) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +88,9 @@ public class CustomClassManager
|
||||
// Register handlers
|
||||
RegisterHandler<JanitorConfig>(new JanitorHandler(this));
|
||||
RegisterHandler<ResearchSubjectConfig>(new ResearchSubjectHandler(this));
|
||||
RegisterHandler<HeadGuardConfig>(new HeadGuardHandler(this));
|
||||
RegisterHandler<HeadGuardConfig>(new HeadGuardHandler());
|
||||
RegisterHandler<MedicConfig>(new MedicHandler());
|
||||
RegisterHandler<GamblerConfig>(new GamblerHandler());
|
||||
}
|
||||
|
||||
public void TeleportPlayerToAround(Player player, Vector3 position)
|
||||
@@ -117,90 +141,121 @@ public class CustomClassManager
|
||||
|
||||
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 false;
|
||||
Timing.CallDelayed(0.5f, () => { handler.HandleSpawn(player, config, _random); });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICustomClassHandler
|
||||
{
|
||||
bool HandleSpawn(Player player, CustomClassConfig config, Random random);
|
||||
void HandleSpawn(Player player, CustomClassConfig config, Random random);
|
||||
}
|
||||
|
||||
public class JanitorHandler(CustomClassManager manager) : ICustomClassHandler
|
||||
{
|
||||
public bool HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
public void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
var scp914 = Map.Rooms.First(r => r.Name == RoomName.Lcz914);
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
|
||||
manager.TeleportPlayerToAround(player, scp914.Position);
|
||||
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
manager.TeleportPlayerToAround(player, scp914.Position);
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
return true;
|
||||
player.SendBroadcast("You're a <color=#A0A0A0>Janitor</color>!", 3);
|
||||
}
|
||||
}
|
||||
|
||||
public class ResearchSubjectHandler(CustomClassManager manager) : ICustomClassHandler
|
||||
{
|
||||
public bool HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
public void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
var scientist = Player.ReadyList.First(p => p.Role == RoleTypeId.Scientist);
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
manager.TeleportPlayerToAround(player, scientist.Position);
|
||||
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
manager.TeleportPlayerToAround(player, scientist.Position);
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
return true;
|
||||
player.SendBroadcast("You're a <color=#944710>Research Subject</color>!", 3);
|
||||
}
|
||||
}
|
||||
|
||||
public class HeadGuardHandler(CustomClassManager manager) : ICustomClassHandler
|
||||
public class HeadGuardHandler : ICustomClassHandler
|
||||
{
|
||||
public bool HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
public void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
Timing.CallDelayed(0.5f, () =>
|
||||
player.RemoveItem(ItemType.KeycardGuard);
|
||||
|
||||
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);
|
||||
var firearm = (FirearmPickup)pickup;
|
||||
if (firearm != null)
|
||||
{
|
||||
player.RemoveItem(ItemType.KeycardGuard);
|
||||
firearm.Base.Template.TryGetModule(out MagazineModule magazine);
|
||||
magazine.ServerSetInstanceAmmo(firearm.Base.Template.ItemSerial, magazine.AmmoMax);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error("Failed to get firearm from pickup");
|
||||
}
|
||||
|
||||
KeycardItem.CreateCustomKeycardTaskForce(player, "Head Guard Keycard", $"HG. {player.Nickname}",
|
||||
new KeycardLevels(1, 1, 2), Color.blue, Color.cyan, "1", 0);
|
||||
if (pickup != null) player.AddItem(pickup);
|
||||
|
||||
player.AddItem(ItemType.Adrenaline, ItemAddReason.StartingItem);
|
||||
player.SetAmmo(ItemType.Ammo9x19, 120);
|
||||
|
||||
player.RemoveItem(ItemType.ArmorLight);
|
||||
player.AddItem(ItemType.ArmorCombat, ItemAddReason.StartingItem);
|
||||
player.SendBroadcast("You're a <color=#00B7EB>Head Guard</color>!", 3);
|
||||
}
|
||||
}
|
||||
|
||||
player.RemoveItem(ItemType.GunFSP9);
|
||||
public class MedicHandler : ICustomClassHandler
|
||||
{
|
||||
public void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
|
||||
var pickup = Pickup.Create(ItemType.GunCrossvec, Vector3.one);
|
||||
player.SendBroadcast("You're a <color=#727472>Medic</color>!", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (pickup != null) player.AddItem(pickup);
|
||||
public abstract class SimpleAddItemHandler : ICustomClassHandler
|
||||
{
|
||||
public virtual void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
foreach (var spawnItem in config.Items)
|
||||
{
|
||||
player.AddItem(spawnItem, ItemAddReason.StartingItem);
|
||||
Logger.Debug($"Gave player {player.Nickname} spawn item {spawnItem}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.SetAmmo(ItemType.Ammo9x19, 120);
|
||||
|
||||
player.SendBroadcast("You're a <color=#00B7EB>Head Guard</color>!", 3);
|
||||
});
|
||||
|
||||
return true;
|
||||
public class GamblerHandler : SimpleAddItemHandler
|
||||
{
|
||||
public override void HandleSpawn(Player player, CustomClassConfig config, Random random)
|
||||
{
|
||||
base.HandleSpawn(player, config, random);
|
||||
player.SendBroadcast("You're a <color=#FF9966>Gambler</color>!", 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,3 +288,19 @@ public class HeadGuardConfig : CustomClassConfig
|
||||
public override int MinPlayers { get; set; } = 9;
|
||||
public override RoleTypeId RequiredRole { get; set; } = RoleTypeId.FacilityGuard;
|
||||
}
|
||||
|
||||
public class MedicConfig : CustomClassConfig
|
||||
{
|
||||
public override int MinPlayers { get; set; } = 5;
|
||||
public override double ChancePerPlayer { get; set; } = 0.3;
|
||||
public override int MaxSpawns { get; set; } = 1;
|
||||
public override ItemType[] Items { get; set; } = [ItemType.Medkit, ItemType.Adrenaline];
|
||||
public override RoleTypeId RequiredRole { get; set; } = RoleTypeId.Scientist;
|
||||
}
|
||||
|
||||
public class GamblerConfig : CustomClassConfig
|
||||
{
|
||||
public override double ChancePerPlayer { get; set; } = 0.3;
|
||||
public override int MaxSpawns { get; set; } = 5;
|
||||
public override ItemType[] Items { get; set; } = [ItemType.Coin, ItemType.Coin];
|
||||
}
|
||||
Reference in New Issue
Block a user