Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Harmony/Harmony_SpawnManagerBiomes.cs
Nathaniel Cosford e06f2bd282 Add All Mods
2025-05-29 23:33:28 +09:30

308 lines
12 KiB
C#

using System.Collections.Generic;
using System.Numerics;
namespace Harmony.SpawnManagerBiomesPatches
{
/*public struct SCountAndRespawnDelay
{
public SCountAndRespawnDelay(int _count, ulong _delayWorldTime)
{
__instance.count = _count;
__instance.delayWorldTime = _delayWorldTime;
}
public override string ToString()
{
return string.Format("cnt={0} wtime={1}", __instance.count, __instance.delayWorldTime);
}
public int count;
public ulong delayWorldTime;
}*/
[HarmonyPatch(typeof(ChunkAreaBiomeSpawnData))]
[HarmonyPatch("ResetRespawn")]
public class ResetRespawnPatch
{
public static bool Prefix(ChunkAreaBiomeSpawnData __instance, int _idHash, World _world, int _maxCount)
{
//Log.Out("SpawnManagerBiomesPatches-ResetRespawn START");
BiomeDefinition biome = _world.Biomes.GetBiome(__instance.biomeId);
if (biome == null)
return false;
BiomeSpawnEntityGroupList spawnEntityGroupList = BiomeSpawningClass.list[biome.m_sBiomeName];
if (spawnEntityGroupList == null)
return false;
BiomeSpawnEntityGroupData spawnEntityGroupData = spawnEntityGroupList.Find(_idHash);
if (spawnEntityGroupData == null)
return false;
ChunkAreaBiomeSpawnData.CountsAndTime countsAndTime;
__instance.entitesSpawned.TryGetValue(_idHash, out countsAndTime);
float multiplier = 1f;
bool optionFeelingLucky = RebirthVariables.customFeelingLucky;
if (GameManager.Instance.World.IsDaytime())
{
optionFeelingLucky = false;
}
if (optionFeelingLucky)
{
if (multiplier < 1f)
{
multiplier = multiplier * 0.9f;
}
else
{
multiplier = multiplier * 0.8f;
}
}
countsAndTime.delayWorldTime = _world.worldTime + (ulong)((double)spawnEntityGroupData.respawnDelayInWorldTime * multiplier * (double)_world.RandomRange(0.9f, 1.1f));
//Log.Out("SpawnManagerBiomesPatches-ResetRespawn multiplier: " + multiplier);
//Log.Out("SpawnManagerBiomesPatches-ResetRespawn countsAndTime.delayWorldTime: " + countsAndTime.delayWorldTime);
countsAndTime.maxCount = _maxCount;
__instance.entitesSpawned[_idHash] = countsAndTime;
__instance.chunk.isModified = true;
return false;
}
}
/*[HarmonyPatch(typeof(ChunkAreaBiomeSpawnData))]
[HarmonyPatch("SetRespawnDelay")]
public class SetRespawnDelayPatch
{
public static bool Prefix(ChunkAreaBiomeSpawnData __instance, string _entityGroupName, ulong _currentWorldTime, WorldBiomes _worldBiomes,
ref Dictionary<string, SCountAndRespawnDelay> ___entitesSpawned
)
{
if (_entityGroupName == null)
{
return false;
}
BiomeDefinition biome = _worldBiomes.GetBiome(__instance.biomeId);
if (biome == null)
{
return false;
}
BiomeSpawnEntityGroupList biomeSpawnEntityGroupList = BiomeSpawningClass.list[biome.m_sBiomeName];
if (biomeSpawnEntityGroupList == null)
{
return false;
}
BiomeSpawnEntityGroupData biomeSpawnEntityGroupData = biomeSpawnEntityGroupList.Find(_entityGroupName);
if (biomeSpawnEntityGroupData == null)
{
return false;
}
int count = ___entitesSpawned.ContainsKey(_entityGroupName) ? ___entitesSpawned[_entityGroupName].count : 0;
if (_entityGroupName.ToLower().StartsWith("zombies"))
{
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay respawnDelayInWorldTime: " + biomeSpawnEntityGroupData.respawnDelayInWorldTime);
string spawnMultiplierOption = RebirthVariables.customFreqZombieSpawns;
float multiplier = 1f;
if (spawnMultiplierOption == "slowest")
{
multiplier = 4f;
}
else if (spawnMultiplierOption == "slow")
{
multiplier = 2f;
}
else if (spawnMultiplierOption == "fast")
{
multiplier = 0.8f;
}
else if (spawnMultiplierOption == "faster")
{
multiplier = 0.6f;
}
else if (spawnMultiplierOption == "fastest")
{
multiplier = 0.4f;
}
else if (spawnMultiplierOption == "relentless")
{
multiplier = 0.2f;
}
else if (spawnMultiplierOption == "gradualslower")
{
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
if (currentDay <= 14)
{
multiplier = 4f;
}
else if (currentDay > 15 && currentDay <= 28)
{
multiplier = 2f;
}
else if (currentDay > 29 && currentDay <= 49)
{
multiplier = 1f;
}
else if (currentDay > 50 && currentDay <= 70)
{
multiplier = 0.8f;
}
else if (currentDay > 71)
{
multiplier = 0.6f;
}
}
else if (spawnMultiplierOption == "gradual")
{
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
if (currentDay <= 7)
{
multiplier = 4f;
}
else if (currentDay > 7 && currentDay <= 14)
{
multiplier = 2f;
}
else if (currentDay > 15 && currentDay <= 28)
{
multiplier = 1f;
}
else if (currentDay > 29 && currentDay <= 42)
{
multiplier = 0.8f;
}
else if (currentDay > 43)
{
multiplier = 0.6f;
}
}
else if (spawnMultiplierOption == "gradualfaster")
{
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
if (currentDay <= 7)
{
multiplier = 4f;
}
else if (currentDay > 8 && currentDay <= 14)
{
multiplier = 2f;
}
else if (currentDay > 15 && currentDay <= 21)
{
multiplier = 1f;
}
else if (currentDay > 22 && currentDay <= 28)
{
multiplier = 0.8f;
}
else if (currentDay > 29)
{
multiplier = 0.6f;
}
}
bool optionFeelingLucky = RebirthVariables.customFeelingLucky;
if (GameManager.Instance.World.IsDaytime())
{
optionFeelingLucky = false;
}
if (optionFeelingLucky)
{
if (multiplier < 1f)
{
multiplier = multiplier * 0.9f;
}
else
{
multiplier = multiplier * 0.8f;
}
}
ulong respawnDelay = (ulong)((long)biomeSpawnEntityGroupData.respawnDelayInWorldTime);
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay respawnDelay: " + respawnDelay);
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay multiplier: " + multiplier);
if (respawnDelay > 0)
{
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay BEFORE respawnDelay: " + respawnDelay);
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay multiplier: " + multiplier);
respawnDelay = (ulong)(respawnDelay * multiplier);
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay MULTIPLIER respawnDelay: " + respawnDelay);
//Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay AFTER respawnDelay: " + respawnDelay);
}
respawnDelay = _currentWorldTime + respawnDelay;
try
{
___entitesSpawned[_entityGroupName] = new SCountAndRespawnDelay(count, respawnDelay);
}
catch
{
Log.Out("SpawnManagerBiomesPatches-SetRespawnDelay error accessing array for group: " + _entityGroupName);
return true;
}
__instance.chunk.isModified = true;
return false;
}
return true;
}
}*/
[HarmonyPatch(typeof(SpawnManagerBiomes))]
[HarmonyPatch("SpawnUpdate")]
public class SpawnUpdatePatch
{
public static bool Prefix(SpawnManagerBiomes __instance, string _spawnerName, bool _isSpawnEnemy, ChunkAreaBiomeSpawnData _spawnData,
World ___world
)
{
List<EntityPlayer> players = ___world.GetPlayers();
for (int i = 0; i < players.Count; i++)
{
EntityPlayer entityPlayer = players[i];
if (entityPlayer.Spawned)
{
//Log.Out("SpawnManagerBiomesPatches-SpawnUpdate entityPlayer: " + entityPlayer.EntityName);
Rect rect = new Rect(entityPlayer.position.x - 40f, entityPlayer.position.z - 40f, 80f, 80f);
if (rect.Overlaps(_spawnData.area))
{
RebirthVariables.playerLevel = entityPlayer.Progression.Level;
//Log.Out("SpawnManagerBiomesPatches-SpawnUpdate RebirthVariables.playerLevel: " + RebirthVariables.playerLevel);
RebirthVariables.biomeGameStage = entityPlayer.gameStage;
if (RebirthUtilities.ScenarioSkip())
{
string biomeName = RebirthUtilities.GetBiomeName(entityPlayer);
//Log.Out("SpawnManagerBiomesPatches-SpawnUpdate START: " + entityPlayer.biomeStandingOn.m_sBiomeName + $" ({entityPlayer.position})");
if (biomeName != "")
{
RebirthUtilities.SetHiveSpawnGroup(biomeName);
}
}
//Log.Out("SpawnManagerBiomesPatches-SpawnUpdate Player [" + entityPlayer.EntityName + "] gameStage: " + entityPlayer.gameStage);
break;
}
}
}
return true;
}
}
}