186 lines
9.0 KiB
C#
186 lines
9.0 KiB
C#
internal class Dayuppy_AIDirectorWanderingHordeComponentPatches
|
|
{
|
|
[HarmonyPatch(typeof(AIDirectorWanderingHordeComponent))]
|
|
[HarmonyPatch("StartSpawning")]
|
|
public class StartSpawningPatch
|
|
{
|
|
public static bool Prefix(AIDirectorWanderingHordeComponent __instance, AIWanderingHordeSpawner.SpawnType _spawnType)
|
|
{
|
|
string optionWanderingHordeFrequencyMultiplier = RebirthVariables.customWanderingHordeFrequency;
|
|
|
|
if (optionWanderingHordeFrequencyMultiplier == "0")
|
|
{
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-StartSpawning EXIT");
|
|
__instance.CleanupType(_spawnType);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(AIDirectorWanderingHordeComponent))]
|
|
[HarmonyPatch("ChooseNextTime")]
|
|
public class AIDirectorWanderingHordeComponentChooseNextTime
|
|
{
|
|
public static void Postfix(AIDirectorWanderingHordeComponent __instance, AIWanderingHordeSpawner.SpawnType _spawnType, ref ulong ___HordeNextTime)
|
|
{
|
|
string optionWanderingHordeFrequencyMultiplier = RebirthVariables.customWanderingHordeFrequency;
|
|
|
|
if (optionWanderingHordeFrequencyMultiplier == "0")
|
|
{
|
|
return;
|
|
}
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime START, optionWanderingHordeFrequencyMultiplier: " + optionWanderingHordeFrequencyMultiplier);
|
|
|
|
int multiplier = 1;
|
|
switch (_spawnType)
|
|
{
|
|
case AIWanderingHordeSpawner.SpawnType.Horde:
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime HORDE");
|
|
if (optionWanderingHordeFrequencyMultiplier.Length == 1)
|
|
{
|
|
multiplier = int.Parse(optionWanderingHordeFrequencyMultiplier);
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 1 multiplier: " + multiplier);
|
|
|
|
___HordeNextTime = __instance.Director.World.worldTime + (ulong)__instance.Random.RandomRange(12000 / multiplier, 24000 / multiplier);
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 1 Current Time: " + __instance.Director.World.worldTime);
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 1 ___HordeNextTime: " + ___HordeNextTime);
|
|
}
|
|
else if (optionWanderingHordeFrequencyMultiplier == "random")
|
|
{
|
|
GameRandom gameRandom = GameManager.Instance.World.GetGameRandom();
|
|
multiplier = gameRandom.RandomRange(1, RebirthVariables.maxWanderingHordeFrequency);
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 2 multiplier: " + multiplier);
|
|
|
|
___HordeNextTime = __instance.Director.World.worldTime + (ulong)__instance.Random.RandomRange(12000 / multiplier, 24000 / multiplier);
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 2 Current Time: " + __instance.Director.World.worldTime);
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 2 ___HordeNextTime: " + ___HordeNextTime);
|
|
}
|
|
else if (optionWanderingHordeFrequencyMultiplier.Contains("gradual"))
|
|
{
|
|
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
|
|
|
int dayDivisor = 14;
|
|
|
|
if (optionWanderingHordeFrequencyMultiplier.Contains("slower"))
|
|
{
|
|
dayDivisor = dayDivisor * 2;
|
|
}
|
|
else if (optionWanderingHordeFrequencyMultiplier.Contains("faster"))
|
|
{
|
|
dayDivisor = dayDivisor / 2;
|
|
}
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 3 currentDay: " + currentDay);
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 3 dayDivisor: " + dayDivisor);
|
|
|
|
multiplier = 1 + (int)(currentDay / dayDivisor);
|
|
|
|
if (multiplier > RebirthVariables.maxWanderingHordeFrequency - 1)
|
|
{
|
|
multiplier = RebirthVariables.maxWanderingHordeFrequency - 1;
|
|
}
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 3 multiplier: " + multiplier);
|
|
|
|
___HordeNextTime = __instance.Director.World.worldTime + (ulong)__instance.Random.RandomRange(12000 / multiplier, 24000 / multiplier);
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 3 Current Time: " + __instance.Director.World.worldTime);
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime 3 ___HordeNextTime: " + ___HordeNextTime);
|
|
}
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime multiplier: " + multiplier);
|
|
|
|
int whSizeMultiplierMax = RebirthVariables.maxWanderingHordeMultiplier;
|
|
string optionWanderingHordeSizeMultiplier = RebirthVariables.customWanderingHordeSizeMultiplier;
|
|
|
|
int whSizeMultiplier = 1;
|
|
|
|
if (optionWanderingHordeSizeMultiplier == "random")
|
|
{
|
|
GameRandom gameRandom = GameManager.Instance.World.GetGameRandom();
|
|
whSizeMultiplier = gameRandom.RandomRange(2, whSizeMultiplierMax);
|
|
}
|
|
else if (optionWanderingHordeSizeMultiplier.Contains("gradual"))
|
|
{
|
|
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
|
|
|
int dayDivisor = 14;
|
|
|
|
if (optionWanderingHordeSizeMultiplier.Contains("slower"))
|
|
{
|
|
dayDivisor = dayDivisor * 2;
|
|
}
|
|
else if (optionWanderingHordeSizeMultiplier.Contains("faster"))
|
|
{
|
|
dayDivisor = dayDivisor / 2;
|
|
}
|
|
|
|
whSizeMultiplier = 1 + (int)(currentDay / dayDivisor);
|
|
|
|
if (whSizeMultiplier > whSizeMultiplierMax - 1)
|
|
{
|
|
whSizeMultiplier = whSizeMultiplierMax - 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
whSizeMultiplier = int.Parse(optionWanderingHordeSizeMultiplier);
|
|
}
|
|
|
|
if (whSizeMultiplier > whSizeMultiplierMax)
|
|
{
|
|
whSizeMultiplier = whSizeMultiplierMax;
|
|
}
|
|
|
|
RebirthVariables.wanderingHordeMultiplier = whSizeMultiplier;
|
|
|
|
//Log.Out("Dayuppy_AIDirectorWanderingHordeComponentPatches-ChooseNextTime RebirthVariables.wanderingHordeMultiplier: " + RebirthVariables.wanderingHordeMultiplier);
|
|
|
|
break;
|
|
}
|
|
|
|
__instance.LogTimes();
|
|
}
|
|
}
|
|
|
|
// had to override this function to catch if the list was decreased in the Update patch - UpdateSpawn
|
|
[HarmonyPatch(typeof(AIDirectorWanderingHordeComponent), nameof(AIDirectorWanderingHordeComponent.TickActiveSpawns))]
|
|
public class TickActiveSpawnsPatch
|
|
{
|
|
public static bool Prefix(AIDirectorWanderingHordeComponent __instance, float dt)
|
|
{
|
|
for (int index = __instance.spawners.Count - 1; index >= 0; index--)
|
|
{
|
|
int spawnersCount = __instance.spawners.Count;
|
|
AIWanderingHordeSpawner aIWanderingHordeSpawner = __instance.spawners[index];
|
|
if (aIWanderingHordeSpawner.Update(__instance.Director.World, dt))
|
|
{
|
|
AIDirector.LogAIExtra("Wandering spawner finished {0}", aIWanderingHordeSpawner.spawnType);
|
|
aIWanderingHordeSpawner.Cleanup();
|
|
int curCount = __instance.spawners.Count;
|
|
Log.Out($"TickActiveSpawns - Update true - starting spawnersCount: {spawnersCount}, current spawners count: {curCount}, current index: {index}");
|
|
|
|
if (curCount > index)
|
|
{
|
|
Log.Out($"Removing spawner at index: {index}");
|
|
__instance.spawners.RemoveAt(index);
|
|
}
|
|
else
|
|
{
|
|
Log.Out($"Unable to remove spawner at index: {index}, current spawners count: {curCount}");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |