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
120 lines
3.7 KiB
C#
120 lines
3.7 KiB
C#
using DunGen;
|
|
using ScarletMansion.GamePatch.Managers;
|
|
using ScarletMansion.GamePatch.Props;
|
|
using System;
|
|
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 class TreasureRoomRadioEvent : TreasureRoom {
|
|
|
|
[Header("References")]
|
|
public Transform radioParentTransform;
|
|
public ScarletRadio radio;
|
|
|
|
private int selectedAudioIndex;
|
|
private int selectedVolume;
|
|
|
|
public override bool CanOpen() {
|
|
var ready = GetDoorStatusValue() == 3;
|
|
if (ready) {
|
|
Plugin.logger.LogDebug($"Opening cause radio all setup");
|
|
return ready;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override int GetDoorStatusValue() {
|
|
if (radio == null) return 3;
|
|
|
|
var count = 0;
|
|
if (radio.playing) count++;
|
|
if (radio.audioIndex == selectedAudioIndex) count++;
|
|
if (radio.volume == selectedVolume) count++;
|
|
return count;
|
|
}
|
|
|
|
private IEnumerable<Transform> GetChildren(Transform parent){
|
|
foreach(Transform child in parent){
|
|
yield return child;
|
|
}
|
|
}
|
|
|
|
protected override void OnTreasureRoomSetup(bool hasTreasureRoom) {
|
|
|
|
var randomStream = DunGenPatch.Patch.GetRandomStream();
|
|
var randomProps = GetChildren(radioParentTransform).Where(t => t.gameObject.activeSelf).ToArray();
|
|
Utility.Shuffle(randomStream, randomProps);
|
|
|
|
var spawnedRadioProp = false;
|
|
foreach(var parentTransform in randomProps) {
|
|
var prop = parentTransform.GetComponentInChildren<RandomPrefabBasic>();
|
|
|
|
if (hasTreasureRoom) {
|
|
if (!spawnedRadioProp) {
|
|
prop.ProcessIndex(randomStream, 0);
|
|
spawnedRadioProp = true;
|
|
} else {
|
|
prop.ProcessSkipCount(randomStream, 1);
|
|
}
|
|
} else {
|
|
prop.Process(randomStream, null);
|
|
}
|
|
|
|
// so the children get the process prop cycling as well
|
|
DunGenPatch.Patch.generatorInstance.ProcessProps(null, prop.transform.GetChild(0).gameObject);
|
|
}
|
|
|
|
// hack so i can set up the SpawnSycnedObject myself
|
|
if (hasTreasureRoom) {
|
|
radioParentTransform.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
protected override void LockTreasureDoor(List<Doorway> doorways) {
|
|
base.LockTreasureDoor(doorways);
|
|
|
|
radioParentTransform.gameObject.SetActive(true);
|
|
|
|
if (StartOfRound.Instance.IsHost) {
|
|
|
|
Plugin.logger.LogDebug("HOST: Creating scarlet radio");
|
|
|
|
var mapPropsContainer = GetMapPropsContainer();
|
|
var ssoList = radioParentTransform.GetComponentsInChildren<SpawnSyncedObject>();
|
|
foreach(var sso in ssoList) {
|
|
var ssoGameobject = GameObject.Instantiate(sso.spawnPrefab, sso.transform.position, sso.transform.rotation, mapPropsContainer.transform);
|
|
var networkObject = ssoGameobject.GetComponent<NetworkObject>();
|
|
|
|
Plugin.logger.LogDebug($"Spawned {ssoGameobject.name}");
|
|
|
|
var r = ssoGameobject.GetComponentInChildren<ScarletRadio>();
|
|
if (r != null) {
|
|
radio = r;
|
|
radio.treasureRoomEvent = this;
|
|
}
|
|
|
|
networkObject.Spawn(true);
|
|
}
|
|
|
|
if (radio == null) {
|
|
Plugin.logger.LogError($"Somehow didn't spawn a scarlet radio. Not really expected but the world won't explode");
|
|
return;
|
|
}
|
|
|
|
selectedAudioIndex = UnityEngine.Random.Range(0, radio.audioClips.Length);
|
|
selectedVolume = UnityEngine.Random.Range(1, 11);
|
|
CreateDoorStatuses(doorways);
|
|
|
|
UpdateTreasureDoorStatus();
|
|
|
|
Plugin.logger.LogDebug($"HOST: Radio combination is song index {selectedAudioIndex} and volume {selectedVolume}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|