SDM_LethalCompany_Mod/ScarletMansion/ScarletMansion/GamePatch/Components/ScarletDoor.cs
LadyAliceMargatroid 4413d12ea3 Added new treasure room spawn (servant's quarters)
Fixed treasure room event for bedroom
Fixed painting's interaction with MattyFixes
Fixed critical damage bug introduced by v62
Increased lights spawn for all presets by a lot
Added Coroner compatibility
Added Scarlet Devil Mansion (moon) to the interior's spawn list
Lights now have a chance of flickering and dying
2024-09-01 18:45:16 -07:00

94 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Unity.Netcode;
using UnityEngine.AI;
using ScarletMansion.GamePatch.Managers;
namespace ScarletMansion.GamePatch.Components {
public class ScarletDoor : NetworkBehaviour {
[Header("Door Reference")]
public ScarletDoorLock door;
public bool doorState;
public bool overrideLock;
public bool overrideUnlock;
[Header("Personal Refs")]
public NavMeshObstacle obstacle;
public BoxCollider boxCollider;
public ParticleSystem ps;
private bool previousDoorLockValue;
void Awake(){
ScarletGenericManager.Instance.AddDoor(this);
}
[ClientRpc]
public void LockDoorClientRpc(){
doorState = true;
ReevalulateDoorState();
}
[ClientRpc]
public void UnlockDoorClientRpc(){
doorState = false;
ReevalulateDoorState();
}
[ClientRpc]
public void LockDoorOverrideClientRpc(bool state){
overrideLock = state;
ReevalulateDoorState();
}
[ClientRpc]
public void UnlockDoorOverrideClientRpc(bool state){
overrideUnlock = state;
ReevalulateDoorState();
}
private void ReevalulateDoorState(){
var state = doorState;
if (overrideUnlock) state = false;
if (overrideLock) state = true;
if (state) LockDoorCall();
else UnlockDoorCall();
}
private void LockDoorCall(){
if (door){
door.isDoorOpened = false;
door.navMeshObstacle.enabled = true;
if (RoundManager.Instance.IsServer)
door.GetComponent<AnimatedObjectTrigger>().TriggerAnimationNonPlayer(false, true, true);
door.doorTrigger.interactable = false;
previousDoorLockValue = door.isLocked;
door.isLocked = true;
}
obstacle.enabled = true;
boxCollider.enabled = true;
ps.Play();
}
private void UnlockDoorCall() {
if (door){
door.doorTrigger.interactable = true;
door.isLocked = previousDoorLockValue;
}
obstacle.enabled = false;
boxCollider.enabled = false;
ps.Stop();
}
}
}