SDM_LethalCompany_Mod/ScarletMansion/ScarletMansion/PresetConfig.cs
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

427 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using BepInEx.Configuration;
namespace ScarletMansion {
public class PresetConfig {
public enum DungeonGeneration {
Custom,
Default,
Small,
MoreLoot,
BitMoreLoot,
Vanilla
}
public static ChangeList customChangeList = new ChangeList("Custom", "Disables auto loading of preset config values.");
public static ChangeList defaultGeneration = new ChangeList(
"Default",
"The default generation values. Intended for lobbies with 3+ players.",
//new ChangeMinMaxFloat ( PluginConfig.dunGenMultiplier ),
new ChangeInt ( PluginConfig.dunGenWidthBase ),
new ChangeInt ( PluginConfig.dunGenLengthBase ),
new ChangeFloat ( PluginConfig.dunGenWidthMultiFactor ),
new ChangeFloat ( PluginConfig.dunGenLengthMultiFactor ),
new ChangeInt ( PluginConfig.mainPathCount ),
new ChangeMinMaxInt ( PluginConfig.mainPathLength ),
new ChangeBranchingPath( PluginConfig.branchPathSectionOne ),
new ChangeBranchingPath( PluginConfig.branchPathSectionTwo ),
new ChangeBranchingPath( PluginConfig.branchPathSectionThree ),
new ChangeFloat ( PluginConfig.lootMultiplier ),
new ChangeInt ( PluginConfig.paintingCount ),
new ChangeMinMaxInt( PluginConfig.paintingExtraLoot ),
new ChangeInt( PluginConfig.treasureRoomCount ),
new ChangeMinMaxInt( PluginConfig.treasureRoomLoot ),
new ChangeFloat ( PluginConfig.mapHazardsMultiplier ),
new ChangeInt ( PluginConfig.minIndoorEnemySpawnCount )
);
public static ChangeList smallGeneration = new ChangeList(
"Small",
"A smaller variation of the default generation values. Intended for lobbies with 1-3 players.",
defaultGeneration,
new ChangeInt ( PluginConfig.mainPathCount, 2 ),
/*
new ChangeBranchingPath( PluginConfig.branchPathSectionOne, int.MaxValue, int.MaxValue, 3, 4 ),
new ChangeBranchingPath( PluginConfig.branchPathSectionTwo, int.MaxValue, int.MaxValue, 1, 2 ),
new ChangeBranchingPath( PluginConfig.branchPathSectionThree, int.MaxValue, int.MaxValue, 0, 1 ),
*/
new ChangeFloat ( PluginConfig.lootMultiplier, 1.2f ),
new ChangeFloat ( PluginConfig.mapHazardsMultiplier, 1.3f )
);
public static ChangeList moreLootGeneration = new ChangeList(
"More Loot, More Danger",
"Increases the amount of loot, map hazards, and starting enemies in the mansion. Intended for lobbies with 3+ players.",
defaultGeneration,
new ChangeFloat ( PluginConfig.lootMultiplier, 1.8f ),
new ChangeInt ( PluginConfig.paintingCount, 3 ),
new ChangeMinMaxInt( PluginConfig.paintingExtraLoot, 1 , 3 ),
new ChangeInt( PluginConfig.treasureRoomCount, 3 ),
new ChangeMinMaxInt( PluginConfig.treasureRoomLoot, 3, 4 ),
new ChangeFloat ( PluginConfig.mapHazardsMultiplier, 2.2f ),
new ChangeInt ( PluginConfig.minIndoorEnemySpawnCount, 2 )
);
public static ChangeList bitMoreLootGeneration = new ChangeList(
"Bit More Loot, Bit More Danger",
"Increases the amount of loot, map hazards, and starting enemies in the mansion a bit. Intended for lobbies with 1-3 players.",
smallGeneration,
new ChangeFloat ( PluginConfig.lootMultiplier, 1.5f ),
new ChangeInt ( PluginConfig.paintingCount, 3 ),
new ChangeInt( PluginConfig.treasureRoomCount, 3 ),
new ChangeFloat ( PluginConfig.mapHazardsMultiplier, 1.75f ),
new ChangeInt ( PluginConfig.minIndoorEnemySpawnCount, 2 )
);
public static ChangeList vanillaGeneration = new ChangeList(
"Vanilla",
"Changes the dungeon generation to match closer to a vanilla dungeon.",
defaultGeneration,
//new ChangeMinMaxFloat ( PluginConfig.dunGenMultiplier, float.MaxValue, 10f ),
new ChangeInt ( PluginConfig.dunGenWidthBase, 200 ),
new ChangeInt ( PluginConfig.dunGenLengthBase, 200 ),
new ChangeFloat ( PluginConfig.dunGenWidthMultiFactor, 4f ),
new ChangeFloat ( PluginConfig.dunGenLengthMultiFactor, 4f ),
new ChangeInt ( PluginConfig.mainPathCount, 1 ),
new ChangeMinMaxInt ( PluginConfig.mainPathLength, 6, 9 ),
new ChangeBranchingPath( PluginConfig.branchPathSectionOne, 4, 6, 3, 4 ),
new ChangeBranchingPath( PluginConfig.branchPathSectionTwo, 2, 3, 2, 3 ),
new ChangeBranchingPath( PluginConfig.branchPathSectionThree, 1, 2, 1, 2 ),
new ChangeFloat ( PluginConfig.lootMultiplier, 1f ),
new ChangeFloat ( PluginConfig.mapHazardsMultiplier, 1f ),
new ChangeInt ( PluginConfig.minIndoorEnemySpawnCount, 0 )
);
public enum DungeonLighting {
Custom,
Default,
Bright,
Dark
}
// 1, 8, 2
public static ChangeList defaultLighting = new ChangeList(
"Default",
"The default lighting values.",
new ChangeInt ( PluginConfig.hallwayLightsWeight ),
new ChangeInt ( PluginConfig.ceilingLightsWeight ),
new ChangeInt ( PluginConfig.lightsSpawnZeroWeight ),
new ChangeInt ( PluginConfig.lightsSpawnOneWeight ),
new ChangeInt ( PluginConfig.lightsSpawnTwoWeight )
//new ChangeInt ( PluginConfig.lightsSpawnThreeWeight )
);
public static ChangeList brightLighting = new ChangeList(
"Bright",
"Makes light sources much more common.",
new ChangeInt ( PluginConfig.hallwayLightsWeight, 450 ),
new ChangeInt ( PluginConfig.ceilingLightsWeight, 450 ),
new ChangeInt ( PluginConfig.lightsSpawnZeroWeight, 0 ),
new ChangeInt ( PluginConfig.lightsSpawnOneWeight, 7 ),
new ChangeInt ( PluginConfig.lightsSpawnTwoWeight, 3 )
//new ChangeInt ( PluginConfig.lightsSpawnThreeWeight, 2 )
);
public static ChangeList darkLighting = new ChangeList(
"Dark",
"Makes light sources much less common.",
new ChangeInt ( PluginConfig.hallwayLightsWeight, 50 ),
new ChangeInt ( PluginConfig.ceilingLightsWeight, 50 ),
new ChangeInt ( PluginConfig.lightsSpawnZeroWeight, 2 ),
new ChangeInt ( PluginConfig.lightsSpawnOneWeight, 8 ),
new ChangeInt ( PluginConfig.lightsSpawnTwoWeight, 0 )
//new ChangeInt ( PluginConfig.lightsSpawnThreeWeight, 0 )
);
public static List<ChangeList> dungeonGenerationChangeList = new List<ChangeList>() {
customChangeList,
defaultGeneration,
smallGeneration,
moreLootGeneration,
bitMoreLootGeneration,
vanillaGeneration
};
public static List<ChangeList> dungeonLightingChangeList = new List<ChangeList>() {
customChangeList,
defaultLighting,
brightLighting,
darkLighting
};
public static void UpdateFromPresetValue(int value, List<ChangeList> changeList){
if (value >= 0 && value < changeList.Count) {
var target = changeList[value];
target.UpdateChanges();
}
}
public class ChangeList {
public string name;
public string description;
public Change[] changes;
public ChangeList(string name, string description, params Change[] changes){
this.name = name;
this.description = description;
this.changes = changes;
}
public ChangeList(string name, string description, ChangeList baseList, params Change[] changes){
this.name = name;
this.description = description;
var newChanges = new List<Change>();
foreach(var c in baseList.changes){
newChanges.Add(c);
}
foreach(var c in changes){
var added = false;
for(var i = 0; i < newChanges.Count; ++i) {
if (newChanges[i].IsEqual(c)){
newChanges[i] = c;
added = true;
break;
}
}
if (!added) newChanges.Add(c);
}
this.changes = newChanges.ToArray();
}
public void UpdateChanges(){
Plugin.logger.LogDebug($"Updating config values with preset {name}");
foreach(var c in changes){
c.Update();
}
Plugin.Instance.Config.Save();
Plugin.Instance.Config.Reload();
}
public override string ToString() {
var str = string.Empty;
foreach(var c in changes){
str += c.ToString() + "\n";
}
if (string.IsNullOrWhiteSpace(str)){
str = "No changes.\n";
}
return str;
}
public HashSet<ConfigEntryBase> GetAllConfigEntries(){
var set = new HashSet<ConfigEntryBase>();
foreach(var a in changes.SelectMany(c => c.configBases)){
set.Add(a);
}
return set;
}
}
public abstract class Change {
public abstract void Update();
public abstract bool IsEqual(Change target);
public abstract IEnumerable<ConfigEntryBase> configBases { get; }
}
public abstract class ChangeType<T> : Change {
public PluginConfig.ConfigEntryBundle<T> configBundle;
public ConfigEntry<T> configEntry => configBundle.config;
public T value;
public override IEnumerable<ConfigEntryBase> configBases {
get {
yield return configEntry;
}
}
public ChangeType(PluginConfig.ConfigEntryBundle<T> configBundle){
this.configBundle = configBundle;
this.value = configBundle.defaultValue;
}
public ChangeType(PluginConfig.ConfigEntryBundle<T> configBundle, T value){
this.configBundle = configBundle;
this.value = value;
}
public override void Update(){
configEntry.BoxedValue = value;
}
public override bool IsEqual(Change obj) {
var target = obj as ChangeType<T>;
if (target != null) return configEntry.Definition == target.configEntry.Definition;
return false;
}
public override string ToString() {
return $"{configBundle.definition.Key}: {value}";
}
}
public class ChangeBool : ChangeType<bool> {
public ChangeBool(PluginConfig.ConfigEntryBundle<bool> configEntry) : base (configEntry){ }
public ChangeBool(PluginConfig.ConfigEntryBundle<bool> configEntry, bool value) : base (configEntry, value){ }
}
public class ChangeFloat : ChangeType<float> {
public ChangeFloat(PluginConfig.ConfigEntryBundle<float> configEntry) : base (configEntry){ }
public ChangeFloat(PluginConfig.ConfigEntryBundle<float> configEntry, float value) : base (configEntry, value){ }
}
public class ChangeInt : ChangeType<int> {
public ChangeInt(PluginConfig.ConfigEntryBundle<int> configEntry) : base (configEntry){ }
public ChangeInt(PluginConfig.ConfigEntryBundle<int> configEntry, int value) : base (configEntry, value){ }
}
public class ChangeMinMaxInt : Change {
public ChangeInt min;
public ChangeInt max;
public override IEnumerable<ConfigEntryBase> configBases {
get {
yield return min.configEntry;
yield return max.configEntry;
}
}
public ChangeMinMaxInt(PluginConfig.ConfigEntryBundleMinMax<int> configBundle){
min = new ChangeInt(configBundle.min);
max = new ChangeInt(configBundle.max);
}
public ChangeMinMaxInt(PluginConfig.ConfigEntryBundleMinMax<int> configBundle, int minValue, int maxValue){
min = new ChangeInt(configBundle.min, minValue == int.MaxValue ? configBundle.min.defaultValue : minValue);
max = new ChangeInt(configBundle.max, maxValue == int.MaxValue ? configBundle.max.defaultValue : maxValue);
}
public override void Update() {
min.Update();
max.Update();
}
public override bool IsEqual(Change obj) {
var target = obj as ChangeMinMaxInt;
if (target != null) return min.IsEqual(target.min) && max.IsEqual(target.max);
return false;
}
public override string ToString() {
return $"{min.ToString()}\n{max.ToString()}";
}
}
public class ChangeMinMaxFloat : Change{
public ChangeFloat min;
public ChangeFloat max;
public override IEnumerable<ConfigEntryBase> configBases {
get {
yield return min.configEntry;
yield return max.configEntry;
}
}
public ChangeMinMaxFloat(PluginConfig.ConfigEntryBundleMinMax<float> configBundle){
min = new ChangeFloat(configBundle.min);
max = new ChangeFloat(configBundle.max);
}
public ChangeMinMaxFloat(PluginConfig.ConfigEntryBundleMinMax<float> configBundle, float minValue, float maxValue){
min = new ChangeFloat(configBundle.min, minValue == float.MaxValue ? configBundle.min.defaultValue : minValue);
max = new ChangeFloat(configBundle.max, maxValue == float.MaxValue ? configBundle.max.defaultValue : maxValue);
}
public override void Update() {
min.Update();
max.Update();
}
public override bool IsEqual(Change obj) {
var target = obj as ChangeMinMaxFloat;
if (target != null) return min.IsEqual(target.min) && max.IsEqual(target.max);
return false;
}
public override string ToString() {
return $"{min.ToString()}\n{max.ToString()}";
}
}
public class ChangeBranchingPath : Change{
public ChangeMinMaxInt count;
public ChangeMinMaxInt depth;
public override IEnumerable<ConfigEntryBase> configBases {
get {
foreach(var a in count.configBases) yield return a;
foreach(var a in depth.configBases) yield return a;
}
}
public ChangeBranchingPath(PluginConfig.ConfigEntryBundleBranchingPath configBundle){
count = new ChangeMinMaxInt(configBundle.count);
depth = new ChangeMinMaxInt(configBundle.depth);
}
public ChangeBranchingPath(PluginConfig.ConfigEntryBundleBranchingPath configBundle, int countMin, int countMax, int depthMin, int depthMax){
count = new ChangeMinMaxInt(configBundle.count, countMin, countMax);
depth = new ChangeMinMaxInt(configBundle.depth, depthMin, depthMax);
}
public override void Update() {
count.Update();
depth.Update();
}
public override bool IsEqual(Change obj) {
var target = obj as ChangeBranchingPath;
if (target != null) return count.IsEqual(target.count) && depth.IsEqual(target.depth);
return false;
}
public override string ToString() {
return $"{count.ToString()}\n{depth.ToString()}";
}
}
}
}