forked from nikita/muzika-gromche
Compare commits
1 Commits
2e938dfc8d
...
d02e594457
Author | SHA1 | Date |
---|---|---|
|
d02e594457 |
|
@ -553,6 +553,7 @@ namespace MuzikaGromche
|
|||
harmony.PatchAll(typeof(AllPoweredLightsPatch));
|
||||
harmony.PatchAll(typeof(DiscoBallTilePatch));
|
||||
harmony.PatchAll(typeof(DiscoBallDespawnPatch));
|
||||
harmony.PatchAll(typeof(SpawnRatePatch));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1427,6 +1428,8 @@ namespace MuzikaGromche
|
|||
|
||||
public static ConfigEntry<bool> SkipExplicitTracks { get; private set; } = null!;
|
||||
|
||||
public static SyncedEntry<bool> OverrideSpawnRates { get; private set; } = null!;
|
||||
|
||||
public static bool ShouldSkipWindingPhase { get; private set; } = false;
|
||||
|
||||
public static Palette? PaletteOverride { get; private set; } = null;
|
||||
|
@ -1455,6 +1458,11 @@ namespace MuzikaGromche
|
|||
new ConfigDescription("When choosing tracks at random, skip the ones with Explicit Content/Lyrics."));
|
||||
LethalConfigManager.AddConfigItem(new BoolCheckBoxConfigItem(SkipExplicitTracks, requiresRestart: false));
|
||||
|
||||
OverrideSpawnRates = configFile.BindSyncedEntry("General", "Override Spawn Rates", false,
|
||||
new ConfigDescription("Deviate from vanilla spawn rates to experience content of this mod more often."));
|
||||
LethalConfigManager.AddConfigItem(new BoolCheckBoxConfigItem(OverrideSpawnRates.Entry, Default(new BoolCheckBoxOptions())));
|
||||
CSyncHackAddSyncedEntry(OverrideSpawnRates);
|
||||
|
||||
#if DEBUG
|
||||
SetupEntriesToSkipWinding(configFile);
|
||||
SetupEntriesForPaletteOverride(configFile);
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
using HarmonyLib;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuzikaGromche
|
||||
{
|
||||
[HarmonyPatch(typeof(RoundManager))]
|
||||
static class SpawnRatePatch
|
||||
{
|
||||
const string JesterEnemyName = "Jester";
|
||||
|
||||
// If set to null, do not override spawn chances. Otherwise, it is an index of Jester in RoundManager.currentLevel.Enemies
|
||||
static int? JesterEnemyIndex = null;
|
||||
static float? SpawnTime = null;
|
||||
|
||||
[HarmonyPatch(nameof(RoundManager.AssignRandomEnemyToVent))]
|
||||
[HarmonyPrefix]
|
||||
static void AssignRandomEnemyToVentPrefix(RoundManager __instance, EnemyVent vent, float spawnTime)
|
||||
{
|
||||
if (!Config.OverrideSpawnRates.Value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var index = __instance.currentLevel.Enemies.FindIndex(enemy => enemy.enemyType.enemyName == JesterEnemyName);
|
||||
if (index == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JesterEnemyIndex = index;
|
||||
SpawnTime = spawnTime;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(RoundManager.AssignRandomEnemyToVent))]
|
||||
[HarmonyPostfix]
|
||||
static void AssignRandomEnemyToVentPostfix(RoundManager __instance, EnemyVent vent, float spawnTime)
|
||||
{
|
||||
JesterEnemyIndex = null;
|
||||
SpawnTime = null;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(RoundManager.GetRandomWeightedIndex))]
|
||||
[HarmonyPostfix]
|
||||
static void GetRandomWeightedIndexPostfix(RoundManager __instance, ref int[] weights, ref System.Random randomSeed)
|
||||
{
|
||||
if (JesterEnemyIndex is int index && SpawnTime is float spawnTime)
|
||||
{
|
||||
if (__instance.EnemyCannotBeSpawned(index))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var minMultiplierTime = 3 * __instance.timeScript.lengthOfHours;
|
||||
var maxMultiplierTime = 7 * __instance.timeScript.lengthOfHours;
|
||||
var normalizedMultiplierTime = Math.Clamp((spawnTime - minMultiplierTime) / (maxMultiplierTime - minMultiplierTime), 0f, 1f);
|
||||
|
||||
// TODO: Try Expo function instead of Lerp?
|
||||
var minMultiplier = Mathf.Max(1, __instance.minEnemiesToSpawn);
|
||||
var maxMultiplier = 9 + __instance.minEnemiesToSpawn;
|
||||
var multiplier = Mathf.Lerp(minMultiplier, maxMultiplier, normalizedMultiplierTime);
|
||||
|
||||
var newWeight = (int)(weights[index] * multiplier);
|
||||
Debug.Log($"{nameof(MuzikaGromche)} Overriding Jester spawn weight {weights[index]} * {multiplier} => {newWeight}");
|
||||
weights[index] = newWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue