freeslot(
"MT_HYPERSPARKLE",
"S_HYPERSPARKLE",
"SPR_ASPK",
"S_HYPERSPARKLE2",
"S_HYPERSPARKLE3",
"S_HYPERSPARKLE4",
"S_HYPERSPARKLE5"
)

-- mobjinfo --
mobjinfo[MT_HYPERSPARKLE] = {
	doomednum = -1,
	spawnstate = S_HYPERSPARKLE,
	flags = MF_NOCLIP|MF_SCENERY|MF_NOGRAVITY|MF_NOCLIPHEIGHT
}

states[S_HYPERSPARKLE] = {
	sprite = SPR_ASPK,
	frame = TR_TRANS30|A,
	nextstate = S_HYPERSPARKLE2
}

states[S_HYPERSPARKLE2] = {
	sprite = SPR_ASPK,
	frame = TR_TRANS30|B,
    nextstate = S_HYPERSPARKLE3
}

states[S_HYPERSPARKLE3] = {
	sprite = SPR_ASPK,
	frame = TR_TRANS30|C,
	nextstate = S_HYPERSPARKLE4
}

states[S_HYPERSPARKLE4] = {
	sprite = SPR_ASPK,
	frame = TR_TRANS30|D,
	nextstate = S_HYPERSPARKLE5
}

states[S_HYPERSPARKLE5] = {
	sprite = SPR_ASPK,
	frame = TR_TRANS30|E,
	nextstate = S_NULL
}


-- hyper --
local function HyperX(player)
	if (player.mo.skin != "nasidafjv") return end
	
	if player.hypertrans == nil
		player.hypertrans = false
	end
	
	if player.sparkleoffset == nil
		player.sparkleoffset = 0
	end
	
	if player.rings >= 100 -- you have 100 rings?
	and player.powers[pw_super] > 1 -- and super?
		player.hypercapable = true
	elseif (player.rings < 100 and player.powers[pw_super]) -- super and 100 rings!
	or not player.powers[pw_super] -- not super
		player.hypercapable = false -- NO! Hyper
	end -- end the action
	
	if player.Xhyper -- are you going hyper
	or (mrce_hyperunlocked != nil and mrce_hyperunlocked == false)
		player.hypercapable = false
	end
	
	if player.hypercapable
	and player.powers[pw_super] -- be super
	and player.cmd.buttons & BT_CUSTOM3 --press c3!
	and player.pflags & PF_JUMPED --jump!
	and not player.Xhyper --not hyper?
	and not player.turnedsuper -- not player turned super
		player.pflags = $1|PF_THOKKED -- and thok? i dot know
		player.mo.state = S_PLAY_SUPER_TRANS1 -- DO TRNS1!
		player.hypertrans = true -- yes you can be hyper!
		S_StartSound(player.mo, sfx_s3k9f) -- YES DO THAT SICK SONIC3 SOUND
		player.Xhyper = true -- yes yes!
	end --end this action
	 -- im sleeping sooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
	if player.hypertrans
		player.mo.momx = 0
		player.mo.momy = 0
		player.mo.momz = 0
	end
	
	if player.hypertrans
	and not (player.mo.state >= S_PLAY_SUPER_TRANS1 and player.mo.state <= S_PLAY_SUPER_TRANS6)
		player.hypertrans = false
		player.pflags = $1 & ~PF_THOKKED
		P_StartQuake(25*FRACUNIT, 16)
		P_NukeEnemies(player.mo, player.mo, 5000*FRACUNIT)
		if player.Xflashes
			P_FlashPal(player, PAL_NUKE, 8)
		end
		S_StartSound(player.mo, sfx_s3k4e)
	end
	
	if player.Xhyper
	and not player.powers[pw_super]
		player.Xhyper = false
	end

	if player.Xhyper
		player.powers[pw_underwater] = 100*TICRATE
		player.powers[pw_spacetime] = 100*TICRATE
		
		if player.mo.skin == "nasidafjv"
			if player.hypertrans
			and player.mo.state != S_PLAY_SUPER_TRANS1
			and player.mo.state != S_PLAY_SUPER_TRANS2
			and player.mo.state != S_PLAY_SUPER_TRANS3
				player.mo.color = SKINCOLOR_SUPERHYPER1
			elseif not player.hypertrans
				player.mo.color = (SKINCOLOR_SUPERHYPER1 + abs(((player.powers[pw_super] >> 2) % 9) - 6))
			end
		end
		
		if (player.speed > 1*FRACUNIT or player.mo.momz > 1*FRACUNIT or player.mo.momz < -1*FRACUNIT)
		and not player.hypertrans
			local afterimage = P_SpawnGhostMobj(player.mo)
			
			afterimage.color = (SKINCOLOR_SUPER_HYPER_1 + abs(((player.powers[pw_super] >> 2) % 9) - 6))
			afterimage.colorized = true
		end
		
		player.jumpfactor = skins[player.mo.skin].jumpfactor * 3 / 2
		
		if player.charability2 == CA2_SPINDASH
			player.mindash = 60*FRACUNIT
			player.maxdash = 120*FRACUNIT
		end
		
		
		if leveltime % 5 == 0
			local strikesparkle = P_SpawnMobj(player.mo.x+(P_RandomRange(16,-16)*FRACUNIT),player.mo.y+(P_RandomRange(16,-16)*FRACUNIT),player.mo.z+(player.mo.height/2)+(P_RandomRange(8,-8)*FRACUNIT),MT_HYPERSPARKLE)
			strikesparkle.color = player.mo.color
			strikesparkle.colorized = true
			strikesparkle.scale = player.mo.scale * 3 / 2
			
			strikesparkle.momx = P_RandomRange(5,-5)*FRACUNIT
			strikesparkle.momy = P_RandomRange(5,-5)*FRACUNIT
			strikesparkle.momz = P_RandomRange(5,-5)*FRACUNIT
		end
		
		if (leveltime % 35 == 18) and not player.hypertrans
			P_GivePlayerRings(player, -1)
		end
		
		if player.powers[pw_super] and player.Xhyper and not (player.powers[pw_extralife])
			S_ChangeMusic("NASHYPER", true, player)
		end

		if player.cmd.buttons & BT_CUSTOM2
		and player.pflags & PF_JUMPED
		and not player.dehyper
			player.Xhyper = false
			player.dehyper = true
			if player.dashmode2 < 2*TICRATE
				player.jumpfactor = skins[player.mo.skin].jumpfactor
			end
			if player.charability2 == CA2_SPINDASH
				player.mindash = skins[player.mo.skin].mindash
				player.maxdash = skins[player.mo.skin].maxdash
			end
			P_RestoreMusic(player)
		end
	else
		if player.dashmode2 > 2*TICRATE
			player.jumpfactor = skins[player.mo.skin].jumpfactor
		end
		if player.charability2 == CA2_SPINDASH
			player.mindash = skins[player.mo.skin].mindash
			player.maxdash = skins[player.mo.skin].maxdash
		end
		if player.sparkleoffset
			player.sparkleoffset = 0
		end
	end
	
	if P_IsObjectOnGround(player.mo)
		player.dehyper = false
	end
	
	if player.powers[pw_super]
	and not player.Xhyper
		if player.cmd.buttons & BT_CUSTOM2
		and not player.prejumpcustom2
		and not player.dehyper
		and player.pflags & PF_JUMPED
			player.powers[pw_super] = 0
			P_RestoreMusic(player)
			P_SpawnShieldOrb(player)
			player.mo.color = player.skincolor
		end
	end
		
	if player.cmd.buttons & BT_CUSTOM2
		player.prejumpcustom2 = true
	else
		player.prejumpcustom2 = false
	end
