diff --git a/EXILED/Exiled.API/Enums/CustomizableKeycardType.cs b/EXILED/Exiled.API/Enums/CustomizableKeycardType.cs new file mode 100644 index 000000000..323ac48d8 --- /dev/null +++ b/EXILED/Exiled.API/Enums/CustomizableKeycardType.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Enums +{ + /// + /// Customizable Keycard types present in the game. + /// + /// + public enum CustomizableKeycardType + { + /// + /// Not Customizable Keycard. + /// + None, + + /// + /// Used by . + /// + Vertical, + + /// + /// Used by . + /// + MetalFramed, + + /// + /// Used by . + /// + Perforated, + + /// + /// Used by . + /// + Standard, + } +} diff --git a/EXILED/Exiled.API/Extensions/ItemExtensions.cs b/EXILED/Exiled.API/Extensions/ItemExtensions.cs index 1c03c97d9..9bd84ca2f 100644 --- a/EXILED/Exiled.API/Extensions/ItemExtensions.cs +++ b/EXILED/Exiled.API/Extensions/ItemExtensions.cs @@ -201,6 +201,20 @@ public static int GetMaxAmmo(this FirearmType item) _ => ItemType.None, }; + /// + /// Converts an into it's corresponding . + /// + /// The to convert. + /// The Item type of the specified customizable keycard. + public static ItemType GetItemType(this CustomizableKeycardType type) => type switch + { + CustomizableKeycardType.Vertical => ItemType.KeycardCustomManagement, + CustomizableKeycardType.Standard => ItemType.KeycardCustomSite02, + CustomizableKeycardType.MetalFramed => ItemType.KeycardCustomMetalCase, + CustomizableKeycardType.Perforated => ItemType.KeycardCustomTaskForce, + _ => ItemType.None, + }; + /// /// Converts a into it's corresponding . /// diff --git a/EXILED/Exiled.API/Features/Items/Keycard.cs b/EXILED/Exiled.API/Features/Items/Keycard.cs index 4e68dd60a..408f3a455 100644 --- a/EXILED/Exiled.API/Features/Items/Keycard.cs +++ b/EXILED/Exiled.API/Features/Items/Keycard.cs @@ -10,8 +10,12 @@ namespace Exiled.API.Features.Items using System; using Exiled.API.Enums; + using Exiled.API.Extensions; using Exiled.API.Interfaces; + using Interactables.Interobjects.DoorUtils; + using InventorySystem; using InventorySystem.Items.Keycards; + using UnityEngine; /// /// A wrapper class for . @@ -42,6 +46,11 @@ internal Keycard(ItemType type) /// public new KeycardItem Base { get; } + /// + /// Gets a value indicating whether . + /// + public bool IsCustomizable => Base.Customizable; + /// /// Gets or sets the of the keycard. /// @@ -63,8 +72,46 @@ public KeycardPermissions Permissions return KeycardPermissions.None; } - [Obsolete("Not functional anymore", true)] - set => _ = value; + set + { + if (!Base.Customizable) + { + Log.Error($"The keycard {Type} is not customizable, so you cannot set permissions on it."); + return; + } + + KeycardDetailSynchronizer.Database.Remove(Serial); + CustomPermsDetail._customLevels = new KeycardLevels((DoorPermissionFlags)value); + KeycardDetailSynchronizer.ServerProcessItem(Base); + } + } + + /// + /// Creates and returns a representing the provided . + /// + /// The type of keycard to create. + /// The name of keycard. + /// The label text to display on the keycard. + /// The name of the owner to display on the keycard. + /// The level associated with the keycard. + /// The color representing the levels on the keycard. + /// The tilt color of the keycard. + /// The color of the label text on the keycard. + /// The newly created . + public static Keycard CreateCustom(CustomizableKeycardType keycardType, string keycardName, string labelText, string ownerName, KeycardLevels levels, Color32 levelsColor, Color32 tintColor, Color32 labelColor) + { + if (!keycardType.GetItemType().TryGetTemplate(out KeycardItem keycard) || !keycard.Customizable) + throw new ArgumentException($"The provided ItemType {keycardType} is not a valid keycard type or cant be customizable type.", nameof(keycardType)); + + NametagDetail._customNametag = ownerName; + CustomPermsDetail._customLevels = levels; + CustomLabelDetail._customText = labelText; + CustomTintDetail._customColor = tintColor; + CustomLabelDetail._customColor = labelColor; + CustomPermsDetail._customColor = levelsColor; + CustomItemNameDetail._customText = keycardName; + + return new Keycard(keycard.ItemTypeId); } /// @@ -73,4 +120,4 @@ public KeycardPermissions Permissions /// A string containing Keycard-related data. public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Permissions}|"; } -} \ No newline at end of file +} diff --git a/EXILED/Exiled.API/Features/Pickups/KeycardPickup.cs b/EXILED/Exiled.API/Features/Pickups/KeycardPickup.cs index e7e29ff13..47c639eb3 100644 --- a/EXILED/Exiled.API/Features/Pickups/KeycardPickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/KeycardPickup.cs @@ -10,9 +10,10 @@ namespace Exiled.API.Features.Pickups using Exiled.API.Enums; using Exiled.API.Features.Items; using Exiled.API.Interfaces; - + using Interactables.Interobjects.DoorUtils; using InventorySystem.Items; using InventorySystem.Items.Keycards; + using UnityEngine; using BaseKeycard = InventorySystem.Items.Keycards.KeycardPickup; @@ -51,6 +52,81 @@ internal KeycardPickup(ItemType type) /// public new BaseKeycard Base { get; } + /// + /// Creates and returns a representing the provided . + /// + /// The type of keycard to create. + /// The display name of the keycard. + /// The label text shown on the keycard. + /// The name of the owner displayed on the keycard. + /// The door permission flags for the card. + /// The color representing the permission levels on the keycard. + /// The tint color of the card. + /// The color of the label text. + /// The position of the pickup. + /// The rotation of pickup. + /// Whether the pickup will spawn or not. + /// The newly created . + public static KeycardPickup CreateCustomKeycardPickup(CustomizableKeycardType keycardType, string keycardName, string labelText, string ownerName, DoorPermissionFlags permissions, Color32 levelsColor, Color32 tintColor, Color32 labelColor, Vector3 spawnPosition, Quaternion rotation, bool spawn = false) + { + Keycard item = Keycard.CreateCustom(keycardType, keycardName, labelText, ownerName, new KeycardLevels(permissions), levelsColor, tintColor, labelColor); + + KeycardPickup pickup = (KeycardPickup)item.CreatePickup(spawnPosition, rotation, spawn); + + return pickup; + } + + /// + /// Creates and returns a representing the provided . + /// + /// The type of keycard to create. + /// The display name of the keycard. + /// The label text shown on the keycard. + /// The name of the owner displayed on the keycard. + /// The containment access level. + /// The armory access level. + /// The admin access level. + /// The color representing the permission levels on the keycard. + /// The tint color of the card. + /// The color of the label text. + /// The position of the pickup. + /// The rotation of pickup. + /// Whether the pickup will spawn or not. + /// /// Whether to clamp the access level values to valid ranges. + /// The newly created . + public static KeycardPickup CreateCustomKeycardPickup(CustomizableKeycardType keycardType, string keycardName, string labelText, string ownerName, int containmentLevel, int armoryLevel, int adminLevel, Color32 levelsColor, Color32 tintColor, Color32 labelColor, Vector3 spawnPosition, Quaternion rotation, bool spawn = false, bool clampLevels = true) + { + Keycard item = Keycard.CreateCustom(keycardType, keycardName, labelText, ownerName, new KeycardLevels(containmentLevel, armoryLevel, adminLevel, clampLevels), levelsColor, tintColor, labelColor); + + KeycardPickup pickup = (KeycardPickup)item.CreatePickup(spawnPosition, rotation, spawn); + + return pickup; + } + + /// + /// Creates and returns a representing the provided . + /// + /// The type of keycard to create. + /// The display name of the keycard. + /// The label text shown on the keycard. + /// The name of the owner displayed on the keycard. + /// The level associated with the keycard. + /// The color representing the permission levels on the keycard. + /// The tint color of the card. + /// The color of the label text. + /// The position of the pickup. + /// The rotation of pickup. + /// Whether the pickup will spawn or not. + /// The newly created . + public static KeycardPickup CreateCustomKeycardPickup(CustomizableKeycardType keycardType, string keycardName, string labelText, string ownerName, KeycardLevels levels, Color32 levelsColor, Color32 tintColor, Color32 labelColor, Vector3 spawnPosition, Quaternion rotation, bool spawn = false) + { + Keycard item = Keycard.CreateCustom(keycardType, keycardName, labelText, ownerName, levels, levelsColor, tintColor, labelColor); + + KeycardPickup pickup = (KeycardPickup)item.CreatePickup(spawnPosition, rotation, spawn); + + return pickup; + } + /// internal override void ReadItemInfo(Item item) {