freeslot("MT_MIZZYSHOT", "S_MIZZYSHOT", "SPR_JMPP") --All of the battlemod code here was made by Mr. FondusBroMan

mobjinfo[MT_MIZZYSHOT] = {
	height = 16*FRACUNIT,
	radius = 8*FRACUNIT,
	flags = mobjinfo[MT_TORPEDO].flags|MF_GRENADEBOUNCE|MF_BOUNCE,
	speed = 96*FRACUNIT,
	spawnstate = S_MIZZYSHOT
}

states[S_MIZZYSHOT] = {
	tics = 5*TICRATE/4,
	sprite = SPR_JMPP,
	frame = FF_ANIMATE,
	action = A_SetScale,
	var1 = 4,
	var1 = 2*FRACUNIT,
	nextstate = S_CACOFIRE_EXPLODE1
}

addHook("MobjThinker", function(phase)
	if phase and phase.valid and phase.type == MT_MIZZYSHOT
		local attack = P_SpawnMobjFromMobj(phase, P_RandomRange(-18, 18) * FRACUNIT, P_RandomRange(-18, 18) * FRACUNIT, P_RandomRange(0, 32) * FRACUNIT, MT_FLAMEPARTICLE)
		attack.color = SKINCOLOR_RED
		attack.colorized = true
		attack.blendmode = AST_ADD
		attack.state = S_WATERZAP
		local phaseghost = P_SpawnGhostMobj(phase)
		phaseghost.blendmode = AST_ADD
		P_InstaThrust(phase, P_RandomRange(1, 360)*ANG1, 60*FRACUNIT)
		for i = 0,9
			phaseghost.fuse = 6
			phaseghost.scale = (FRACUNIT * 8/10) - (i * FRACUNIT/320)
			phaseghost.destscale = 0
		end
	end
end, MT_MIZZYSHOT)

local BattleFuncSet = false

addHook("ThinkFrame",function()
	if (BattleFuncSet) or not(CBW_Battle and CBW_Battle.SkinVars) then return end
		BattleFuncSet = true
		local MizzyPriority = function(player)
			if player.mo.state == S_PHASE
				CBW_Battle.SetPriority(player,2,2,nil,2,2,"Mizzy Dash")
			end
			if (player.mo.state == S_PHASEJUMP or player.mo.state == S_PHASEFALL)
				CBW_Battle.SetPriority(player,1,2,nil,1,2,"Mizzy Dash, but he is small")
			end
			if player.mo.frontiersshot
				CBW_Battle.SetPriority(player,1,2,nil,1,2,"Phase Charge")
			end
		end
		local MizzyAbility = function(mo,doaction,pressedaction)
		local player = mo.player
		if not(CBW_Battle.CanDoAction(player))
			player.actionstate = 0
			return
		end
		player.actiontext = "Phase Shot"
		player.actionrings = 10	
		if player.actionstate != 0
			player.canguard = false
		end
		if player.actionstate == 0
			if doaction == 1
				CBW_Battle.PayRings(player)
				S_StartSound(player.mo, sfx_mzphas)
				CBW_Battle.ApplyCooldown(player,TICRATE*2)
				player.mo.frontiersshot = 15
			end
			if (player.cmd.buttons & BT_USE)
			and (player.mizzyphase >= 1)
			and player.mo.state == S_PHASE
				player.canguard = false
			else
				player.canguard = true
			end
		end
	end
	CBW_Battle.SkinVars["mizzy"] = {
		flags = SKINVARS_GUARD|SKINVARS_NOSPINSHIELD,
		weight = 100,
		shields = 1,
		special = MizzyAbility,
		func_collide = TDCollide,
		func_priority_ext = MizzyPriority
	}
	print("Mizzy The Silverfish Battle Mode support has been added!")
end)