From 2160ccabd9b504ee3d634f0924fc6346449e2c09 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:24:43 +0200 Subject: [PATCH 1/9] Add a bunch --- EXILED/Exiled.API/Enums/HazardType.cs | 37 +++++++++++ .../Extensions/BitwiseExtensions.cs | 63 +++++++++++++++++++ .../Features/Hazards/AmnesticCloudHazard.cs | 22 ++++++- EXILED/Exiled.API/Features/Hazards/Hazard.cs | 13 ++++ .../Features/Hazards/SinkholeHazard.cs | 4 ++ .../Features/Hazards/TantrumHazard.cs | 44 +++++++++++++ EXILED/Exiled.API/Features/Map.cs | 51 +-------------- EXILED/Exiled.API/Features/Player.cs | 2 +- EXILED/Exiled.API/Features/PrefabHelper.cs | 19 +++++- EXILED/Exiled.API/Features/Server.cs | 9 +++ EXILED/Exiled.Events/Commands/TpsCommand.cs | 46 ++++++++++++++ 11 files changed, 257 insertions(+), 53 deletions(-) create mode 100644 EXILED/Exiled.API/Enums/HazardType.cs create mode 100644 EXILED/Exiled.API/Extensions/BitwiseExtensions.cs create mode 100644 EXILED/Exiled.Events/Commands/TpsCommand.cs diff --git a/EXILED/Exiled.API/Enums/HazardType.cs b/EXILED/Exiled.API/Enums/HazardType.cs new file mode 100644 index 000000000..f05f8852f --- /dev/null +++ b/EXILED/Exiled.API/Enums/HazardType.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Enums +{ + using Exiled.API.Features.Hazards; + + /// + /// Unique identifier for a . + /// + public enum HazardType + { + /// + /// SCP-939 amnestic cloud. + /// + AmnesticCloud, + + /// + /// Sinkhole spawned at start of round. + /// + Sinkhole, + + /// + /// SCP-173 tantrum. + /// + Tantrum, + + /// + /// Should never happen + /// + Unknown, + } +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Extensions/BitwiseExtensions.cs b/EXILED/Exiled.API/Extensions/BitwiseExtensions.cs new file mode 100644 index 000000000..2f8473784 --- /dev/null +++ b/EXILED/Exiled.API/Extensions/BitwiseExtensions.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Extensions +{ + using System; + + /// + /// Extensions for bitwise operations. + /// + public static class BitwiseExtensions + { + /// + /// Adds the specified flags to the given enum value. + /// + /// The type of the enum. + /// The enum value to add flags to. + /// The flags to add. + /// The enum value with the specified flags added. + public static T AddFlags(this T flags, params T[] newFlags) + where T : Enum => flags.ModifyFlags(true, newFlags); + + /// + /// Removes the specified flags from the given enum value. + /// + /// The type of the enum. + /// The enum value to remove flags from. + /// The flags to remove. + /// The enum value with the specified flags removed. + public static T RemoveFlags(this T flags, params T[] oldFlags) + where T : Enum => flags.ModifyFlags(false, oldFlags); + + /// + /// Sets the specified flag to the given value, default is true. + /// + /// The flags enum to modify. + /// The value to set the flag to. + /// The flags to modify. + /// The type of the enum. + /// The flags enum with the flag set to the given value. + public static T ModifyFlags(this T flags, bool value, params T[] changeFlags) + where T : Enum + { + long currentValue = Convert.ToInt64(flags); + + foreach (T flag in changeFlags) + { + long flagValue = Convert.ToInt64(flag); + + if (value) + currentValue |= flagValue; + else + currentValue &= ~flagValue; + } + + return (T)Enum.ToObject(typeof(T), currentValue); + } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs b/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs index c385c143f..c15098e96 100644 --- a/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs @@ -3,10 +3,11 @@ // Copyright (c) Exiled Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. // -// ----------------------------------------------------------------------- +// ------------------------------------------------------------------------ namespace Exiled.API.Features.Hazards { + using Exiled.API.Enums; using PlayerRoles.PlayableScps.Scp939; /// @@ -14,6 +15,8 @@ namespace Exiled.API.Features.Hazards /// public class AmnesticCloudHazard : TemporaryHazard { + private static Scp939AmnesticCloudInstance amnesticCloudPrefab; + /// /// Initializes a new instance of the class. /// @@ -26,9 +29,26 @@ public AmnesticCloudHazard(Scp939AmnesticCloudInstance hazard) Owner = Player.Get(Ability.Owner); } + /// + /// Gets the amnestic cloud prefab. + /// + public static Scp939AmnesticCloudInstance AmnesticCloudPrefab + { + get + { + if (amnesticCloudPrefab == null) + amnesticCloudPrefab = PrefabHelper.GetPrefab(PrefabType.AmnesticCloudHazard); + + return amnesticCloudPrefab; + } + } + /// public new Scp939AmnesticCloudInstance Base { get; } + /// + public override HazardType Type { get; } = HazardType.AmnesticCloud; + /// /// Gets the for this instance. /// diff --git a/EXILED/Exiled.API/Features/Hazards/Hazard.cs b/EXILED/Exiled.API/Features/Hazards/Hazard.cs index 6861d1a68..5fe6bde97 100644 --- a/EXILED/Exiled.API/Features/Hazards/Hazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/Hazard.cs @@ -11,6 +11,7 @@ namespace Exiled.API.Features.Hazards using System.Collections.Generic; using System.Linq; + using Exiled.API.Enums; using Exiled.API.Features.Core; using Exiled.API.Interfaces; using global::Hazards; @@ -48,6 +49,11 @@ public Hazard(EnvironmentalHazard hazard) /// public EnvironmentalHazard Base { get; } + /// + /// Gets the associated with the current Hazard. + /// + public virtual HazardType Type { get; } = HazardType.Unknown; + /// /// Gets or sets the list with all affected by this hazard players. /// @@ -144,6 +150,13 @@ public static Hazard Get(EnvironmentalHazard environmentalHazard) => /// of based on predicate. public static IEnumerable Get(Func predicate) => List.Where(predicate); + /// + /// Gets an of . + /// + /// The to get. + /// of based on type. + public static IEnumerable Get(HazardType type) => Get(h => h.Type == type); + /// /// Checks if player is in hazard zone. /// diff --git a/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs b/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs index e8e0c4f3a..0033ef231 100644 --- a/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs @@ -7,6 +7,7 @@ namespace Exiled.API.Features.Hazards { + using Exiled.API.Enums; using global::Hazards; /// @@ -28,5 +29,8 @@ public SinkholeHazard(SinkholeEnvironmentalHazard hazard) /// Gets the . /// public new SinkholeEnvironmentalHazard Base { get; } + + /// + public override HazardType Type { get; } = HazardType.Sinkhole; } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs index 15f54b5ac..56bd73a1c 100644 --- a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs @@ -7,7 +7,9 @@ namespace Exiled.API.Features.Hazards { + using Exiled.API.Enums; using global::Hazards; + using Mirror; using RelativePositioning; using UnityEngine; @@ -16,6 +18,8 @@ namespace Exiled.API.Features.Hazards /// public class TantrumHazard : TemporaryHazard { + private static TantrumEnvironmentalHazard tantrumPrefab; + /// /// Initializes a new instance of the class. /// @@ -26,11 +30,28 @@ public TantrumHazard(TantrumEnvironmentalHazard hazard) Base = hazard; } + /// + /// Gets the tantrum prefab. + /// + public static TantrumEnvironmentalHazard TantrumPrefab + { + get + { + if (tantrumPrefab == null) + tantrumPrefab = PrefabHelper.GetPrefab(PrefabType.TantrumObj); + + return tantrumPrefab; + } + } + /// /// Gets the . /// public new TantrumEnvironmentalHazard Base { get; } + /// + public override HazardType Type { get; } = HazardType.Tantrum; + /// /// Gets or sets a value indicating whether or not sizzle should be played. /// @@ -57,5 +78,28 @@ public Transform CorrectPosition get => Base._correctPosition; set => Base._correctPosition = value; } + + /// + /// Places a Tantrum (SCP-173's ability) in the indicated position. + /// + /// The position where you want to spawn the Tantrum. + /// Whether or not the tantrum will apply the effect. + /// If is , the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work. + /// The instance. + public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) + { + TantrumEnvironmentalHazard tantrum = Object.Instantiate(TantrumPrefab); + + if (!isActive) + tantrum.SynchronizedPosition = new(position); + else + tantrum.SynchronizedPosition = new(position + (Vector3.up * 0.25f)); + + tantrum._destroyed = !isActive; + + NetworkServer.Spawn(tantrum.gameObject); + + return Get(tantrum) as TantrumHazard; + } } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Map.cs b/EXILED/Exiled.API/Features/Map.cs index 14f6d8214..c604214b3 100644 --- a/EXILED/Exiled.API/Features/Map.cs +++ b/EXILED/Exiled.API/Features/Map.cs @@ -62,48 +62,17 @@ public static class Map /// internal static readonly List ToysValue = new(); - private static TantrumEnvironmentalHazard tantrumPrefab; - private static Scp939AmnesticCloudInstance amnesticCloudPrefab; - private static AmbientSoundPlayer ambientSoundPlayer; /// /// Gets the tantrum prefab. /// - public static TantrumEnvironmentalHazard TantrumPrefab - { - get - { - if (tantrumPrefab == null) - { - Scp173GameRole scp173Role = (Scp173GameRole)RoleTypeId.Scp173.GetRoleBase(); - - if (scp173Role.SubroutineModule.TryGetSubroutine(out Scp173TantrumAbility scp173TantrumAbility)) - tantrumPrefab = scp173TantrumAbility._tantrumPrefab; - } - - return tantrumPrefab; - } - } + public static TantrumEnvironmentalHazard TantrumPrefab => TantrumHazard.TantrumPrefab; // TODO: Remove this. /// /// Gets the amnestic cloud prefab. /// - public static Scp939AmnesticCloudInstance AmnesticCloudPrefab - { - get - { - if (amnesticCloudPrefab == null) - { - Scp939GameRole scp939Role = (Scp939GameRole)RoleTypeId.Scp939.GetRoleBase(); - - if (scp939Role.SubroutineModule.TryGetSubroutine(out Scp939AmnesticCloudAbility ability)) - amnesticCloudPrefab = ability._instancePrefab; - } - - return amnesticCloudPrefab; - } - } + public static Scp939AmnesticCloudInstance AmnesticCloudPrefab => AmnesticCloudHazard.AmnesticCloudPrefab; // TODO: Remove this. /// /// Gets a value indicating whether decontamination has begun in the light containment zone. @@ -286,21 +255,7 @@ public static void PlayAmbientSound(int id) /// Whether or not the tantrum will apply the effect. /// If is , the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work. /// The instance. - public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) - { - TantrumEnvironmentalHazard tantrum = Object.Instantiate(TantrumPrefab); - - if (!isActive) - tantrum.SynchronizedPosition = new RelativePosition(position); - else - tantrum.SynchronizedPosition = new RelativePosition(position + (Vector3.up * 0.25f)); - - tantrum._destroyed = !isActive; - - NetworkServer.Spawn(tantrum.gameObject); - - return Hazard.Get(tantrum).Cast(); - } + public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) => TantrumHazard.PlaceTantrum(position, isActive); // TODO: Remove this. /// /// Destroy all objects. diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index ed937ead5..2022df9a9 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -3241,7 +3241,7 @@ public void ChangeEffectIntensity(string effectName, byte intensity, float durat /// Whether or not the tantrum will apply the effect. /// If is , the tantrum is moved slightly up from its original position. Otherwise, the collision will not be detected and the slowness will not work. /// The instance.. - public TantrumHazard PlaceTantrum(bool isActive = true) => Map.PlaceTantrum(Position, isActive); + public TantrumHazard PlaceTantrum(bool isActive = true) => TantrumHazard.PlaceTantrum(Position, isActive); /// /// Gives a new to the player. diff --git a/EXILED/Exiled.API/Features/PrefabHelper.cs b/EXILED/Exiled.API/Features/PrefabHelper.cs index de97e15d5..1c40199f4 100644 --- a/EXILED/Exiled.API/Features/PrefabHelper.cs +++ b/EXILED/Exiled.API/Features/PrefabHelper.cs @@ -41,6 +41,21 @@ public static PrefabAttribute GetPrefabAttribute(this PrefabType prefabType) return type.GetField(Enum.GetName(type, prefabType)).GetCustomAttribute(); } + /// + /// Gets the prefab of the specified . + /// + /// The to get prefab of. + /// The to get. + /// Returns the prefab component as . + public static T GetPrefab(PrefabType type) + where T : Component + { + if (!Stored.TryGetValue(type, out GameObject gameObject) || !gameObject.TryGetComponent(out T component)) + return null; + + return component; + } + /// /// Spawns a prefab on server. /// @@ -68,9 +83,7 @@ public static GameObject Spawn(PrefabType prefabType, Vector3 position = default public static T Spawn(PrefabType prefabType, Vector3 position = default, Quaternion rotation = default) where T : Component { - if (!Stored.TryGetValue(prefabType, out GameObject gameObject) || !gameObject.TryGetComponent(out T component)) - return null; - T obj = UnityEngine.Object.Instantiate(component, position, rotation); + T obj = UnityEngine.Object.Instantiate(GetPrefab(prefabType), position, rotation); NetworkServer.Spawn(obj.gameObject); return obj; } diff --git a/EXILED/Exiled.API/Features/Server.cs b/EXILED/Exiled.API/Features/Server.cs index 908096434..b1b05e8c1 100644 --- a/EXILED/Exiled.API/Features/Server.cs +++ b/EXILED/Exiled.API/Features/Server.cs @@ -111,6 +111,15 @@ public static string Name /// public static double Tps => Math.Round(1f / Time.smoothDeltaTime); + /// + /// Gets or sets the max ticks per second of the server. + /// + public static short MaxTps + { + get => ServerStatic.ServerTickrate; + set => ServerStatic.ServerTickrate = value; + } + /// /// Gets the actual frametime of the server. /// diff --git a/EXILED/Exiled.Events/Commands/TpsCommand.cs b/EXILED/Exiled.Events/Commands/TpsCommand.cs new file mode 100644 index 000000000..fe2aa69c2 --- /dev/null +++ b/EXILED/Exiled.Events/Commands/TpsCommand.cs @@ -0,0 +1,46 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Commands +{ + using System; + + using CommandSystem; + using Exiled.API.Features; + + /// + /// Command for showing current server TPS. + /// + [CommandHandler(typeof(RemoteAdminCommandHandler))] + [CommandHandler(typeof(GameConsoleCommandHandler))] + public class TpsCommand : ICommand + { + /// + public string Command { get; } = "tps"; + + /// + public string[] Aliases { get; } = Array.Empty(); + + /// + public string Description { get; } = "Shows the current TPS of the server"; + + /// + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + double diff = Server.Tps / ServerStatic.ServerTickrate; + string color = diff switch + { + > 0.9 => "green", + > 0.5 => "yellow", + _ => "red" + }; + + response = $"{Server.Tps}/{ServerStatic.ServerTickrate}"; + return true; + } + } +} \ No newline at end of file From b88489992135412d9ac572a88308d731f40acd6e Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:30:47 +0200 Subject: [PATCH 2/9] Fix --- EXILED/Exiled.API/Features/PrefabHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/PrefabHelper.cs b/EXILED/Exiled.API/Features/PrefabHelper.cs index 1c40199f4..fd18e9fe9 100644 --- a/EXILED/Exiled.API/Features/PrefabHelper.cs +++ b/EXILED/Exiled.API/Features/PrefabHelper.cs @@ -46,7 +46,7 @@ public static PrefabAttribute GetPrefabAttribute(this PrefabType prefabType) /// /// The to get prefab of. /// The to get. - /// Returns the prefab component as . + /// Returns the prefab component as {T}. public static T GetPrefab(PrefabType type) where T : Component { From aca9dfdb70d08dffae270518f33185c7b8f3b056 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:40:51 +0200 Subject: [PATCH 3/9] Security --- EXILED/Exiled.API/Features/Roles/FpcRole.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Roles/FpcRole.cs b/EXILED/Exiled.API/Features/Roles/FpcRole.cs index 27abeded8..19bcc2aaf 100644 --- a/EXILED/Exiled.API/Features/Roles/FpcRole.cs +++ b/EXILED/Exiled.API/Features/Roles/FpcRole.cs @@ -47,9 +47,18 @@ protected FpcRole(FpcStandardRoleBase baseRole) public FpcStandardRoleBase FirstPersonController { get; } /// - /// Gets or sets the player's relative position. + /// Gets or sets the player's relative position as perceived by the server. /// public RelativePosition RelativePosition + { + get => new(Owner.Position); + set => Owner.Position = value.Position; + } + + /// + /// Gets or sets the player's relative position as perceived by the client. + /// + public RelativePosition ClientRelativePosition { get => FirstPersonController.FpcModule.Motor.ReceivedPosition; set => FirstPersonController.FpcModule.Motor.ReceivedPosition = value; From dff21c7e75d277c1677c84cd1fd796f98cf72bda Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:10:30 +0200 Subject: [PATCH 4/9] Make changes --- EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs | 2 +- EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs | 2 +- EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs b/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs index c15098e96..31c9ad244 100644 --- a/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/AmnesticCloudHazard.cs @@ -47,7 +47,7 @@ public static Scp939AmnesticCloudInstance AmnesticCloudPrefab public new Scp939AmnesticCloudInstance Base { get; } /// - public override HazardType Type { get; } = HazardType.AmnesticCloud; + public override HazardType Type => HazardType.AmnesticCloud; /// /// Gets the for this instance. diff --git a/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs b/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs index 0033ef231..34cbaacd5 100644 --- a/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/SinkholeHazard.cs @@ -31,6 +31,6 @@ public SinkholeHazard(SinkholeEnvironmentalHazard hazard) public new SinkholeEnvironmentalHazard Base { get; } /// - public override HazardType Type { get; } = HazardType.Sinkhole; + public override HazardType Type => HazardType.Sinkhole; } } \ No newline at end of file diff --git a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs index 56bd73a1c..3d9d81cb3 100644 --- a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs @@ -50,7 +50,7 @@ public static TantrumEnvironmentalHazard TantrumPrefab public new TantrumEnvironmentalHazard Base { get; } /// - public override HazardType Type { get; } = HazardType.Tantrum; + public override HazardType Type => HazardType.Tantrum; /// /// Gets or sets a value indicating whether or not sizzle should be played. From c2cee9b2833409290727dd84568afcf59af0803b Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:12:41 +0200 Subject: [PATCH 5/9] remove unused usings --- EXILED/Exiled.API/Features/Map.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/EXILED/Exiled.API/Features/Map.cs b/EXILED/Exiled.API/Features/Map.cs index c604214b3..a508f132b 100644 --- a/EXILED/Exiled.API/Features/Map.cs +++ b/EXILED/Exiled.API/Features/Map.cs @@ -28,9 +28,6 @@ namespace Exiled.API.Features using LightContainmentZoneDecontamination; using MapGeneration; using MapGeneration.Distributors; - using Mirror; - using PlayerRoles; - using PlayerRoles.PlayableScps.Scp173; using PlayerRoles.PlayableScps.Scp939; using PlayerRoles.Ragdolls; using RelativePositioning; @@ -39,8 +36,6 @@ namespace Exiled.API.Features using Utils.Networking; using Object = UnityEngine.Object; - using Scp173GameRole = PlayerRoles.PlayableScps.Scp173.Scp173Role; - using Scp939GameRole = PlayerRoles.PlayableScps.Scp939.Scp939Role; /// /// A set of tools to easily handle the in-game map. From 972f06df109a1fc417891d007448b182ee1b4110 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:35:35 +0200 Subject: [PATCH 6/9] Getting inventory --- .../Exiled.API/Extensions/RoleExtensions.cs | 23 +++++++++++-------- .../EventArgs/Player/ChangingRoleEventArgs.cs | 21 ++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/EXILED/Exiled.API/Extensions/RoleExtensions.cs b/EXILED/Exiled.API/Extensions/RoleExtensions.cs index e9186ba71..c674af1bf 100644 --- a/EXILED/Exiled.API/Extensions/RoleExtensions.cs +++ b/EXILED/Exiled.API/Extensions/RoleExtensions.cs @@ -140,18 +140,22 @@ public static SpawnLocation GetRandomSpawnLocation(this RoleTypeId roleType) return null; } + /// + /// Gets the starting of a . + /// + /// The . + /// The that the role receives on spawn. + public static InventoryRoleInfo GetInventory(this RoleTypeId role) + => StartingInventories.DefinedInventories.TryGetValue(role, out InventoryRoleInfo info) + ? info + : new(Array.Empty(), new()); + /// /// Gets the starting items of a . /// /// The . /// An of that the role receives on spawn. Will be empty for classes that do not spawn with items. - public static ItemType[] GetStartingInventory(this RoleTypeId roleType) - { - if (StartingInventories.DefinedInventories.TryGetValue(roleType, out InventoryRoleInfo info)) - return info.Items; - - return Array.Empty(); - } + public static ItemType[] GetStartingInventory(this RoleTypeId roleType) => GetInventory(roleType).Items; /// /// Gets the starting ammo of a . @@ -160,10 +164,9 @@ public static ItemType[] GetStartingInventory(this RoleTypeId roleType) /// An of that the role receives on spawn. Will be empty for classes that do not spawn with ammo. public static Dictionary GetStartingAmmo(this RoleTypeId roleType) { - if (StartingInventories.DefinedInventories.TryGetValue(roleType, out InventoryRoleInfo info)) - return info.Ammo.ToDictionary(kvp => kvp.Key.GetAmmoType(), kvp => kvp.Value); + InventoryRoleInfo info = roleType.GetInventory(); - return new(); + return info.Ammo.ToDictionary(kvp => kvp.Key.GetAmmoType(), kvp => kvp.Value); } } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs index 552d70a73..32f3d94e0 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs @@ -11,11 +11,11 @@ namespace Exiled.Events.EventArgs.Player using API.Enums; using API.Features; + using Exiled.API.Extensions; using Exiled.API.Features.Pools; using Interfaces; - + using InventorySystem; using InventorySystem.Configs; - using PlayerRoles; /// @@ -70,17 +70,16 @@ public RoleTypeId NewRole get => newRole; set { - if (StartingInventories.DefinedInventories.ContainsKey(value)) - { - Items.Clear(); - Ammo.Clear(); + InventoryRoleInfo inventory = value.GetInventory(); + + Items.Clear(); + Ammo.Clear(); - foreach (ItemType itemType in StartingInventories.DefinedInventories[value].Items) - Items.Add(itemType); + foreach (ItemType itemType in inventory.Items) + Items.Add(itemType); - foreach (KeyValuePair ammoPair in StartingInventories.DefinedInventories[value].Ammo) - Ammo.Add(ammoPair.Key, ammoPair.Value); - } + foreach (KeyValuePair ammoPair in inventory.Ammo) + Ammo.Add(ammoPair.Key, ammoPair.Value); newRole = value; } From 4d30e48ef73864c79f574c81e2ca686376db2269 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Fri, 2 Aug 2024 22:35:47 +0200 Subject: [PATCH 7/9] oops --- EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs index 32f3d94e0..c8ab4d9ba 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingRoleEventArgs.cs @@ -15,7 +15,6 @@ namespace Exiled.Events.EventArgs.Player using Exiled.API.Features.Pools; using Interfaces; using InventorySystem; - using InventorySystem.Configs; using PlayerRoles; /// From 4d28d2ea408757a4f7a39cd8abd0bf74a8d2f3f1 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Sat, 10 Aug 2024 11:33:30 +0200 Subject: [PATCH 8/9] Dev commit --- EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs index 3d9d81cb3..906bd4faf 100644 --- a/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/TantrumHazard.cs @@ -99,7 +99,7 @@ public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) NetworkServer.Spawn(tantrum.gameObject); - return Get(tantrum) as TantrumHazard; + return Get(tantrum); } } } \ No newline at end of file From 9e3ef7cfb2aaad8e15c9d90050473f90c2dbed9c Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Sat, 10 Aug 2024 11:35:24 +0200 Subject: [PATCH 9/9] use exiled --- EXILED/Exiled.Events/Commands/TpsCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.Events/Commands/TpsCommand.cs b/EXILED/Exiled.Events/Commands/TpsCommand.cs index fe2aa69c2..2d7412919 100644 --- a/EXILED/Exiled.Events/Commands/TpsCommand.cs +++ b/EXILED/Exiled.Events/Commands/TpsCommand.cs @@ -31,7 +31,7 @@ public class TpsCommand : ICommand /// public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) { - double diff = Server.Tps / ServerStatic.ServerTickrate; + double diff = Server.Tps / Server.MaxTps; string color = diff switch { > 0.9 => "green", @@ -39,7 +39,7 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s _ => "red" }; - response = $"{Server.Tps}/{ServerStatic.ServerTickrate}"; + response = $"{Server.Tps}/{Server.MaxTps}"; return true; } }