From 4409e71deb4fecdc390e2d7481c0c8fc8a01395b Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Thu, 30 May 2024 22:17:57 +0200 Subject: [PATCH 01/23] changes --- Common Utilities/API.cs | 6 +- Common Utilities/Common Utilities.csproj | 2 +- Common Utilities/Config.cs | 28 ++- Common Utilities/EventHandlers/MapHandlers.cs | 32 +-- .../EventHandlers/PlayerHandlers.cs | 82 +++---- .../EventHandlers/ServerHandlers.cs | 4 +- Common Utilities/Main.cs | 219 ----------------- .../Patches/ServerGrantLoadoutPatches.cs | 4 +- Common Utilities/Plugin.cs | 231 ++++++++++++++++++ 9 files changed, 308 insertions(+), 300 deletions(-) delete mode 100644 Common Utilities/Main.cs create mode 100644 Common Utilities/Plugin.cs diff --git a/Common Utilities/API.cs b/Common Utilities/API.cs index 7ff51f0..ea3fd1b 100644 --- a/Common Utilities/API.cs +++ b/Common Utilities/API.cs @@ -7,10 +7,10 @@ namespace Common_Utilities public static class API { - public static List GetStartItems(RoleTypeId role) => Main.Instance.PlayerHandlers.StartItems(role); + public static List GetStartItems(RoleTypeId role) => Plugin.Instance.PlayerHandlers.StartItems(role); - public static List GetStartItems(RoleTypeId role, Player player) => Main.Instance.PlayerHandlers.StartItems(role, player); + public static List GetStartItems(RoleTypeId role, Player player) => Plugin.Instance.PlayerHandlers.StartItems(role, player); - public static float GetHealthOnKill(RoleTypeId role) => Main.Instance.Config.HealthOnKill?.ContainsKey(role) ?? false ? Main.Instance.Config.HealthOnKill[role] : 0f; + public static float GetHealthOnKill(RoleTypeId role) => Plugin.Instance.Config.HealthOnKill?.ContainsKey(role) ?? false ? Plugin.Instance.Config.HealthOnKill[role] : 0f; } } \ No newline at end of file diff --git a/Common Utilities/Common Utilities.csproj b/Common Utilities/Common Utilities.csproj index 209b54c..eac8e35 100644 --- a/Common Utilities/Common Utilities.csproj +++ b/Common Utilities/Common Utilities.csproj @@ -23,7 +23,7 @@ - + diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index eb379fc..dfa92a1 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -14,14 +14,23 @@ namespace Common_Utilities public class Config : IConfig { + [Description("If the plugin is enabled or not.")] + public bool IsEnabled { get; set; } = true; + [Description("Whether or not debug messages should be shown.")] public bool Debug { get; set; } = false; - [Description("Whether or not MTF/CI can 'escape' while disarmed to switch teams.")] - public bool DisarmSwitchTeams { get; set; } = true; - - [Description("Whether or not disarmed people will be prevented from interacting with doors/elevators.")] - public bool RestrictiveDisarming { get; set; } = true; + [Description("Roles that when cuffed in the escape area will change into the target one.")] + public Dictionary DisarmedEscapeSwitchRole { get; set; } = + new() + { + { + RoleTypeId.NtfCaptain, RoleTypeId.ChaosMarauder + }, + { + RoleTypeId.ChaosMarauder, RoleTypeId.NtfCaptain + }, + }; [Description("The text displayed at the timed interval specified below.")] public string TimedBroadcast { get; set; } = "This server is running EXILED Common-Utilities, enjoy your stay!"; @@ -62,8 +71,8 @@ public class Config : IConfig [Description("The multiplier applied to radio battery usage. Set to 0 to disable radio battery drain.")] public float RadioBatteryDrainMultiplier { get; set; } = 1f; - [Description("The color to use for lights while the warhead is active.")] - public Color WarheadColor { get; set; } = new(1f, 0.2f, 0.2f); + [Description("The color to use for lights while the warhead is active. In the RGBA format using values between 0 and 1.")] + public Color WarheadColor { get; set; } = new(1f, 0.2f, 0.2f, 1); [Description("The maximum time, in seconds, that a player can be AFK before being kicked. Set to -1 to disable AFK system.")] public int AfkLimit { get; set; } = 120; @@ -124,7 +133,7 @@ public class Config : IConfig }; [Description("The list of custom 914 recipies. Original is the item being upgraded, New is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item.")] - public Dictionary> Scp914ItemChanges { get; set; } = new() + public Dictionary> Scp914ItemChances { get; set; } = new() { { Scp914KnobSetting.Rough, new List @@ -252,8 +261,5 @@ public class Config : IConfig RoleTypeId.NtfCaptain, 150 }, }; - - [Description("If the plugin is enabled or not.")] - public bool IsEnabled { get; set; } = true; } } diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index 36ca19f..c7bdd79 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -19,23 +19,23 @@ namespace Common_Utilities.EventHandlers public class MapHandlers { - private readonly Main plugin; + private readonly Plugin plugin; - public MapHandlers(Main plugin) => this.plugin = plugin; + public MapHandlers(Plugin plugin) => this.plugin = plugin; public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) { - if (plugin.Config.Scp914ItemChanges.ContainsKey(ev.KnobSetting)) + if (plugin.Config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List chances)) { - IEnumerable itemUpgradeChance = plugin.Config.Scp914ItemChanges[ev.KnobSetting].Where(x => x.Original == ev.Pickup.Type); + IEnumerable itemUpgradeChance = chances.Where(x => x.Original == ev.Pickup.Type); foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) { double r; if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); + r = Plugin.Random.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"{nameof(OnScp914UpgradingItem)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {r <= chance} ({r})"); if (r <= chance) @@ -52,17 +52,17 @@ public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) { - if (plugin.Config.Scp914ItemChanges.ContainsKey(ev.KnobSetting)) + if (plugin.Config.Scp914ItemChances.ContainsKey(ev.KnobSetting)) { - IEnumerable itemUpgradeChance = plugin.Config.Scp914ItemChanges[ev.KnobSetting].Where(x => x.Original == ev.Item.Type); + IEnumerable itemUpgradeChance = plugin.Config.Scp914ItemChances[ev.KnobSetting].Where(x => x.Original == ev.Item.Type); foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) { double r; if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); + r = Plugin.Random.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"{nameof(OnScp914UpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {r <= chance} ({r})"); if (r <= chance) @@ -97,9 +97,9 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) { double r; if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * playerUpgradeChance.Sum(x => x.Chance); + r = Plugin.Random.NextDouble() * playerUpgradeChance.Sum(x => x.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role})is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {r <= chance} ({r})"); if (r <= chance) @@ -155,9 +155,9 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) { double r; if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * scp914EffectChances.Sum(x => x.Chance); + r = Plugin.Random.NextDouble() * scp914EffectChances.Sum(x => x.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to gain an effect. {effect} ({chance}). Should be added: {r <= chance} ({r})"); if (r <= chance) @@ -179,9 +179,9 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) { double r; if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * scp914TeleportChances.Sum(x => x.Chance); + r = Plugin.Random.NextDouble() * scp914TeleportChances.Sum(x => x.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset} ({chance}). Should be teleported: {r <= chance} ({r})"); if (r <= chance) diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 6fddbb6..a2059c7 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -1,3 +1,5 @@ +using PluginAPI.Roles; + namespace Common_Utilities.EventHandlers { #pragma warning disable IDE0018 @@ -19,15 +21,15 @@ namespace Common_Utilities.EventHandlers public class PlayerHandlers { - private readonly Main plugin; + private readonly Config config; - public PlayerHandlers(Main plugin) => this.plugin = plugin; + public PlayerHandlers(Plugin plugin) => this.config = plugin.Config; public void OnPlayerVerified(VerifiedEventArgs ev) { string message = FormatJoinMessage(ev.Player); if (!string.IsNullOrEmpty(message)) - ev.Player.Broadcast(plugin.Config.JoinMessageDuration, message); + ev.Player.Broadcast(config.JoinMessageDuration, message); } public void OnChangingRole(ChangingRoleEventArgs ev) @@ -38,7 +40,7 @@ public void OnChangingRole(ChangingRoleEventArgs ev) return; } - if (plugin.Config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory) + if (config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory) { if (ev.Items == null) { @@ -49,12 +51,12 @@ public void OnChangingRole(ChangingRoleEventArgs ev) ev.Items.Clear(); ev.Items.AddRange(StartItems(ev.NewRole, ev.Player)); - if (plugin.Config.StartingInventories[ev.NewRole].Ammo != null && plugin.Config.StartingInventories[ev.NewRole].Ammo.Count > 0) + if (config.StartingInventories[ev.NewRole].Ammo != null && config.StartingInventories[ev.NewRole].Ammo.Count > 0) { - if (plugin.Config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) + if (config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) { ev.Ammo.Clear(); - foreach ((ItemType type, ushort amount, string group) in plugin.Config.StartingInventories[ev.NewRole].Ammo) + foreach ((ItemType type, ushort amount, string group) in config.StartingInventories[ev.NewRole].Ammo) { if (string.IsNullOrEmpty(group) || group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(group, out UserGroup userGroup) && userGroup == ev.Player.Group)) { @@ -75,26 +77,26 @@ public void OnSpawned(SpawnedEventArgs ev) } RoleTypeId newRole = ev.Player.Role.Type; - if (plugin.Config.HealthValues != null && plugin.Config.HealthValues.TryGetValue(newRole, out int health)) + if (config.HealthValues != null && config.HealthValues.TryGetValue(newRole, out int health)) { ev.Player.Health = health; ev.Player.MaxHealth = health; } - if (ev.Player.Role is FpcRole && plugin.Config.PlayerHealthInfo) + if (ev.Player.Role is FpcRole && config.PlayerHealthInfo) { ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; } - if (plugin.Config.AfkIgnoredRoles.Contains(newRole) && plugin.AfkDict.TryGetValue(ev.Player, out Tuple value)) - plugin.AfkDict[ev.Player] = new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); + if (config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple value)) + Plugin.AfkDict[ev.Player] = new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); } public void OnPlayerDied(DiedEventArgs ev) { - if (ev.Attacker != null && plugin.Config.HealthOnKill.ContainsKey(ev.Attacker.Role)) + if (ev.Attacker != null && config.HealthOnKill.ContainsKey(ev.Attacker.Role)) { - ev.Attacker.Heal(plugin.Config.HealthOnKill[ev.Attacker.Role]); + ev.Attacker.Heal(config.HealthOnKill[ev.Attacker.Role]); } } @@ -102,14 +104,14 @@ public List StartItems(RoleTypeId role, Player player = null) { List items = new(); - for (int i = 0; i < plugin.Config.StartingInventories[role].UsedSlots; i++) + for (int i = 0; i < config.StartingInventories[role].UsedSlots; i++) { - IEnumerable itemChances = plugin.Config.StartingInventories[role][i].Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)); + IEnumerable itemChances = config.StartingInventories[role][i].Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)); double r; - if (plugin.Config.AdditiveProbabilities) - r = plugin.Rng.NextDouble() * itemChances.Sum(val => val.Chance); + if (config.AdditiveProbabilities) + r = Plugin.Random.NextDouble() * itemChances.Sum(val => val.Chance); else - r = plugin.Rng.NextDouble() * 100; + r = Plugin.Random.NextDouble() * 100; Log.Debug($"[StartItems] ActualChance ({r})/{itemChances.Sum(val => val.Chance)}"); foreach ((string item, double chance, string groupKey) in itemChances) { @@ -142,77 +144,65 @@ public List StartItems(RoleTypeId role, Player player = null) } public string FormatJoinMessage(Player player) => - string.IsNullOrEmpty(plugin.Config.JoinMessage) ? string.Empty : plugin.Config.JoinMessage.Replace("%player%", player.Nickname).Replace("%server%", Server.Name).Replace("%count%", $"{Player.Dictionary.Count}"); + string.IsNullOrEmpty(config.JoinMessage) ? string.Empty : config.JoinMessage.Replace("%player%", player.Nickname).Replace("%server%", Server.Name).Replace("%count%", $"{Player.Dictionary.Count}"); public void OnPlayerHurting(HurtingEventArgs ev) { float damageMultiplier; - if (plugin.Config.RoleDamageMultipliers != null && ev.Attacker != null && plugin.Config.RoleDamageMultipliers.TryGetValue(ev.Attacker.Role, out damageMultiplier)) + if (config.RoleDamageMultipliers != null && ev.Attacker != null && config.RoleDamageMultipliers.TryGetValue(ev.Attacker.Role, out damageMultiplier)) ev.Amount *= damageMultiplier; - if (plugin.Config.DamageMultipliers != null && plugin.Config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier)) + if (config.DamageMultipliers != null && config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier)) ev.Amount *= damageMultiplier; - if (plugin.Config.PlayerHealthInfo) + if (config.PlayerHealthInfo) ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; - if (ev.Attacker is not null && plugin.AfkDict.ContainsKey(ev.Attacker)) + if (ev.Attacker is not null && Plugin.AfkDict.ContainsKey(ev.Attacker)) { Log.Debug($"Resetting {ev.Attacker.Nickname} AFK timer."); - plugin.AfkDict[ev.Attacker] = new Tuple(0, ev.Attacker.Position); + Plugin.AfkDict[ev.Attacker] = new Tuple(0, ev.Attacker.Position); } } public void OnInteractingDoor(InteractingDoorEventArgs ev) { - if (ev.Player.IsCuffed && plugin.Config.RestrictiveDisarming) - ev.IsAllowed = false; - - if (plugin.AfkDict.ContainsKey(ev.Player)) + if (Plugin.AfkDict.ContainsKey(ev.Player)) { Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); + Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); } } public void OnInteractingElevator(InteractingElevatorEventArgs ev) { - if (ev.Player.IsCuffed && plugin.Config.RestrictiveDisarming) - ev.IsAllowed = false; - - if (plugin.AfkDict.ContainsKey(ev.Player)) + if (Plugin.AfkDict.ContainsKey(ev.Player)) { Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); + Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); } } public void OnEscaping(EscapingEventArgs ev) { - if (ev.EscapeScenario is EscapeScenario.CustomEscape) + if (ev.Player.IsCuffed && config.DisarmedEscapeSwitchRole.TryGetValue(ev.Player.Role, out RoleTypeId newRole)) { - ev.NewRole = ev.Player.Role.Type switch - { - RoleTypeId.FacilityGuard or RoleTypeId.NtfPrivate or RoleTypeId.NtfSergeant or RoleTypeId.NtfCaptain or RoleTypeId.NtfSpecialist => RoleTypeId.ChaosConscript, - RoleTypeId.ChaosConscript or RoleTypeId.ChaosMarauder or RoleTypeId.ChaosRepressor or RoleTypeId.ChaosRifleman => RoleTypeId.ChaosConscript, - _ => RoleTypeId.None, - }; - - ev.IsAllowed = ev.NewRole is not RoleTypeId.None; + ev.NewRole = newRole; + ev.IsAllowed = newRole != RoleTypeId.None; } } public void OnUsingRadioBattery(UsingRadioBatteryEventArgs ev) { - ev.Drain *= plugin.Config.RadioBatteryDrainMultiplier; + ev.Drain *= config.RadioBatteryDrainMultiplier; } public void AntiAfkEventHandler(IPlayerEvent ev) { - if (ev.Player != null && plugin.AfkDict.ContainsKey(ev.Player)) + if (ev.Player != null && Plugin.AfkDict.ContainsKey(ev.Player)) { Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); + Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); } } } diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index aed321d..0014d12 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -19,11 +19,11 @@ namespace Common_Utilities.EventHandlers public class ServerHandlers { - private readonly Main plugin; + private readonly Plugin plugin; private bool friendlyFireDisable = false; - public ServerHandlers(Main plugin) => this.plugin = plugin; + public ServerHandlers(Plugin plugin) => this.plugin = plugin; public void OnRoundStarted() { diff --git a/Common Utilities/Main.cs b/Common Utilities/Main.cs deleted file mode 100644 index 6c73de9..0000000 --- a/Common Utilities/Main.cs +++ /dev/null @@ -1,219 +0,0 @@ -namespace Common_Utilities -{ -#pragma warning disable SA1401 // Fields should be private - using System; - using System.Collections.Generic; - - using ConfigObjects; - using Configs; - using EventHandlers; - using Exiled.API.Enums; - using Exiled.API.Features; - using HarmonyLib; - using MEC; - using PlayerRoles; - using Scp914; - using UnityEngine; - - using Player = Exiled.Events.Handlers.Player; - using Random = System.Random; - using Scp914 = Exiled.Events.Handlers.Scp914; - using Server = Exiled.Events.Handlers.Server; - - public class Main : Plugin - { - public static Main Instance; - public PlayerHandlers PlayerHandlers; - public ServerHandlers ServerHandlers; - public MapHandlers MapHandlers; - public Random Rng = new(); - public Harmony Harmony; - public string HarmonyName; - - public override string Name { get; } = "Common Utilities"; - - public override string Author { get; } = "Exiled-Team"; - - public override Version Version { get; } = new(7, 1, 1); - - public override Version RequiredExiledVersion { get; } = new(8, 5, 0); - - public override string Prefix { get; } = "CommonUtilities"; - - public override PluginPriority Priority => PluginPriority.Higher; - - public List Coroutines { get; } = new(); - - public Dictionary> AfkDict { get; } = new(); - - public override void OnEnabled() - { - if (Config.Debug) - DebugConfig(); - - Instance = this; - - Log.Info($"Instantiating Events.."); - PlayerHandlers = new PlayerHandlers(this); - ServerHandlers = new ServerHandlers(this); - MapHandlers = new MapHandlers(this); - - Log.Info($"Registering EventHandlers.."); - if (Config.HealthOnKill != null) - Player.Died += PlayerHandlers.OnPlayerDied; - Player.Hurting += PlayerHandlers.OnPlayerHurting; - Player.Verified += PlayerHandlers.OnPlayerVerified; - if (Config.StartingInventories != null) - Player.ChangingRole += PlayerHandlers.OnChangingRole; - Player.Spawned += PlayerHandlers.OnSpawned; - Player.InteractingDoor += PlayerHandlers.OnInteractingDoor; - if (Config.RadioBatteryDrainMultiplier is not 1) - Player.UsingRadioBattery += PlayerHandlers.OnUsingRadioBattery; - Player.InteractingElevator += PlayerHandlers.OnInteractingElevator; - if (Config.DisarmSwitchTeams) - Player.Escaping += PlayerHandlers.OnEscaping; - if (Config.AfkLimit > 0) - { - Player.Jumping += PlayerHandlers.AntiAfkEventHandler; - Player.Shooting += PlayerHandlers.AntiAfkEventHandler; - Player.UsingItem += PlayerHandlers.AntiAfkEventHandler; - Player.MakingNoise += PlayerHandlers.AntiAfkEventHandler; - Player.ReloadingWeapon += PlayerHandlers.AntiAfkEventHandler; - Player.ThrownProjectile += PlayerHandlers.AntiAfkEventHandler; - Player.ChangingMoveState += PlayerHandlers.AntiAfkEventHandler; - } - - Server.RoundEnded += ServerHandlers.OnRoundEnded; - Server.RoundStarted += ServerHandlers.OnRoundStarted; - Server.RestartingRound += ServerHandlers.OnRestartingRound; - Server.WaitingForPlayers += ServerHandlers.OnWaitingForPlayers; - - if (Config.Scp914ItemChanges != null) - Scp914.UpgradingPickup += MapHandlers.OnScp914UpgradingItem; - if (Config.Scp914ItemChanges != null) - Scp914.UpgradingInventoryItem += MapHandlers.OnScp914UpgradingInventoryItem; - Scp914.UpgradingPlayer += MapHandlers.OnScp914UpgradingPlayer; - - Exiled.Events.Handlers.Warhead.Starting += ServerHandlers.OnWarheadStarting; - Exiled.Events.Handlers.Warhead.Stopping += ServerHandlers.OnWarheadStopping; - - HarmonyName = $"com-joker.cu-{DateTime.UtcNow.Ticks}"; - Harmony = new Harmony(HarmonyName); - Harmony.PatchAll(); - - base.OnEnabled(); - } - - public override void OnDisabled() - { - Player.Died -= PlayerHandlers.OnPlayerDied; - Player.Jumping -= PlayerHandlers.AntiAfkEventHandler; - Player.Shooting -= PlayerHandlers.AntiAfkEventHandler; - Player.UsingItem -= PlayerHandlers.AntiAfkEventHandler; - Player.Hurting -= PlayerHandlers.OnPlayerHurting; - Player.Verified -= PlayerHandlers.OnPlayerVerified; - Player.MakingNoise -= PlayerHandlers.AntiAfkEventHandler; - Player.ReloadingWeapon -= PlayerHandlers.AntiAfkEventHandler; - Player.ChangingRole -= PlayerHandlers.OnChangingRole; - Player.Spawned -= PlayerHandlers.OnSpawned; - Player.ThrownProjectile -= PlayerHandlers.AntiAfkEventHandler; - Player.InteractingDoor -= PlayerHandlers.OnInteractingDoor; - Player.UsingRadioBattery -= PlayerHandlers.OnUsingRadioBattery; - Player.ChangingMoveState -= PlayerHandlers.AntiAfkEventHandler; - Player.InteractingElevator -= PlayerHandlers.OnInteractingElevator; - Player.Escaping -= PlayerHandlers.OnEscaping; - - Server.RoundEnded -= ServerHandlers.OnRoundEnded; - Server.RoundStarted -= ServerHandlers.OnRoundStarted; - Server.RestartingRound -= ServerHandlers.OnRestartingRound; - Server.WaitingForPlayers -= ServerHandlers.OnWaitingForPlayers; - - Scp914.UpgradingPickup -= MapHandlers.OnScp914UpgradingItem; - Scp914.UpgradingPlayer -= MapHandlers.OnScp914UpgradingPlayer; - Scp914.UpgradingInventoryItem -= MapHandlers.OnScp914UpgradingInventoryItem; - - Exiled.Events.Handlers.Warhead.Starting -= ServerHandlers.OnWarheadStarting; - Exiled.Events.Handlers.Warhead.Stopping -= ServerHandlers.OnWarheadStopping; - - Harmony.UnpatchAll(HarmonyName); - - ServerHandlers = null; - PlayerHandlers = null; - MapHandlers = null; - base.OnDisabled(); - } - - public void DebugConfig() - { - if (Config.StartingInventories != null) - { - Log.Debug($"{Config.StartingInventories.Count}"); - foreach (KeyValuePair inv in Config.StartingInventories) - { - for (int i = 0; i < inv.Value.UsedSlots; i++) - { - foreach (ItemChance chance in inv.Value[i]) - { - Log.Debug($"Inventory Config: {inv.Key} - Slot{i + 1}: {chance.ItemName} ({chance.Chance})"); - } - } - - foreach ((ItemType type, ushort amount, string group) in inv.Value.Ammo) - { - Log.Debug($"Ammo Config: {inv.Key} - {type} {amount} ({group})"); - } - } - } - - if (Config.Scp914ItemChanges != null) - { - Log.Debug($"{Config.Scp914ItemChanges.Count}"); - foreach (KeyValuePair> upgrade in Config.Scp914ItemChanges) - { - foreach ((ItemType oldItem, ItemType newItem, double chance, int count) in upgrade.Value) - Log.Debug($"914 Item Config: {upgrade.Key}: {oldItem} -> {newItem}x({count}) - {chance}"); - } - } - - if (Config.Scp914ClassChanges != null) - { - Log.Debug($"{Config.Scp914ClassChanges.Count}"); - foreach (KeyValuePair> upgrade in Config.Scp914ClassChanges) - { - foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value) - Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory} keepHealth: {keepHealth}"); - } - } - - if (Config.Scp914EffectChances != null) - { - Log.Debug($"{Config.Scp914EffectChances.Count}"); - foreach (KeyValuePair> upgrade in Config.Scp914EffectChances) - { - foreach ((EffectType effect, double chance, float duration) in upgrade.Value) - Log.Debug($"914 Effect Config: {upgrade.Key}: {effect} + {duration} - {chance}"); - } - } - - if (Config.Scp914TeleportChances != null) - { - Log.Debug($"{Config.Scp914TeleportChances.Count}"); - foreach (KeyValuePair> upgrade in Config.Scp914TeleportChances) - { - foreach ((RoomType room, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value) - { - Log.Debug($"914 Teleport Config: {upgrade.Key}: {room}/{zone} + {offset} - {chance} [{damage}]"); - Log.Debug("Ignored rooms:"); - if (ignoredRooms != null) - { - foreach (RoomType roomType in ignoredRooms) - { - Log.Debug(roomType); - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index c5824af..2bd8fdc 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -15,13 +15,13 @@ public class ServerGrantLoadoutPatches { public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool resetInventory = true) { - if (Main.Instance.Config.StartingInventories == null || !Main.Instance.Config.StartingInventories.TryGetValue(roleTypeId, out RoleInventory startingInventories) || !Player.TryGet(target, out Player player)) + if (Plugin.Instance.Config.StartingInventories == null || !Plugin.Instance.Config.StartingInventories.TryGetValue(roleTypeId, out RoleInventory startingInventories) || !Player.TryGet(target, out Player player)) return true; if (resetInventory) player.ClearInventory(); - player.AddItem(Main.Instance.PlayerHandlers.StartItems(roleTypeId, player)); + player.AddItem(Plugin.Instance.PlayerHandlers.StartItems(roleTypeId, player)); if (startingInventories.Ammo != null && startingInventories.Ammo.Count > 0) { diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs new file mode 100644 index 0000000..32ae547 --- /dev/null +++ b/Common Utilities/Plugin.cs @@ -0,0 +1,231 @@ +// ReSharper disable InconsistentNaming +namespace Common_Utilities; + +#pragma warning disable SA1401 // Fields should be private +using System; +using System.Collections.Generic; + +using ConfigObjects; +using Configs; +using EventHandlers; +using Exiled.API.Enums; +using Exiled.API.Features; +using HarmonyLib; +using MEC; +using PlayerRoles; +using Scp914; +using UnityEngine; + +#pragma warning disable SA1211 +using player = Exiled.Events.Handlers.Player; +using scp914 = Exiled.Events.Handlers.Scp914; +using server = Exiled.Events.Handlers.Server; +using warhead = Exiled.Events.Handlers.Warhead; +using Random = System.Random; +#pragma warning restore SA1211 + +public class Plugin : Plugin +{ + public static Plugin Instance; + public static Random Random; + private PlayerHandlers playerHandlers; + private ServerHandlers serverHandlers; + private MapHandlers mapHandlers; + private Harmony harmony; + private string harmonyName; + + public static Dictionary> AfkDict { get; } = new(); + + public override string Name { get; } = "Common Utilities"; + + public override string Author { get; } = "Exiled-Team"; + + public override Version Version { get; } = new(7, 1, 1); + + public override Version RequiredExiledVersion { get; } = new(8, 9, 2); + + public override string Prefix { get; } = "CommonUtilities"; + + public override PluginPriority Priority => PluginPriority.Higher; + + public List Coroutines { get; } = new(); + + public override void OnEnabled() + { + if (Config.Debug) + DebugConfig(); + + Instance = this; + + Random = new Random(); + + Log.Info($"Instantiating Events.."); + + playerHandlers = new PlayerHandlers(this); + serverHandlers = new ServerHandlers(this); + mapHandlers = new MapHandlers(this); + + Log.Info($"Registering EventHandlers.."); + + player.Hurting += playerHandlers.OnPlayerHurting; + player.Verified += playerHandlers.OnPlayerVerified; + player.Spawned += playerHandlers.OnSpawned; + player.InteractingDoor += playerHandlers.OnInteractingDoor; + player.InteractingElevator += playerHandlers.OnInteractingElevator; + player.Escaping += playerHandlers.OnEscaping; + + if (Config.HealthOnKill != null) + player.Died += playerHandlers.OnPlayerDied; + + if (Config.StartingInventories != null) + player.ChangingRole += playerHandlers.OnChangingRole; + + if (Config.RadioBatteryDrainMultiplier is not 1) + player.UsingRadioBattery += playerHandlers.OnUsingRadioBattery; + + if (Config.AfkLimit > 0) + { + player.Jumping += playerHandlers.AntiAfkEventHandler; + player.Shooting += playerHandlers.AntiAfkEventHandler; + player.UsingItem += playerHandlers.AntiAfkEventHandler; + player.MakingNoise += playerHandlers.AntiAfkEventHandler; + player.ReloadingWeapon += playerHandlers.AntiAfkEventHandler; + player.ThrownProjectile += playerHandlers.AntiAfkEventHandler; + player.ChangingMoveState += playerHandlers.AntiAfkEventHandler; + } + + server.RoundEnded += serverHandlers.OnRoundEnded; + server.RoundStarted += serverHandlers.OnRoundStarted; + server.RestartingRound += serverHandlers.OnRestartingRound; + server.WaitingForPlayers += serverHandlers.OnWaitingForPlayers; + + scp914.UpgradingPlayer += mapHandlers.OnScp914UpgradingPlayer; + + if (Config.Scp914ItemChances != null) + scp914.UpgradingPickup += mapHandlers.OnScp914UpgradingItem; + if (Config.Scp914ItemChances != null) + scp914.UpgradingInventoryItem += mapHandlers.OnScp914UpgradingInventoryItem; + + warhead.Starting += serverHandlers.OnWarheadStarting; + warhead.Stopping += serverHandlers.OnWarheadStopping; + + harmonyName = $"com-exiled-team.cu-{DateTime.UtcNow.Ticks}"; + harmony = new Harmony(harmonyName); + harmony.PatchAll(); + + base.OnEnabled(); + } + + public override void OnDisabled() + { + player.Died -= playerHandlers.OnPlayerDied; + player.Jumping -= playerHandlers.AntiAfkEventHandler; + player.Shooting -= playerHandlers.AntiAfkEventHandler; + player.UsingItem -= playerHandlers.AntiAfkEventHandler; + player.Hurting -= playerHandlers.OnPlayerHurting; + player.Verified -= playerHandlers.OnPlayerVerified; + player.MakingNoise -= playerHandlers.AntiAfkEventHandler; + player.ReloadingWeapon -= playerHandlers.AntiAfkEventHandler; + player.ChangingRole -= playerHandlers.OnChangingRole; + player.Spawned -= playerHandlers.OnSpawned; + player.ThrownProjectile -= playerHandlers.AntiAfkEventHandler; + player.InteractingDoor -= playerHandlers.OnInteractingDoor; + player.UsingRadioBattery -= playerHandlers.OnUsingRadioBattery; + player.ChangingMoveState -= playerHandlers.AntiAfkEventHandler; + player.InteractingElevator -= playerHandlers.OnInteractingElevator; + player.Escaping -= playerHandlers.OnEscaping; + + server.RoundEnded -= serverHandlers.OnRoundEnded; + server.RoundStarted -= serverHandlers.OnRoundStarted; + server.RestartingRound -= serverHandlers.OnRestartingRound; + server.WaitingForPlayers -= serverHandlers.OnWaitingForPlayers; + + scp914.UpgradingPickup -= mapHandlers.OnScp914UpgradingItem; + scp914.UpgradingPlayer -= mapHandlers.OnScp914UpgradingPlayer; + scp914.UpgradingInventoryItem -= mapHandlers.OnScp914UpgradingInventoryItem; + + warhead.Stopping -= serverHandlers.OnWarheadStopping; + warhead.Starting -= serverHandlers.OnWarheadStarting; + + harmony.UnpatchAll(harmonyName); + + serverHandlers = null; + playerHandlers = null; + mapHandlers = null; + + base.OnDisabled(); + } + + private void DebugConfig() + { + if (Config.StartingInventories != null) + { + Log.Debug($"Starting Inventories: {Config.StartingInventories.Count}"); + foreach (KeyValuePair kvp in Config.StartingInventories) + { + for (int i = 0; i < kvp.Value.UsedSlots; i++) + { + foreach (ItemChance chance in kvp.Value[i]) + { + Log.Debug($"Inventory Config: {kvp.Key} - Slot{i + 1}: {chance.ItemName} ({chance.Chance})"); + } + } + + foreach ((ItemType type, ushort amount, string group) in kvp.Value.Ammo) + { + Log.Debug($"Ammo Config: {kvp.Key} - {type} {amount} ({group})"); + } + } + } + + if (Config.Scp914ItemChances != null) + { + Log.Debug($"{Config.Scp914ItemChances.Count}"); + foreach (KeyValuePair> upgrade in Config.Scp914ItemChances) + { + foreach ((ItemType oldItem, ItemType newItem, double chance, int count) in upgrade.Value) + Log.Debug($"914 Item Config: {upgrade.Key}: {oldItem} -> {newItem}x({count}) - {chance}"); + } + } + + if (Config.Scp914ClassChanges != null) + { + Log.Debug($"{Config.Scp914ClassChanges.Count}"); + foreach (KeyValuePair> upgrade in Config.Scp914ClassChanges) + { + foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value) + Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory} keepHealth: {keepHealth}"); + } + } + + if (Config.Scp914EffectChances != null) + { + Log.Debug($"{Config.Scp914EffectChances.Count}"); + foreach (KeyValuePair> upgrade in Config.Scp914EffectChances) + { + foreach ((EffectType effect, double chance, float duration) in upgrade.Value) + Log.Debug($"914 Effect Config: {upgrade.Key}: {effect} + {duration} - {chance}"); + } + } + + if (Config.Scp914TeleportChances != null) + { + Log.Debug($"{Config.Scp914TeleportChances.Count}"); + foreach (KeyValuePair> upgrade in Config.Scp914TeleportChances) + { + foreach ((RoomType room, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in upgrade.Value) + { + Log.Debug($"914 Teleport Config: {upgrade.Key}: {room}/{zone} + {offset} - {chance} [{damage}]"); + Log.Debug("Ignored rooms:"); + if (ignoredRooms != null) + { + foreach (RoomType roomType in ignoredRooms) + { + Log.Debug(roomType); + } + } + } + } + } + } +} \ No newline at end of file From 52455c5e2bc482485dfcdd54be7208f51ebc0d7e Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Thu, 30 May 2024 23:21:14 +0200 Subject: [PATCH 02/23] more changes --- Common Utilities/API.cs | 16 - .../EventHandlers/PlayerHandlers.cs | 300 +++++++++--------- .../EventHandlers/ServerHandlers.cs | 92 +++--- .../Patches/ServerGrantLoadoutPatches.cs | 2 +- Common Utilities/Plugin.cs | 28 +- 5 files changed, 204 insertions(+), 234 deletions(-) delete mode 100644 Common Utilities/API.cs diff --git a/Common Utilities/API.cs b/Common Utilities/API.cs deleted file mode 100644 index ea3fd1b..0000000 --- a/Common Utilities/API.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Common_Utilities -{ - using System.Collections.Generic; - - using Exiled.API.Features; - using PlayerRoles; - - public static class API - { - public static List GetStartItems(RoleTypeId role) => Plugin.Instance.PlayerHandlers.StartItems(role); - - public static List GetStartItems(RoleTypeId role, Player player) => Plugin.Instance.PlayerHandlers.StartItems(role, player); - - public static float GetHealthOnKill(RoleTypeId role) => Plugin.Instance.Config.HealthOnKill?.ContainsKey(role) ?? false ? Plugin.Instance.Config.HealthOnKill[role] : 0f; - } -} \ No newline at end of file diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index a2059c7..4062d8c 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -1,209 +1,195 @@ -using PluginAPI.Roles; +namespace Common_Utilities.EventHandlers; -namespace Common_Utilities.EventHandlers -{ #pragma warning disable IDE0018 - using System; - using System.Collections.Generic; - using System.Linq; - - using Common_Utilities.ConfigObjects; - using Exiled.API.Enums; - using Exiled.API.Features; - using Exiled.API.Features.Roles; - using Exiled.CustomItems.API.Features; - using Exiled.Events.EventArgs.Interfaces; - using Exiled.Events.EventArgs.Player; - using PlayerRoles; - using UnityEngine; - - using Player = Exiled.API.Features.Player; - - public class PlayerHandlers - { - private readonly Config config; +using System; +using System.Collections.Generic; +using System.Linq; + +using ConfigObjects; +using Exiled.API.Features; +using Exiled.API.Features.Roles; +using Exiled.CustomItems.API.Features; +using Exiled.Events.EventArgs.Interfaces; +using Exiled.Events.EventArgs.Player; +using PlayerRoles; +using UnityEngine; + +using Player = Exiled.API.Features.Player; + +public class PlayerHandlers +{ + private readonly Config config; - public PlayerHandlers(Plugin plugin) => this.config = plugin.Config; + public PlayerHandlers(Plugin plugin) => this.config = plugin.Config; - public void OnPlayerVerified(VerifiedEventArgs ev) + public void OnPlayerVerified(VerifiedEventArgs ev) + { + string message = FormatJoinMessage(ev.Player); + + if (!string.IsNullOrEmpty(message)) + ev.Player.Broadcast(config.JoinMessageDuration, message); + } + + public void OnChangingRole(ChangingRoleEventArgs ev) + { + if (ev.Player == null) { - string message = FormatJoinMessage(ev.Player); - if (!string.IsNullOrEmpty(message)) - ev.Player.Broadcast(config.JoinMessageDuration, message); + Log.Warn($"{nameof(OnChangingRole)}: Triggering player is null."); + return; } - public void OnChangingRole(ChangingRoleEventArgs ev) + if (config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory) { - if (ev.Player == null) + if (ev.Items == null) { - Log.Warn($"{nameof(OnChangingRole)}: Triggering player is null."); + Log.Warn("items is null"); return; } - if (config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory) - { - if (ev.Items == null) - { - Log.Warn("items is null"); - return; - } + ev.Items.Clear(); + ev.Items.AddRange(StartItems(ev.NewRole, ev.Player)); - ev.Items.Clear(); - ev.Items.AddRange(StartItems(ev.NewRole, ev.Player)); - - if (config.StartingInventories[ev.NewRole].Ammo != null && config.StartingInventories[ev.NewRole].Ammo.Count > 0) + if (config.StartingInventories[ev.NewRole].Ammo != null && config.StartingInventories[ev.NewRole].Ammo.Count > 0) + { + if (config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) { - if (config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) + ev.Ammo.Clear(); + foreach ((ItemType type, ushort amount, string group) in config.StartingInventories[ev.NewRole].Ammo) { - ev.Ammo.Clear(); - foreach ((ItemType type, ushort amount, string group) in config.StartingInventories[ev.NewRole].Ammo) + if (string.IsNullOrEmpty(group) || group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(group, out UserGroup userGroup) && userGroup == ev.Player.Group)) { - if (string.IsNullOrEmpty(group) || group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(group, out UserGroup userGroup) && userGroup == ev.Player.Group)) - { - ev.Ammo.Add(type, amount); - } + ev.Ammo.Add(type, amount); } } } } } + } - public void OnSpawned(SpawnedEventArgs ev) + public void OnSpawned(SpawnedEventArgs ev) + { + if (ev.Player == null) { - if (ev.Player == null) - { - Log.Warn($"{nameof(OnSpawned)}: Triggering player is null."); - return; - } - - RoleTypeId newRole = ev.Player.Role.Type; - if (config.HealthValues != null && config.HealthValues.TryGetValue(newRole, out int health)) - { - ev.Player.Health = health; - ev.Player.MaxHealth = health; - } - - if (ev.Player.Role is FpcRole && config.PlayerHealthInfo) - { - ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; - } - - if (config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple value)) - Plugin.AfkDict[ev.Player] = new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); + Log.Warn($"{nameof(OnSpawned)}: Triggering player is null."); + return; } - public void OnPlayerDied(DiedEventArgs ev) + RoleTypeId newRole = ev.Player.Role.Type; + if (config.HealthValues != null && config.HealthValues.TryGetValue(newRole, out int health)) { - if (ev.Attacker != null && config.HealthOnKill.ContainsKey(ev.Attacker.Role)) - { - ev.Attacker.Heal(config.HealthOnKill[ev.Attacker.Role]); - } + ev.Player.Health = health; + ev.Player.MaxHealth = health; } - public List StartItems(RoleTypeId role, Player player = null) + if (ev.Player.Role is FpcRole && config.PlayerHealthInfo) { - List items = new(); - - for (int i = 0; i < config.StartingInventories[role].UsedSlots; i++) - { - IEnumerable itemChances = config.StartingInventories[role][i].Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)); - double r; - if (config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * itemChances.Sum(val => val.Chance); - else - r = Plugin.Random.NextDouble() * 100; - Log.Debug($"[StartItems] ActualChance ({r})/{itemChances.Sum(val => val.Chance)}"); - foreach ((string item, double chance, string groupKey) in itemChances) - { - Log.Debug($"[StartItems] Probability ({r})/{chance}"); - if (r <= chance) - { - if (Enum.TryParse(item, true, out ItemType type)) - { - items.Add(type); - break; - } - else if (CustomItem.TryGet(item, out CustomItem customItem)) - { - if (player != null) - customItem!.Give(player); - else - Log.Warn($"{nameof(StartItems)}: Tried to give {customItem!.Name} to a null player."); - - break; - } - else - Log.Warn($"{nameof(StartItems)}: {item} is not a valid ItemType or it is a CustomItem that is not installed! It is being skipper in inventory decisions."); - } + ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; + } - r -= chance; - } - } + if (config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple value)) + Plugin.AfkDict[ev.Player] = new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); + } - return items; + public void OnPlayerDied(DiedEventArgs ev) + { + if (ev.Attacker != null && config.HealthOnKill.ContainsKey(ev.Attacker.Role)) + { + ev.Attacker.Heal(config.HealthOnKill[ev.Attacker.Role]); } - - public string FormatJoinMessage(Player player) => - string.IsNullOrEmpty(config.JoinMessage) ? string.Empty : config.JoinMessage.Replace("%player%", player.Nickname).Replace("%server%", Server.Name).Replace("%count%", $"{Player.Dictionary.Count}"); + } - public void OnPlayerHurting(HurtingEventArgs ev) - { - float damageMultiplier; - if (config.RoleDamageMultipliers != null && ev.Attacker != null && config.RoleDamageMultipliers.TryGetValue(ev.Attacker.Role, out damageMultiplier)) - ev.Amount *= damageMultiplier; - - if (config.DamageMultipliers != null && config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier)) - ev.Amount *= damageMultiplier; + public void OnPlayerHurting(HurtingEventArgs ev) + { + if (config.RoleDamageMultipliers != null && ev.Attacker != null && config.RoleDamageMultipliers.TryGetValue(ev.Attacker.Role, out var damageMultiplier)) + ev.Amount *= damageMultiplier; - if (config.PlayerHealthInfo) - ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; + if (config.DamageMultipliers != null && config.DamageMultipliers.TryGetValue(ev.DamageHandler.Type, out damageMultiplier)) + ev.Amount *= damageMultiplier; - if (ev.Attacker is not null && Plugin.AfkDict.ContainsKey(ev.Attacker)) - { - Log.Debug($"Resetting {ev.Attacker.Nickname} AFK timer."); - Plugin.AfkDict[ev.Attacker] = new Tuple(0, ev.Attacker.Position); - } - } + if (config.PlayerHealthInfo) + ev.Player.CustomInfo = $"({ev.Player.Health}/{ev.Player.MaxHealth}) {(!string.IsNullOrEmpty(ev.Player.CustomInfo) ? ev.Player.CustomInfo.Substring(ev.Player.CustomInfo.LastIndexOf(')') + 1) : string.Empty)}"; - public void OnInteractingDoor(InteractingDoorEventArgs ev) + if (ev.Attacker is not null && Plugin.AfkDict.ContainsKey(ev.Attacker)) { - if (Plugin.AfkDict.ContainsKey(ev.Player)) - { - Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); - } + Log.Debug($"Resetting {ev.Attacker.Nickname} AFK timer."); + Plugin.AfkDict[ev.Attacker] = new Tuple(0, ev.Attacker.Position); } + } - public void OnInteractingElevator(InteractingElevatorEventArgs ev) + public void OnEscaping(EscapingEventArgs ev) + { + if (ev.Player.IsCuffed && config.DisarmedEscapeSwitchRole.TryGetValue(ev.Player.Role, out RoleTypeId newRole)) { - if (Plugin.AfkDict.ContainsKey(ev.Player)) - { - Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); - } + ev.NewRole = newRole; + ev.IsAllowed = newRole != RoleTypeId.None; } + } - public void OnEscaping(EscapingEventArgs ev) - { - if (ev.Player.IsCuffed && config.DisarmedEscapeSwitchRole.TryGetValue(ev.Player.Role, out RoleTypeId newRole)) - { - ev.NewRole = newRole; - ev.IsAllowed = newRole != RoleTypeId.None; - } - } + public void OnUsingRadioBattery(UsingRadioBatteryEventArgs ev) + { + ev.Drain *= config.RadioBatteryDrainMultiplier; + } - public void OnUsingRadioBattery(UsingRadioBatteryEventArgs ev) + public void AntiAfkEventHandler(IPlayerEvent ev) + { + if (ev.Player != null && Plugin.AfkDict.ContainsKey(ev.Player)) { - ev.Drain *= config.RadioBatteryDrainMultiplier; + Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); + Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); } + } + + public List StartItems(RoleTypeId role, Player player = null) + { + List items = new(); - public void AntiAfkEventHandler(IPlayerEvent ev) + for (int i = 0; i < config.StartingInventories[role].UsedSlots; i++) { - if (ev.Player != null && Plugin.AfkDict.ContainsKey(ev.Player)) + var itemChances = (List)config.StartingInventories[role][i].Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)); + double r; + if (config.AdditiveProbabilities) + r = Plugin.Random.NextDouble() * itemChances.Sum(val => val.Chance); + else + r = Plugin.Random.NextDouble() * 100; + Log.Debug($"[StartItems] ActualChance ({r})/{itemChances.Sum(val => val.Chance)}"); + foreach ((string item, double chance, string groupKey) in itemChances) { - Log.Debug($"Resetting {ev.Player.Nickname} AFK timer."); - Plugin.AfkDict[ev.Player] = new Tuple(0, ev.Player.Position); + Log.Debug($"[StartItems] Probability ({r})/{chance}"); + if (r <= chance) + { + if (Enum.TryParse(item, true, out ItemType type)) + { + items.Add(type); + break; + } + else if (CustomItem.TryGet(item, out CustomItem customItem)) + { + if (player != null) + customItem!.Give(player); + else + Log.Warn($"{nameof(StartItems)}: Tried to give {customItem!.Name} to a null player."); + + break; + } + else + Log.Warn($"{nameof(StartItems)}: {item} is not a valid ItemType or it is a CustomItem that is not installed! It is being skipper in inventory decisions."); + } + + r -= chance; } } + + return items; + } + + private string FormatJoinMessage(Player player) + { + return + string.IsNullOrEmpty(config.JoinMessage) + ? string.Empty + : config.JoinMessage + .Replace("%player%", player.Nickname) + .Replace("%server%", Server.Name) + .Replace("%count%", $"{Player.Dictionary.Count}"); } } \ No newline at end of file diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index 0014d12..9cb443b 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -1,3 +1,4 @@ +// ReSharper disable IteratorNeverReturns namespace Common_Utilities.EventHandlers { #pragma warning disable SA1313 // Parameter names should begin with lower-case letter @@ -19,30 +20,29 @@ namespace Common_Utilities.EventHandlers public class ServerHandlers { - private readonly Plugin plugin; + private readonly Config config; + private bool friendlyFireDisable; - private bool friendlyFireDisable = false; - - public ServerHandlers(Plugin plugin) => this.plugin = plugin; + public ServerHandlers(Plugin plugin) => config = config; public void OnRoundStarted() { - if (plugin.Config.AutonukeTime > -1) - plugin.Coroutines.Add(Timing.CallDelayed(plugin.Config.AutonukeTime, AutoNuke)); + if (config.AutonukeTime > -1) + Plugin.Coroutines.Add(Timing.CallDelayed(config.AutonukeTime, AutoNuke)); - if (plugin.Config.RagdollCleanupDelay > 0) - plugin.Coroutines.Add(Timing.RunCoroutine(RagdollCleanup())); + if (config.RagdollCleanupDelay > 0) + Plugin.Coroutines.Add(Timing.RunCoroutine(RagdollCleanup())); - if (plugin.Config.ItemCleanupDelay > 0) - plugin.Coroutines.Add(Timing.RunCoroutine(ItemCleanup())); + if (config.ItemCleanupDelay > 0) + Plugin.Coroutines.Add(Timing.RunCoroutine(ItemCleanup())); } public void OnWaitingForPlayers() { - if (plugin.Config.AfkLimit > 0) + if (config.AfkLimit > 0) { - plugin.AfkDict.Clear(); - plugin.Coroutines.Add(Timing.RunCoroutine(AfkCheck())); + Plugin.AfkDict.Clear(); + Plugin.Coroutines.Add(Timing.RunCoroutine(AfkCheck())); } if (friendlyFireDisable) @@ -52,8 +52,8 @@ public void OnWaitingForPlayers() friendlyFireDisable = false; } - if (plugin.Config.TimedBroadcastDelay > 0) - plugin.Coroutines.Add(Timing.RunCoroutine(ServerBroadcast())); + if (config.TimedBroadcastDelay > 0) + Plugin.Coroutines.Add(Timing.RunCoroutine(ServerBroadcast())); // Fix GrandLoadout not able to give this 2 inventory StartingInventories.DefinedInventories[RoleTypeId.Tutorial] = new(Array.Empty(), new()); @@ -64,80 +64,80 @@ public void OnWaitingForPlayers() public void OnRoundEnded(RoundEndedEventArgs ev) { - if (plugin.Config.FriendlyFireOnRoundEnd && !Server.FriendlyFire) + if (config.FriendlyFireOnRoundEnd && !Server.FriendlyFire) { Log.Debug($"{nameof(OnRoundEnded)}: Enabling friendly fire."); Server.FriendlyFire = true; friendlyFireDisable = true; } - foreach (CoroutineHandle coroutine in plugin.Coroutines) + foreach (CoroutineHandle coroutine in Plugin.Coroutines) Timing.KillCoroutines(coroutine); - plugin.Coroutines.Clear(); + Plugin.Coroutines.Clear(); } - public IEnumerator ServerBroadcast() + private IEnumerator ServerBroadcast() { for (; ; ) { - yield return Timing.WaitForSeconds(plugin.Config.TimedBroadcastDelay); + yield return Timing.WaitForSeconds(config.TimedBroadcastDelay); - Map.Broadcast(plugin.Config.TimedBroadcastDuration, plugin.Config.TimedBroadcast); + Map.Broadcast(config.TimedBroadcastDuration, config.TimedBroadcast); } } - public IEnumerator ItemCleanup() + private IEnumerator ItemCleanup() { for (; ; ) { - yield return Timing.WaitForSeconds(plugin.Config.ItemCleanupDelay); + yield return Timing.WaitForSeconds(config.ItemCleanupDelay); foreach (Pickup pickup in Pickup.List.ToList()) { - if (!plugin.Config.ItemCleanupOnlyPocket || pickup.Position.y < -1500f) + if (!config.ItemCleanupOnlyPocket || pickup.Position.y < -1500f) pickup.Destroy(); } } } - public IEnumerator RagdollCleanup() + private IEnumerator RagdollCleanup() { for (; ; ) { - yield return Timing.WaitForSeconds(plugin.Config.RagdollCleanupDelay); + yield return Timing.WaitForSeconds(config.RagdollCleanupDelay); foreach (Ragdoll ragdoll in Ragdoll.List.ToList()) { - if (!plugin.Config.RagdollCleanupOnlyPocket || ragdoll.Position.y < -1500f) + if (!config.RagdollCleanupOnlyPocket || ragdoll.Position.y < -1500f) ragdoll.Destroy(); } } } - public void AutoNuke() + private void AutoNuke() { if (!Warhead.IsInProgress) { - switch (plugin.Config.AutonukeBroadcast.Duration) + switch (config.AutonukeBroadcast.Duration) { case 0: break; case 1: - Cassie.Message(plugin.Config.AutonukeBroadcast.Content); + Cassie.Message(config.AutonukeBroadcast.Content); break; default: - Map.Broadcast(plugin.Config.AutonukeBroadcast); + Map.Broadcast(config.AutonukeBroadcast); break; } Warhead.Start(); } - if (plugin.Config.AutonukeLock) + if (config.AutonukeLock) Warhead.IsLocked = true; } - public IEnumerator AfkCheck() + private IEnumerator AfkCheck() { for (; ; ) { @@ -145,10 +145,10 @@ public IEnumerator AfkCheck() foreach (Player player in Player.List) { - if (!plugin.AfkDict.ContainsKey(player)) - plugin.AfkDict.Add(player, new Tuple(0, player.Position)); + if (!Plugin.AfkDict.ContainsKey(player)) + Plugin.AfkDict.Add(player, new Tuple(0, player.Position)); - if (player.Role.IsDead || player.IsGodModeEnabled || player.IsNoclipPermitted || player.Role is FpcRole { IsGrounded: false } || player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity) || plugin.Config.AfkIgnoredRoles.Contains(player.Role.Type)) + if (player.Role.IsDead || player.IsGodModeEnabled || player.IsNoclipPermitted || player.Role is FpcRole { IsGrounded: false } || player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity) || config.AfkIgnoredRoles.Contains(player.Role.Type)) { #pragma warning disable SA1013 Log.Debug($"Player {player.Nickname} ({player.Role.Type}) is not a checkable player. NoClip: {player.IsNoclipPermitted} GodMode: {player.IsGodModeEnabled} IsNotGrounded: {player.Role is FpcRole { IsGrounded: false }} AFKImunity: {player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity)}"); @@ -156,39 +156,39 @@ public IEnumerator AfkCheck() #pragma warning restore SA1013 } - if ((plugin.AfkDict[player].Item2 - player.Position).sqrMagnitude > 2) + if ((Plugin.AfkDict[player].Item2 - player.Position).sqrMagnitude > 2) { Log.Debug($"Player {player.Nickname} has moved, resetting AFK timer."); - plugin.AfkDict[player] = new Tuple(0, player.Position); + Plugin.AfkDict[player] = new Tuple(0, player.Position); } - if (plugin.AfkDict[player].Item1 >= plugin.Config.AfkLimit) + if (Plugin.AfkDict[player].Item1 >= config.AfkLimit) { - plugin.AfkDict.Remove(player); + Plugin.AfkDict.Remove(player); Log.Debug($"Kicking {player.Nickname} for being AFK."); player.Kick("You were kicked by CommonUtilities for being AFK."); } - else if (plugin.AfkDict[player].Item1 >= (plugin.Config.AfkLimit / 2)) + else if (Plugin.AfkDict[player].Item1 >= (config.AfkLimit / 2)) { - player.Broadcast(2, $"You have been AFK for {plugin.AfkDict[player].Item1} seconds. You will be automatically kicked if you remain AFK for a total of {plugin.Config.AfkLimit} seconds.", shouldClearPrevious: true); + player.Broadcast(2, $"You have been AFK for {Plugin.AfkDict[player].Item1} seconds. You will be automatically kicked if you remain AFK for a total of {config.AfkLimit} seconds.", shouldClearPrevious: true); } - plugin.AfkDict[player] = new Tuple(plugin.AfkDict[player].Item1 + 1, plugin.AfkDict[player].Item2); + Plugin.AfkDict[player] = new Tuple(Plugin.AfkDict[player].Item1 + 1, Plugin.AfkDict[player].Item2); } } } public void OnRestartingRound() { - foreach (CoroutineHandle coroutine in plugin.Coroutines) + foreach (CoroutineHandle coroutine in Plugin.Coroutines) Timing.KillCoroutines(coroutine); - plugin.Coroutines.Clear(); + Plugin.Coroutines.Clear(); } public void OnWarheadStarting(StartingEventArgs _) { foreach (Room room in Room.List) - room.Color = plugin.Config.WarheadColor; + room.Color = config.WarheadColor; } public void OnWarheadStopping(StoppingEventArgs _) diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index 2bd8fdc..9d2df60 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -21,7 +21,7 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset if (resetInventory) player.ClearInventory(); - player.AddItem(Plugin.Instance.PlayerHandlers.StartItems(roleTypeId, player)); + player.AddItem(Plugin.Instance.playerHandlers.StartItems(roleTypeId, player)); if (startingInventories.Ammo != null && startingInventories.Ammo.Count > 0) { diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index 32ae547..289c56f 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -28,7 +28,7 @@ public class Plugin : Plugin { public static Plugin Instance; public static Random Random; - private PlayerHandlers playerHandlers; + public PlayerHandlers playerHandlers; private ServerHandlers serverHandlers; private MapHandlers mapHandlers; private Harmony harmony; @@ -48,7 +48,7 @@ public class Plugin : Plugin public override PluginPriority Priority => PluginPriority.Higher; - public List Coroutines { get; } = new(); + public static List Coroutines { get; } = new(); public override void OnEnabled() { @@ -70,8 +70,6 @@ public override void OnEnabled() player.Hurting += playerHandlers.OnPlayerHurting; player.Verified += playerHandlers.OnPlayerVerified; player.Spawned += playerHandlers.OnSpawned; - player.InteractingDoor += playerHandlers.OnInteractingDoor; - player.InteractingElevator += playerHandlers.OnInteractingElevator; player.Escaping += playerHandlers.OnEscaping; if (Config.HealthOnKill != null) @@ -92,6 +90,8 @@ public override void OnEnabled() player.ReloadingWeapon += playerHandlers.AntiAfkEventHandler; player.ThrownProjectile += playerHandlers.AntiAfkEventHandler; player.ChangingMoveState += playerHandlers.AntiAfkEventHandler; + player.InteractingDoor += playerHandlers.AntiAfkEventHandler; + player.InteractingElevator += playerHandlers.AntiAfkEventHandler; } server.RoundEnded += serverHandlers.OnRoundEnded; @@ -118,34 +118,34 @@ public override void OnEnabled() public override void OnDisabled() { + player.Hurting -= playerHandlers.OnPlayerHurting; + player.Verified -= playerHandlers.OnPlayerVerified; + player.Spawned -= playerHandlers.OnSpawned; + player.Escaping -= playerHandlers.OnEscaping; player.Died -= playerHandlers.OnPlayerDied; + player.ChangingRole -= playerHandlers.OnChangingRole; + player.UsingRadioBattery -= playerHandlers.OnUsingRadioBattery; player.Jumping -= playerHandlers.AntiAfkEventHandler; player.Shooting -= playerHandlers.AntiAfkEventHandler; player.UsingItem -= playerHandlers.AntiAfkEventHandler; - player.Hurting -= playerHandlers.OnPlayerHurting; - player.Verified -= playerHandlers.OnPlayerVerified; player.MakingNoise -= playerHandlers.AntiAfkEventHandler; player.ReloadingWeapon -= playerHandlers.AntiAfkEventHandler; - player.ChangingRole -= playerHandlers.OnChangingRole; - player.Spawned -= playerHandlers.OnSpawned; player.ThrownProjectile -= playerHandlers.AntiAfkEventHandler; - player.InteractingDoor -= playerHandlers.OnInteractingDoor; - player.UsingRadioBattery -= playerHandlers.OnUsingRadioBattery; player.ChangingMoveState -= playerHandlers.AntiAfkEventHandler; - player.InteractingElevator -= playerHandlers.OnInteractingElevator; - player.Escaping -= playerHandlers.OnEscaping; + player.InteractingDoor -= playerHandlers.AntiAfkEventHandler; + player.InteractingElevator -= playerHandlers.AntiAfkEventHandler; server.RoundEnded -= serverHandlers.OnRoundEnded; server.RoundStarted -= serverHandlers.OnRoundStarted; server.RestartingRound -= serverHandlers.OnRestartingRound; server.WaitingForPlayers -= serverHandlers.OnWaitingForPlayers; - scp914.UpgradingPickup -= mapHandlers.OnScp914UpgradingItem; scp914.UpgradingPlayer -= mapHandlers.OnScp914UpgradingPlayer; + scp914.UpgradingPickup -= mapHandlers.OnScp914UpgradingItem; scp914.UpgradingInventoryItem -= mapHandlers.OnScp914UpgradingInventoryItem; - warhead.Stopping -= serverHandlers.OnWarheadStopping; warhead.Starting -= serverHandlers.OnWarheadStarting; + warhead.Stopping -= serverHandlers.OnWarheadStopping; harmony.UnpatchAll(harmonyName); From 11a19224fb59b67cdee5bad9b4338923bc25c53c Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Thu, 30 May 2024 23:25:00 +0200 Subject: [PATCH 03/23] indents I think --- Common Utilities/EventHandlers/PlayerHandlers.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 4062d8c..698a6dd 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -49,17 +49,17 @@ public void OnChangingRole(ChangingRoleEventArgs ev) ev.Items.Clear(); ev.Items.AddRange(StartItems(ev.NewRole, ev.Player)); - if (config.StartingInventories[ev.NewRole].Ammo != null && config.StartingInventories[ev.NewRole].Ammo.Count > 0) + if (config.StartingInventories[ev.NewRole].Ammo == null || config.StartingInventories[ev.NewRole].Ammo.Count <= 0) + return; + + if (config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) { - if (config.StartingInventories[ev.NewRole].Ammo.Any(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == ev.Player.Group))) + ev.Ammo.Clear(); + foreach ((ItemType type, ushort amount, string group) in config.StartingInventories[ev.NewRole].Ammo) { - ev.Ammo.Clear(); - foreach ((ItemType type, ushort amount, string group) in config.StartingInventories[ev.NewRole].Ammo) + if (string.IsNullOrEmpty(group) || group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(group, out UserGroup userGroup) && userGroup == ev.Player.Group)) { - if (string.IsNullOrEmpty(group) || group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(group, out UserGroup userGroup) && userGroup == ev.Player.Group)) - { - ev.Ammo.Add(type, amount); - } + ev.Ammo.Add(type, amount); } } } From 83d083a6df7e7d58f7c579ed2c40968b627ccbdb Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Fri, 31 May 2024 14:20:18 +0200 Subject: [PATCH 04/23] mainly event handler changes --- Common Utilities/API.cs | 20 + Common Utilities/ConfigObjects/ItemChance.cs | 5 +- .../ConfigObjects/ItemUpgradeChance.cs | 2 +- .../ConfigObjects/PlayerUpgradeChance.cs | 2 +- .../ConfigObjects/Scp914EffectChance.cs | 2 +- .../ConfigObjects/Scp914TeleportChance.cs | 2 +- Common Utilities/EventHandlers/MapHandlers.cs | 344 +++++++++--------- .../EventHandlers/PlayerHandlers.cs | 40 +- Common Utilities/Interfaces/IChanceObject.cs | 6 + .../Patches/ServerGrantLoadoutPatches.cs | 19 +- 10 files changed, 234 insertions(+), 208 deletions(-) create mode 100644 Common Utilities/API.cs create mode 100644 Common Utilities/Interfaces/IChanceObject.cs diff --git a/Common Utilities/API.cs b/Common Utilities/API.cs new file mode 100644 index 0000000..535be5c --- /dev/null +++ b/Common Utilities/API.cs @@ -0,0 +1,20 @@ +namespace Common_Utilities; + +using System.Collections.Generic; +using System.Linq; +using ConfigObjects; + +public class API +{ + public static double RollChance(IEnumerable scp914EffectChances) + { + double rolledChance; + + if (Plugin.Instance.Config.AdditiveProbabilities) + rolledChance = Plugin.Random.NextDouble() * scp914EffectChances.Sum(x => x.Chance); + else + rolledChance = Plugin.Random.NextDouble() * 100; + + return rolledChance; + } +} \ No newline at end of file diff --git a/Common Utilities/ConfigObjects/ItemChance.cs b/Common Utilities/ConfigObjects/ItemChance.cs index 0aaf0c4..5316097 100644 --- a/Common Utilities/ConfigObjects/ItemChance.cs +++ b/Common Utilities/ConfigObjects/ItemChance.cs @@ -1,6 +1,6 @@ namespace Common_Utilities.ConfigObjects; -public class ItemChance +public class ItemChance : IChanceObject { public string ItemName { get; set; } = ItemType.None.ToString(); @@ -8,10 +8,9 @@ public class ItemChance public string Group { get; set; } = "none"; - public void Deconstruct(out string name, out double i, out string groupKey) + public void Deconstruct(out string name, out double i) { name = ItemName; i = Chance; - groupKey = Group; } } \ No newline at end of file diff --git a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs index afa921f..9f44436 100644 --- a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs @@ -1,6 +1,6 @@ namespace Common_Utilities.ConfigObjects { - public class ItemUpgradeChance + public class ItemUpgradeChance : IChanceObject { public ItemType Original { get; set; } diff --git a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs index 72fb0e4..336cf02 100644 --- a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs @@ -2,7 +2,7 @@ namespace Common_Utilities.ConfigObjects { using PlayerRoles; - public class PlayerUpgradeChance + public class PlayerUpgradeChance : IChanceObject { public RoleTypeId Original { get; set; } diff --git a/Common Utilities/ConfigObjects/Scp914EffectChance.cs b/Common Utilities/ConfigObjects/Scp914EffectChance.cs index f0a0918..2868b95 100644 --- a/Common Utilities/ConfigObjects/Scp914EffectChance.cs +++ b/Common Utilities/ConfigObjects/Scp914EffectChance.cs @@ -2,7 +2,7 @@ namespace Common_Utilities.ConfigObjects { using Exiled.API.Enums; - public class Scp914EffectChance + public class Scp914EffectChance : IChanceObject { public EffectType Effect { get; set; } diff --git a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs index ba8a1e4..9b740e2 100644 --- a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs +++ b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs @@ -5,7 +5,7 @@ namespace Common_Utilities.ConfigObjects using Exiled.API.Enums; using UnityEngine; - public class Scp914TeleportChance + public class Scp914TeleportChance : IChanceObject { public ZoneType Zone { get; set; } = ZoneType.Unspecified; diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index c7bdd79..d8e19be 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -1,238 +1,222 @@ -using Exiled.API.Extensions; -using Exiled.API.Features.Items; +namespace Common_Utilities.EventHandlers; -namespace Common_Utilities.EventHandlers +using Exiled.API.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using ConfigObjects; +using Exiled.API.Enums; +using Exiled.API.Features; +using Exiled.API.Features.Pickups; +using Exiled.CustomRoles.API.Features; +using Exiled.Events.EventArgs.Scp914; +using MEC; +using PlayerRoles; +using UnityEngine; + +public class MapHandlers { - using System; - using System.Collections.Generic; - using System.Linq; - - using Common_Utilities.ConfigObjects; - using Exiled.API.Enums; - using Exiled.API.Features; - using Exiled.API.Features.Pickups; - using Exiled.CustomRoles.API.Features; - using Exiled.Events.EventArgs.Scp914; - using MEC; - using PlayerRoles; - using UnityEngine; - - public class MapHandlers - { - private readonly Plugin plugin; + private readonly Config config; - public MapHandlers(Plugin plugin) => this.plugin = plugin; + public MapHandlers(Plugin plugin) => config = plugin.Config; - public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) + public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) + { + if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List chances)) { - if (plugin.Config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List chances)) - { - IEnumerable itemUpgradeChance = chances.Where(x => x.Original == ev.Pickup.Type); + var itemUpgradeChance = (List)chances.Where(x => x.Original == ev.Pickup.Type); - foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) - { - double r; - if (plugin.Config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); - else - r = Plugin.Random.NextDouble() * 100; - - Log.Debug($"{nameof(OnScp914UpgradingItem)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {r <= chance} ({r})"); - if (r <= chance) - { - UpgradeItem(ev.Pickup, destinationItem, ev.OutputPosition, count); - ev.IsAllowed = false; - break; - } + double rolledChance = API.RollChance(itemUpgradeChance); - r -= chance; + foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) + { + Log.Debug($"{nameof(OnScp914UpgradingItem)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); + + if (rolledChance <= chance) + { + UpgradeItem(ev.Pickup, destinationItem, ev.OutputPosition, count); + ev.IsAllowed = false; + break; } + + if (config.AdditiveProbabilities) + rolledChance -= chance; } } + } - public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) + public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) + { + if (config.Scp914ItemChances.ContainsKey(ev.KnobSetting)) { - if (plugin.Config.Scp914ItemChances.ContainsKey(ev.KnobSetting)) - { - IEnumerable itemUpgradeChance = plugin.Config.Scp914ItemChances[ev.KnobSetting].Where(x => x.Original == ev.Item.Type); + var itemUpgradeChance = (List)config.Scp914ItemChances[ev.KnobSetting].Where(x => x.Original == ev.Item.Type); + + double rolledChance = API.RollChance(itemUpgradeChance); - foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) + foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) + { + Log.Debug($"{nameof(OnScp914UpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); + + if (rolledChance <= chance) { - double r; - if (plugin.Config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * itemUpgradeChance.Sum(x => x.Chance); - else - r = Plugin.Random.NextDouble() * 100; - - Log.Debug($"{nameof(OnScp914UpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {r <= chance} ({r})"); - if (r <= chance) + if (destinationItem is not ItemType.None) { ev.Player.RemoveItem(ev.Item); - if (destinationItem is not ItemType.None) + + for (int i = 0; i < count; i++) { - for (int i = 0; i < count; i++) - { - if (!ev.Player.IsInventoryFull) - ev.Player.AddItem(destinationItem); - else - Pickup.CreateAndSpawn(destinationItem, Scp914.OutputPosition, ev.Player.Rotation, ev.Player); - } + if (!ev.Player.IsInventoryFull) + ev.Player.AddItem(destinationItem); + else + Pickup.CreateAndSpawn(destinationItem, Scp914.OutputPosition, ev.Player.Rotation, ev.Player); } - - break; } - r -= chance; + break; } + + if (config.AdditiveProbabilities) + rolledChance -= chance; } } + } - public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) + public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) + { + if (config.Scp914ClassChanges != null && config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change)) { - if (plugin.Config.Scp914ClassChanges != null && plugin.Config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change)) - { - IEnumerable playerUpgradeChance = change.Where(x => x.Original == ev.Player.Role); + var playerUpgradeChance = (List)change.Where(x => x.Original == ev.Player.Role); - foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance) + double rolledChance = API.RollChance(playerUpgradeChance); + + foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance) + { + Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role})is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {rolledChance <= chance} ({rolledChance})"); + if (rolledChance <= chance) { - double r; - if (plugin.Config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * playerUpgradeChance.Sum(x => x.Chance); - else - r = Plugin.Random.NextDouble() * 100; - - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role})is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {r <= chance} ({r})"); - if (r <= chance) - { - float originalHealth = ev.Player.Health; - var originalItems = ev.Player.Items; - var originalAmmo = ev.Player.Ammo; + float originalHealth = ev.Player.Health; + var originalItems = ev.Player.Items; + var originalAmmo = ev.Player.Ammo; - if (Enum.TryParse(destinationRole, true, out RoleTypeId roleType)) - { - ev.Player.Role.Set(roleType, SpawnReason.Respawn, RoleSpawnFlags.None); - } - else if (CustomRole.TryGet(destinationRole, out CustomRole customRole)) + if (Enum.TryParse(destinationRole, true, out RoleTypeId roleType)) + { + ev.Player.Role.Set(roleType, SpawnReason.Respawn, RoleSpawnFlags.None); + } + else if (CustomRole.TryGet(destinationRole, out CustomRole customRole)) + { + if (customRole is not null) { - if (customRole is not null) - { - customRole.AddRole(ev.Player); - Timing.CallDelayed(0.5f, () => ev.Player.Teleport(ev.OutputPosition)); - } + customRole.AddRole(ev.Player); + Timing.CallDelayed(0.5f, () => ev.Player.Teleport(ev.OutputPosition)); } + } + + if (keepHealth) + { + ev.Player.Health = originalHealth; + } - if (keepHealth) + if (keepInventory) + { + foreach (var item in originalItems) { - ev.Player.Health = originalHealth; + ev.Player.AddItem(item); } - if (keepInventory) + foreach (var kvp in originalAmmo) { - foreach (var item in originalItems) - { - ev.Player.AddItem(item); - } - - foreach (var kvp in originalAmmo) - { - ev.Player.SetAmmo(kvp.Key.GetAmmoType(), kvp.Value); - } + ev.Player.SetAmmo(kvp.Key.GetAmmoType(), kvp.Value); } - - ev.Player.Position = ev.OutputPosition; - break; } - - r -= chance; + + ev.Player.Position = ev.OutputPosition; + break; } + + if (config.AdditiveProbabilities) + rolledChance -= chance; } + } - if (plugin.Config.Scp914EffectChances != null && plugin.Config.Scp914EffectChances.ContainsKey(ev.KnobSetting) && (ev.Player.Role.Side != Side.Scp || !plugin.Config.ScpsImmuneTo914Effects)) - { - IEnumerable scp914EffectChances = plugin.Config.Scp914EffectChances[ev.KnobSetting]; + if (config.Scp914EffectChances != null && config.Scp914EffectChances.ContainsKey(ev.KnobSetting) && (ev.Player.Role.Side != Side.Scp || !config.ScpsImmuneTo914Effects)) + { + IEnumerable scp914EffectChances = config.Scp914EffectChances[ev.KnobSetting]; + + double rolledChance = API.RollChance(scp914EffectChances); - foreach ((EffectType effect, double chance, float duration) in scp914EffectChances) + foreach ((EffectType effect, double chance, float duration) in scp914EffectChances) + { + Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to gain an effect through SCP-914. {effect} ({chance}). Should be added: {rolledChance <= chance} ({rolledChance})"); + + if (rolledChance <= chance) { - double r; - if (plugin.Config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * scp914EffectChances.Sum(x => x.Chance); - else - r = Plugin.Random.NextDouble() * 100; - - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to gain an effect. {effect} ({chance}). Should be added: {r <= chance} ({r})"); - if (r <= chance) - { - ev.Player.EnableEffect(effect, duration); - if (plugin.Config.Scp914EffectsExclusivity) - break; - } - - r -= chance; + ev.Player.EnableEffect(effect, duration); + if (config.Scp914EffectsExclusivity) + break; } + + if (config.AdditiveProbabilities) + rolledChance -= chance; } + } + + if (config.Scp914TeleportChances != null && config.Scp914TeleportChances.ContainsKey(ev.KnobSetting)) + { + IEnumerable scp914TeleportChances = config.Scp914TeleportChances[ev.KnobSetting]; + + double rolledChance = API.RollChance(scp914TeleportChances); - if (plugin.Config.Scp914TeleportChances != null && plugin.Config.Scp914TeleportChances.ContainsKey(ev.KnobSetting)) + foreach ((RoomType roomType, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in config.Scp914TeleportChances[ev.KnobSetting]) { - IEnumerable scp914TeleportChances = plugin.Config.Scp914TeleportChances[ev.KnobSetting]; + Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset} ({chance}). Should be teleported: {rolledChance <= chance} ({rolledChance})"); - foreach ((RoomType roomType, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in plugin.Config.Scp914TeleportChances[ev.KnobSetting]) + if (rolledChance <= chance) { - double r; - if (plugin.Config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * scp914TeleportChances.Sum(x => x.Chance); - else - r = Plugin.Random.NextDouble() * 100; - - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset} ({chance}). Should be teleported: {r <= chance} ({r})"); - if (r <= chance) - { - if (zone != ZoneType.Unspecified) - { - ev.OutputPosition = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset); - if (damage > 0f) - { - float amount = ev.Player.MaxHealth * damage; - if (damage > 1f) - amount = damage; - - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is being damaged for {amount}. -- {ev.Player.Health} * {damage}"); - ev.Player.Hurt(amount, "SCP-914 Teleport", "SCP-914"); - } - } - else - { - ev.OutputPosition = Room.Get(roomType).Position + (Vector3.up * 1.5f) + offset; - if (damage > 0f) - { - float amount = ev.Player.MaxHealth * damage; - if (damage > 1f) - amount = damage; - - Log.Debug( - $"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is being damaged for {amount}. -- {ev.Player.Health} * {damage}"); - ev.Player.Hurt(amount, "SCP-914 Teleport", "SCP-914"); - } - } + ev.OutputPosition = ChoosePosition(zone, ignoredRooms, offset, roomType); + + DealDamage(ev.Player, damage); - break; - } - - r -= chance; + break; } + + if (config.AdditiveProbabilities) + rolledChance -= chance; } } + } + + private static Vector3 ChoosePosition(ZoneType zone, List ignoredRooms, Vector3 offset, RoomType roomType) + { + Vector3 pos1 = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset); + Vector3 pos2 = Room.Get(roomType).Position + (Vector3.up * 1.5f) + offset; + + return zone != ZoneType.Unspecified ? pos1 : pos2; + } + + private void DealDamage(Player player, float damage) + { + if (damage > 0f) + { + float amount = player.MaxHealth * damage; + if (damage > 1f) + amount = damage; + + Log.Debug( + $"{nameof(OnScp914UpgradingPlayer)}: {player.Nickname} is being damaged for {amount}. -- {player.Health} * {damage}"); + player.Hurt(amount, "SCP-914 Teleport", "SCP-914"); + } + } - internal void UpgradeItem(Pickup oldItem, ItemType newItem, Vector3 pos, int count) + private void UpgradeItem(Pickup oldItem, ItemType newItem, Vector3 pos, int count) + { + Quaternion quaternion = oldItem.Rotation; + Player previousOwner = oldItem.PreviousOwner; + oldItem.Destroy(); + if (newItem is not ItemType.None) { - Quaternion quaternion = oldItem.Rotation; - Player previousOwner = oldItem.PreviousOwner; - oldItem.Destroy(); - if (newItem is not ItemType.None) + for (int i = 0; i < count; i++) { - for (int i = 0; i < count; i++) - { - Pickup.CreateAndSpawn(newItem, pos, quaternion, previousOwner); - } + Pickup.CreateAndSpawn(newItem, pos, quaternion, previousOwner); } } } diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 698a6dd..8b2018d 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -142,27 +142,36 @@ public void AntiAfkEventHandler(IPlayerEvent ev) public List StartItems(RoleTypeId role, Player player = null) { List items = new(); - + + // iterate through slots for (int i = 0; i < config.StartingInventories[role].UsedSlots; i++) { - var itemChances = (List)config.StartingInventories[role][i].Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)); - double r; - if (config.AdditiveProbabilities) - r = Plugin.Random.NextDouble() * itemChances.Sum(val => val.Chance); - else - r = Plugin.Random.NextDouble() * 100; - Log.Debug($"[StartItems] ActualChance ({r})/{itemChances.Sum(val => val.Chance)}"); - foreach ((string item, double chance, string groupKey) in itemChances) +#pragma warning disable SA1119 + // item chances for that slot + var itemChances = (List)config.StartingInventories[role][i] + .Where(x => player == null + || string.IsNullOrEmpty(x.Group) + || x.Group == "none" + || ((ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group))); +#pragma warning restore SA1119 + + double rolledChance = API.RollChance(itemChances); + + Log.Debug($"[StartItems] RolledChance ({rolledChance})/{itemChances.Sum(val => val.Chance)}"); + + foreach ((string item, double chance) in itemChances) { - Log.Debug($"[StartItems] Probability ({r})/{chance}"); - if (r <= chance) + Log.Debug($"[StartItems] Probability ({rolledChance})/{chance}"); + + if (rolledChance <= chance) { if (Enum.TryParse(item, true, out ItemType type)) { items.Add(type); break; } - else if (CustomItem.TryGet(item, out CustomItem customItem)) + + if (CustomItem.TryGet(item, out CustomItem customItem)) { if (player != null) customItem!.Give(player); @@ -171,11 +180,12 @@ public List StartItems(RoleTypeId role, Player player = null) break; } - else - Log.Warn($"{nameof(StartItems)}: {item} is not a valid ItemType or it is a CustomItem that is not installed! It is being skipper in inventory decisions."); + + Log.Warn($"{nameof(StartItems)}: {item} is not a valid ItemType or CustomItem! It is being skipped in inventory decisions."); } - r -= chance; + if (config.AdditiveProbabilities) + rolledChance -= chance; } } diff --git a/Common Utilities/Interfaces/IChanceObject.cs b/Common Utilities/Interfaces/IChanceObject.cs new file mode 100644 index 0000000..96c5d34 --- /dev/null +++ b/Common Utilities/Interfaces/IChanceObject.cs @@ -0,0 +1,6 @@ +namespace Common_Utilities.ConfigObjects; + +public interface IChanceObject +{ + public double Chance { get; set; } +} \ No newline at end of file diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index 9d2df60..68a06e9 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; - using Common_Utilities.ConfigObjects; - using Common_Utilities.Configs; + using ConfigObjects; + using Configs; using Exiled.API.Features; using HarmonyLib; using InventorySystem; @@ -15,7 +15,9 @@ public class ServerGrantLoadoutPatches { public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool resetInventory = true) { - if (Plugin.Instance.Config.StartingInventories == null || !Plugin.Instance.Config.StartingInventories.TryGetValue(roleTypeId, out RoleInventory startingInventories) || !Player.TryGet(target, out Player player)) + if (Plugin.Instance.Config.StartingInventories == null + || !Plugin.Instance.Config.StartingInventories.TryGetValue(roleTypeId, out RoleInventory startingInventories) + || !Player.TryGet(target, out Player player)) return true; if (resetInventory) @@ -23,9 +25,15 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset player.AddItem(Plugin.Instance.playerHandlers.StartItems(roleTypeId, player)); - if (startingInventories.Ammo != null && startingInventories.Ammo.Count > 0) + if (startingInventories.Ammo is { Count: > 0 }) { - IEnumerable startingAmmo = startingInventories.Ammo.Where(s => string.IsNullOrEmpty(s.Group) || s.Group == "none" || (ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == player.Group)); +#pragma warning disable SA1119 + List startingAmmo = (List)startingInventories.Ammo + .Where(s => + string.IsNullOrEmpty(s.Group) + || s.Group == "none" + || ((ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == player.Group))); +#pragma warning restore SA1119 if (startingAmmo.Any()) { player.Ammo.Clear(); @@ -36,7 +44,6 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset } } } - return false; } } From d5a2a174ff72b8f4693da97533c2ecb33d7ab97a Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Fri, 31 May 2024 14:38:47 +0200 Subject: [PATCH 05/23] more handler changes --- .../EventHandlers/PlayerHandlers.cs | 3 +- .../EventHandlers/ServerHandlers.cs | 67 ++++++++++--------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 8b2018d..b83beca 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -4,7 +4,6 @@ namespace Common_Utilities.EventHandlers; using System; using System.Collections.Generic; using System.Linq; - using ConfigObjects; using Exiled.API.Features; using Exiled.API.Features.Roles; @@ -20,7 +19,7 @@ public class PlayerHandlers { private readonly Config config; - public PlayerHandlers(Plugin plugin) => this.config = plugin.Config; + public PlayerHandlers(Plugin plugin) => config = plugin.Config; public void OnPlayerVerified(VerifiedEventArgs ev) { diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index 9cb443b..8b5318b 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -7,7 +7,6 @@ namespace Common_Utilities.EventHandlers using System.Collections.Generic; using System.Linq; - using Exiled.API.Enums; using Exiled.API.Features; using Exiled.API.Features.Pickups; using Exiled.API.Features.Roles; @@ -23,7 +22,7 @@ public class ServerHandlers private readonly Config config; private bool friendlyFireDisable; - public ServerHandlers(Plugin plugin) => config = config; + public ServerHandlers(Plugin plugin) => config = plugin.Config; public void OnRoundStarted() { @@ -55,6 +54,7 @@ public void OnWaitingForPlayers() if (config.TimedBroadcastDelay > 0) Plugin.Coroutines.Add(Timing.RunCoroutine(ServerBroadcast())); + // TODO: test if the stuff below is actually necessary // Fix GrandLoadout not able to give this 2 inventory StartingInventories.DefinedInventories[RoleTypeId.Tutorial] = new(Array.Empty(), new()); StartingInventories.DefinedInventories[RoleTypeId.ClassD] = new(Array.Empty(), new()); @@ -71,14 +71,36 @@ public void OnRoundEnded(RoundEndedEventArgs ev) friendlyFireDisable = true; } + Timing.KillCoroutines(Plugin.Coroutines.ToArray()); + + Plugin.Coroutines.Clear(); + } + + public void OnRestartingRound() + { foreach (CoroutineHandle coroutine in Plugin.Coroutines) Timing.KillCoroutines(coroutine); Plugin.Coroutines.Clear(); } + public void OnWarheadStarting(StartingEventArgs _) + { + foreach (Room room in Room.List) + room.Color = config.WarheadColor; + } + + public void OnWarheadStopping(StoppingEventArgs _) + { + if (Warhead.IsLocked) + return; + + foreach (Room room in Room.List) + room.ResetColor(); + } + private IEnumerator ServerBroadcast() { - for (; ; ) + while(true) { yield return Timing.WaitForSeconds(config.TimedBroadcastDelay); @@ -88,11 +110,11 @@ private IEnumerator ServerBroadcast() private IEnumerator ItemCleanup() { - for (; ; ) + while(true) { yield return Timing.WaitForSeconds(config.ItemCleanupDelay); - foreach (Pickup pickup in Pickup.List.ToList()) + foreach (Pickup pickup in Pickup.List) { if (!config.ItemCleanupOnlyPocket || pickup.Position.y < -1500f) pickup.Destroy(); @@ -102,11 +124,11 @@ private IEnumerator ItemCleanup() private IEnumerator RagdollCleanup() { - for (; ; ) + while(true) { yield return Timing.WaitForSeconds(config.RagdollCleanupDelay); - foreach (Ragdoll ragdoll in Ragdoll.List.ToList()) + foreach (Ragdoll ragdoll in Ragdoll.List) { if (!config.RagdollCleanupOnlyPocket || ragdoll.Position.y < -1500f) ragdoll.Destroy(); @@ -139,7 +161,7 @@ private void AutoNuke() private IEnumerator AfkCheck() { - for (; ; ) + while(true) { yield return Timing.WaitForSeconds(1f); @@ -148,7 +170,12 @@ private IEnumerator AfkCheck() if (!Plugin.AfkDict.ContainsKey(player)) Plugin.AfkDict.Add(player, new Tuple(0, player.Position)); - if (player.Role.IsDead || player.IsGodModeEnabled || player.IsNoclipPermitted || player.Role is FpcRole { IsGrounded: false } || player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity) || config.AfkIgnoredRoles.Contains(player.Role.Type)) + if (player.Role.IsDead + || player.IsGodModeEnabled + || player.IsNoclipPermitted + || player.Role is FpcRole { IsGrounded: false } + || player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity) + || config.AfkIgnoredRoles.Contains(player.Role.Type)) { #pragma warning disable SA1013 Log.Debug($"Player {player.Nickname} ({player.Role.Type}) is not a checkable player. NoClip: {player.IsNoclipPermitted} GodMode: {player.IsGodModeEnabled} IsNotGrounded: {player.Role is FpcRole { IsGrounded: false }} AFKImunity: {player.RemoteAdminPermissions.HasFlag(PlayerPermissions.AFKImmunity)}"); @@ -177,27 +204,5 @@ private IEnumerator AfkCheck() } } } - - public void OnRestartingRound() - { - foreach (CoroutineHandle coroutine in Plugin.Coroutines) - Timing.KillCoroutines(coroutine); - Plugin.Coroutines.Clear(); - } - - public void OnWarheadStarting(StartingEventArgs _) - { - foreach (Room room in Room.List) - room.Color = config.WarheadColor; - } - - public void OnWarheadStopping(StoppingEventArgs _) - { - if (Warhead.IsLocked) - return; - - foreach (Room room in Room.List) - room.ResetColor(); - } } } \ No newline at end of file From 1e533908a34ce912916386f090f9ec697b4cf8f9 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:20:34 +0200 Subject: [PATCH 06/23] updated bug template --- .github/ISSUE_TEMPLATE/bug_report.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 52a67da..4878d44 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,7 @@ name: Bug report about: Create a report to help us improve title: '' labels: needs testing -assignees: joker-119 +assignees: Mikihero --- @@ -20,17 +20,17 @@ Steps to reproduce the behavior: **Expected behavior** A clear and concise description of what you expected to happen. -**Server logs** -Please include a pastebin of your localadmin log file (or both MA_log and SCP_log files if you use MultiAdmin) from the time in which the bug occured - -**Copy of current CU config section** +**Actual behavior** +A clear and concise description of what actually happens. +**Copy of the relevant CU config section** +If you're experiencing an issue with the Class Max Health module, then post that entire part. Skip this if config is not relevant. **EXILED Version ("latest" is not a version):** +For example 8.9.2 - -**Results of `show plugins` command in console:** +**Screenshot of the results of the `plym show` command in server console:** **Additional context** -Add any other context about the problem here. +Add any other relevant context about the problem here. \ No newline at end of file From 5f178a84ec268f97af09c9d5b41ad695d5892c3e Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:37:45 +0200 Subject: [PATCH 07/23] fuck off stylecop --- .../ConfigObjects/Scp914TeleportChance.cs | 40 +++++++++---------- .../Patches/ServerGrantLoadoutPatches.cs | 1 + Common Utilities/Plugin.cs | 6 +-- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs index 9b740e2..5529a16 100644 --- a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs +++ b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs @@ -1,32 +1,30 @@ +namespace Common_Utilities.ConfigObjects; + using System.Collections.Generic; +using Exiled.API.Enums; +using UnityEngine; -namespace Common_Utilities.ConfigObjects +public class Scp914TeleportChance : IChanceObject { - using Exiled.API.Enums; - using UnityEngine; - - public class Scp914TeleportChance : IChanceObject - { - public ZoneType Zone { get; set; } = ZoneType.Unspecified; + public ZoneType Zone { get; set; } = ZoneType.Unspecified; - public List IgnoredRooms { get; set; } + public List IgnoredRooms { get; set; } - public RoomType Room { get; set; } + public RoomType Room { get; set; } - public Vector3 Offset { get; set; } = Vector3.zero; + public Vector3 Offset { get; set; } = Vector3.zero; - public double Chance { get; set; } + public double Chance { get; set; } - public float Damage { get; set; } = 0f; + public float Damage { get; set; } = 0f; - public void Deconstruct(out RoomType room, out List ignoredRooms, out Vector3 offset, out double chance, out float damage, out ZoneType zone) - { - room = Room; - ignoredRooms = IgnoredRooms; - offset = Offset; - chance = Chance; - damage = Damage; - zone = Zone; - } + public void Deconstruct(out RoomType room, out List ignoredRooms, out Vector3 offset, out double chance, out float damage, out ZoneType zone) + { + room = Room; + ignoredRooms = IgnoredRooms; + offset = Offset; + chance = Chance; + damage = Damage; + zone = Zone; } } \ No newline at end of file diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index 68a06e9..c6ebc31 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -44,6 +44,7 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset } } } + return false; } } diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index 289c56f..fe8c3d1 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -34,6 +34,8 @@ public class Plugin : Plugin private Harmony harmony; private string harmonyName; + public static List Coroutines { get; } = new(); + public static Dictionary> AfkDict { get; } = new(); public override string Name { get; } = "Common Utilities"; @@ -42,14 +44,12 @@ public class Plugin : Plugin public override Version Version { get; } = new(7, 1, 1); - public override Version RequiredExiledVersion { get; } = new(8, 9, 2); + public override Version RequiredExiledVersion { get; } = new(8, 8, 1); public override string Prefix { get; } = "CommonUtilities"; public override PluginPriority Priority => PluginPriority.Higher; - public static List Coroutines { get; } = new(); - public override void OnEnabled() { if (Config.Debug) From 7e7ee2f8c05706b246c410f7d19717f525ada182 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:44:18 +0200 Subject: [PATCH 08/23] custom item and custom role support for input and output of 914 custom recipes, name consistency changes --- Common Utilities/Config.cs | 13 +- .../ConfigObjects/ItemUpgradeChance.cs | 12 +- .../ConfigObjects/PlayerUpgradeChance.cs | 12 +- .../ConfigObjects/StartingAmmo.cs | 8 +- Common Utilities/EventHandlers/MapHandlers.cs | 113 +++++++++++++----- Common Utilities/Plugin.cs | 12 +- 6 files changed, 111 insertions(+), 59 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index dfa92a1..1d7de2c 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -88,6 +88,7 @@ public class Config : IConfig [Description("Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances)")] public bool AdditiveProbabilities { get; set; } = false; + //TODO: check out starting inventory logic [Description( "The list of starting items for roles. ItemName is the item to give them, and Chance is the percent chance of them spawning with it, and Group allows you to restrict the item to only players with certain RA groups (Leave this as 'none' to allow all players to get the item). You can specify the same item multiple times.")] public Dictionary StartingInventories { get; set; } = new() @@ -123,7 +124,7 @@ public class Config : IConfig { new() { - Type = ItemType.Ammo556x45, + AmmoType = ItemType.Ammo556x45, Amount = 200, Group = "none", }, @@ -132,7 +133,7 @@ public class Config : IConfig }, }; - [Description("The list of custom 914 recipies. Original is the item being upgraded, New is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item.")] + [Description("The list of custom 914 recipies. OriginalItem is the item being upgraded, NewItem is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item.")] public Dictionary> Scp914ItemChances { get; set; } = new() { { @@ -141,8 +142,8 @@ public class Config : IConfig { new() { - Original = ItemType.KeycardO5, - New = ItemType.MicroHID, + OriginalItem = ItemType.KeycardO5.ToString(), + NewItem = ItemType.MicroHID.ToString(), Chance = 50, } }, @@ -159,8 +160,8 @@ public class Config : IConfig { new() { - Original = RoleTypeId.ClassD, - New = RoleTypeId.Spectator.ToString(), + OriginalRole = RoleTypeId.ClassD.ToString(), + NewRole = RoleTypeId.Spectator.ToString(), Chance = 100, } }, diff --git a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs index 9f44436..59b0f8b 100644 --- a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs @@ -2,19 +2,19 @@ namespace Common_Utilities.ConfigObjects { public class ItemUpgradeChance : IChanceObject { - public ItemType Original { get; set; } + public string OriginalItem { get; set; } - public ItemType New { get; set; } + public string NewItem { get; set; } public double Chance { get; set; } public int Count { get; set; } = 1; - public void Deconstruct(out ItemType itemType, out ItemType itemType1, out double i, out int count) + public void Deconstruct(out string originalItem, out string destinationItem, out double chance, out int count) { - itemType = Original; - itemType1 = New; - i = Chance; + originalItem = OriginalItem; + destinationItem = NewItem; + chance = Chance; count = Count; } } diff --git a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs index 336cf02..fbb8229 100644 --- a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs @@ -4,9 +4,9 @@ namespace Common_Utilities.ConfigObjects public class PlayerUpgradeChance : IChanceObject { - public RoleTypeId Original { get; set; } + public string OriginalRole { get; set; } - public string New { get; set; } = RoleTypeId.Spectator.ToString(); + public string NewRole { get; set; } = RoleTypeId.Spectator.ToString(); public double Chance { get; set; } @@ -14,11 +14,11 @@ public class PlayerUpgradeChance : IChanceObject public bool KeepHealth { get; set; } = true; - public void Deconstruct(out RoleTypeId old, out string newRole, out double i, out bool keepInventory, out bool keepHealth) + public void Deconstruct(out string oldRole, out string newRole, out double chance, out bool keepInventory, out bool keepHealth) { - old = Original; - newRole = New; - i = Chance; + oldRole = OriginalRole; + newRole = NewRole; + chance = Chance; keepInventory = KeepInventory; keepHealth = KeepHealth; } diff --git a/Common Utilities/ConfigObjects/StartingAmmo.cs b/Common Utilities/ConfigObjects/StartingAmmo.cs index 40dd0a8..7ce52c3 100644 --- a/Common Utilities/ConfigObjects/StartingAmmo.cs +++ b/Common Utilities/ConfigObjects/StartingAmmo.cs @@ -2,16 +2,16 @@ namespace Common_Utilities.ConfigObjects { public class StartingAmmo { - public ItemType Type { get; set; } + public ItemType AmmoType { get; set; } public ushort Amount { get; set; } public string Group { get; set; } = "none"; - public void Deconstruct(out ItemType type, out ushort limit, out string group) + public void Deconstruct(out ItemType ammoType, out ushort amount, out string group) { - type = Type; - limit = Amount; + ammoType = AmmoType; + amount = Amount; group = Group; } } diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index d8e19be..c0840e7 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -1,5 +1,6 @@ namespace Common_Utilities.EventHandlers; +using Exiled.CustomItems.API.Features; using Exiled.API.Extensions; using System; using System.Collections.Generic; @@ -20,21 +21,36 @@ public class MapHandlers public MapHandlers(Plugin plugin) => config = plugin.Config; - public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) + public void OnUpgradingPickup(UpgradingPickupEventArgs ev) { - if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List chances)) + if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List itemUpgradeChances)) { - var itemUpgradeChance = (List)chances.Where(x => x.Original == ev.Pickup.Type); + var itemUpgradeChance = (List)itemUpgradeChances.Where(x => x.OriginalItem == ev.Pickup.Type.ToString() || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)); double rolledChance = API.RollChance(itemUpgradeChance); - foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) + foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChance) { - Log.Debug($"{nameof(OnScp914UpgradingItem)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); - + Log.Debug($"{nameof(OnUpgradingPickup)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); + if (rolledChance <= chance) { - UpgradeItem(ev.Pickup, destinationItem, ev.OutputPosition, count); + if (Enum.TryParse(destinationItem, out ItemType itemType)) + { + if (itemType is not ItemType.None) + { + UpgradePickup(ev.Pickup, ev.OutputPosition, count, false, itemType: itemType); + } + } + else if (CustomItem.TryGet(destinationItem, out CustomItem customItem)) + { + if (customItem is not null) + { + UpgradePickup(ev.Pickup, ev.OutputPosition, count, true, customItem: customItem); + } + } + + ev.Pickup.Destroy(); ev.IsAllowed = false; break; } @@ -45,30 +61,32 @@ public void OnScp914UpgradingItem(UpgradingPickupEventArgs ev) } } - public void OnScp914UpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) + public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) { - if (config.Scp914ItemChances.ContainsKey(ev.KnobSetting)) + if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List itemUpgradeChances)) { - var itemUpgradeChance = (List)config.Scp914ItemChances[ev.KnobSetting].Where(x => x.Original == ev.Item.Type); + var itemUpgradeChance = (List)itemUpgradeChances.Where(x => x.OriginalItem == ev.Item.Type.ToString() || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)); double rolledChance = API.RollChance(itemUpgradeChance); - foreach ((ItemType sourceItem, ItemType destinationItem, double chance, int count) in itemUpgradeChance) + foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChance) { - Log.Debug($"{nameof(OnScp914UpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); + Log.Debug($"{nameof(OnUpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); if (rolledChance <= chance) { - if (destinationItem is not ItemType.None) + if (Enum.TryParse(destinationItem, out ItemType itemType)) { - ev.Player.RemoveItem(ev.Item); - - for (int i = 0; i < count; i++) + if (itemType is not ItemType.None) + { + UpgradeInventoryItem(ev, count, false, itemType: itemType); + } + } + else if (CustomItem.TryGet(destinationItem, out CustomItem customItem)) + { + if (customItem is not null) { - if (!ev.Player.IsInventoryFull) - ev.Player.AddItem(destinationItem); - else - Pickup.CreateAndSpawn(destinationItem, Scp914.OutputPosition, ev.Player.Rotation, ev.Player); + UpgradeInventoryItem(ev, count, true, customItem: customItem); } } @@ -85,20 +103,22 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) { if (config.Scp914ClassChanges != null && config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change)) { - var playerUpgradeChance = (List)change.Where(x => x.Original == ev.Player.Role); + var playerUpgradeChance = (List)change.Where( + x => x.OriginalRole == ev.Player.Role.ToString() + || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))); double rolledChance = API.RollChance(playerUpgradeChance); - foreach ((RoleTypeId sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance) + foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance) { - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role})is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {rolledChance <= chance} ({rolledChance})"); + Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role}) is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {rolledChance <= chance} ({rolledChance})"); if (rolledChance <= chance) { float originalHealth = ev.Player.Health; var originalItems = ev.Player.Items; var originalAmmo = ev.Player.Ammo; - if (Enum.TryParse(destinationRole, true, out RoleTypeId roleType)) + if (Enum.TryParse(destinationRole, out RoleTypeId roleType)) { ev.Player.Role.Set(roleType, SpawnReason.Respawn, RoleSpawnFlags.None); } @@ -185,7 +205,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) } } - private static Vector3 ChoosePosition(ZoneType zone, List ignoredRooms, Vector3 offset, RoomType roomType) + private Vector3 ChoosePosition(ZoneType zone, List ignoredRooms, Vector3 offset, RoomType roomType) { Vector3 pos1 = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset); Vector3 pos2 = Room.Get(roomType).Position + (Vector3.up * 1.5f) + offset; @@ -207,16 +227,47 @@ private void DealDamage(Player player, float damage) } } - private void UpgradeItem(Pickup oldItem, ItemType newItem, Vector3 pos, int count) + private void UpgradePickup(Pickup oldItem, Vector3 outputPos, int count, bool isCustomItem, ItemType itemType = ItemType.None, CustomItem customItem = null) { - Quaternion quaternion = oldItem.Rotation; - Player previousOwner = oldItem.PreviousOwner; - oldItem.Destroy(); - if (newItem is not ItemType.None) + if (!isCustomItem) + { + Quaternion quaternion = oldItem.Rotation; + Player previousOwner = oldItem.PreviousOwner; + for (int i = 0; i < count; i++) + { + Pickup.CreateAndSpawn(itemType, outputPos, quaternion, previousOwner); + } + } + else + { + for (int i = 0; i < count; i++) + { + customItem!.Spawn(outputPos, oldItem.PreviousOwner); + } + } + } + + private void UpgradeInventoryItem(UpgradingInventoryItemEventArgs ev, int count, bool isCustomItem, ItemType itemType = ItemType.None, CustomItem customItem = null) + { + ev.Player.RemoveItem(ev.Item); + if (!isCustomItem) + { + for (int i = 0; i < count; i++) + { + if (!ev.Player.IsInventoryFull) + ev.Player.AddItem(itemType); + else + Pickup.CreateAndSpawn(itemType, Scp914.OutputPosition, ev.Player.Rotation, ev.Player); + } + } + else { for (int i = 0; i < count; i++) { - Pickup.CreateAndSpawn(newItem, pos, quaternion, previousOwner); + if (!ev.Player.IsInventoryFull) + customItem!.Give(ev.Player); + else + customItem!.Spawn(Scp914.OutputPosition, ev.Player); } } } diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index fe8c3d1..c4fb8df 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -102,9 +102,9 @@ public override void OnEnabled() scp914.UpgradingPlayer += mapHandlers.OnScp914UpgradingPlayer; if (Config.Scp914ItemChances != null) - scp914.UpgradingPickup += mapHandlers.OnScp914UpgradingItem; + scp914.UpgradingPickup += mapHandlers.OnUpgradingPickup; if (Config.Scp914ItemChances != null) - scp914.UpgradingInventoryItem += mapHandlers.OnScp914UpgradingInventoryItem; + scp914.UpgradingInventoryItem += mapHandlers.OnUpgradingInventoryItem; warhead.Starting += serverHandlers.OnWarheadStarting; warhead.Stopping += serverHandlers.OnWarheadStopping; @@ -141,8 +141,8 @@ public override void OnDisabled() server.WaitingForPlayers -= serverHandlers.OnWaitingForPlayers; scp914.UpgradingPlayer -= mapHandlers.OnScp914UpgradingPlayer; - scp914.UpgradingPickup -= mapHandlers.OnScp914UpgradingItem; - scp914.UpgradingInventoryItem -= mapHandlers.OnScp914UpgradingInventoryItem; + scp914.UpgradingPickup -= mapHandlers.OnUpgradingPickup; + scp914.UpgradingInventoryItem -= mapHandlers.OnUpgradingInventoryItem; warhead.Starting -= serverHandlers.OnWarheadStarting; warhead.Stopping -= serverHandlers.OnWarheadStopping; @@ -183,7 +183,7 @@ private void DebugConfig() Log.Debug($"{Config.Scp914ItemChances.Count}"); foreach (KeyValuePair> upgrade in Config.Scp914ItemChances) { - foreach ((ItemType oldItem, ItemType newItem, double chance, int count) in upgrade.Value) + foreach ((string oldItem, string newItem, double chance, int count) in upgrade.Value) Log.Debug($"914 Item Config: {upgrade.Key}: {oldItem} -> {newItem}x({count}) - {chance}"); } } @@ -193,7 +193,7 @@ private void DebugConfig() Log.Debug($"{Config.Scp914ClassChanges.Count}"); foreach (KeyValuePair> upgrade in Config.Scp914ClassChanges) { - foreach ((RoleTypeId oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value) + foreach ((string oldRole, string newRole, double chance, bool keepInventory, bool keepHealth) in upgrade.Value) Log.Debug($"914 Role Config: {upgrade.Key}: {oldRole} -> {newRole} - {chance} keepInventory: {keepInventory} keepHealth: {keepHealth}"); } } From 20d177732acc8553d56b6057e9da8f17e695ee7f Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:08:55 +0200 Subject: [PATCH 09/23] mostly readme --- Common Utilities/Config.cs | 2 +- Common Utilities/Plugin.cs | 2 + README.md | 291 +++++++++++++++++++------------------ 3 files changed, 152 insertions(+), 143 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index 1d7de2c..f88d2d7 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -88,7 +88,7 @@ public class Config : IConfig [Description("Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances)")] public bool AdditiveProbabilities { get; set; } = false; - //TODO: check out starting inventory logic + // TODO: check out starting inventory logic [Description( "The list of starting items for roles. ItemName is the item to give them, and Chance is the percent chance of them spawning with it, and Group allows you to restrict the item to only players with certain RA groups (Leave this as 'none' to allow all players to get the item). You can specify the same item multiple times.")] public Dictionary StartingInventories { get; set; } = new() diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index c4fb8df..0f75cba 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -26,6 +26,7 @@ namespace Common_Utilities; public class Plugin : Plugin { +#pragma warning disable SA1307 public static Plugin Instance; public static Random Random; public PlayerHandlers playerHandlers; @@ -33,6 +34,7 @@ public class Plugin : Plugin private MapHandlers mapHandlers; private Harmony harmony; private string harmonyName; +#pragma warning restore SA1307 public static List Coroutines { get; } = new(); diff --git a/README.md b/README.md index 696161c..71dcc25 100644 --- a/README.md +++ b/README.md @@ -3,153 +3,160 @@ Common Utils is a plugin that serves many common utilites in a day to day server # Main Features ## 914 Features -- Ability to change 914's class upgrading (ex, DClass goes in; scientist comes out.) -- Ability to add custom 914 recipies. +- Ability to change 914's class upgrading (ex, DClass goes in; scientist comes out., supports Custom Roles) +- Ability to add custom 914 recipes (support Custom Items) ## Server Broadcast/Welcoming Features - Ability to completly configure a welcome message. - Ability to completly configure a broadcast message, this can appear every 'x' amount seconds. ## Custom Inventories -- Ability to add custom inventories to all the main classes. - -(These are depricated, if you are using the Exiled 2.0 version of the plugin) +- Ability to add custom inventories to all the main classes # Default config: ```yaml CommonUtilities: -# Whether or not debug messages should be shown. -debug: false -# The SCP Roles able to use V to talk to humans. -scp_speech: -- Scp049 -# Whether or not MTF/CI can 'escape' while disarmed to switch teams. -disarm_switch_teams: true -# Whether or not disarmed people will be prevented from interacting with doors/elevators. -restrictive_disarming: true -# The text displayed at the timed interval specified below. -timed_broadcast: 'This server is running EXILED Common-Utilities, enjoy your stay!' -# The time each timed broadcast will be displayed. -timed_broadcast_duration: 5 -# The delay between each timed broadcast. To disable timed broadcasts, set this to 0 -timed_broadcast_delay: 300 -# The message displayed to the player when they first join the server. Setting this to empty will disable these broadcasts. -join_message: 'Welcome %player%! Please read our rules!' -# The amount of time (in seconds) the join message is displayed. -join_message_duration: 5 -# The amount of time (in seconds) after the round starts, before the facilities auto-nuke will start. -autonuke_time: 1500 -# Wether or not the nuke should be unable to be disabled during the auto-nuke countdown. -autonuke_lock: true -# The message given to all players when the auto-nuke is triggered. A duration of 2 or more will be a text message on-screen. A duration of 1 makes it a cassie announcement. A duration of 0 disables it. -autonuke_broadcast: -# The broadcast content - content: 'The auto nuke has been activated.' - # The broadcast duration - duration: 10 - # The broadcast type - type: Normal - # Indicates whether the broadcast should be shown or not - show: true -# Whether or not to show player's health under their name when you look at them. -player_health_info: true -# Whether or not friendly fire should automatically turn on when a round ends (it will turn itself back off before the next round starts). -friendly_fire_on_round_end: false -# The multiplier applied to radio battery usage. Set to 0 to disable radio battery drain. -radio_battery_drain_multiplier: 1 -# The color to use for lights while the warhead is active. -warhead_color: - r: 1 - g: 0.2 - b: 0.2 - a: 1 -# The maximum time, in seconds, that a player can be AFK before being kicked. Set to -1 to disable AFK system. -afk_limit: 120 -# The roles that are ignored by the AFK system. -afk_ignored_roles: -- Scp079 -- Spectator -- Tutorial -# Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances) -additive_probabilities: false -# The list of starting items for roles. ItemName is the item to give them, and Chance is the percent chance of them spawning with it, and Group allows you to restrict the item to only players with certain RA groups (Leave this as 'none' to allow all players to get the item). You can specify the same item multiple times. -starting_inventories: - ClassD: - slot1: - - item_name: 'KeycardJanitor' - chance: 10 - group: 'none' - - item_name: 'Coin' - chance: 100 - group: 'none' - slot2: - - item_name: 'Flashlight' - chance: 100 - group: 'none' - slot3: [] - slot4: [] - slot5: [] - slot6: [] - slot7: [] - slot8: [] - ammo: - - type: Ammo556x45 - amount: 200 - group: 'none' -# The list of custom 914 recipies. Original is the item being upgraded, New is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item. -scp914_item_changes: - Rough: - - original: KeycardO5 - new: MicroHID - chance: 50 -# The list of custom 914 recipies for roles. Original is the role to be changed, New is the new role to assign, Chance is the % chance of the upgrade occuring. -scp914_class_changes: - Rough: - - original: ClassD - new: Spectator - chance: 100 - spawn_flags: None -# The list of 914 teleport settings. Note that if you set "zone" to anything other than Unspecified, it will always select a random room from that zone, instead of the room type defined. -scp914_teleport_chances: - Rough: - - zone: Unspecified - room: LczClassDSpawn - offset: - x: 0 - y: 0 - z: 0 - chance: 100 - damage: 0 -# A dictionary of random effects to apply to players when going through 914 on certain settings. -scp914_effect_chances: - Rough: - - effect: Bleeding - chance: 100 - duration: 0 -# Determines if 914 effects are exclusive, meaning only one can be applied each time a player is processed by 914. -scp914_effects_exclusivity: false -# Whether or not SCPs are immune to effects gained from 914. -scps_immune_to914_effects: false -# The frequency (in seconds) between ragdoll cleanups. Set to 0 to disable. -ragdoll_cleanup_delay: 0 -# If ragdoll cleanup should only happen in the Pocket Dimension or not. -ragdoll_cleanup_only_pocket: false -# The frequency (in seconds) between item cleanups. Set to 0 to disable. -item_cleanup_delay: 0 -# If item cleanup should only happen in the Pocket Dimension or not. -item_cleanup_only_pocket: false -# A list of all roles and their damage modifiers. The number here is a multiplier, not a raw damage amount. Thus, setting it to 1 = normal damage, 1.5 = 50% more damage, and 0.5 = 50% less damage. -role_damage_multipliers: - Scp173: 1 -# A list of all Weapons and their damage modifiers. The number here is a multiplier, not a raw damage amount. Thus, setting it to 1 = normal damage, 1.5 = 50% more damage, and 0.5 = 50% less damage. -damage_multipliers: - E11Sr: 1 -# A list of roles and how much health they should be given when they kill someone. -health_on_kill: - Scp173: 0 - Scp939: 10 -# A list of roles and what their default starting health should be. -health_values: - Scp173: 3200 - NtfCaptain: 150 -# If the plugin is enabled or not. -is_enabled: true - + # If the plugin is enabled or not. + is_enabled: true + # Whether or not debug messages should be shown. + debug: false + # Roles that when cuffed in the escape area will change into the target one. + disarmed_escape_switch_role: + NtfCaptain: ChaosMarauder + ChaosMarauder: NtfCaptain + # The text displayed at the timed interval specified below. + timed_broadcast: 'This server is running EXILED Common-Utilities, enjoy your stay!' + # The time each timed broadcast will be displayed. + timed_broadcast_duration: 5 + # The delay between each timed broadcast. To disable timed broadcasts, set this to 0 + timed_broadcast_delay: 300 + # The message displayed to the player when they first join the server. Setting this to empty will disable these broadcasts. + join_message: 'Welcome %player%! Please read our rules!' + # The amount of time (in seconds) the join message is displayed. + join_message_duration: 5 + # The amount of time (in seconds) after the round starts, before the facilities auto-nuke will start. + autonuke_time: 1500 + # Wether or not the nuke should be unable to be disabled during the auto-nuke countdown. + autonuke_lock: true + # The message given to all players when the auto-nuke is triggered. A duration of 2 or more will be a text message on-screen. A duration of 1 makes it a cassie announcement. A duration of 0 disables it. + autonuke_broadcast: + # The broadcast content + content: 'The auto nuke has been activated.' + # The broadcast duration + duration: 10 + # The broadcast type + type: Normal + # Indicates whether the broadcast should be shown or not + show: true + # Whether or not to show player's health under their name when you look at them. + player_health_info: true + # Whether or not friendly fire should automatically turn on when a round ends (it will turn itself back off before the next round starts). + friendly_fire_on_round_end: false + # The multiplier applied to radio battery usage. Set to 0 to disable radio battery drain. + radio_battery_drain_multiplier: 1 + # The color to use for lights while the warhead is active. In the RGBA format using values between 0 and 1. + warhead_color: + r: 1 + g: 0.2 + b: 0.2 + a: 1 + # The maximum time, in seconds, that a player can be AFK before being kicked. Set to -1 to disable AFK system. + afk_limit: 120 + # The roles that are ignored by the AFK system. + afk_ignored_roles: + - Scp079 + - Spectator + - Tutorial + # Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances) + additive_probabilities: false + # The list of starting items for roles. ItemName is the item to give them, and Chance is the percent chance of them spawning with it, and Group allows you to restrict the item to only players with certain RA groups (Leave this as 'none' to allow all players to get the item). You can specify the same item multiple times. + starting_inventories: + ClassD: + slot1: + - item_name: 'KeycardJanitor' + chance: 10 + group: 'none' + - item_name: 'Coin' + chance: 100 + group: 'none' + slot2: + - item_name: 'Flashlight' + chance: 100 + group: 'none' + slot3: [] + slot4: [] + slot5: [] + slot6: [] + slot7: [] + slot8: [] + ammo: + - ammo_type: Ammo556x45 + amount: 200 + group: 'none' + # The list of custom 914 recipies. OriginalItem is the item being upgraded, NewItem is the item to upgrade to, and Chance is the percent chance of the upgrade happening. You can specify multiple upgrade choices for the same item. + scp914_item_chances: + Rough: + - original_item: 'KeycardO5' + new_item: 'MicroHID' + chance: 50 + count: 1 + # The list of custom 914 recipies for roles. Original is the role to be changed, New is the new role to assign, Chance is the % chance of the upgrade occuring. + scp914_class_changes: + Rough: + - original_role: 'ClassD' + new_role: 'Spectator' + chance: 100 + keep_inventory: true + keep_health: true + # The list of 914 teleport settings. Note that if you set "zone" to anything other than Unspecified, it will always select a random room from that zone that isn't in the ignoredRooms list, instead of the room type defined. + scp914_teleport_chances: + Rough: + - zone: Unspecified + ignored_rooms: + room: LczClassDSpawn + offset: + x: 0 + y: 0 + z: 0 + chance: 100 + damage: 0 + - zone: LightContainment + ignored_rooms: + - Lcz173 + room: Unknown + offset: + x: 0 + y: 0 + z: 0 + chance: 0 + damage: 0 + # A dictionary of random effects to apply to players when going through 914 on certain settings. + scp914_effect_chances: + Rough: + - effect: Bleeding + chance: 100 + duration: 0 + # Determines if 914 effects are exclusive, meaning only one can be applied each time a player is processed by 914. + scp914_effects_exclusivity: false + # Whether or not SCPs are immune to effects gained from 914. + scps_immune_to914_effects: false + # The frequency (in seconds) between ragdoll cleanups. Set to 0 to disable. + ragdoll_cleanup_delay: 0 + # If ragdoll cleanup should only happen in the Pocket Dimension or not. + ragdoll_cleanup_only_pocket: false + # The frequency (in seconds) between item cleanups. Set to 0 to disable. + item_cleanup_delay: 0 + # If item cleanup should only happen in the Pocket Dimension or not. + item_cleanup_only_pocket: false + # A list of all roles and their damage modifiers. The number here is a multiplier, not a raw damage amount. Thus, setting it to 1 = normal damage, 1.5 = 50% more damage, and 0.5 = 50% less damage. + role_damage_multipliers: + Scp173: 1 + # A list of all Weapons and their damage modifiers. The number here is a multiplier, not a raw damage amount. Thus, setting it to 1 = normal damage, 1.5 = 50% more damage, and 0.5 = 50% less damage. + damage_multipliers: + E11Sr: 1 + # A list of roles and how much health they should be given when they kill someone. + health_on_kill: + Scp173: 0 + Scp939: 10 + # A list of roles and what their default starting health should be. + health_values: + Scp173: 3200 + NtfCaptain: 150 ``` From cb7698ccec0b888e057666080baec3cc6cf04352 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:37:18 +0200 Subject: [PATCH 10/23] better naming --- Common Utilities/EventHandlers/PlayerHandlers.cs | 14 +++++++------- .../Patches/ServerGrantLoadoutPatches.cs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index b83beca..26076e5 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -46,7 +46,7 @@ public void OnChangingRole(ChangingRoleEventArgs ev) } ev.Items.Clear(); - ev.Items.AddRange(StartItems(ev.NewRole, ev.Player)); + ev.Items.AddRange(GetStartingInventory(ev.NewRole, ev.Player)); if (config.StartingInventories[ev.NewRole].Ammo == null || config.StartingInventories[ev.NewRole].Ammo.Count <= 0) return; @@ -138,7 +138,7 @@ public void AntiAfkEventHandler(IPlayerEvent ev) } } - public List StartItems(RoleTypeId role, Player player = null) + public List GetStartingInventory(RoleTypeId role, Player player = null) { List items = new(); @@ -149,9 +149,9 @@ public List StartItems(RoleTypeId role, Player player = null) // item chances for that slot var itemChances = (List)config.StartingInventories[role][i] .Where(x => player == null - || string.IsNullOrEmpty(x.Group) - || x.Group == "none" - || ((ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group))); + || string.IsNullOrEmpty(x.Group) + || x.Group == "none" + || ((ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group))); #pragma warning restore SA1119 double rolledChance = API.RollChance(itemChances); @@ -175,12 +175,12 @@ public List StartItems(RoleTypeId role, Player player = null) if (player != null) customItem!.Give(player); else - Log.Warn($"{nameof(StartItems)}: Tried to give {customItem!.Name} to a null player."); + Log.Warn($"{nameof(GetStartingInventory)}: Tried to give {customItem!.Name} to a null player."); break; } - Log.Warn($"{nameof(StartItems)}: {item} is not a valid ItemType or CustomItem! It is being skipped in inventory decisions."); + Log.Warn($"{nameof(GetStartingInventory)}: {item} is not a valid ItemType or CustomItem! It is being skipped in inventory decisions."); } if (config.AdditiveProbabilities) diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index c6ebc31..03d3c64 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -23,7 +23,7 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset if (resetInventory) player.ClearInventory(); - player.AddItem(Plugin.Instance.playerHandlers.StartItems(roleTypeId, player)); + player.AddItem(Plugin.Instance.playerHandlers.GetStartingInventory(roleTypeId, player)); if (startingInventories.Ammo is { Count: > 0 }) { From 3757cac331f95608d101d12cdbd52590394c0010 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:10:23 +0200 Subject: [PATCH 11/23] possible fix --- Common Utilities/EventHandlers/PlayerHandlers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 26076e5..174a732 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -147,11 +147,11 @@ public List GetStartingInventory(RoleTypeId role, Player player = null { #pragma warning disable SA1119 // item chances for that slot - var itemChances = (List)config.StartingInventories[role][i] + List itemChances = config.StartingInventories[role][i] .Where(x => player == null || string.IsNullOrEmpty(x.Group) || x.Group == "none" - || ((ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group))); + || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)).ToList(); #pragma warning restore SA1119 double rolledChance = API.RollChance(itemChances); From 2e53040c71cded85026f2b23757c0ec7e49fade0 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:00:36 +0200 Subject: [PATCH 12/23] work on some errors --- Common Utilities/Config.cs | 9 +-- .../ConfigObjects/Scp914TeleportChance.cs | 6 +- Common Utilities/EventHandlers/MapHandlers.cs | 55 ++++++++++++------- .../EventHandlers/PlayerHandlers.cs | 14 +++-- .../Patches/ServerGrantLoadoutPatches.cs | 4 +- Common Utilities/Plugin.cs | 4 +- 6 files changed, 56 insertions(+), 36 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index f88d2d7..1a856cb 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -33,7 +33,7 @@ public class Config : IConfig }; [Description("The text displayed at the timed interval specified below.")] - public string TimedBroadcast { get; set; } = "This server is running EXILED Common-Utilities, enjoy your stay!"; + public string TimedBroadcast { get; set; } = "This server is running EXILED Common-Utilities, enjoy your stay!"; [Description("The time each timed broadcast will be displayed.")] public ushort TimedBroadcastDuration { get; set; } = 5; @@ -42,7 +42,7 @@ public class Config : IConfig public float TimedBroadcastDelay { get; set; } = 300f; [Description("The message displayed to the player when they first join the server. Setting this to empty will disable these broadcasts.")] - public string JoinMessage { get; set; } = "Welcome %player%! Please read our rules!"; + public string JoinMessage { get; set; } = "Welcome %player%! Please read our rules!"; [Description("The amount of time (in seconds) the join message is displayed.")] public ushort JoinMessageDuration { get; set; } = 5; @@ -169,7 +169,7 @@ public class Config : IConfig }, }; - [Description("The list of 914 teleport settings. Note that if you set \"zone\" to anything other than Unspecified, it will always select a random room from that zone that isn't in the ignoredRooms list, instead of the room type defined.")] + [Description("The list of 914 teleport settings. Note that if you set \"zone\" to anything other than Unspecified, it will always select a random room from that zone that isn't in the ignoredRooms list, instead of the provided room type.")] public Dictionary> Scp914TeleportChances { get; set; } = new() { { @@ -178,7 +178,7 @@ public class Config : IConfig new() { Room = RoomType.LczClassDSpawn, - Chance = 100, + Chance = 50, }, new() { @@ -187,6 +187,7 @@ public class Config : IConfig { RoomType.Lcz173, }, + Chance = 100, }, } }, diff --git a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs index 5529a16..dc22dc1 100644 --- a/Common Utilities/ConfigObjects/Scp914TeleportChance.cs +++ b/Common Utilities/ConfigObjects/Scp914TeleportChance.cs @@ -7,10 +7,10 @@ namespace Common_Utilities.ConfigObjects; public class Scp914TeleportChance : IChanceObject { public ZoneType Zone { get; set; } = ZoneType.Unspecified; - - public List IgnoredRooms { get; set; } - public RoomType Room { get; set; } + public List IgnoredRooms { get; set; } = new(); + + public RoomType Room { get; set; } = RoomType.Unknown; public Vector3 Offset { get; set; } = Vector3.zero; diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index c0840e7..481c333 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -23,13 +23,17 @@ public class MapHandlers public void OnUpgradingPickup(UpgradingPickupEventArgs ev) { - if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List itemUpgradeChances)) + if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List outItemUpgradeChances)) { - var itemUpgradeChance = (List)itemUpgradeChances.Where(x => x.OriginalItem == ev.Pickup.Type.ToString() || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)); + List itemUpgradeChances = outItemUpgradeChances + .Where(x => + x.OriginalItem == ev.Pickup.Type.ToString() + || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)) + .ToList(); - double rolledChance = API.RollChance(itemUpgradeChance); + double rolledChance = API.RollChance(itemUpgradeChances); - foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChance) + foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { Log.Debug($"{nameof(OnUpgradingPickup)}: SCP-914 is trying to upgrade a {ev.Pickup.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); @@ -63,13 +67,17 @@ public void OnUpgradingPickup(UpgradingPickupEventArgs ev) public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) { - if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List itemUpgradeChances)) + if (config.Scp914ItemChances.TryGetValue(ev.KnobSetting, out List outItemUpgradeChances)) { - var itemUpgradeChance = (List)itemUpgradeChances.Where(x => x.OriginalItem == ev.Item.Type.ToString() || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)); + List itemUpgradeChances = outItemUpgradeChances + .Where(x => + x.OriginalItem == ev.Item.Type.ToString() + || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)) + .ToList(); - double rolledChance = API.RollChance(itemUpgradeChance); + double rolledChance = API.RollChance(itemUpgradeChances); - foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChance) + foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { Log.Debug($"{nameof(OnUpgradingInventoryItem)}: {ev.Player.Nickname} is attempting to upgrade hit {ev.Item.Type}. {sourceItem} -> {destinationItem} ({chance}). Should process: {rolledChance <= chance} ({rolledChance})"); @@ -99,19 +107,21 @@ public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) } } - public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) + public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { - if (config.Scp914ClassChanges != null && config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var change)) + if (config.Scp914ClassChanges != null && config.Scp914ClassChanges.TryGetValue(ev.KnobSetting, out var outPlayerUpgradeChances)) { - var playerUpgradeChance = (List)change.Where( - x => x.OriginalRole == ev.Player.Role.ToString() - || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))); + List playerUpgradeChances = outPlayerUpgradeChances + .Where(x => + x.OriginalRole == ev.Player.Role.ToString() + || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))) + .ToList(); - double rolledChance = API.RollChance(playerUpgradeChance); + double rolledChance = API.RollChance(playerUpgradeChances); - foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChance) + foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChances) { - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role}) is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {rolledChance <= chance} ({rolledChance})"); + Log.Debug($"{nameof(OnUpgradingPlayer)}: {ev.Player.Nickname} ({ev.Player.Role}) is trying to upgrade his class. {sourceRole} -> {destinationRole} ({chance}). Should be processed: {rolledChance <= chance} ({rolledChance})"); if (rolledChance <= chance) { float originalHealth = ev.Player.Health; @@ -166,7 +176,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) foreach ((EffectType effect, double chance, float duration) in scp914EffectChances) { - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to gain an effect through SCP-914. {effect} ({chance}). Should be added: {rolledChance <= chance} ({rolledChance})"); + Log.Debug($"{nameof(OnUpgradingPlayer)}: {ev.Player.Nickname} is trying to gain an effect through SCP-914. {effect} ({chance}). Should be added: {rolledChance <= chance} ({rolledChance})"); if (rolledChance <= chance) { @@ -188,7 +198,7 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) foreach ((RoomType roomType, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in config.Scp914TeleportChances[ev.KnobSetting]) { - Log.Debug($"{nameof(OnScp914UpgradingPlayer)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset} ({chance}). Should be teleported: {rolledChance <= chance} ({rolledChance})"); + Log.Debug($"{nameof(OnUpgradingPlayer)}: {ev.Player.Nickname} is trying to be teleported by 914. {roomType} + {offset} ({chance}). Should be teleported: {rolledChance <= chance} ({rolledChance})"); if (rolledChance <= chance) { @@ -207,8 +217,11 @@ public void OnScp914UpgradingPlayer(UpgradingPlayerEventArgs ev) private Vector3 ChoosePosition(ZoneType zone, List ignoredRooms, Vector3 offset, RoomType roomType) { - Vector3 pos1 = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue().Position + ((Vector3.up * 1.5f) + offset); - Vector3 pos2 = Room.Get(roomType).Position + (Vector3.up * 1.5f) + offset; + Room room1 = Room.List.Where(x => x.Zone == zone && !ignoredRooms.Contains(x.Type)).GetRandomValue(); + Vector3 pos1 = (room1?.Position ?? Vector3.zero) + (Vector3.up * 1.5f); + + Room room2 = Room.Get(roomType); + Vector3 pos2 = room2?.Position ?? Vector3.zero + (Vector3.up * 1.5f) + offset; return zone != ZoneType.Unspecified ? pos1 : pos2; } @@ -222,7 +235,7 @@ private void DealDamage(Player player, float damage) amount = damage; Log.Debug( - $"{nameof(OnScp914UpgradingPlayer)}: {player.Nickname} is being damaged for {amount}. -- {player.Health} * {damage}"); + $"{nameof(OnUpgradingPlayer)}: {player.Nickname} is being damaged for {amount}. -- {player.Health} * {damage}"); player.Hurt(amount, "SCP-914 Teleport", "SCP-914"); } } diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 174a732..ae4c9b1 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -1,3 +1,5 @@ +using Exiled.API.Enums; + namespace Common_Utilities.EventHandlers; #pragma warning disable IDE0018 @@ -44,7 +46,7 @@ public void OnChangingRole(ChangingRoleEventArgs ev) Log.Warn("items is null"); return; } - + ev.Items.Clear(); ev.Items.AddRange(GetStartingInventory(ev.NewRole, ev.Player)); @@ -148,10 +150,12 @@ public List GetStartingInventory(RoleTypeId role, Player player = null #pragma warning disable SA1119 // item chances for that slot List itemChances = config.StartingInventories[role][i] - .Where(x => player == null - || string.IsNullOrEmpty(x.Group) - || x.Group == "none" - || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)).ToList(); + .Where(x => + player == null + || string.IsNullOrEmpty(x.Group) + || x.Group == "none" + || (ServerStatic.PermissionsHandler._groups.TryGetValue(x.Group, out var group) && group == player.Group)) + .ToList(); #pragma warning restore SA1119 double rolledChance = API.RollChance(itemChances); diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs index 03d3c64..6c3cfe7 100644 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs @@ -1,4 +1,5 @@ -namespace Common_Utilities.Patches +/* +namespace Common_Utilities.Patches { using System.Collections.Generic; using System.Linq; @@ -49,3 +50,4 @@ public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool reset } } } +*/ diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index 0f75cba..b75a330 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -101,7 +101,7 @@ public override void OnEnabled() server.RestartingRound += serverHandlers.OnRestartingRound; server.WaitingForPlayers += serverHandlers.OnWaitingForPlayers; - scp914.UpgradingPlayer += mapHandlers.OnScp914UpgradingPlayer; + scp914.UpgradingPlayer += mapHandlers.OnUpgradingPlayer; if (Config.Scp914ItemChances != null) scp914.UpgradingPickup += mapHandlers.OnUpgradingPickup; @@ -142,7 +142,7 @@ public override void OnDisabled() server.RestartingRound -= serverHandlers.OnRestartingRound; server.WaitingForPlayers -= serverHandlers.OnWaitingForPlayers; - scp914.UpgradingPlayer -= mapHandlers.OnScp914UpgradingPlayer; + scp914.UpgradingPlayer -= mapHandlers.OnUpgradingPlayer; scp914.UpgradingPickup -= mapHandlers.OnUpgradingPickup; scp914.UpgradingInventoryItem -= mapHandlers.OnUpgradingInventoryItem; From 08df36fbf396382461e9a799543e327bf29c4432 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:09:55 +0200 Subject: [PATCH 13/23] asd --- Common Utilities/Common Utilities.csproj | 2 +- Common Utilities/EventHandlers/PlayerHandlers.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Common Utilities/Common Utilities.csproj b/Common Utilities/Common Utilities.csproj index eac8e35..ea3cd28 100644 --- a/Common Utilities/Common Utilities.csproj +++ b/Common Utilities/Common Utilities.csproj @@ -23,7 +23,7 @@ - + diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index ae4c9b1..6749e44 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -1,5 +1,3 @@ -using Exiled.API.Enums; - namespace Common_Utilities.EventHandlers; #pragma warning disable IDE0018 From a49d703dcf0d52ee39dc97304379dc904217ef59 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:42:41 +0200 Subject: [PATCH 14/23] tested spawn inventories, removed unncecessary shit --- Common Utilities/API.cs | 2 +- Common Utilities/Common Utilities.csproj | 1 - .../EventHandlers/PlayerHandlers.cs | 10 ++-- .../EventHandlers/ServerHandlers.cs | 10 +--- .../Patches/ServerGrantLoadoutPatches.cs | 53 ------------------- Common Utilities/Plugin.cs | 17 ++---- 6 files changed, 13 insertions(+), 80 deletions(-) delete mode 100644 Common Utilities/Patches/ServerGrantLoadoutPatches.cs diff --git a/Common Utilities/API.cs b/Common Utilities/API.cs index 535be5c..a3672b2 100644 --- a/Common Utilities/API.cs +++ b/Common Utilities/API.cs @@ -4,7 +4,7 @@ using System.Linq; using ConfigObjects; -public class API +public static class API { public static double RollChance(IEnumerable scp914EffectChances) { diff --git a/Common Utilities/Common Utilities.csproj b/Common Utilities/Common Utilities.csproj index ea3cd28..8a733f9 100644 --- a/Common Utilities/Common Utilities.csproj +++ b/Common Utilities/Common Utilities.csproj @@ -25,7 +25,6 @@ - diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 6749e44..a7aa74f 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -36,7 +36,8 @@ public void OnChangingRole(ChangingRoleEventArgs ev) Log.Warn($"{nameof(OnChangingRole)}: Triggering player is null."); return; } - + + // no clue why this works while in ChangingRole instead of spawned but if it ain't broke don't fix it if (config.StartingInventories.ContainsKey(ev.NewRole) && !ev.ShouldPreserveInventory) { if (ev.Items == null) @@ -76,8 +77,8 @@ public void OnSpawned(SpawnedEventArgs ev) RoleTypeId newRole = ev.Player.Role.Type; if (config.HealthValues != null && config.HealthValues.TryGetValue(newRole, out int health)) { - ev.Player.Health = health; ev.Player.MaxHealth = health; + ev.Player.Health = health; } if (ev.Player.Role is FpcRole && config.PlayerHealthInfo) @@ -86,7 +87,10 @@ public void OnSpawned(SpawnedEventArgs ev) } if (config.AfkIgnoredRoles.Contains(newRole) && Plugin.AfkDict.TryGetValue(ev.Player, out Tuple value)) - Plugin.AfkDict[ev.Player] = new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); + { + Plugin.AfkDict[ev.Player] = + new Tuple(newRole is RoleTypeId.Spectator ? value.Item1 : 0, ev.Player.Position); + } } public void OnPlayerDied(DiedEventArgs ev) diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index 8b5318b..eea6d60 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -5,16 +5,13 @@ namespace Common_Utilities.EventHandlers using System; using System.Collections.Generic; - using System.Linq; - + using Exiled.API.Features; using Exiled.API.Features.Pickups; using Exiled.API.Features.Roles; using Exiled.Events.EventArgs.Server; using Exiled.Events.EventArgs.Warhead; - using InventorySystem.Configs; using MEC; - using PlayerRoles; using UnityEngine; public class ServerHandlers @@ -54,11 +51,6 @@ public void OnWaitingForPlayers() if (config.TimedBroadcastDelay > 0) Plugin.Coroutines.Add(Timing.RunCoroutine(ServerBroadcast())); - // TODO: test if the stuff below is actually necessary - // Fix GrandLoadout not able to give this 2 inventory - StartingInventories.DefinedInventories[RoleTypeId.Tutorial] = new(Array.Empty(), new()); - StartingInventories.DefinedInventories[RoleTypeId.ClassD] = new(Array.Empty(), new()); - Warhead.IsLocked = false; } diff --git a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs b/Common Utilities/Patches/ServerGrantLoadoutPatches.cs deleted file mode 100644 index 6c3cfe7..0000000 --- a/Common Utilities/Patches/ServerGrantLoadoutPatches.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* -namespace Common_Utilities.Patches -{ - using System.Collections.Generic; - using System.Linq; - - using ConfigObjects; - using Configs; - using Exiled.API.Features; - using HarmonyLib; - using InventorySystem; - using PlayerRoles; - - [HarmonyPatch(typeof(InventoryItemProvider), nameof(InventoryItemProvider.ServerGrantLoadout))] - public class ServerGrantLoadoutPatches - { - public static bool Prefix(ReferenceHub target, RoleTypeId roleTypeId, bool resetInventory = true) - { - if (Plugin.Instance.Config.StartingInventories == null - || !Plugin.Instance.Config.StartingInventories.TryGetValue(roleTypeId, out RoleInventory startingInventories) - || !Player.TryGet(target, out Player player)) - return true; - - if (resetInventory) - player.ClearInventory(); - - player.AddItem(Plugin.Instance.playerHandlers.GetStartingInventory(roleTypeId, player)); - - if (startingInventories.Ammo is { Count: > 0 }) - { -#pragma warning disable SA1119 - List startingAmmo = (List)startingInventories.Ammo - .Where(s => - string.IsNullOrEmpty(s.Group) - || s.Group == "none" - || ((ServerStatic.PermissionsHandler._groups.TryGetValue(s.Group, out UserGroup userGroup) && userGroup == player.Group))); -#pragma warning restore SA1119 - if (startingAmmo.Any()) - { - player.Ammo.Clear(); - - foreach ((ItemType type, ushort amount, string group) in startingAmmo) - { - player.Ammo.Add(type, amount); - } - } - } - - return false; - } - } -} -*/ diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index b75a330..0083274 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -10,7 +10,6 @@ namespace Common_Utilities; using EventHandlers; using Exiled.API.Enums; using Exiled.API.Features; -using HarmonyLib; using MEC; using PlayerRoles; using Scp914; @@ -29,11 +28,9 @@ public class Plugin : Plugin #pragma warning disable SA1307 public static Plugin Instance; public static Random Random; - public PlayerHandlers playerHandlers; + private PlayerHandlers playerHandlers; private ServerHandlers serverHandlers; private MapHandlers mapHandlers; - private Harmony harmony; - private string harmonyName; #pragma warning restore SA1307 public static List Coroutines { get; } = new(); @@ -42,11 +39,11 @@ public class Plugin : Plugin public override string Name { get; } = "Common Utilities"; - public override string Author { get; } = "Exiled-Team"; + public override string Author { get; } = "ExMod-Team, overhaul by Mikihero"; public override Version Version { get; } = new(7, 1, 1); - public override Version RequiredExiledVersion { get; } = new(8, 8, 1); + public override Version RequiredExiledVersion { get; } = new(8, 11, 0); public override string Prefix { get; } = "CommonUtilities"; @@ -111,10 +108,6 @@ public override void OnEnabled() warhead.Starting += serverHandlers.OnWarheadStarting; warhead.Stopping += serverHandlers.OnWarheadStopping; - harmonyName = $"com-exiled-team.cu-{DateTime.UtcNow.Ticks}"; - harmony = new Harmony(harmonyName); - harmony.PatchAll(); - base.OnEnabled(); } @@ -148,9 +141,7 @@ public override void OnDisabled() warhead.Starting -= serverHandlers.OnWarheadStarting; warhead.Stopping -= serverHandlers.OnWarheadStopping; - - harmony.UnpatchAll(harmonyName); - + serverHandlers = null; playerHandlers = null; mapHandlers = null; From 9d5b3bdad2372dc9aabb1462f14307ab34ace4a1 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:07:11 +0200 Subject: [PATCH 15/23] readded api methods as yamato suggested, slightly changed project structure --- Common Utilities/API/API.cs | 13 +++++++++++++ Common Utilities/EventHandlers/MapHandlers.cs | 10 +++++----- Common Utilities/EventHandlers/PlayerHandlers.cs | 2 +- Common Utilities/Plugin.cs | 2 +- Common Utilities/{API.cs => Utils/Utils.cs} | 6 +++--- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 Common Utilities/API/API.cs rename Common Utilities/{API.cs => Utils/Utils.cs} (88%) diff --git a/Common Utilities/API/API.cs b/Common Utilities/API/API.cs new file mode 100644 index 0000000..4d8a0b9 --- /dev/null +++ b/Common Utilities/API/API.cs @@ -0,0 +1,13 @@ +namespace Common_Utilities.API; + +using System.Collections.Generic; +using Exiled.API.Features; +using PlayerRoles; + +public static class API +{ + // API methods for potential use by other plugins, not sure if anyone actually uses this + public static float GetHealthOnKill(RoleTypeId role) => Plugin.Instance.Config.HealthOnKill?.ContainsKey(role) ?? false ? Plugin.Instance.Config.HealthOnKill[role] : 0f; + + public static List GetStartItems(RoleTypeId role, Player player = null) => Plugin.Instance.playerHandlers.GetStartingInventory(role, player); +} \ No newline at end of file diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index 481c333..4b6de92 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -31,7 +31,7 @@ public void OnUpgradingPickup(UpgradingPickupEventArgs ev) || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)) .ToList(); - double rolledChance = API.RollChance(itemUpgradeChances); + double rolledChance = Utils.Utils.RollChance(itemUpgradeChances); foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { @@ -75,7 +75,7 @@ public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)) .ToList(); - double rolledChance = API.RollChance(itemUpgradeChances); + double rolledChance = Utils.Utils.RollChance(itemUpgradeChances); foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { @@ -117,7 +117,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))) .ToList(); - double rolledChance = API.RollChance(playerUpgradeChances); + double rolledChance = Utils.Utils.RollChance(playerUpgradeChances); foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChances) { @@ -172,7 +172,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { IEnumerable scp914EffectChances = config.Scp914EffectChances[ev.KnobSetting]; - double rolledChance = API.RollChance(scp914EffectChances); + double rolledChance = Utils.Utils.RollChance(scp914EffectChances); foreach ((EffectType effect, double chance, float duration) in scp914EffectChances) { @@ -194,7 +194,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { IEnumerable scp914TeleportChances = config.Scp914TeleportChances[ev.KnobSetting]; - double rolledChance = API.RollChance(scp914TeleportChances); + double rolledChance = Utils.Utils.RollChance(scp914TeleportChances); foreach ((RoomType roomType, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in config.Scp914TeleportChances[ev.KnobSetting]) { diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index a7aa74f..bd4b4a4 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -160,7 +160,7 @@ public List GetStartingInventory(RoleTypeId role, Player player = null .ToList(); #pragma warning restore SA1119 - double rolledChance = API.RollChance(itemChances); + double rolledChance = Utils.Utils.RollChance(itemChances); Log.Debug($"[StartItems] RolledChance ({rolledChance})/{itemChances.Sum(val => val.Chance)}"); diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index 0083274..f466e89 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -28,7 +28,7 @@ public class Plugin : Plugin #pragma warning disable SA1307 public static Plugin Instance; public static Random Random; - private PlayerHandlers playerHandlers; + public PlayerHandlers playerHandlers; private ServerHandlers serverHandlers; private MapHandlers mapHandlers; #pragma warning restore SA1307 diff --git a/Common Utilities/API.cs b/Common Utilities/Utils/Utils.cs similarity index 88% rename from Common Utilities/API.cs rename to Common Utilities/Utils/Utils.cs index a3672b2..1f256be 100644 --- a/Common Utilities/API.cs +++ b/Common Utilities/Utils/Utils.cs @@ -1,10 +1,10 @@ -namespace Common_Utilities; +namespace Common_Utilities.Utils; -using System.Collections.Generic; using System.Linq; using ConfigObjects; +using System.Collections.Generic; -public static class API +public static class Utils { public static double RollChance(IEnumerable scp914EffectChances) { From e99d2f027b93859f1ac0d9d18a1a887b6f6d8aca Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:07:39 +0200 Subject: [PATCH 16/23] requested changes --- Common Utilities/Config.cs | 6 ++++-- Common Utilities/EventHandlers/ServerHandlers.cs | 8 +++++--- Common Utilities/Plugin.cs | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index 1a856cb..9c8b77a 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -71,7 +71,10 @@ public class Config : IConfig [Description("The multiplier applied to radio battery usage. Set to 0 to disable radio battery drain.")] public float RadioBatteryDrainMultiplier { get; set; } = 1f; - [Description("The color to use for lights while the warhead is active. In the RGBA format using values between 0 and 1.")] + [Description("Whether to change the color of lights while warhead is active.")] + public bool ChangeWarheadColor { get; set; } = true; + + [Description("The color to use for lights while the warhead is active. In the RGBA format using values between 0 and 1. Ignored if ChangeWarheadColor is set to false.")] public Color WarheadColor { get; set; } = new(1f, 0.2f, 0.2f, 1); [Description("The maximum time, in seconds, that a player can be AFK before being kicked. Set to -1 to disable AFK system.")] @@ -88,7 +91,6 @@ public class Config : IConfig [Description("Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances)")] public bool AdditiveProbabilities { get; set; } = false; - // TODO: check out starting inventory logic [Description( "The list of starting items for roles. ItemName is the item to give them, and Chance is the percent chance of them spawning with it, and Group allows you to restrict the item to only players with certain RA groups (Leave this as 'none' to allow all players to get the item). You can specify the same item multiple times.")] public Dictionary StartingInventories { get; set; } = new() diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index eea6d60..7725027 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -16,11 +16,10 @@ namespace Common_Utilities.EventHandlers public class ServerHandlers { - private readonly Config config; + private Config config => Plugin.Instance.Config; + private bool friendlyFireDisable; - public ServerHandlers(Plugin plugin) => config = plugin.Config; - public void OnRoundStarted() { if (config.AutonukeTime > -1) @@ -77,6 +76,9 @@ public void OnRestartingRound() public void OnWarheadStarting(StartingEventArgs _) { + if (!config.ChangeWarheadColor) + return; + foreach (Room room in Room.List) room.Color = config.WarheadColor; } diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index f466e89..22f2635 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -39,7 +39,7 @@ public class Plugin : Plugin public override string Name { get; } = "Common Utilities"; - public override string Author { get; } = "ExMod-Team, overhaul by Mikihero"; + public override string Author { get; } = "ExMod-Team"; public override Version Version { get; } = new(7, 1, 1); @@ -58,13 +58,13 @@ public override void OnEnabled() Random = new Random(); - Log.Info($"Instantiating Events.."); + Log.Debug("Instantiating Events.."); playerHandlers = new PlayerHandlers(this); serverHandlers = new ServerHandlers(this); mapHandlers = new MapHandlers(this); - Log.Info($"Registering EventHandlers.."); + Log.Debug("Registering EventHandlers.."); player.Hurting += playerHandlers.OnPlayerHurting; player.Verified += playerHandlers.OnPlayerVerified; @@ -107,6 +107,8 @@ public override void OnEnabled() warhead.Starting += serverHandlers.OnWarheadStarting; warhead.Stopping += serverHandlers.OnWarheadStopping; + + Log.Debug("Registered EventHandlers"); base.OnEnabled(); } From 84bce8f32907d7a15167e0376b38afe90b88856b Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:09:53 +0200 Subject: [PATCH 17/23] forgot these two lol --- Common Utilities/EventHandlers/MapHandlers.cs | 4 +--- Common Utilities/EventHandlers/PlayerHandlers.cs | 6 ++---- Common Utilities/Plugin.cs | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index 4b6de92..9e49086 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -17,9 +17,7 @@ namespace Common_Utilities.EventHandlers; public class MapHandlers { - private readonly Config config; - - public MapHandlers(Plugin plugin) => config = plugin.Config; + private Config config => Plugin.Instance.Config; public void OnUpgradingPickup(UpgradingPickupEventArgs ev) { diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index bd4b4a4..78b8c0e 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -17,10 +17,8 @@ namespace Common_Utilities.EventHandlers; public class PlayerHandlers { - private readonly Config config; - - public PlayerHandlers(Plugin plugin) => config = plugin.Config; - + private Config config => Plugin.Instance.Config; + public void OnPlayerVerified(VerifiedEventArgs ev) { string message = FormatJoinMessage(ev.Player); diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index 22f2635..effc036 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -60,9 +60,9 @@ public override void OnEnabled() Log.Debug("Instantiating Events.."); - playerHandlers = new PlayerHandlers(this); - serverHandlers = new ServerHandlers(this); - mapHandlers = new MapHandlers(this); + playerHandlers = new PlayerHandlers(); + serverHandlers = new ServerHandlers(); + mapHandlers = new MapHandlers(); Log.Debug("Registering EventHandlers.."); From c6903280ace1ff9f7cbd427a6d5ca0e1b8bf0c29 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:33:23 +0200 Subject: [PATCH 18/23] I did indeed forgot about the second handler --- Common Utilities/Config.cs | 2 +- Common Utilities/EventHandlers/MapHandlers.cs | 10 +++++----- Common Utilities/EventHandlers/PlayerHandlers.cs | 2 +- Common Utilities/EventHandlers/ServerHandlers.cs | 2 +- Common Utilities/{Utils => }/Utils.cs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename Common Utilities/{Utils => }/Utils.cs (93%) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index 9c8b77a..0a576ee 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -72,7 +72,7 @@ public class Config : IConfig public float RadioBatteryDrainMultiplier { get; set; } = 1f; [Description("Whether to change the color of lights while warhead is active.")] - public bool ChangeWarheadColor { get; set; } = true; + public bool ChangeWarheadColor { get; set; } = false; [Description("The color to use for lights while the warhead is active. In the RGBA format using values between 0 and 1. Ignored if ChangeWarheadColor is set to false.")] public Color WarheadColor { get; set; } = new(1f, 0.2f, 0.2f, 1); diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index 9e49086..3122e05 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -29,7 +29,7 @@ public void OnUpgradingPickup(UpgradingPickupEventArgs ev) || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)) .ToList(); - double rolledChance = Utils.Utils.RollChance(itemUpgradeChances); + double rolledChance = Utils.RollChance(itemUpgradeChances); foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { @@ -73,7 +73,7 @@ public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)) .ToList(); - double rolledChance = Utils.Utils.RollChance(itemUpgradeChances); + double rolledChance = Utils.RollChance(itemUpgradeChances); foreach ((string sourceItem, string destinationItem, double chance, int count) in itemUpgradeChances) { @@ -115,7 +115,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))) .ToList(); - double rolledChance = Utils.Utils.RollChance(playerUpgradeChances); + double rolledChance = Utils.RollChance(playerUpgradeChances); foreach ((string sourceRole, string destinationRole, double chance, bool keepInventory, bool keepHealth) in playerUpgradeChances) { @@ -170,7 +170,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { IEnumerable scp914EffectChances = config.Scp914EffectChances[ev.KnobSetting]; - double rolledChance = Utils.Utils.RollChance(scp914EffectChances); + double rolledChance = Utils.RollChance(scp914EffectChances); foreach ((EffectType effect, double chance, float duration) in scp914EffectChances) { @@ -192,7 +192,7 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { IEnumerable scp914TeleportChances = config.Scp914TeleportChances[ev.KnobSetting]; - double rolledChance = Utils.Utils.RollChance(scp914TeleportChances); + double rolledChance = Utils.RollChance(scp914TeleportChances); foreach ((RoomType roomType, List ignoredRooms, Vector3 offset, double chance, float damage, ZoneType zone) in config.Scp914TeleportChances[ev.KnobSetting]) { diff --git a/Common Utilities/EventHandlers/PlayerHandlers.cs b/Common Utilities/EventHandlers/PlayerHandlers.cs index 78b8c0e..49043a2 100644 --- a/Common Utilities/EventHandlers/PlayerHandlers.cs +++ b/Common Utilities/EventHandlers/PlayerHandlers.cs @@ -158,7 +158,7 @@ public List GetStartingInventory(RoleTypeId role, Player player = null .ToList(); #pragma warning restore SA1119 - double rolledChance = Utils.Utils.RollChance(itemChances); + double rolledChance = Utils.RollChance(itemChances); Log.Debug($"[StartItems] RolledChance ({rolledChance})/{itemChances.Sum(val => val.Chance)}"); diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index 7725027..eae0ebe 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -85,7 +85,7 @@ public void OnWarheadStarting(StartingEventArgs _) public void OnWarheadStopping(StoppingEventArgs _) { - if (Warhead.IsLocked) + if (config.ChangeWarheadColor || Warhead.IsLocked) return; foreach (Room room in Room.List) diff --git a/Common Utilities/Utils/Utils.cs b/Common Utilities/Utils.cs similarity index 93% rename from Common Utilities/Utils/Utils.cs rename to Common Utilities/Utils.cs index 1f256be..410ec3e 100644 --- a/Common Utilities/Utils/Utils.cs +++ b/Common Utilities/Utils.cs @@ -1,8 +1,8 @@ -namespace Common_Utilities.Utils; +namespace Common_Utilities; +using System.Collections.Generic; using System.Linq; using ConfigObjects; -using System.Collections.Generic; public static class Utils { From 27c19fc8a30be4116fbf82451e58835aa82f6ba4 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:54:48 +0200 Subject: [PATCH 19/23] brainfart moment --- Common Utilities/EventHandlers/ServerHandlers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common Utilities/EventHandlers/ServerHandlers.cs b/Common Utilities/EventHandlers/ServerHandlers.cs index eae0ebe..f580c43 100644 --- a/Common Utilities/EventHandlers/ServerHandlers.cs +++ b/Common Utilities/EventHandlers/ServerHandlers.cs @@ -85,7 +85,7 @@ public void OnWarheadStarting(StartingEventArgs _) public void OnWarheadStopping(StoppingEventArgs _) { - if (config.ChangeWarheadColor || Warhead.IsLocked) + if (!config.ChangeWarheadColor || Warhead.IsLocked) return; foreach (Room room in Room.List) @@ -199,4 +199,4 @@ private IEnumerator AfkCheck() } } } -} \ No newline at end of file +} From 937f310d1acbfa4d6699fe4af240ca192eeda937 Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Sun, 22 Sep 2024 22:17:03 +0200 Subject: [PATCH 20/23] revert breaking config changes --- Common Utilities/Config.cs | 8 ++++---- Common Utilities/ConfigObjects/ItemUpgradeChance.cs | 8 ++++---- .../ConfigObjects/PlayerUpgradeChance.cs | 8 ++++---- Common Utilities/EventHandlers/MapHandlers.cs | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index 0a576ee..42e36a9 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -144,8 +144,8 @@ public class Config : IConfig { new() { - OriginalItem = ItemType.KeycardO5.ToString(), - NewItem = ItemType.MicroHID.ToString(), + Original = ItemType.KeycardO5.ToString(), + New = ItemType.MicroHID.ToString(), Chance = 50, } }, @@ -162,8 +162,8 @@ public class Config : IConfig { new() { - OriginalRole = RoleTypeId.ClassD.ToString(), - NewRole = RoleTypeId.Spectator.ToString(), + Original = RoleTypeId.ClassD.ToString(), + New = RoleTypeId.Spectator.ToString(), Chance = 100, } }, diff --git a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs index 59b0f8b..d0c5d98 100644 --- a/Common Utilities/ConfigObjects/ItemUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/ItemUpgradeChance.cs @@ -2,9 +2,9 @@ namespace Common_Utilities.ConfigObjects { public class ItemUpgradeChance : IChanceObject { - public string OriginalItem { get; set; } + public string Original { get; set; } - public string NewItem { get; set; } + public string New { get; set; } public double Chance { get; set; } @@ -12,8 +12,8 @@ public class ItemUpgradeChance : IChanceObject public void Deconstruct(out string originalItem, out string destinationItem, out double chance, out int count) { - originalItem = OriginalItem; - destinationItem = NewItem; + originalItem = Original; + destinationItem = New; chance = Chance; count = Count; } diff --git a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs index fbb8229..2d8ddeb 100644 --- a/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs +++ b/Common Utilities/ConfigObjects/PlayerUpgradeChance.cs @@ -4,9 +4,9 @@ namespace Common_Utilities.ConfigObjects public class PlayerUpgradeChance : IChanceObject { - public string OriginalRole { get; set; } + public string Original { get; set; } - public string NewRole { get; set; } = RoleTypeId.Spectator.ToString(); + public string New { get; set; } = RoleTypeId.Spectator.ToString(); public double Chance { get; set; } @@ -16,8 +16,8 @@ public class PlayerUpgradeChance : IChanceObject public void Deconstruct(out string oldRole, out string newRole, out double chance, out bool keepInventory, out bool keepHealth) { - oldRole = OriginalRole; - newRole = NewRole; + oldRole = Original; + newRole = New; chance = Chance; keepInventory = KeepInventory; keepHealth = KeepHealth; diff --git a/Common Utilities/EventHandlers/MapHandlers.cs b/Common Utilities/EventHandlers/MapHandlers.cs index 3122e05..f93c13b 100644 --- a/Common Utilities/EventHandlers/MapHandlers.cs +++ b/Common Utilities/EventHandlers/MapHandlers.cs @@ -25,8 +25,8 @@ public void OnUpgradingPickup(UpgradingPickupEventArgs ev) { List itemUpgradeChances = outItemUpgradeChances .Where(x => - x.OriginalItem == ev.Pickup.Type.ToString() - || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.OriginalItem)) + x.Original == ev.Pickup.Type.ToString() + || (CustomItem.TryGet(ev.Pickup, out CustomItem item) && item!.Name == x.Original)) .ToList(); double rolledChance = Utils.RollChance(itemUpgradeChances); @@ -69,8 +69,8 @@ public void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev) { List itemUpgradeChances = outItemUpgradeChances .Where(x => - x.OriginalItem == ev.Item.Type.ToString() - || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.OriginalItem)) + x.Original == ev.Item.Type.ToString() + || (CustomItem.TryGet(ev.Item, out CustomItem item) && item!.Name == x.Original)) .ToList(); double rolledChance = Utils.RollChance(itemUpgradeChances); @@ -111,8 +111,8 @@ public void OnUpgradingPlayer(UpgradingPlayerEventArgs ev) { List playerUpgradeChances = outPlayerUpgradeChances .Where(x => - x.OriginalRole == ev.Player.Role.ToString() - || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.OriginalRole))) + x.Original == ev.Player.Role.ToString() + || (CustomRole.TryGet(ev.Player, out IReadOnlyCollection customRoles) && customRoles.Select(r => r.Name).Contains(x.Original))) .ToList(); double rolledChance = Utils.RollChance(playerUpgradeChances); From c64056c23945c480a8d14e56209b93ab72d335cb Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:56:13 +0200 Subject: [PATCH 21/23] disabled most configs by default --- Common Utilities/Config.cs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/Common Utilities/Config.cs b/Common Utilities/Config.cs index 42e36a9..957fd8f 100644 --- a/Common Utilities/Config.cs +++ b/Common Utilities/Config.cs @@ -39,16 +39,16 @@ public class Config : IConfig public ushort TimedBroadcastDuration { get; set; } = 5; [Description("The delay between each timed broadcast. To disable timed broadcasts, set this to 0")] - public float TimedBroadcastDelay { get; set; } = 300f; + public float TimedBroadcastDelay { get; set; } = 0; [Description("The message displayed to the player when they first join the server. Setting this to empty will disable these broadcasts.")] - public string JoinMessage { get; set; } = "Welcome %player%! Please read our rules!"; + public string JoinMessage { get; set; } = string.Empty; [Description("The amount of time (in seconds) the join message is displayed.")] public ushort JoinMessageDuration { get; set; } = 5; - [Description("The amount of time (in seconds) after the round starts, before the facilities auto-nuke will start.")] - public float AutonukeTime { get; set; } = 1500f; + [Description("The amount of time (in seconds) after the round starts, before the facilities auto-nuke will start. Set to -1 to disable.")] + public float AutonukeTime { get; set; } = -1; [Description("Wether or not the nuke should be unable to be disabled during the auto-nuke countdown.")] public bool AutonukeLock { get; set; } = true; @@ -63,7 +63,7 @@ public class Config : IConfig }; [Description("Whether or not to show player's health under their name when you look at them.")] - public bool PlayerHealthInfo { get; set; } = true; + public bool PlayerHealthInfo { get; set; } = false; [Description("Whether or not friendly fire should automatically turn on when a round ends (it will turn itself back off before the next round starts).")] public bool FriendlyFireOnRoundEnd { get; set; } = false; @@ -78,7 +78,7 @@ public class Config : IConfig public Color WarheadColor { get; set; } = new(1f, 0.2f, 0.2f, 1); [Description("The maximum time, in seconds, that a player can be AFK before being kicked. Set to -1 to disable AFK system.")] - public int AfkLimit { get; set; } = 120; + public int AfkLimit { get; set; } = -1; [Description("The roles that are ignored by the AFK system.")] public List AfkIgnoredRoles { get; set; } = new() @@ -86,6 +86,8 @@ public class Config : IConfig RoleTypeId.Scp079, RoleTypeId.Spectator, RoleTypeId.Tutorial, + RoleTypeId.Filmmaker, + RoleTypeId.Overwatch, }; [Description("Whether or not probabilities should be additive (50 + 50 = 100) or not (50 + 50 = 2 seperate 50% chances)")] @@ -141,13 +143,11 @@ public class Config : IConfig { Scp914KnobSetting.Rough, new List { + new() { - new() - { - Original = ItemType.KeycardO5.ToString(), - New = ItemType.MicroHID.ToString(), - Chance = 50, - } + Original = ItemType.KeycardO5.ToString(), + New = ItemType.MicroHID.ToString(), + Chance = 50, }, } }, @@ -250,9 +250,6 @@ public class Config : IConfig { RoleTypeId.Scp173, 0 }, - { - RoleTypeId.Scp939, 10 - }, }; [Description("A list of roles and what their default starting health should be.")] @@ -261,9 +258,6 @@ public class Config : IConfig { RoleTypeId.Scp173, 3200 }, - { - RoleTypeId.NtfCaptain, 150 - }, }; } } From bb61f35eed734704427490f83a41b9a47be7900d Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:51:02 +0200 Subject: [PATCH 22/23] v bumpo --- Common Utilities/Plugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common Utilities/Plugin.cs b/Common Utilities/Plugin.cs index effc036..debac66 100644 --- a/Common Utilities/Plugin.cs +++ b/Common Utilities/Plugin.cs @@ -41,7 +41,7 @@ public class Plugin : Plugin public override string Author { get; } = "ExMod-Team"; - public override Version Version { get; } = new(7, 1, 1); + public override Version Version { get; } = new(7, 2, 0); public override Version RequiredExiledVersion { get; } = new(8, 11, 0); From 4652081ccfb764ca9c00bb2fb4b4f3283a9e0bea Mon Sep 17 00:00:00 2001 From: Miki_hero <100715076+Mikihero@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:48:04 +0200 Subject: [PATCH 23/23] the point of not removing this was to not break shit lol --- Common Utilities/{API => }/API.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Common Utilities/{API => }/API.cs (100%) diff --git a/Common Utilities/API/API.cs b/Common Utilities/API.cs similarity index 100% rename from Common Utilities/API/API.cs rename to Common Utilities/API.cs