local B = CBW_Battle
local BattleFuncSet = false
local state_footstool_wait = 1
local state_footstool = 2
rawget(_G, HoneyFootstool)
freeslot("MT_HTECH")
addHook("ThinkFrame",function()
	if (BattleFuncSet) or not(CBW_Battle and CBW_Battle.SkinVars) then return end
	BattleFuncSet = true

 

	local HoneyFunction = function(player)
		if player.mo.state == S_PLAY_HONEYDIVE or player.mo.state == S_PLAY_HONEYDIVEEND then 
			CBW_Battle.SetPriority(player,1,1,nil,1,1,"Pounce")
		 end	
		 if player.mo.state == S_PLAY_HONEYMELEE1 or player.mo.state == S_PLAY_HONEYMELEE2 then 
			CBW_Battle.SetPriority(player,2,1,"knuckles_glide",1,0,"Booty Bop")
		 end
		 if player.mo.state == S_PLAY_HONEYBACKFLIP then 
			CBW_Battle.SetPriority(player,2,2,nil,2,2,"Moon Kick")
		 end
		 if player.honey.stomptime then 
			CBW_Battle.SetPriority(player,1,1,"fang_tailbounce",2,1,"Heel Stomp")
		 end
		 if player.mo.state == S_PLAY_FOOTSTOOL_WAIT then 
			CBW_Battle.SetPriority(player,0,0,nil,0,0,"Footstool")
		 end
		 if player.mo.state == S_PLAY_FOOTSTOOL then 
			CBW_Battle.SetPriority(player,1,1,nil,1,1,"Footstool")
		 end
		 if player.mo.state == S_PLAY_SUPER_TRANS1 or player.mo.state == S_PLAY_SUPER_TRANS2 or player.mo.state == S_PLAY_SUPER_TRANS3 or player.mo.state == S_PLAY_SUPER_TRANS4 or player.mo.state == S_PLAY_SUPER_TRANS5 or player.mo.state == S_PLAY_SUPER_TRANS6 then 
			CBW_Battle.SetPriority(player,0,3,nil,0,3,nil)
		 end
	end
	
	
		local function CounterGrab(mo, doaction)
			
			local player = mo.player
			
			local onGround = P_IsObjectOnGround(mo)
			if not (onGround)
				player.actiontext = "Footstool"
				player.actionrings = 8	--## How many rings should a footstool manuever cost?
				
				if not(CBW_Battle.CanDoAction(player))
					player.actionstate = 0
					return
				end
			else
				player.actiontext = "Air Only!!"
			end
			
			
			--Let's define behavior for the action's neutral state
			if player.actionstate == 0
				if doaction == 1
					if not (onGround)
						player.actionstate = state_footstool_wait
						if(HoneyFootstool and HoneyFootstool(player))
							CBW_Battle.PayRings(player)
							CBW_Battle.ApplyCooldown(player,3*TICRATE,true)

							
							S_StartSound(player.mo, sfx_cdfm23)
						end
					end
					
					
				end
			elseif((mo.state ~= S_PLAY_FOOTSTOOL) and (mo.state ~= S_PLAY_FOOTSTOOL_WAIT))
				player.actionstate = 0
			end
			
		end
	  
	CBW_Battle.SkinVars["honey"] = {
		flags = SKINVARS_GUARD|SKINVARS_NOSPINSHIELD,
		weight = 110,
		shields = 1, 
		special = CounterGrab,
		guard_frame = 1,
		func_priority_ext = HoneyFunction,
	}
end)