This repository was archived by the owner on Dec 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WildlifeBegone: Add config file, support moose, fix bugs
- Loading branch information
1 parent
acb2a27
commit 97a4402
Showing
7 changed files
with
385 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using System; | ||
using System.Linq; | ||
using Harmony; | ||
using UnityEngine; | ||
|
||
namespace WildlifeBegone { | ||
internal class Patches { | ||
|
||
[HarmonyPatch(typeof(SpawnRegion), "Start", new Type[0])] | ||
private class SpawnRegionPatch { | ||
static void Prefix(SpawnRegion __instance) { | ||
bool m_StartHasBeenCalled = (bool) AccessTools.Field(typeof(SpawnRegion), "m_StartHasBeenCalled").GetValue(__instance); | ||
if (m_StartHasBeenCalled || GameManager.IsStoryMode()) | ||
return; | ||
|
||
GameObject spawnedObject = __instance.m_SpawnablePrefab; | ||
BaseAi ai = spawnedObject.GetComponent<BaseAi>(); | ||
if (ai == null) | ||
return; | ||
|
||
SpawnRateSetting spawnRates = WildlifeBegone.Config.spawnRates[(int) ai.m_AiSubType]; | ||
AdjustRegion(__instance, spawnRates); | ||
} | ||
|
||
private static void AdjustRegion(SpawnRegion region, SpawnRateSetting spawnRates) { | ||
float activeMultiplier = spawnRates.SpawnRegionActiveTimeMultiplier; | ||
float respawnMultiplier = spawnRates.MaximumRespawnsPerDayMultiplier; | ||
float maximumCountMultiplier = spawnRates.MaximumSpawnedAnimalsMultiplier; | ||
|
||
float oldChanceActive = region.m_ChanceActive; | ||
region.m_ChanceActive *= activeMultiplier; | ||
|
||
float oldRespawnTime = region.m_MaxRespawnsPerDayStalker; | ||
region.m_MaxRespawnsPerDayPilgrim *= respawnMultiplier; | ||
region.m_MaxRespawnsPerDayVoyageur *= respawnMultiplier; | ||
region.m_MaxRespawnsPerDayStalker *= respawnMultiplier; | ||
region.m_MaxRespawnsPerDayInterloper *= respawnMultiplier; | ||
|
||
int oldMaximumCountDay = region.m_MaxSimultaneousSpawnsDayStalker; | ||
int oldMaximumCountNight = region.m_MaxSimultaneousSpawnsNightStalker; | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsDayPilgrim, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsDayVoyageur, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsDayStalker, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsDayInterloper, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsNightPilgrim, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsNightVoyageur, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsNightStalker, maximumCountMultiplier); | ||
RoundingMultiply(ref region.m_MaxSimultaneousSpawnsNightInterloper, maximumCountMultiplier); | ||
|
||
if (WildlifeBegone.Config.logging) { | ||
Debug.LogFormat("Adjusted spawner {0}: Active chance {1:F1} -> {2:F1}, respawns / day {3:F2} -> {4:F2}, maximum spawns ({5:D}, {6:D}) -> ({7:D}, {8:D})", | ||
region.name, | ||
oldChanceActive, region.m_ChanceActive, | ||
oldRespawnTime, region.m_MaxRespawnsPerDayStalker, | ||
oldMaximumCountDay, oldMaximumCountNight, region.m_MaxSimultaneousSpawnsDayStalker, region.m_MaxSimultaneousSpawnsNightStalker | ||
); | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(RandomSpawnObject), "Start", new Type[0])] | ||
private class RandomSpawnObjectPatch { | ||
static void Prefix(RandomSpawnObject __instance) { | ||
if (GameManager.IsStoryMode() || __instance.m_RerollAfterGameHours <= 0.0) | ||
return; | ||
|
||
float oldRerollTime = __instance.m_RerollAfterGameHours; | ||
int oldMaxObjects = __instance.m_NumObjectsToEnableStalker; | ||
|
||
RSOSettings rsoSettings = WildlifeBegone.Config.rsoSettings; | ||
float maximumCountMultiplier = rsoSettings.ActiveSpawnerCountMultiplier; | ||
|
||
__instance.m_RerollAfterGameHours *= rsoSettings.RerollActiveSpawnersTimeMultiplier; | ||
RoundingMultiply(ref __instance.m_NumObjectsToEnablePilgrim, maximumCountMultiplier); | ||
RoundingMultiply(ref __instance.m_NumObjectsToEnableVoyageur, maximumCountMultiplier); | ||
RoundingMultiply(ref __instance.m_NumObjectsToEnableStalker, maximumCountMultiplier); | ||
RoundingMultiply(ref __instance.m_NumObjectsToEnableInterloper, maximumCountMultiplier); | ||
|
||
if (WildlifeBegone.Config.logging) { | ||
Debug.LogFormat("Adjusted RSO {0}: Reroll time {1:F1} -> {2:F1}, maximum active {3:D} -> {4:D}", | ||
__instance.name, | ||
oldRerollTime, __instance.m_RerollAfterGameHours, | ||
oldMaxObjects, __instance.m_NumObjectsToEnableStalker); | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(ConsoleManager), "RegisterCommands", new Type[0])] | ||
private class AddConsoleCommands { | ||
static void Postfix() { | ||
uConsole.RegisterCommand("animals_count", new uConsole.DebugCommand(CountAnimals)); | ||
uConsole.RegisterCommand("animals_kill_all", new uConsole.DebugCommand(KillAllAnimals)); | ||
} | ||
|
||
const int numAnimalTypes = 6; | ||
|
||
private static void CountAnimals() { | ||
int[] counts = new int[numAnimalTypes]; | ||
BaseAi[] animals = UnityEngine.Object.FindObjectsOfType<BaseAi>(); | ||
foreach (BaseAi animal in animals) { | ||
if (animal.GetAiMode() != AiMode.Dead) { | ||
int ordinal = (int) animal.m_AiSubType; | ||
if (ordinal >= numAnimalTypes) | ||
ordinal = 0; | ||
++counts[ordinal]; | ||
} | ||
} | ||
|
||
object[] args = counts.Cast<object>().ToArray(); | ||
Debug.LogFormat("{2} bears, {4} rabbits, {3} deer, {1} wolves, {5} moose, {0} unknown", args); | ||
} | ||
|
||
private static void KillAllAnimals() { | ||
int[] counts = new int[numAnimalTypes]; | ||
BaseAi[] animals = UnityEngine.Object.FindObjectsOfType<BaseAi>(); | ||
foreach (BaseAi animal in animals) { | ||
if (animal.GetAiMode() != AiMode.Dead) { | ||
animal.SetAiMode(AiMode.Dead); | ||
animal.Despawn(); | ||
|
||
int ordinal = (int) animal.m_AiSubType; | ||
if (ordinal >= numAnimalTypes) | ||
ordinal = 0; | ||
++counts[ordinal]; | ||
} | ||
} | ||
|
||
object[] args = counts.Cast<object>().ToArray(); | ||
Debug.LogFormat("Killed {2} bears, {4} rabbits, {3} deer, {1} wolves, {5} moose, {0} unknown", args); | ||
} | ||
} | ||
|
||
private static void RoundingMultiply(ref int field, float multiplier) { | ||
field = Math.Max(1, Mathf.RoundToInt(field * multiplier)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> | ||
<data name="WildlifeBegoneConfig" type="System.Resources.ResXFileRef, System.Windows.Forms"> | ||
<value>..\wildlifebegoneconfig.json;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</data> | ||
</root> |
Oops, something went wrong.