LadyAliceMargatroid e9152782aa Added treasure rooms
Added keyslot compatibility
Frames look at when you look away
Fixed snow globes
2024-08-04 22:02:12 -07:00

107 lines
3.4 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 randomStream;
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);
}
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) {
AngerManager.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);
}
}
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<Doorway> doorways){
if (!StartOfRound.Instance.IsHost) yield break;
yield return new WaitForSecondsRealtime(4f);
Plugin.logger.LogInfo("Setting up lock for treasure room");
treasureDoorLocks = new List<ScarletDoor>();
foreach(var d in doorways){
var doorLock = AngerManager.Instance.GetScarletDoor(d.transform.position);
doorLock.LockDoorOverrideClientRpc(true);
treasureDoorLocks.Add(doorLock);
}
}
}
}