//join chill
addHook("BotTiccmd", function(bot)
	local player = players[0]
	local mo = players[0].mo
	if player.exiting then 
		return
	end
	if bot.mo and player.mo.skin == "rafael" and player and mo
		if player.rafxtra then
			if bot.mo.state != S_PLAY_RAFXTRA
				bot.mo.state = S_PLAY_RAFXTRA
			end
		else
			if bot.mo.state == S_PLAY_RAFXTRA
				bot.mo.state = S_PLAY_WALK
			end
		end
	elseif bot.mo and player.mo.skin == "pedro" and player and mo
		if player.pedxtra then
			if bot.mo.state != S_PLAY_PJXTRA
			and bot.mo.state != S_PLAY_PJXTRAB
				bot.mo.state = S_PLAY_PJXTRA
			end
		else
			if bot.mo.state == S_PLAY_PJXTRA
			or bot.mo.state == S_PLAY_PJXTRAB
				bot.mo.state = S_PLAY_WALK
			end
		end
	elseif bot.mo and player.mo.skin == "frank" and player and mo
		if player.distracting then
			if bot.mo.state != S_FRANK_DISTRACT
			and bot.mo.state != S_FRANK_JIMDISTRACT
				bot.mo.state = S_FRANK_JIMDISTRACT
			end
		else
			if bot.mo.state == S_FRANK_JIMDISTRACT
			or bot.mo.state == S_FRANK_DISTRACT
				bot.mo.state = S_PLAY_WALK
			end
		end
	end
end)

//water move
addHook("BotTiccmd", function(bot)
	local player = players[0]
	local mo = players[0].mo
	if player.exiting then 
		return
	end
	if bot.mo and player and mo and bot.mo.skin == "m.jimmyharold" then
		if (bot.mo.eflags & MFE_UNDERWATER) then
			if (player.mo.z >= bot.mo.z) then
				bot.mo.momz = $ + 1*FRACUNIT
			elseif (player.mo.z <= bot.mo.z) then
				bot.mo.momz = $ - 1*FRACUNIT
			end
		end
	end
end)

addHook("BotTiccmd", function(bot)
	local player = players[0]
	local mo = players[0].mo
	if player.exiting then 
		return
	end
	if (player.mo and player.mo.valid and player.powers[pw_underwater] == 0 and player.mo.skin == "rafael") then
		if player.partnerulti and player.emotapping or player.ultimer then
			player.powers[pw_invulnerability] = 70
			if player.ultimer >= 70 then
				bot.mo.state = S_PLAY_JIMOUCH
			end
		end
	end
end)

addHook("PlayerThink", function(player)
	if player.mo.skin == "rafael" then
		if not (player.cmd.buttons & BT_CUSTOM2) then
			player.emotapready = true
			player.emotapping = false
		elseif player.emotapready then
			player.emotapping = true
			player.emotapready = false
		else
			player.emotapping = false
		end
	end
end)

addHook("PlayerThink", function(player)
	if (player.mo and player.mo.valid and player.powers[pw_underwater] == 0 and player.mo.skin == "rafael") then
		player.ultimer = $ or 0
		if player.partnerulti and player.emotapping or player.ultimer then
			player.ultimer = $ + 1
			player.powers[pw_invulnerability] = 70
			if player.ultimer >= 70 then
				P_BlackOw(player)
				player.ultimer = 0
				player.partnerulti = false
				player.rings = $ - 50
			end
		end
	end
end)

addHook("PlayerThink", function(player)
	if (player.mo and player.mo.valid and player.powers[pw_underwater] == 0 and player.mo.skin == "rafael") then
		if player.rings >= 50 then
			player.partnerulti = true
		end
	end
end)

