refactor
This commit is contained in:
@@ -12,13 +12,13 @@ public enum DoorType
|
||||
|
||||
public class DoorLockConfiguration
|
||||
{
|
||||
public Dictionary<DoorType, float> LockDurations { get; set; }= new()
|
||||
public Dictionary<DoorType, float> LockDurations { get; set; } = new()
|
||||
{
|
||||
{ DoorType.Normal, 5f },
|
||||
{ DoorType.Gate, 8f },
|
||||
{ DoorType.Checkpoint, 3f }
|
||||
};
|
||||
|
||||
|
||||
public static DoorType GetDoorType(DoorVariant door)
|
||||
{
|
||||
Logger.Debug("Door name: " + door.name);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using Interactables.Interobjects;
|
||||
using Interactables.Interobjects.DoorButtons;
|
||||
using Interactables.Interobjects.DoorUtils;
|
||||
using LabApi.Events.Arguments.PlayerEvents;
|
||||
@@ -10,224 +9,175 @@ using UnityEngine;
|
||||
using KeycardItem = InventorySystem.Items.Keycards.KeycardItem;
|
||||
using Logger = LabApi.Features.Console.Logger;
|
||||
|
||||
namespace KeycardButModern
|
||||
namespace KeycardButModern;
|
||||
|
||||
public class Plugin : LabApi.Loader.Features.Plugins.Plugin
|
||||
{
|
||||
public class Plugin: LabApi.Loader.Features.Plugins.Plugin
|
||||
public static Plugin Singleton;
|
||||
|
||||
public DoorLockConfiguration DoorLockConfiguration;
|
||||
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);
|
||||
|
||||
public override void LoadConfigs()
|
||||
{
|
||||
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);
|
||||
base.LoadConfigs();
|
||||
|
||||
public DoorLockConfiguration DoorLockConfiguration;
|
||||
public static Plugin Singleton;
|
||||
DoorLockConfiguration = this.LoadConfig<DoorLockConfiguration>("door_locks.yml");
|
||||
}
|
||||
|
||||
public override void LoadConfigs()
|
||||
private void OnInteractingDoor(PlayerInteractingDoorEventArgs ev)
|
||||
{
|
||||
if (ev.CanOpen) return;
|
||||
|
||||
if (ev.Door.IsLocked) return;
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
base.LoadConfigs();
|
||||
|
||||
DoorLockConfiguration = this.LoadConfig< DoorLockConfiguration > ("door_locks.yml");
|
||||
}
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem) continue;
|
||||
|
||||
private void OnInteractingDoor(PlayerInteractingDoorEventArgs ev)
|
||||
{
|
||||
if (ev.CanOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!ev.Door.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Door.IsOpened = !ev.Door.IsOpened;
|
||||
|
||||
if (ev.Door.IsLocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ev.Door.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Door.IsOpened = !ev.Door.IsOpened;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractingGenerator(PlayerInteractingGeneratorEventArgs ev)
|
||||
{
|
||||
if (!ev.IsAllowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Player.CurrentItem?.Base is KeycardItem keycard)
|
||||
{
|
||||
if (ev.Generator.Base.CheckPermissions(keycard, out _))
|
||||
{
|
||||
ev.Generator.IsUnlocked = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ev.Generator.IsUnlocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ev.Generator.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Generator.IsOpen = !ev.Generator.IsOpen;
|
||||
ev.Generator.IsUnlocked = true;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractingLocker(PlayerInteractingLockerEventArgs ev)
|
||||
{
|
||||
if (!ev.IsAllowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Chamber.Base.RequiredPermissions == DoorPermissionFlags.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Player.CurrentItem?.Base is KeycardItem keycard)
|
||||
{
|
||||
if (ev.Chamber.Base.CheckPermissions(keycard, out _)) return;
|
||||
}
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ev.Chamber.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Chamber.IsOpen = !ev.Chamber.IsOpen;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnlockingWarhead(PlayerUnlockingWarheadButtonEventArgs ev)
|
||||
{
|
||||
if (ev.IsAllowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AlphaWarheadActivationPanel.Instance.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.IsAllowed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnBulletHole(PlayerPlacedBulletHoleEventArgs ev)
|
||||
{
|
||||
var direction = (ev.HitPosition - ev.RaycastStart).normalized;
|
||||
var distance = Vector3.Distance(ev.RaycastStart, ev.HitPosition);
|
||||
|
||||
var hits = Physics.RaycastAll(ev.RaycastStart, direction, distance);
|
||||
foreach (var hit in hits)
|
||||
{
|
||||
ButtonVariant doorButton = hit.collider.GetComponent<LcdButton>();
|
||||
if (!doorButton)
|
||||
{
|
||||
doorButton = hit.collider.GetComponent<CheckpointKeycardButton>();
|
||||
}
|
||||
if (!doorButton)
|
||||
{
|
||||
doorButton = hit.collider.GetComponent<KeycardButton>();
|
||||
}
|
||||
if (!doorButton)
|
||||
{
|
||||
doorButton = hit.collider.GetComponent<SimpleButton>();
|
||||
}
|
||||
|
||||
if (!doorButton)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var doorVariant = DoorVariant.AllDoors.AsEnumerable()!.First(x => x.Buttons.Any(c=>c.GetInstanceID() == doorButton.GetInstanceID()));
|
||||
|
||||
doorVariant.ServerInteract(ev.Player.ReferenceHub, doorButton.ColliderId);
|
||||
StartDoorLockCoroutine(doorVariant);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
Logger.Debug("starting...");
|
||||
Singleton = this;
|
||||
|
||||
PlayerEvents.InteractingDoor += OnInteractingDoor;
|
||||
PlayerEvents.InteractingGenerator += OnInteractingGenerator;
|
||||
PlayerEvents.InteractingLocker += OnInteractingLocker;
|
||||
PlayerEvents.UnlockingWarheadButton += OnUnlockingWarhead;
|
||||
|
||||
PlayerEvents.PlacedBulletHole += OnBulletHole;
|
||||
|
||||
}
|
||||
|
||||
private static void StartDoorLockCoroutine(DoorVariant door)
|
||||
{
|
||||
door.StartCoroutine(LockDoorCoroutine(door));
|
||||
}
|
||||
|
||||
private static IEnumerator LockDoorCoroutine(DoorVariant door)
|
||||
{
|
||||
var doorType = DoorLockConfiguration.GetDoorType(door);
|
||||
var lockDuration = Singleton.DoorLockConfiguration.LockDurations[doorType];
|
||||
|
||||
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, true);
|
||||
yield return new WaitForSeconds(lockDuration);
|
||||
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, false);
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
PlayerEvents.InteractingDoor -= OnInteractingDoor;
|
||||
PlayerEvents.InteractingGenerator -= OnInteractingGenerator;
|
||||
PlayerEvents.InteractingLocker -= OnInteractingLocker;
|
||||
PlayerEvents.UnlockingWarheadButton -= OnUnlockingWarhead;
|
||||
|
||||
PlayerEvents.PlacedBulletHole -= OnBulletHole;
|
||||
Logger.Debug("unloading...");
|
||||
|
||||
Singleton = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractingGenerator(PlayerInteractingGeneratorEventArgs ev)
|
||||
{
|
||||
if (!ev.IsAllowed) return;
|
||||
|
||||
if (ev.Player.CurrentItem?.Base is KeycardItem keycard)
|
||||
if (ev.Generator.Base.CheckPermissions(keycard, out _))
|
||||
{
|
||||
ev.Generator.IsUnlocked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Generator.IsUnlocked) return;
|
||||
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem) continue;
|
||||
|
||||
if (!ev.Generator.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Generator.IsOpen = !ev.Generator.IsOpen;
|
||||
ev.Generator.IsUnlocked = true;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractingLocker(PlayerInteractingLockerEventArgs ev)
|
||||
{
|
||||
if (!ev.IsAllowed) return;
|
||||
|
||||
if (ev.Chamber.Base.RequiredPermissions == DoorPermissionFlags.None) return;
|
||||
|
||||
if (ev.Player.CurrentItem?.Base is KeycardItem keycard)
|
||||
if (ev.Chamber.Base.CheckPermissions(keycard, out _))
|
||||
return;
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem) continue;
|
||||
|
||||
if (!ev.Chamber.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Chamber.IsOpen = !ev.Chamber.IsOpen;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnlockingWarhead(PlayerUnlockingWarheadButtonEventArgs ev)
|
||||
{
|
||||
if (ev.IsAllowed) return;
|
||||
|
||||
foreach (var playerItem in ev.Player.Items)
|
||||
{
|
||||
//is keycard?
|
||||
if (playerItem.Type is > ItemType.KeycardO5 and < ItemType.KeycardCustomTaskForce) continue;
|
||||
if (playerItem.Base is not KeycardItem keycardItem) continue;
|
||||
|
||||
if (!AlphaWarheadActivationPanel.Instance.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.IsAllowed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnBulletHole(PlayerPlacedBulletHoleEventArgs ev)
|
||||
{
|
||||
var direction = (ev.HitPosition - ev.RaycastStart).normalized;
|
||||
var distance = Vector3.Distance(ev.RaycastStart, ev.HitPosition);
|
||||
|
||||
var hits = Physics.RaycastAll(ev.RaycastStart, direction, distance);
|
||||
foreach (var hit in hits)
|
||||
{
|
||||
ButtonVariant doorButton = hit.collider.GetComponent<LcdButton>();
|
||||
if (!doorButton) doorButton = hit.collider.GetComponent<CheckpointKeycardButton>();
|
||||
if (!doorButton) doorButton = hit.collider.GetComponent<KeycardButton>();
|
||||
if (!doorButton) doorButton = hit.collider.GetComponent<SimpleButton>();
|
||||
|
||||
if (!doorButton) continue;
|
||||
|
||||
var doorVariant = DoorVariant.AllDoors.AsEnumerable()!.First(x =>
|
||||
x.Buttons.Any(c => c.GetInstanceID() == doorButton.GetInstanceID()));
|
||||
|
||||
doorVariant.ServerInteract(ev.Player.ReferenceHub, doorButton.ColliderId);
|
||||
StartDoorLockCoroutine(doorVariant);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
Logger.Debug("starting...");
|
||||
Singleton = this;
|
||||
|
||||
PlayerEvents.InteractingDoor += OnInteractingDoor;
|
||||
PlayerEvents.InteractingGenerator += OnInteractingGenerator;
|
||||
PlayerEvents.InteractingLocker += OnInteractingLocker;
|
||||
PlayerEvents.UnlockingWarheadButton += OnUnlockingWarhead;
|
||||
|
||||
PlayerEvents.PlacedBulletHole += OnBulletHole;
|
||||
}
|
||||
|
||||
private static void StartDoorLockCoroutine(DoorVariant door)
|
||||
{
|
||||
door.StartCoroutine(LockDoorCoroutine(door));
|
||||
}
|
||||
|
||||
private static IEnumerator LockDoorCoroutine(DoorVariant door)
|
||||
{
|
||||
var doorType = DoorLockConfiguration.GetDoorType(door);
|
||||
var lockDuration = Singleton.DoorLockConfiguration.LockDurations[doorType];
|
||||
|
||||
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, true);
|
||||
yield return new WaitForSeconds(lockDuration);
|
||||
door.ServerChangeLock(DoorLockReason.SpecialDoorFeature, false);
|
||||
}
|
||||
|
||||
public override void Disable()
|
||||
{
|
||||
PlayerEvents.InteractingDoor -= OnInteractingDoor;
|
||||
PlayerEvents.InteractingGenerator -= OnInteractingGenerator;
|
||||
PlayerEvents.InteractingLocker -= OnInteractingLocker;
|
||||
PlayerEvents.UnlockingWarheadButton -= OnUnlockingWarhead;
|
||||
|
||||
PlayerEvents.PlacedBulletHole -= OnBulletHole;
|
||||
Logger.Debug("unloading...");
|
||||
|
||||
Singleton = null;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<Optimize>true</Optimize>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mirror">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mirror">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>..\..\.local\share\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Northwood.LabAPI" Version="1.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Northwood.LabAPI" Version="1.0.2"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user