end

addHook("PlayerThink", HyperX)

// Power Share!
// Press Custom 3 on the ground near other players to give them Super if you are Hyper!
// Even applies to characters that aren't meant to have Super normally.

local function PowerShare(mo1, mo2)
	if not mo1.valid and mo2.valid return end
	
	local player1 = mo1.player
	local player2 = mo2.player
	
	if not (player1 and player2)
	
	or mo1.z > mo2.z + mo2.height 
	or mo2.z > mo1.z + mo1.height
	or player2.powers[pw_carry]
	or player2.playerstate ~= PST_LIVE
	or player2.spectator
	or P_PlayerInPain(player2)
	or mo1.skin ~= "nasidafjv"
	or not P_IsObjectOnGround(mo1)
	or not P_IsObjectOnGround(mo2)
	or not player1.Xhyper
		return
	end
	
	if player1.cmd.buttons & BT_CUSTOM3
	and not player2.powers[pw_super]
		if player2.rings < 50
			player2.rings = 50
		end
		
		if not (player2.charflags & SF_SUPER)
			player2.forcedsuper = true
			player2.charflags = $|SF_SUPER
		end
	
		P_DoSuperTransformation(player2)
		player2.turnedsuper = true
		for i = 0, 8
			local fa = (i*(ANGLE_180/4))
			local strikesparkle = P_SpawnMobj(mo2.x, mo2.y, mo2.z+(mo2.height/2), MT_HYPERSPARKLE)
			strikesparkle.momx = FixedMul(sin(fa),5*FRACUNIT)
			strikesparkle.momy = FixedMul(cos(fa),5*FRACUNIT)
			strikesparkle.color = player1.mo.color
			strikesparkle.scale = player1.mo.scale * 2
			strikesparkle.colorized = true
		end
	end
end

addHook("MobjMoveCollide", PowerShare)