<repo_name>moisterrific/FTWProtection<file_sep>/README.md
# FTWProtection
Replaces for the worthy bombs with other projectiles  
On for the worthy, skeletron prime bombs will destroy tiles when they explode and bombs can fall out of trees when shaken or when pots are broken.  
These are replaced with non-destructive projectiles. In this case, both are hard-coded to use beehives, matching the current dg survival world (drunk + expert + not the bees + ftw flag).  
Could use cannonballs for prime bombs with how similar they are. Bombs from the environment could be replaced with an item drop or any other projectile.  
<file_sep>/FTWProtection/FTWProtection.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TShockAPI;
using Terraria;
using TerrariaApi.Server;
using Terraria.ID;

namespace FTWProtection
{
	[ApiVersion(2, 1)]
	public class FTWProtection : TerrariaPlugin
	{
		public override string Author => "Quinci";

		public override string Description => "Prevents explosion griefing in for the worthy";

		public override string Name => "For the Worthy Protection";

		public override Version Version => new Version(1, 0, 0, 0);

		public FTWProtection(Main game) : base(game)
		{
			Order = 40;
		}

		public override void Initialize()
		{
			ServerApi.Hooks.ProjectileSetDefaults.Register(this, OnProjectileSetDefaults);
			ServerApi.Hooks.ProjectileAIUpdate.Register(this, OnProjectileAIUpdate);
		}

		private void OnProjectileSetDefaults(SetDefaultsEventArgs<Projectile, int> args)
		{
			if (args.Object.type == ProjectileID.BombSkeletronPrime && Main.getGoodWorld) // 102 && ftw flag
			{
				args.Object.type = ProjectileID.BeeHive; // 655;
				args.Object.aiStyle = 25; // Beehive AI, rolls along the ground until crashing
				NetMessage.SendData((int)PacketTypes.ProjectileNew, -1, -1, null, args.Object.identity);
			}
		}

		private void OnProjectileAIUpdate(ProjectileAiUpdateEventArgs args)
		{
			// Only possible via modified client (where there are other issues) as x velocity will always be 5 if y = 0, regardless of tile collision.
			if (args.Projectile.type == ProjectileID.Bomb && args.Projectile.timeLeft == 3600 && args.Projectile.oldVelocity.Y == 0f && 0.202f >= Math.Abs(args.Projectile.oldVelocity.X))
			{
				args.Projectile.type = ProjectileID.BeeHive; // 655;
				args.Projectile.aiStyle = 25; // Beehive AI, rolls along the ground until crashing
				NetMessage.SendData((int)PacketTypes.ProjectileNew, -1, -1, null, args.Projectile.identity);
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				ServerApi.Hooks.ProjectileSetDefaults.Deregister(this, OnProjectileSetDefaults);
				ServerApi.Hooks.ProjectileAIUpdate.Deregister(this, OnProjectileAIUpdate);

			}
			base.Dispose(disposing);
		}
	}
}