--this is just an edit of the default lua lmao

local ScriptLoaded = false

addHook("ThinkFrame", function()
	if not(ScriptLoaded)
		and CBW_Battle
		then
		ScriptLoaded = true
		local B = CBW_Battle
				
		local Corks = function(mo,doaction)
			local player = mo.player
			
			--Now for some definitions:
			player.actiontext = "C o r k s" --This is the HUD text
			player.actionrings = 10
			player.action2text = nil
			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)
					S_StartSound(mo,sfx_s3k3c)
					
				end
			end
			
			if player.actionstate == 1
				player.actiontime = $+1
				
				--Halt our momentum
				P_InstaThrust(mo,mo.angle,0)
				P_SetObjectMomZ(mo,P_MobjFlip(mo)*mo.scale,0)
				--Make us spin
				player.pflags = ($|PF_SPINNING)&~PF_JUMPED
				mo.state = S_PLAY_ROLL
				P_SpawnThokMobj(player) --Just a little aesthetics
				
				if player.actiontime == 20 then
					player.actionstate = 2
					player.actiontime = 0
				end
			end
			
			if player.actionstate == 2
				player.actiontime = $+1
				if player.actiontime%1==0
					P_SPMAngle(mo,MT_CORK,mo.angle,0)
				end
				
				--Do some recoil
				P_SetObjectMomZ(mo,P_MobjFlip(mo)*mo.scale*2,0)
				P_InstaThrust(mo,mo.angle+ANGLE_180,mo.scale*6)
				B.ApplyCooldown(player,TICRATE*2)
				mo.state = S_PLAY_FALL
				player.pflags = $&~(PF_SPINNING)
				player.drawangle = mo.angle
				
				--Reset player state
				if player.actiontime == 20
					player.actionstate = 0
				end
			end
			
		end --End of action function.
		
		local PriorityFunc = function(player)
			if player.actionstate == 1 then
				B.SetPriority(player,1,3,nil,1,3,"midair charge spin")
				/* Arguments
					1: Player properties to modify
					2: Attack priority. Higher priorities will pierce through stronger enemy defense.
					3: Defense priority. Higher priorities will resist enemy attacks.
					4: "Special" priority condition. If returns true, uses arguments 5 & 6 to determine attack/defense priority for this frame.
					5: Special attack, if argument 4's function returns true.
					6: Special defense, if argument 4's function returns true.
					7: Attack text to display in the console when an opponent takes damage from a player-to-player collision
						(i.e. "Cyan's midair charge spin hit Cman"
				*/
			end
		end
		
		
		--Let's now assign these functions to the character:
		CBW_Battle.SkinVars["cyan"] = {
			special = Corks,
			func_priority_ext = PriorityFunc
		}
	end
end)