Town NPC spawn manipulation changes
This commit is contained in:
1 parent
5e80dd00e8
commit
b8a11d850d
2 files changed
+59
No files matched your search
@@ -128,6 +128,24 @@ namespace CalamityMod
|
||||
[Tooltip("Sets Reactive Boss DR to always be full strength, even if the boss has already been defeated.\nIf disabled, the effect is only 66% as powerful after the boss has been defeated.\n\nReactive Boss DR makes bosses smoothly take less damage if they are being killed very quickly.\nIn most cases, the system has no noticeable effect.")]
|
||||
public bool FullPowerReactiveBossDR { get; set; }
|
||||
|
||||
[Label("Let Town NPCs spawn at night.")]
|
||||
[BackgroundColor(192, 54, 64, 192)]
|
||||
[DefaultValue(false)]
|
||||
[Tooltip("Allows you to determine if town NPCs (including the Old Man) can spawn at night.")]
|
||||
public bool CanTownNPCsSpawnAtNight { get; set; }
|
||||
|
||||
private const int MinTownNPCSpawnMultiplier = 1;
|
||||
private const int MaxTownNPCSpawnMultiplier = 10;
|
||||
|
||||
[Label("Town NPC Spawn Rate Multiplier")]
|
||||
[BackgroundColor(192, 54, 64, 192)]
|
||||
[Range(MinTownNPCSpawnMultiplier, MaxTownNPCSpawnMultiplier)]
|
||||
[Increment(1)]
|
||||
[DrawTicks]
|
||||
[DefaultValue(MinTownNPCSpawnMultiplier)]
|
||||
[Tooltip("Makes town NPCs spawn more quickly, the higher this value is.")]
|
||||
public int TownNPCSpawnRateMultiplier { get; set; }
|
||||
|
||||
private const float MinBossHealthBoost = 0f;
|
||||
private const float MaxBossHealthBoost = 900f;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Mono.Cecil.Cil;
|
||||
using MonoMod.Cil;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Terraria;
|
||||
using Terraria.GameInput;
|
||||
using Terraria.ID;
|
||||
@@ -27,9 +28,13 @@ namespace CalamityMod.ILEditing
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
var spawnTownNPCMethod = typeof(Main).GetMethod("UpdateTime_SpawnTownNPCs", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
cachedUpdateTime_SpawnTownNPCs = Delegate.CreateDelegate(typeof(Action), spawnTownNPCMethod) as Action;
|
||||
|
||||
On.Terraria.NPC.SlimeRainSpawns += PreventBossSlimeRainSpawns;
|
||||
ApplyLifeBytesChanges();
|
||||
SlideDungeonOver();
|
||||
AlterTownNPCSpawnRate();
|
||||
LabDoorFixes();
|
||||
PreventStupidTreesNearOcean();
|
||||
}
|
||||
@@ -79,6 +84,42 @@ namespace CalamityMod.ILEditing
|
||||
if (!Main.player[plr].Calamity().bossZen)
|
||||
orig(plr);
|
||||
}
|
||||
|
||||
private static Action cachedUpdateTime_SpawnTownNPCs;
|
||||
|
||||
private static void AlterTownNPCSpawnRate()
|
||||
{
|
||||
IL.Terraria.Main.UpdateTime += (il) =>
|
||||
{
|
||||
// Don't do town NPC spawning at the end (after a !Main.dayTime return).
|
||||
// Do it at the beginning in spite of time.
|
||||
|
||||
var cursor = new ILCursor(il);
|
||||
cursor.EmitDelegate<Action>(() =>
|
||||
{
|
||||
// A cached delegate is used here instead of direct reflection for performance reasons
|
||||
// since UpdateTime is called every frame.
|
||||
if (Main.dayTime || CalamityConfig.Instance.CanTownNPCsSpawnAtNight)
|
||||
cachedUpdateTime_SpawnTownNPCs();
|
||||
});
|
||||
|
||||
if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt<Main>("UpdateTime_SpawnTownNPCs")))
|
||||
{
|
||||
CalamityMod.Instance.Logger.Warn("Town NPC spawn editing code failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.Emit(OpCodes.Ret);
|
||||
};
|
||||
|
||||
On.Terraria.Main.UpdateTime_SpawnTownNPCs += (orig) =>
|
||||
{
|
||||
int oldWorldRate = Main.worldRate;
|
||||
Main.worldRate *= CalamityConfig.Instance.TownNPCSpawnRateMultiplier;
|
||||
orig();
|
||||
Main.worldRate = oldWorldRate;
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IL Editing Injection Functions
|
||||
|
||||
Reference in new issue
Block a user