This commit is contained in:
LadyAliceMargatroid 2024-04-28 14:41:33 -07:00
parent 7a77b79dc5
commit cdadd75ee9
104 changed files with 9416 additions and 0 deletions

View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class FireExitEmptySpaceCheck : RandomProp {
public GameObject target;
public Bounds bounds;
public override void Process(RandomStream randomStream, Tile tile) {
var b = GetBounds();
var layerMask = LayerMask.GetMask(new string[3] { "Room", "Railing", "MapHazards" });
if (Physics.CheckBox(b.center, b.extents, transform.rotation, layerMask)){
Plugin.logger.LogInfo("Disabling fire exit potential spawn due to overlapping space");
target.SetActive(false);
}
}
public Bounds GetBounds(){
return transform.TransformBounds(bounds);
}
public void OnDrawGizmosSelected(){
var b = GetBounds();
Gizmos.DrawWireCube(b.center, b.size);
}
}
}

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DunGen;
using UnityEngine;
namespace ScarletMansion.GamePatch.Props {
public class FloorPropBasedOnFloor : RandomProp {
public GameObject topFloorPrefab;
public List<GameObject> secondFloorPrefabs;
public GameObject mainFloorPrefab;
public List<GameObject> basementFloorPrefabs;
public GameObject bottomFloorPrefab;
public override void Process(RandomStream randomStream, Tile tile) {
var baseY = KnightSpawnManager.Instance.transform.position.y;
var currentY = tile.transform.position.y;
var floor = Mathf.RoundToInt((currentY - baseY) / 8f);
Plugin.logger.LogInfo($"F{floor}");
// fuck it im lazy
GameObject p;
if (floor == 0) {
p = mainFloorPrefab;
} else if (floor == 1) {
p = secondFloorPrefabs[randomStream.Next(secondFloorPrefabs.Count)];
} else if (floor == -1) {
p = basementFloorPrefabs[randomStream.Next(basementFloorPrefabs.Count)];
} else if (floor >= 2) {
p = topFloorPrefab;
} else {
p = bottomFloorPrefab;
}
var gameObject = GameObject.Instantiate(p);
var gameObjectTransform = gameObject.transform;
gameObjectTransform.parent = transform;
gameObjectTransform.localPosition = Vector3.zero;
gameObjectTransform.localRotation = Quaternion.identity;
}
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
}

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class LocalPropSetBasic : RandomProp {
public override void Process(RandomStream randomStream, Tile tile) {
var transformCount = transform.childCount;
var count = Mathf.Clamp(propCount.GetRandom(randomStream), 0, transformCount);
var array = new GameObject[transformCount];
for(var i = 0; i < transformCount; ++i){
array[i] = transform.GetChild(i).gameObject;
}
Utility.Shuffle(randomStream, array);
for(var i = count; i < transformCount; ++i){
UnityUtil.Destroy(array[i]);
}
}
public IntRange propCount = new IntRange(1, 1);
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class LocalPropSingle : RandomProp {
public override void Process(RandomStream randomStream, Tile tile) {
if (randomizePosition){
var x = (float)randomStream.NextDouble() * randomPositionRange;
var z = (float)randomStream.NextDouble() * randomPositionRange;
transform.localPosition = new Vector3(x, 0f, z);
}
if (randomizeRotation){
var y = randomRotationRange.GetRandom(randomStream);
transform.localEulerAngles = new Vector3(0f, y, 0f);
}
}
public bool randomizePosition = false;
public float randomPositionRange = 0f;
public bool randomizeRotation = false;
public FloatRange randomRotationRange = new FloatRange(0f, 360f);
public void OnDrawGizmosSelected(){
if (randomizePosition) {
Utility.DrawGizmoCircle(transform, randomPositionRange, Color.green);
}
}
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class RandomPrefabBasic : RandomPrefabBase {
public override void Process(RandomStream randomStream, Tile tile) {
if (props.Count <= 0) return;
var value = randomStream.Next(props.Count);
var prefab = props[value];
SpawnGameObject(randomStream, prefab);
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public abstract class RandomPrefabBase : RandomProp {
public List<GameObject> props = new List<GameObject>();
public bool randomizePosition = false;
public float randomPositionRange = 0f;
public bool randomizeRotation = true;
public FloatRange randomRotationRange = new FloatRange(0f, 360f);
public void SpawnGameObject(RandomStream randomStream, GameObject prefab){
var gameObject = GameObject.Instantiate(prefab);
var gameObjectTransform = gameObject.transform;
gameObjectTransform.parent = transform;
if (randomizePosition){
var x = (float)randomStream.NextDouble() * randomPositionRange;
var z = (float)randomStream.NextDouble() * randomPositionRange;
gameObjectTransform.localPosition = new Vector3(x, 0f, z);
} else {
gameObjectTransform.localPosition = Vector3.zero;
}
if (randomizeRotation){
var y = randomRotationRange.GetRandom(randomStream);
gameObjectTransform.localEulerAngles = new Vector3(0f, y, 0f);
} else {
gameObjectTransform.localRotation = Quaternion.identity;
}
}
public void OnDrawGizmosSelected(){
if (randomizePosition) {
Utility.DrawGizmoCircle(transform, randomPositionRange, Color.green);
}
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class RandomPrefabCycle : RandomPrefabBase {
public static int cycle = 0;
public static void UpdateCycle(int value){
Plugin.logger.LogInfo($"Updating RandomPrefab cylce to {value}");
cycle = value;
}
public override void Process(RandomStream randomStream, Tile tile) {
if (props.Count <= 0) return;
Plugin.logger.LogInfo($"Cycle {cycle}");
var cycleValue = cycle++;
var index = cycleValue % props.Count;
var prefab = props[index];
SpawnGameObject(randomStream, prefab);
}
}
}

View file

@ -0,0 +1,32 @@
using System;
using UnityEngine;
using DunGen;
namespace ScarletMansion {
[AddComponentMenu("DunGen/Random Props/Random Prefab with Scale")]
public class RandomPrefabWithScale : RandomProp {
public override void Process(RandomStream randomStream, Tile tile) {
if (Props.Weights.Count <= 0) return;
var value = this.Props.GetRandom(randomStream, tile.Placement.IsOnMainPath, tile.Placement.NormalizedDepth, null, true, true).Value;
var gameObject = Instantiate<GameObject>(value, transform);
var t = gameObject.transform;
if (ZeroPosition) t.localPosition = Vector3.zero;
else t.localPosition = value.transform.localPosition;
if (ZeroRotation) t.localRotation = Quaternion.identity;
else t.localRotation = value.transform.localRotation;
}
[AcceptGameObjectTypes(GameObjectFilter.Asset)]
public GameObjectChanceTable Props = new GameObjectChanceTable();
public bool ZeroPosition = true;
public bool ZeroRotation = true;
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using DunGen;
namespace ScarletMansion.GamePatch.Props {
public class SpawnSyncedObjectCycle : MonoBehaviour, IDungeonCompleteReceiver {
public static int cycle;
public static Dictionary<int, int> cycleDictionary;
public SpawnSyncedObject spawn;
public int id;
public List<GameObject> props = new List<GameObject>();
void Reset(){
spawn = GetComponent<SpawnSyncedObject>();
}
public static void UpdateCycle(int value){
Plugin.logger.LogInfo($"Updating SpawnSyncedObject start cycle to {value}");
cycle = value;
cycleDictionary = new Dictionary<int, int>();
}
public int GetCycle(int id){
if (!cycleDictionary.TryGetValue(id, out var value)){
value = cycle;
cycleDictionary.Add(id, value);
}
cycleDictionary[id] = value + 1;
Plugin.logger.LogInfo($"Cycle{id}: {value}");
return value;
}
public void OnDungeonComplete(Dungeon dungeon) {
var index = GetCycle(id) % props.Count;
var prefab = props[index];
spawn.spawnPrefab = prefab;
}
}
}