init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using InventorySystem.Items.Keycards;
|
||||
using LabApi.Events.Arguments.PlayerEvents;
|
||||
using LabApi.Events.Handlers;
|
||||
using LabApi.Features;
|
||||
using LabApi.Features.Console;
|
||||
|
||||
namespace KeycardButModern
|
||||
{
|
||||
public class Plugin: LabApi.Loader.Features.Plugins.Plugin
|
||||
{
|
||||
public override string Name => "KeycardButModern";
|
||||
public override string Description => "Ever thought you wanted your keycard implanted in your body? No? Same.";
|
||||
public override string Author => "Code002Lover";
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override Version RequiredApiVersion { get; } = new (LabApiProperties.CompiledVersion);
|
||||
|
||||
private void OnInteractingDoor(PlayerInteractingDoorEventArgs ev)
|
||||
{
|
||||
if (ev.CanOpen)
|
||||
{
|
||||
Logger.Debug("Door can be opened, no need for implant check");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Door.IsLocked)
|
||||
{
|
||||
Logger.Debug("Door has active locks");
|
||||
return;
|
||||
}
|
||||
|
||||
var permissions = ev.Door.Permissions;
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type > ItemType.KeycardO5) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var keycardPermissions = keycardItem.GetPermissions(ev.Door.Base);
|
||||
|
||||
Logger.Debug($"Item is a keycard: {keycardPermissions} vs {permissions} = {keycardPermissions & permissions}");
|
||||
|
||||
if ((keycardPermissions & permissions) != permissions) continue;
|
||||
ev.Door.IsOpened = true;
|
||||
Logger.Debug("Door can be opened");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
Logger.Debug("starting...");
|
||||
PlayerEvents.InteractingDoor += OnInteractingDoor;
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
PlayerEvents.InteractingDoor -= OnInteractingDoor;
|
||||
Logger.Debug("unloading...");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user