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 treasureDoorStatuses; protected System.Random randomStream; protected List 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); } 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 doorways) { treasureDoorStatuses = new List(); 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(); var doorStatus = doorStatusGameObject.GetComponentInChildren(); treasureDoorStatuses.Add(doorStatus); networkObject.Spawn(true); } } public virtual void OnDungeonComplete(Dungeon dungeon) { AngerManager.Instance.AddRoomOfInterest(transform); var tile = GetComponentInParent(); var doorways = tile.UsedDoorways; var targetDoorways = new List(); foreach(var d in doorways) { var neighboorTile = d.ConnectedDoorway.Tile.gameObject.name.ToLowerInvariant(); if (neighboorTile.Contains("treasure")){ targetDoorways.Add(d); } } if (targetDoorways.Count > 0) { var dunRandom = DunGenPatch.Patch.generatorInstance.RandomStream; randomStream = new System.Random((int)(dunRandom.NextDouble() * int.MaxValue)); StartCoroutine(LockTreasureDoor(targetDoorways)); } } protected virtual IEnumerator LockTreasureDoor(List doorways){ if (!StartOfRound.Instance.IsHost) yield break; yield return new WaitForSecondsRealtime(4f); Plugin.logger.LogInfo("Setting up lock for treasure room"); treasureDoorLocks = new List(); foreach(var d in doorways){ var doorLock = AngerManager.Instance.GetScarletDoor(d.transform.position); doorLock.LockDoorOverrideClientRpc(true); treasureDoorLocks.Add(doorLock); } } } }