Skip to content

Commit

Permalink
Add RecursiveTileFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Aug 10, 2024
1 parent e0458bb commit 2118496
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@ public record class MitigationSettings
/// </summary>
public Optional<bool> RecursiveTileBreak = Optional.Default(false, true);

/// <summary>
/// TileFrame-ed tile will be tracked and TileFrame-ed again.
/// This will trigger recursive tile break.
/// </summary>
public Optional<bool> RecursiveTileFrame = Optional.Default(false, true);

public enum DisabledDamageAction
{
AsIs,
Expand Down
1 change: 1 addition & 0 deletions Core/Mitigations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ private void TAHook_Mitigation_GameUpdate(EventArgs _)

this.Statistics.MitigationNewTileKillTriggered += this._pendingKilled.Count - count;
this._pendingKilled.Clear();
this._pendingTileFrame.Clear();
}
}

Expand Down
2 changes: 2 additions & 0 deletions Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions Core/WorldGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ulong, int> _pendingTileFrame = new Dictionary<ulong, int>();
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);
}
}
}

0 comments on commit 2118496

Please sign in to comment.