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

119 lines
3.9 KiB
C#

using DunGen;
using ScarletMansion.GamePatch.Managers;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.Netcode;
using UnityEngine;
namespace ScarletMansion.GamePatch.Components.TreasureRoom {
public abstract class TreasureRoom : MonoBehaviour, IDungeonCompleteReceiver {
[Header("Door Statuses")]
public GameObject doorStatusPrefab;
protected List<TreasureRoomDoorStatus> treasureDoorStatuses;
protected System.Random systemRandom;
protected List<ScarletDoor> treasureDoorLocks;
protected bool opened;
public void Update(){
if (treasureDoorLocks == null) return;
if (!StartOfRound.Instance.IsHost || opened) return;
var time = Utility.GetTime();
if (CanOpen()) {
foreach(var d in treasureDoorLocks){
d.LockDoorOverrideClientRpc(false);
d.door?.DestroyDoorClientRpc(d.transform.forward);
}
opened = true;
}
}
public abstract bool CanOpen();
public virtual int GetDoorStatusValue() => 0;
public void UpdateTreasureDoorStatus(){
var value = GetDoorStatusValue();
foreach(var d in treasureDoorStatuses){
d.UpdateDoorStatusClientRpc(value);
}
}
protected GameObject GetMapPropsContainer(){
var roundManager = RoundManager.Instance;
if (roundManager.mapPropsContainer == null) {
roundManager.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
}
return roundManager.mapPropsContainer;
}
protected void CreateDoorStatuses(List<Doorway> doorways) {
treasureDoorStatuses = new List<TreasureRoomDoorStatus>();
var mapPropsContainer = GetMapPropsContainer();
foreach(var doorway in doorways) {
var doorStatusGameObject = GameObject.Instantiate(doorStatusPrefab, doorway.transform.position, doorway.transform.rotation, mapPropsContainer.transform);
var networkObject = doorStatusGameObject.GetComponent<NetworkObject>();
var doorStatus = doorStatusGameObject.GetComponentInChildren<TreasureRoomDoorStatus>();
treasureDoorStatuses.Add(doorStatus);
networkObject.Spawn(true);
}
}
public virtual void OnDungeonComplete(Dungeon dungeon) {
ScarletGenericManager.Instance.AddRoomOfInterest(transform);
var tile = GetComponentInParent<Tile>();
var doorways = tile.UsedDoorways;
var targetDoorways = new List<Doorway>();
foreach(var d in doorways) {
var neighboorTile = d.ConnectedDoorway.Tile.gameObject.name.ToLowerInvariant();
if (neighboorTile.Contains("treasure")){
targetDoorways.Add(d);
}
}
var hasTreasureRoom = targetDoorways.Count > 0;
if (hasTreasureRoom) {
systemRandom = DunGenPatch.Patch.CreateSystemRandom();
Plugin.logger.LogInfo($"Adding treasure room event {GetType().ToString()}");
DunGenPlus.Managers.DoorwayManager.onMainEntranceTeleportSpawnedEvent.AddTemporaryEvent("TreasureRoom", () => LockTreasureDoor(targetDoorways));
}
OnTreasureRoomSetup(hasTreasureRoom);
}
protected virtual void OnTreasureRoomSetup(bool hasTreasureRoom){
}
protected virtual void LockTreasureDoor(List<Doorway> doorways){
if (!StartOfRound.Instance.IsHost) return;
Plugin.logger.LogDebug($"Setting up lock for treasure room ({GetType().ToString()})");
treasureDoorLocks = new List<ScarletDoor>();
foreach(var d in doorways){
if (d == null) {
Plugin.logger.LogWarning("For some reason, a doorway is null");
continue;
}
var doorPosition = d.transform.position;
var doorLock = ScarletGenericManager.Instance.GetScarletDoor(doorPosition);
doorLock.LockDoorOverrideClientRpc(true);
treasureDoorLocks.Add(doorLock);
}
}
}
}