Skip to content

Commit 002e540

Browse files
committed
Fix stuff
1 parent 04c6d69 commit 002e540

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

EXILED/Exiled.API/Features/Items/Item.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ public static T Get<T>(ushort serial)
306306
public static Item Create(ItemType type, Player owner = null) => type.GetTemplate() switch
307307
{
308308
InventorySystem.Items.Firearms.Firearm => new Firearm(type),
309-
KeycardItem => new Keycard(type),
309+
KeycardItem when !type.IsCustomKeycard() => new Keycard(type),
310+
KeycardItem => CustomKeycard.GetKeycard(type),
310311
UsableItem usable => usable switch
311312
{
312313
Scp330Bag => new Scp330(),

EXILED/Exiled.API/Features/Items/Keycards/CustomKeycard.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Exiled.API.Features.Items.Keycards
1010
using System;
1111
using System.Linq;
1212

13-
using Exiled.API.Enums;
1413
using Exiled.API.Extensions;
1514
using Exiled.API.Interfaces.Keycards;
1615

@@ -37,16 +36,25 @@ internal CustomKeycard(KeycardItem itemBase)
3736
{
3837
}
3938

39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="CustomKeycard"/> class.
41+
/// </summary>
42+
/// <param name="itemType">The <see cref="ItemType"/> of the item to create.</param>
43+
internal CustomKeycard(ItemType itemType)
44+
: base(itemType)
45+
{
46+
}
47+
4048
/// <summary>
4149
/// Gets or sets the permissions this keycard has.
4250
/// </summary>
43-
public KeycardPermissions Permissions
51+
public KeycardLevels Permissions
4452
{
45-
get => CustomPermsDetail.CustomPermissions.TryGetValue(Serial, out DoorPermissionFlags flags) ? (KeycardPermissions)flags : KeycardPermissions.None;
53+
get => CustomPermsDetail.CustomPermissions.TryGetValue(Serial, out DoorPermissionFlags flags) ? new KeycardLevels(flags) : new KeycardLevels(0, 0, 0);
4654

4755
set
4856
{
49-
CustomPermsDetail.CustomPermissions[Serial] = (DoorPermissionFlags)value;
57+
CustomPermsDetail.CustomPermissions[Serial] = value.Permissions;
5058

5159
Resync();
5260
}
@@ -124,7 +132,7 @@ public Color Color
124132
public void Resync()
125133
{
126134
// we loveeeeeeeeeeeee NW static fields trusttttttttttttttt I'm not mad at allllllllllll
127-
CustomPermsDetail._customLevels = new KeycardLevels((DoorPermissionFlags)Permissions);
135+
CustomPermsDetail._customLevels = Permissions;
128136
CustomPermsDetail._customColor = PermissionsColor;
129137

130138
CustomItemNameDetail._customText = ItemName;
@@ -180,5 +188,22 @@ internal static CustomKeycard GetKeycard(KeycardItem itemBase)
180188
_ => throw new ArgumentOutOfRangeException(nameof(ItemType), itemBase.ItemTypeId.ToString()),
181189
};
182190
}
191+
192+
/// <summary>
193+
/// Creates a <see cref="CustomKeycard"/> based on its ItemType.
194+
/// </summary>
195+
/// <param name="type">The type to create the wrapper from.</param>
196+
/// <returns>The newly created <see cref="CustomKeycard"/>.</returns>
197+
internal static CustomKeycard GetKeycard(ItemType type)
198+
{
199+
return type switch
200+
{
201+
ItemType.KeycardCustomTaskForce => new TaskForceKeycard(type),
202+
ItemType.KeycardCustomSite02 => new Site02Keycard(type),
203+
ItemType.KeycardCustomManagement => new ManagementKeycard(type),
204+
ItemType.KeycardCustomMetalCase => new MetalKeycard(type),
205+
_ => throw new ArgumentOutOfRangeException(nameof(ItemType), type.ToString()),
206+
};
207+
}
183208
}
184209
}

EXILED/Exiled.API/Features/Items/Keycards/ManagementKeycard.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ internal ManagementKeycard(KeycardItem itemBase)
2828
{
2929
}
3030

31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="ManagementKeycard"/> class.
33+
/// </summary>
34+
/// <param name="itemType">The <see cref="ItemType"/> of the item to create.</param>
35+
internal ManagementKeycard(ItemType itemType)
36+
: base(itemType)
37+
{
38+
}
39+
3140
/// <inheritdoc cref="ILabelKeycard.Label"/>
3241
public string Label
3342
{

EXILED/Exiled.API/Features/Items/Keycards/MetalKeycard.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ internal MetalKeycard(KeycardItem itemBase)
3434
{
3535
}
3636

37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="MetalKeycard"/> class.
39+
/// </summary>
40+
/// <param name="itemType">The <see cref="ItemType"/> of the item to create.</param>
41+
internal MetalKeycard(ItemType itemType)
42+
: base(itemType)
43+
{
44+
}
45+
3746
/// <inheritdoc cref="INameTagKeycard.NameTag"/>
3847
public string NameTag
3948
{

EXILED/Exiled.API/Features/Items/Keycards/Site02Keycard.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ internal Site02Keycard(KeycardItem itemBase)
2828
{
2929
}
3030

31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="Site02Keycard"/> class.
33+
/// </summary>
34+
/// <param name="itemType">The <see cref="ItemType"/> of the item to create.</param>
35+
internal Site02Keycard(ItemType itemType)
36+
: base(itemType)
37+
{
38+
}
39+
3140
/// <inheritdoc cref="INameTagKeycard.NameTag"/>
3241
public string NameTag
3342
{

EXILED/Exiled.API/Features/Items/Keycards/TaskForceKeycard.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ internal TaskForceKeycard(KeycardItem itemBase)
3737
{
3838
}
3939

40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="TaskForceKeycard"/> class.
42+
/// </summary>
43+
/// <param name="itemType">The <see cref="ItemType"/> of the item to create.</param>
44+
internal TaskForceKeycard(ItemType itemType)
45+
: base(itemType)
46+
{
47+
}
48+
4049
/// <inheritdoc cref="INameTagKeycard.NameTag"/>
4150
public string NameTag
4251
{

0 commit comments

Comments
 (0)