From 21184966de0598da3a1866b64b02c7756f02e391 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sat, 10 Aug 2024 12:17:56 +0900 Subject: [PATCH] Add RecursiveTileFrame --- Core/Config.cs | 6 ++++++ Core/Mitigations.cs | 1 + Core/Plugin.cs | 2 ++ Core/WorldGen.cs | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/Core/Config.cs b/Core/Config.cs index ca9a050..762b01a 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -778,6 +778,12 @@ public record class MitigationSettings /// public Optional RecursiveTileBreak = Optional.Default(false, true); + /// + /// TileFrame-ed tile will be tracked and TileFrame-ed again. + /// This will trigger recursive tile break. + /// + public Optional RecursiveTileFrame = Optional.Default(false, true); + public enum DisabledDamageAction { AsIs, diff --git a/Core/Mitigations.cs b/Core/Mitigations.cs index efde1a1..8810b27 100644 --- a/Core/Mitigations.cs +++ b/Core/Mitigations.cs @@ -340,6 +340,7 @@ private void TAHook_Mitigation_GameUpdate(EventArgs _) this.Statistics.MitigationNewTileKillTriggered += this._pendingKilled.Count - count; this._pendingKilled.Clear(); + this._pendingTileFrame.Clear(); } } diff --git a/Core/Plugin.cs b/Core/Plugin.cs index 2d9db2c..014aef7 100644 --- a/Core/Plugin.cs +++ b/Core/Plugin.cs @@ -310,6 +310,7 @@ public override void Initialize() On.Terraria.Initializers.ChatInitializer.Load += this.MMHook_Mitigation_I18nCommand; On.Terraria.WorldGen.nextCount += this.MMHook_Mitigation_WorldGenNextCount; On.Terraria.WorldGen.KillTile += this.MMHook_WorldGen_KillTile; + On.Terraria.WorldGen.TileFrame += this.MMHook_WorldGen_TileFrame; OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_Ghost_SendBytes; OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_DebugPacket_SendBytes; OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Ping_GetData; @@ -354,6 +355,7 @@ protected override void Dispose(bool disposing) On.Terraria.Initializers.ChatInitializer.Load -= this.MMHook_Mitigation_I18nCommand; On.Terraria.WorldGen.nextCount -= this.MMHook_Mitigation_WorldGenNextCount; On.Terraria.WorldGen.KillTile -= this.MMHook_WorldGen_KillTile; + On.Terraria.WorldGen.TileFrame -= this.MMHook_WorldGen_TileFrame; OTAPI.Hooks.NetMessage.SendBytes -= this.OTHook_Ghost_SendBytes; OTAPI.Hooks.NetMessage.SendBytes -= this.OTHook_DebugPacket_SendBytes; OTAPI.Hooks.MessageBuffer.GetData -= this.OTHook_Mitigation_GetData; diff --git a/Core/WorldGen.cs b/Core/WorldGen.cs index 3d46d71..bb8a9a8 100644 --- a/Core/WorldGen.cs +++ b/Core/WorldGen.cs @@ -154,4 +154,20 @@ private void MMHook_WorldGen_KillTile(On.Terraria.WorldGen.orig_KillTile orig, i } orig(i, j, fail, effectOnly, noItem); } + + private readonly Dictionary _pendingTileFrame = new Dictionary(); + private void MMHook_WorldGen_TileFrame(On.Terraria.WorldGen.orig_TileFrame orig, int i, int j, bool resetFrame, bool noBreak) + { + var pos = (((ulong) i) << 32) | ((uint) j); + if (this.config.Mitigation.Value.RecursiveTileFrame.Value) + { + if (this._pendingTileFrame.TryGetValue(pos, out var frames) && frames > 2) + { + return; + } + this._pendingTileFrame[pos] = frames + 1; + Terraria.WorldGen.destroyObject = false; + orig(i, j, resetFrame, noBreak); + } + } } \ No newline at end of file