did a few things
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using System.Collections;
|
||||
using Interactables.Interobjects;
|
||||
using Interactables.Interobjects.DoorButtons;
|
||||
using Interactables.Interobjects.DoorUtils;
|
||||
using InventorySystem.Items.Keycards;
|
||||
using LabApi.Events.Arguments.PlayerEvents;
|
||||
using LabApi.Events.Handlers;
|
||||
using LabApi.Features;
|
||||
using LabApi.Features.Console;
|
||||
using PlayerRoles;
|
||||
using LabApi.Loader;
|
||||
using UnityEngine;
|
||||
using KeycardItem = InventorySystem.Items.Keycards.KeycardItem;
|
||||
using Logger = LabApi.Features.Console.Logger;
|
||||
|
||||
namespace KeycardButModern
|
||||
{
|
||||
@@ -16,6 +20,16 @@ namespace KeycardButModern
|
||||
public override Version Version { get; } = new(1, 0, 0);
|
||||
public override Version RequiredApiVersion { get; } = new (LabApiProperties.CompiledVersion);
|
||||
|
||||
public DoorLockConfiguration DoorLockConfiguration;
|
||||
public static Plugin Singleton;
|
||||
|
||||
public override void LoadConfigs()
|
||||
{
|
||||
base.LoadConfigs();
|
||||
|
||||
DoorLockConfiguration = this.LoadConfig< DoorLockConfiguration > ("door_locks.yml");
|
||||
}
|
||||
|
||||
private void OnInteractingDoor(PlayerInteractingDoorEventArgs ev)
|
||||
{
|
||||
if (ev.CanOpen)
|
||||
@@ -25,7 +39,6 @@ namespace KeycardButModern
|
||||
|
||||
if (ev.Door.IsLocked)
|
||||
{
|
||||
Logger.Debug("Door has active locks");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +53,6 @@ namespace KeycardButModern
|
||||
|
||||
if (!ev.Door.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Door.IsOpened = !ev.Door.IsOpened;
|
||||
Logger.Debug("Door can be opened");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -64,7 +76,6 @@ namespace KeycardButModern
|
||||
|
||||
if (ev.Generator.IsUnlocked)
|
||||
{
|
||||
Logger.Debug("Generator can be opened; Unlocked");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +92,6 @@ namespace KeycardButModern
|
||||
if (!ev.Generator.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Generator.IsOpen = !ev.Generator.IsOpen;
|
||||
ev.Generator.IsUnlocked = true;
|
||||
Logger.Debug("Generator can be opened");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -115,7 +125,6 @@ namespace KeycardButModern
|
||||
|
||||
if (!ev.Chamber.Base.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.Chamber.IsOpen = !ev.Chamber.IsOpen;
|
||||
Logger.Debug("Locker can be opened");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +148,42 @@ namespace KeycardButModern
|
||||
|
||||
if (!AlphaWarheadActivationPanel.Instance.CheckPermissions(keycardItem, out _)) continue;
|
||||
ev.IsAllowed = true;
|
||||
Logger.Debug("Nuke can be unlocked");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -147,19 +191,43 @@ namespace KeycardButModern
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user