80 lines
4.7 KiB
C#
80 lines
4.7 KiB
C#
using BepInEx.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ScarletMansion.Configs {
|
|
|
|
public partial class ConfigManager<T> : SyncedInstance<T> where T: ConfigManager<T> {
|
|
|
|
public class ConfigEntryBundleEnemy : ConfigEntryBundleBase {
|
|
public ConfigEntryBundle<bool> enabled;
|
|
public ConfigEntryBundle<int> health;
|
|
public ConfigEntryBundle<float> speed;
|
|
|
|
public ConfigEntryBundleEnemy(string section, string enemyName, int baseHealth, float baseSpeed, ConfigEntryBundleExtraParameters extra = null){
|
|
var enabledDesc = $"If disabled, {enemyName} is disabled from spawning.";
|
|
var healthDesc = $"The health of the {enemyName}. A shovel is 1 damage.";
|
|
var speedDesc = $"The speed of the {enemyName} during their killing/aggressive stance. The player's default speed is 4.6.";
|
|
|
|
enabled = new ConfigEntryBundle<bool>(section, "Enabled", true, enabledDesc, extra);
|
|
health = new ConfigEntryBundle<int>(section, "Health", baseHealth, healthDesc, extra, new AcceptableValueRange<int>(1, 20));
|
|
speed = new ConfigEntryBundle<float>(section, "Speed", baseSpeed, speedDesc, extra, new AcceptableValueRange<float>(1f, 20f));
|
|
}
|
|
|
|
public override void Bind(ConfigFile cfg, T instance, FieldPropertyInfo memberInfo, object memberTarget) {
|
|
var type = memberInfo.GetFieldPropertyType();
|
|
var enabledProp = type.GetField("enabled", BindingFlags.Public | BindingFlags.Instance);
|
|
var healthProp = type.GetField("health", BindingFlags.Public | BindingFlags.Instance);
|
|
var speedProp = type.GetField("speed", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
enabled.Bind(cfg, instance, new FieldPropertyInfo(enabledProp), memberInfo.GetValue(memberTarget));
|
|
if (health.defaultValue > 0) health.Bind(cfg, instance, new FieldPropertyInfo(healthProp), memberInfo.GetValue(memberTarget));
|
|
speed.Bind(cfg, instance, new FieldPropertyInfo(speedProp), memberInfo.GetValue(memberTarget));
|
|
|
|
}
|
|
|
|
public override IEnumerable<ConfigEntryBase> GetConfigs() {
|
|
yield return enabled.config;
|
|
if (health.defaultValue > 0) yield return health.config;
|
|
yield return speed.config;
|
|
}
|
|
}
|
|
|
|
public class ConfigEntryBundleSpawnableEnemy : ConfigEntryBundleEnemy {
|
|
public ConfigEntryBundle<int> spawnWeightBase;
|
|
public ConfigEntryBundle<float> spawnWeightStealPercentage;
|
|
|
|
public ConfigEntryBundleSpawnableEnemy(string section, string enemyName, string replacementEnemyName, int baseHealth, float baseSpeed, ConfigEntryBundleExtraParameters extra = null) : base(section, enemyName, baseHealth, baseSpeed, extra) {
|
|
|
|
var weightBaseDesc = $"The base spawn weight of the {enemyName}. This is added onto the spawn weight stolen from the {replacementEnemyName}, or the base weight of 10 if the moon doesn't spawn the {replacementEnemyName}.";
|
|
var weightStealPercentageDesc = $"The percentage of spawn weight that the {enemyName} steals from the {replacementEnemyName} for that moon.\nSetting this 0 means that the {replacementEnemyName}'s weight is unaffected and the {enemyName}'s weight is based entirely by Spawn Weight Base.\nSetting this 1 means the {enemyName} effectively replaces the {replacementEnemyName}.";
|
|
|
|
spawnWeightBase = new ConfigEntryBundle<int>(section, "Spawn Weight Base", 0, weightBaseDesc, extra, new AcceptableValueRange<int>(0, 999));
|
|
spawnWeightStealPercentage = new ConfigEntryBundle<float>(section, "Spawn Weight Steal Percentage", 0.75f, weightStealPercentageDesc, extra, new AcceptableValueRange<float>(0f, 1f));
|
|
}
|
|
|
|
public override void Bind(ConfigFile cfg, T instance, FieldPropertyInfo memberInfo, object memberTarget) {
|
|
base.Bind(cfg, instance, memberInfo, memberTarget);
|
|
|
|
var type = memberInfo.GetFieldPropertyType();
|
|
var weightBaseProp = type.GetField("spawnWeightBase", BindingFlags.Public | BindingFlags.Instance);
|
|
var weightStealPercentageProp = type.GetField("spawnWeightStealPercentage", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
spawnWeightBase.Bind(cfg, instance, new FieldPropertyInfo(weightBaseProp), memberInfo.GetValue(memberTarget));
|
|
spawnWeightStealPercentage.Bind(cfg, instance, new FieldPropertyInfo(weightStealPercentageProp), memberInfo.GetValue(memberTarget));
|
|
}
|
|
|
|
public override IEnumerable<ConfigEntryBase> GetConfigs() {
|
|
foreach(var a in base.GetConfigs()) {
|
|
yield return a;
|
|
}
|
|
yield return spawnWeightBase.config;
|
|
yield return spawnWeightStealPercentage.config;
|
|
}
|
|
}
|
|
}
|
|
}
|