-- BattleMod Support --

local ScriptLoaded = false

addHook("ThinkFrame", function()
	if not (ScriptLoaded)
		and CBW_Battle
		then
		ScriptLoaded = true
		local B = CBW_Battle
		
		local SirenSong = function(mo,doaction)
			local player = mo.player
			if (P_PlayerInPain(player) or (player.playerstate == PST_DEAD))
				player.screennuked = false
			end
			player.actiontext = "Siren Song"
			player.actionrings = 50
			player.action2text = "A blaring screen nuke."
			player.action2rings = 0
			if not (B.CanDoAction(player))
				player.actionstate = 0
				return end
			if player.actionstate == 0
				if doaction == 1
					player.actionstate = 1
					player.actiontime = 0
					B.PayRings(player)
				end
			end
			if player.actionstate == 1
				player.actiontime = $+1
				P_InstaThrust(mo,mo.angle,0)
				P_SetObjectMomZ(mo, 0, 0)
				mo.state = S_SIRENSONG1
				if player.actiontime == 10
					player.actionstate = 2
					player.actiontime = 0
				end
			end
			if player.actionstate == 2
				player.actiontime = $+1
				B.ApplyCooldown(player,TICRATE*50)
				if not player.screennuked then
					P_BlackOw(player)
					S_StartSound(mo, sfx_csimia)
					player.screennuked = true
				end
				mo.state = S_SIRENSONG2
				S_StopSoundByID(mo, sfx_bkpoof)
				if player.actiontime == 20
					player.actionstate = 3
					player.actiontime = 0
					mo.state = S_PLAY_FALL
				end
			end
			if player.actionstate == 3
				player.actiontime = $+1
				if player.actiontime == 1
					player.screennuked = false
					player.actionstate = 0
				end
			end
		end
		
		CBW_Battle.SkinVars["flchan"] = {
			weight = 50,
			shields = 0,
			special = SirenSong,
			guard_frame = 6,
			sprites = {}
		}
	end
end)

addHook("PlayerSpawn", function(player)
	player.screennuked = false
end)

-- Henry Support
addHook("MobjDeath", function(mo, inflictor, source, damagetype)
	if mo.skin == "henry"
	and mo.valid and not (mo.player.powers[pw_carry] == CR_NIGHTSMODE)
		local player = mo.player
		if inflictor and inflictor.skin == "flchan"
			player.failwhy = "When FL Chan said she would dance on"
			player.failwhy2 = "your grave tonight, she wasn't joking."
			player.failwhy3 = ""
			player.failwhy4 = "In fact, she danced you INTO your grave."
			player.failwhy5 = "So that's a double win for her."
			player.failwhy6 = nil
			player.failwhy7 = nil
			player.failwhy8 = nil
			player.failwhy9 = nil
			player.failwhy10 = nil
		end
	end
end, MT_PLAYER)