local TBLAST = function(v, player, cam)
	local mo = players[0].mo
	if player.mo and player.mo.valid and player.mo.skin == "rafael" then
		if player.ultimer then
			if player.ultimer >= 60 and player.ultimer << 64 then
				v.draw(0, 0, v.cachePatch("JBLAST16"))
			elseif player.ultimer >= 56 and player.ultimer << 60 then
				v.draw(0, 0, v.cachePatch("JBLAST15"))
			elseif player.ultimer >= 52 and player.ultimer << 56 then
				v.draw(0, 0, v.cachePatch("JBLAST14"))
			elseif player.ultimer >= 48 and player.ultimer << 52 then
				v.draw(0, 0, v.cachePatch("JBLAST13"))
			elseif player.ultimer >= 44 and player.ultimer << 48 then
				v.draw(0, 0, v.cachePatch("JBLAST12"))
			elseif player.ultimer >= 40 and player.ultimer << 44 then
				v.draw(0, 0, v.cachePatch("JBLAST11"))
			elseif player.ultimer >= 36 and player.ultimer << 40 then
				v.draw(0, 0, v.cachePatch("JBLAST10"))
			elseif player.ultimer >= 32 and player.ultimer << 36 then
				v.draw(0, 0, v.cachePatch("JBLAST9"))
			elseif player.ultimer >= 28 and player.ultimer << 32 then
				v.draw(0, 0, v.cachePatch("JBLAST8"))
			elseif player.ultimer >= 24 and player.ultimer << 28 then
				v.draw(0, 0, v.cachePatch("JBLAST7"))
			elseif player.ultimer >= 20 and player.ultimer << 24 then
				v.draw(0, 0, v.cachePatch("JBLAST6"))
			elseif player.ultimer >= 16 and player.ultimer << 20 then
				v.draw(0, 0, v.cachePatch("JBLAST5"))
			elseif player.ultimer >= 12 and player.ultimer << 16 then
				v.draw(0, 0, v.cachePatch("JBLAST4"))
			elseif player.ultimer >= 8 and player.ultimer << 12 then
				v.draw(0, 0, v.cachePatch("JBLAST3"))
			elseif player.ultimer >= 4 and player.ultimer << 8 then
				v.draw(0, 0, v.cachePatch("JBLAST2"))
			elseif player.ultimer >= 1 and player.ultimer << 4 then
				v.draw(0, 0, v.cachePatch("JBLAST1"))
			end
		end
	end
end

hud.add(TBLAST, "game")

//imma gonna make jim a killing machine during boss battles
local jimhomtarget = nil

addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
		if player.mo.state == S_PLAY_WAIT 
		or player.mo.state == S_PLAY_RIDE then
			player.jorbit = true
		else
			jimhomtarget = P_LookForEnemies(player, false, true)
			player.jorbit = false
		end
	end
end)

addHook("BotTiccmd", function(bot)
	local player = players[0]
	if player.exiting then 
		return
	end
	if bot.mo and bot.mo.valid and bot.mo.skin == "m.jimmyharold" then
		if player.jorbit then
			local mo = players[0].mo
			bot.mo.target = player.mo
			P_RadiusAttack(bot.mo, bot.mo, 64*FRACUNIT)
			P_SpawnGhostMobj(bot.mo)
			bot.mo.state = S_PLAY_JIMORBT
		elseif jimhomtarget != nil and not player.powers[pw_sneakers] then
			P_RadiusAttack(bot.mo, bot.mo, 64*FRACUNIT)
			bot.mo.state = S_PLAY_ROLL
			P_HomingAttack(bot.mo, jimhomtarget)
			P_SpawnGhostMobj(bot.mo)
		elseif jimhomtarget != nil and player.powers[pw_sneakers] then
			bot.mo.state = S_PLAY_ROLL
			P_TeleportMove(bot.mo, jimhomtarget.x, jimhomtarget.y, jimhomtarget.z)
			P_DamageMobj(jimhomtarget)
			bot.mo.state = S_PLAY_SPRING
			P_SetObjectMomZ(bot.mo, 12*FRACUNIT, false)
		end
	end
end)

addHook("BotTiccmd", function(bot)
	local player = players[0]
	if player.exiting then 
		return
	end
	if bot.mo and bot.mo.valid and bot.mo.skin == "m.jimmyharold" then
		if player.jorbit then
			bot.pflags = $1&PF_NOCLIP
		else
			bot.pflags = $1&~PF_NOCLIP
		end
	end
end)
		
		
		
		
