
local function fixedlerp (var1, var2, t) 
	var1 = FixedMul($1, FRACUNIT-t)
	var2 = FixedMul($1, t)
	local r = var1+var2
	r = $1
	return r
end

local function getstarcolor()
	if (P_RandomByte() > 220) then
		return P_RandomRange(0,254)
	end
	return 31
end

freeslot("SKINCOLOR_STARCHASER")

skincolors[SKINCOLOR_STARCHASER] = {
    name = "Starchaser",
    ramp = {31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31},
    accessible = false
}
addHook("MapLoad", do
    for player in players.iterate
		if player.mo.skin ~= "nasya" then
			continue
		end

			player.charged = 0
			player.mo.steppause = 0
			player.mo.skipready = false
			player.oldmomx = 0
			player.oldmomy = 0
			player.oldmomz = 0
			player.oldspeed = 0
			player.twirling = 0
			player.jumpdown = 0
			player.jumpangle = 0
			player.transtime = 0
			player.pitbounce = 3
			player.mysticsuper = 0
			player.tumbletime = 0
			player.stepfoot = 0
			player.extrabreath = 0
			player.socialtime = 0
			player.socialangle = 0
    end
end)
addHook("ThinkFrame", function()
	for player in players.iterate do
	
		if (player.twirling and player.mo.skin ~= "nasya") then
			if (player.twirling > 0) then
				player.twirling = $-1
				if not (player.powers[pw_shield] & SH_FORCE) then
					if (player.mo.state ~= S_PLAY_FLOAT) then
						player.mo.state = S_PLAY_FLOAT
					end
					player.drawangle = (player.twirling*ANG30)+player.mo.angle
					if (player.twirling == 0) then
						player.mo.state =  S_PLAY_FLOAT
					end
				end
			end
			continue
		end
		
		if player.mo.skin ~= "nasya" then
			continue
		end
		
		if (player.powers[pw_super]  > 0) then

			
			player.mo.color = SKINCOLOR_STARCHASER
			
			if ((player.powers[pw_super] % 2) == 1) then
				skincolors[SKINCOLOR_STARCHASER].ramp = {
				getstarcolor(),
				skincolors[SKINCOLOR_STARCHASER].ramp[0],
				skincolors[SKINCOLOR_STARCHASER].ramp[1],
				skincolors[SKINCOLOR_STARCHASER].ramp[2],
				
				getstarcolor(),
				skincolors[SKINCOLOR_STARCHASER].ramp[4],
				skincolors[SKINCOLOR_STARCHASER].ramp[5],
				skincolors[SKINCOLOR_STARCHASER].ramp[6],
				
				getstarcolor(),
				skincolors[SKINCOLOR_STARCHASER].ramp[8],
				skincolors[SKINCOLOR_STARCHASER].ramp[9],
				skincolors[SKINCOLOR_STARCHASER].ramp[10],
				
				getstarcolor(),
				skincolors[SKINCOLOR_STARCHASER].ramp[12],
				skincolors[SKINCOLOR_STARCHASER].ramp[13],
				skincolors[SKINCOLOR_STARCHASER].ramp[14],
				
				}
			end	
			if (player.hyper) then
				if (player.hyper.capable) then
					player.mo.color = (SKINCOLOR_SUPER_HYPER_1 + abs( ( (player.powers[pw_super] >> 1) % 9) - 4))
				end
			end
		end
		
		if ((player.pflags & PF_SLIDING) or (player.powers[pw_carry] & CR_ROPEHANG) or (player.powers[pw_carry] & CR_ROLLOUT) ) then
			continue //If you're engaging with these stage gimmicks, you should probably just act like a normal person for a bit.
		end
		if (player.mo.state == S_PLAY_DEAD) then
			player.mo.momz = FRACUNIT*10 //Fly off into the sun for the death animation.
		end
		if (player.pflags & PF_STASIS)  or (player.pflags & PF_FULLSTASIS) or (player.pflags & PF_JUMPSTASIS) or (player.pflags & PF_SLIDING)  or player.mo.state == S_PLAY_DEAD or player.powers[pw_nocontrol]
			continue
		end
		
		if (player.mo.steppause == nil) then
			player.charged = 0
			player.mo.steppause = 0
			player.mo.skipready = false
			player.oldmomx = 0
			player.oldmomy = 0
			player.oldmomz = 0
			player.oldspeed = 0
			player.twirling = 0
			player.jumpdown = 0
			player.jumpangle = 0
			player.transtime = 0
			player.pitbounce = 3
			player.mysticsuper = 0
			player.tumbletime = 0
			player.stepfoot = 0
			player.extrabreath = 0
			player.socialtime = 0
			player.socialangle = 0
		end
		

		if (player.mysticsuper) then //If we're recieving power from a certain gold-and-red hedgehog, we may as well go all in on being stupidly OP.
		//This  is MYSTIC STAR NASYA
			if (player.mo.state ~= S_PLAY_NASYA_MYSTICFLOAT and player.mo.state ~= S_PLAY_NASYA_MYSTICFLY) then //Simplify things with only two character states
				player.mo.state = S_PLAY_NASYA_MYSTICFLOAT
			end
			
			
			if (player.mo.state == S_PLAY_NASYA_MYSTICFLY and player.speed < player.runspeed) then
				player.mo.state = S_PLAY_NASYA_MYSTICFLOAT
			end
			if (player.mo.state == S_PLAY_NASYA_MYSTICFLOAT and player.speed > player.runspeed) then
				player.mo.state = S_PLAY_NASYA_MYSTICFLY
			end
			
			
			player.mo.momz = $1-P_GetMobjGravity(player.mo) //Gravity off completely. We really are The Weightless now.
			
			if (player.cmd.buttons & BT_JUMP) then //Press Jump to Ascend
				player.mo.momz = $1+(FRACUNIT)
			elseif (player.cmd.buttons & BT_USE) then //Since our Mystic Planetoids are taking care of enemies for us, the spin key descends instead
				player.mo.momz = $1-(FRACUNIT)
			else
				player.mo.momz = ($1*9)/10
			end
			
				player.mo.momx = ($1*98)/100 //A bit of friction so we can't quite go infinity fast
				player.mo.momy = ($1*98)/100 
				player.mo.momz = ($1*95)/100 
	
			
				player.mysscolor = 15 
				//SMS will take care of spawning particles, draining rings, and being invincible for us, but we should let him know we want to be gold instead of our usual supercolor
				
				//Okay look I thought about this.
				//SMS becomes gold, has longer spines, red stripes, and green shoes and gloves.
				//But according to Golden, the green shoes are actually weights he uses to control his speed.
				//NASYA shouldn't have weights.
				//So Mystic Star NASYA turns gold, has longer hair, and red markings, but no green anywhere on her design.
				//IT IS VERY IMPORTANT THAT I RESPECT THE WELL-ESTABLISHED SMS LORE
			
			if player.cmd.forwardmove //The same boosted midair control as normal Super NASYA
			or player.cmd.sidemove //Although in this case, it's her primary form of acceleration
				P_Thrust(player.mo, player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT), 50000)
			end
			
		if (player.twirling > 0) then
			player.twirling = $-1
		end
		continue //Just skip the rest of NASYA's code to avoid breaking things.
		end
		
		if (player.cmd.forwardmove == 0 and player.cmd.sidemove == 0 and  (P_IsObjectOnGround(player.mo) == false) and (player.mo.skipready == false) ) then
			player.charged = 20
		else
			if (player.charged > 0) then
				player.charged = $1-1
			end
		end
		
		if player.jumpdown == -1 then
			player.jumpdown = 0
		end
		
		if (player.cmd.buttons & BT_JUMP) then
			player.jumpdown = $1+1
		elseif (player.jumpdown > 0) then
			player.jumpdown = -1
		end
		
		if (player.twirling > 0) then
		
		
			player.twirling = $-1
			if not (player.powers[pw_shield] & SH_FORCE) then
				if (player.mo.state ~= S_PLAY_NASYA_TWIRL) then
					player.mo.state = S_PLAY_NASYA_TWIRL
				end
				player.drawangle = (player.twirling*ANG30)+player.mo.angle
				if (player.twirling == 0) then
					player.mo.state =  S_PLAY_NASYA_FLY
				end
			end
		end


		if (player.transtime == 0 and not (player.mysticsuper) and player.powers[pw_super] == 0) and
		((player.cmd.buttons & BT_CUSTOM3) or (player.cmd.buttons & BT_JUMP and player.cmd.buttons & BT_USE)) then
			if ((All7Emeralds(emeralds) or player.readyforpowershare) and (player.rings >= 50)) then
				player.mo.state = S_PLAY_NASYA_TRANSFORM
				player.transtime = 1
				player.twirling = 0
			end
		end
		
		if (player.cmd.buttons & BT_CUSTOM1 and (player.powers[pw_super]  == 0)) then
			if (player.socialtime == 0) then			
				player.socialangle = player.drawangle
			else
				player.drawangle = player.socialangle
			end
			player.mo.state = S_PLAY_NASYA_SOCIAL
			player.socialtime = $1+1
			if (player.socialtime < 175) then
				player.mo.frame = 0
			elseif (player.socialtime < 350) then
				player.mo.frame = 1
			else
				player.mo.frame = (((player.socialtime-350)/15)%4)+2
			end
		elseif (player.socialtime) then
			player.mo.state = S_PLAY_STND
			player.socialtime = 0
		end
		
		//Debug buttons to speed up testing.
		/*
		if (player.cmd.buttons & BT_CUSTOM2) then
		
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD1)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD2)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD3)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD4)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD5)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD6)
				 P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,MT_EMERALD7)
				 P_GivePlayerRings(player,50)
		end
								
								*/
		if (player.transtime > 0) then //Special transformation animation for funsies
			player.transtime = $1+1
				player.mo.momx = 0
				player.mo.momy = 0
				player.twirling = 0
			if (player.transtime < 10) then
				player.mo.frame = (player.transtime/3) % 2
				player.mo.momz = FRACUNIT*5
			elseif (player.transtime < 12)
				player.mo.frame = 2
				S_StartSound(player.mo,sfx_supert,player)
			elseif (player.transtime < 30)
				for i = 0, 3
					local goldspiral = (ANG1*275)/2
					player.mo.frame = ((player.transtime/3) % 4) + 3
					player.mo.momz = 0
					local starvoid = P_SpawnMobj(
					player.mo.x+(cos(((player.transtime*3)+i)*goldspiral)*250),
					player.mo.y+(sin(((player.transtime*3)+i)*goldspiral)*250),
					player.mo.z+(player.mo.height*i),
					MT_STARVOID)
					starvoid.target = player.mo
					A_FaceTarget(starvoid,0,0)
					starvoid.scale = 0
					starvoid.destscale = (FRACUNIT) + (P_RandomFixed())
					starvoid.scalespeed = FRACUNIT/6
					starvoid.tics = 40-player.transtime
				end
			elseif (player.transtime == 40) then
			
				if (player.readyforpowershare) then 
					local goldspiral = (ANG1*275)/2
					for i = 0, 7
						local planetoid = P_SpawnMobj(
							player.mo.x+(cos(goldspiral*i)*150),
							player.mo.y+(sin(goldspiral*i)*150),
							player.mo.z,
							MT_PLANETOID)
					planetoid.target = player.mo
					P_SetMobjStateNF(planetoid, S_PLANETMYSTIC)
					planetoid.height = 29
					planetoid.radius = 29
					planetoid.tics = 31
					planetoid.reactiontime = i
					end
				
				else
					local planetoid = P_SpawnMobj(
							player.mo.x+(cos(ANGLE_157h)*150),
							player.mo.y+(sin(ANGLE_157h)*150),
							player.mo.z,
							MT_PLANETOID)
					planetoid.target = player.mo
					P_SetMobjStateNF(planetoid, S_PLANETSUN)
					planetoid.height = 96
					planetoid.radius = 96
					planetoid.tics = 31
					planetoid.reactiontime = 5
					
					planetoid = P_SpawnMobj(
							player.mo.x+(cos(ANG60)*150),
							player.mo.y+(sin(ANG60)*150),
							player.mo.z,
							MT_PLANETOID)
					planetoid.target = player.mo
					P_SetMobjStateNF(planetoid, S_PLANETMOON)
					planetoid.height = 75
					planetoid.radius = 75
					planetoid.tics = 31
					planetoid.reactiontime = 4
					
					planetoid = P_SpawnMobj(
							player.mo.x+(cos(ANGLE_270)*150),
							player.mo.y+(sin(ANGLE_270)*150),
							player.mo.z,
							MT_PLANETOID)
					planetoid.target = player.mo
					P_SetMobjStateNF(planetoid, S_PLANETRINGED)
					planetoid.height = 50
					planetoid.radius = 50
					planetoid.tics = 31
					planetoid.reactiontime = 6
				end
			
			elseif (player.transtime < 70)
				player.mo.frame = ((player.transtime/3) % 4) + 3
				player.mo.momz = 0
			else
				player.transtime = 0
				if (player.readyforpowershare) then //And THIS is to go even FURTHER BEYOND
					player.premysticscolor = player.mo.color
					player.mysticsuper = 24 //SMS stop i already did my overdramatic transformation sequence you don't need to do another one
				else
					player.powers[pw_super] = 1
					player.mo.state = S_PLAY_NASYA_TUMBLE
					S_ChangeMusic("_SUPER", true, player)
				end
			end
			
		elseif  (P_IsObjectOnGround(player.mo) or player.mo.skipready) then //On ground / wallcling behavior
		
			player.pitbounce = 3

			if (player.charged > 0) then
				local stepOffset = 10
				if (player.stepfoot == 0) then stepOffset = $1*-1 end
				
				local starcharge = P_SpawnMobj(player.mo.x+(sin(player.drawangle)*stepOffset),
															player.mo.y+16,
															player.mo.z+(cos(player.drawangle)*stepOffset),
															MT_STARCHARGE)
				starcharge.scale = ((player.charged-1)*FRACUNIT)/10
			end
			
			if (player.mo.skipready) then
				player.mo.momz = 0
				player.drawangle = player.mo.drawangle
			end
			if (player.mo.eflags & MFE_JUSTHITFLOOR) and not (player.pflags & PF_STASIS) then
				player.oldmomx = player.mo.momx
				player.oldmomy = player.mo.momy
				player.oldmomz = player.mo.momz
				player.oldspeed = P_AproxDistance(player.speed, player.mo.momz)
				if (player.stepfoot == 0) then player.stepfoot = 1
				else player.stepfoot = 0 end
				player.mo.state = S_PLAY_NASYA_STEP
			else
				if (player.charged <= 0) then
					player.oldmomx = 0
					player.oldmomy = 0
					player.oldmomz = 0
					player.oldspeed = 0
				end
			end
		
		
			
		
		if (player.mo.state == S_PLAY_NASYA_STEP) then
			local stepframe = (19-player.mo.tics)/5
			if (stepframe > 2) stepframe = 2 end
			if (player.stepfoot == 1) then stepframe = $1+3 end
			player.mo.frame = stepframe
		elseif (player.mo.state == S_PLAY_CLING) then
				local angledist = (AngleFixed(player.drawangle)/FRACUNIT)-(AngleFixed(player.mo.angle)/FRACUNIT)
				angledist = $1+45
				angledist = ($1+360)%360
				angledist = (($1)/90)
				player.mo.frame = angledist
		end
		
		
			if (player.mo.standingslope) then
				player.mo.slopeangle = R_PointToAngle2(
																	0,P_GetZAt(player.mo.standingslope, player.mo.x, player.mo.y),
																	FRACUNIT*2,P_GetZAt(player.mo.standingslope, player.mo.x+(cos(player.mo.angle)*2), player.mo.y+(sin(player.mo.angle)*2))
																	)
			else
				player.mo.slopeangle = 0
			end
			
			
			if (player.mo.steppause > 0) then
				player.mo.steppause = $1-1
				player.mo.momx = 0
				player.mo.momy = 0
				if (player.charged > 0) then
                    player.charged = 20
                end
		
			else
				if (player.cmd.forwardmove
					or player.cmd.sidemove) then
						player.drawangle = player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT)
						player.mo.z = $1+player.mo.pmomz
						if (player.charged > 0) then			
							player.mo.momz = FixedMul(sin(player.mo.slopeangle), player.oldspeed+(6*FRACUNIT))+cos(player.mo.slopeangle)
							P_InstaThrust(player.mo, player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT), 
												FixedMul(player.oldspeed+(6*FRACUNIT),cos(player.mo.slopeangle)) )
							P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,player.thokitem)
						else
							if player.oldspeed == 0 or player.mo.skipready  then
								player.mo.momz = (sin(player.mo.slopeangle)*15)+cos(player.mo.slopeangle)
								P_InstaThrust(player.mo, player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT),
								15*cos(player.mo.slopeangle)
								)
							else
                                player.mo.momx = player.oldmomx
                                player.mo.momy = player.oldmomy
								player.mo.momz = $1+FRACUNIT
							end
						end
						S_StartSound(player.mo,sfx_jump,player)
						if player.mo.momz < FRACUNIT then
							player.mo.momz = FRACUNIT
						end
						player.mo.steppause = 3
						player.mo.state = S_PLAY_NASYA_FLY
						player.mo.skipready = false
						player.charged = 0
				
					end
					
					if (player.jumpdown > 0) then
						if (player.charged > 0) then 
							player.charged = 10
						end
						
						local jumphorizangle = 0
						
						if (player.mo.skipready) then //180 degree jump angle from walls
							player.jumpangle = ANGLE_270-((player.jumpdown % 72) * ANG1 * 5)
							
							
							local anglediff = abs(AngleFixed(player.mo.angle-player.drawangle)/FRACUNIT)
							jumphorizangle = player.mo.angle
							if (player.jumpangle > ANGLE_90*-1 and player.jumpangle < ANGLE_90) then
								if (anglediff < 90)  then
									jumphorizangle = player.drawangle + ANGLE_90
								elseif (anglediff > 270)
									jumphorizangle = player.drawangle - ANGLE_90
								end
							end
							
						else //90 degree-ish jump angle from the ground
							player.jumpangle = ((player.jumpdown % 36) * ANG1 * 5)
							jumphorizangle = player.mo.angle
							if (player.jumpangle > ANGLE_90 ) then
								player.jumpangle = ANGLE_90-($1% ANGLE_90)
							end
							if (player.jumpangle < ANG10) then
								player.jumpangle = ANG10
							end
						end
						local indidistance = (16*FRACUNIT)+(player.oldspeed/2)
						for i = 1, 5 do
							local jumplength = FixedMul(cos(player.jumpangle),indidistance)
							local starcharge = P_SpawnMobj(
								player.mo.x+FixedMul(jumplength*i,cos(jumphorizangle)),
								player.mo.y+FixedMul(jumplength*i,sin(jumphorizangle)),
								player.mo.z+FixedMul(sin(player.jumpangle),indidistance*i),
								MT_STARCHARGE)
							starcharge.scale = FRACUNIT/4
						end
				
					end
				if (player.jumpdown == -1) then
						
						local jumphorizangle = player.mo.angle
						if (player.mo.skipready) then
							local anglediff = abs(AngleFixed(player.mo.angle-player.drawangle)/FRACUNIT)
							if (player.jumpangle > ANGLE_90*-1 and player.jumpangle < ANGLE_90) then
								if (anglediff < 90)  then
									jumphorizangle = player.drawangle + ANGLE_90
								elseif (anglediff > 270)
									jumphorizangle = player.drawangle - ANGLE_90
								end
							end
						end
						if (player.charged > 0 and player.oldspeed > (FRACUNIT*5)) then	
							P_InstaThrust(player.mo, jumphorizangle, cos(player.jumpangle)*((player.oldspeed)/FRACUNIT))
							player.mo.momz = sin(player.jumpangle)*((player.oldspeed)/FRACUNIT)
							P_SpawnMobj(player.mo.x,player.mo.y,player.mo.z,player.thokitem)
						else
							P_InstaThrust(player.mo, jumphorizangle, cos(player.jumpangle)*5)
							player.mo.momz = sin(player.jumpangle)*5
						end
						S_StartSound(player.mo,sfx_jump,player)
						player.mo.steppause = 3
						player.mo.state = S_PLAY_NASYA_FLY
						player.mo.skipready = false
						
					end
				
			end
		else //In air behavior
		
		//death pit immunity
		if ((player.mo.subsector.sector.special == 6 or player.mo.subsector.sector.special == 7) and player.pitbounce > -1) then
			local starcharge = P_SpawnMobj(player.mo.x,player.mo.y,player.mo.subsector.sector.floorheight+(16*FRACUNIT),MT_STARCHARGE)
			starcharge.state = S_STARCHARGE2
			starcharge.scale = (FRACUNIT/2)*player.pitbounce
			local overFloorHeight = player.mo.z-player.mo.subsector.sector.floorheight
			if overFloorHeight < 32*FRACUNIT then
				if (overFloorHeight < FRACUNIT*8) and player.pitbounce then
					player.pitbounce = $1-1
					P_TeleportMove(player.mo, player.mo.x, player.mo.y, player.mo.z+(FRACUNIT*8) )
					player.mo.momz = 0
					S_StartSound(player.mo,sfx_spin,player)
				end
				if (player.mo.momz < -1*FRACUNIT and player.pitbounce) then
					local speedCap = (overFloorHeight/2)*-1
					if (player.mo.momz < speedCap) then
						player.mo.momz = speedCap
					end
				elseif (player.mo.momz > -1*FRACUNIT)
					player.mo.momz = (overFloorHeight/2)
				end
				
			end
		end
		if(player.powers[7]) and not player.powers[6] then
			player.extrabreath = $1+1
			if (player.extrabreath == 2) then
				player.extrabreath = 0
				player.powers[7] = $1+1
			end
		elseif (player.extrabreath)
			player.extrabreath = 0
		end
		//Extra midair control for reasons
		if player.cmd.forwardmove
		or player.cmd.sidemove
			if (player.powers[pw_super] == 0)
				P_Thrust(player.mo, player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT), 5000)
			else
				P_Thrust(player.mo, player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT), 50000)					
				player.pitbounce = 3
			end
		end
		
		if (player.mo.state == S_PLAY_NASYA_FLY and player.speed > player.runspeed) then
			player.mo.state = S_PLAY_RUN
		end
		if (player.mo.staet == S_PLAY_RUN and player.speed < player.runspeed) then
			player.mo.state = S_PLAY_NASYA_FLY
		end
		
		if (player.mo.state != S_PLAY_NASYA_TUMBLE) and (player.mo.state != S_PLAY_PAIN) then //Special gravity effects
			player.mo.momz = $1-P_GetMobjGravity(player.mo)
			player.mo.momz = $1-(FRACUNIT/20)
		end
		
		if (P_GetMobjGravity(player.mo) > 0) and (player.mo.eflags & MFE_VERTICALFLIP) then //Inverted gravity immunity
			if (player.mo.flags2 & MF2_OBJECTFLIP)
				player.mo.flags2 = $1&~MF2_OBJECTFLIP
			else
				player.mo.flags2 = $1|MF2_OBJECTFLIP
			end
		end
		
		if (player.jumpdown == 1 and player.mo.state != S_PLAY_NASYA_TUMBLE) then
			player.mo.state = S_PLAY_NASYA_TUMBLE
			player.mo.tics = -1
		elseif (player.jumpdown == 1 and player.mo.state == S_PLAY_NASYA_TUMBLE) then
			player.mo.state = S_PLAY_NASYA_FLY
		elseif (player.mo.state == S_PLAY_WALK or player.mo.state == S_PLAY_NASYA_STEP)
			player.mo.state = S_PLAY_NASYA_FLY
		elseif player.mo.state == S_PLAY_SPRING
			player.mo.state = S_PLAY_NASYA_TUMBLE
		end
		
		if (player.mo.state == S_PLAY_NASYA_FLY or player.mo.state == S_PLAY_RUN or player.mo.state == S_PLAY_FLOAT_RUN) then
			if (player.stepfoot == 0 and player.mo.frame > 2) then player.mo.frame = $1%3
			elseif (player.stepfoot == 1 and player.mo.frame < 3) then player.mo.frame = $1+3 end
		end
		
		if (player.mo.state == S_PLAY_NASYA_TUMBLE) then
		
			player.tumbletime = $1+3
			player.mo.frame = (player.tumbletime/3) % 15
		end
		player.mo.speed = player.speed
		player.mo.lastline = nil
			if player.mo.skipready then
				player.mo.momz = 1
			end
		end
	end
end)


addHook("JumpSpecial", function(player)
	if not (player.mo.skin == "nasya") then 	return end
	if (player.transtime ~= 0) then 	return end
	if ((player.pflags & PF_SLIDING) or (player.powers[pw_carry] & CR_ROPEHANG) or (player.powers[pw_carry] & CR_ROLLOUT) ) then
		if (player.mo.tracer) then
			player.mo.tracer.tracer = nil
		end
		player.mo.z = $1+FRACUNIT
		player.mo.momz = 10*FRACUNIT
		player.oldmomz = 10*FRACUNIT
		S_StartSound(player.mo,sfx_jump,player)
		player.mo.steppause = 3
		player.mo.state = S_PLAY_NASYA_FLY
		player.mo.skipready = false
		player.powers[pw_carry]  = 0
	end

end, false)


addHook("SpinSpecial", function(player)
if not (player.mo.skin == "nasya" or player.cantwirl) then 	return end
if (player.transtime) then return end
if (player.cmd.buttons & BT_JUMP) then return end
	if (player.twirling == 0 or (player.powers[pw_shield] & SH_PROTECTELECTRIC and player.twirling < 10)) 
	and not P_IsObjectOnGround(player.mo)
	and not player.mo.skipready  then
		S_StartSound(player.mo,sfx_nyspin,player)
		player.mo.skipready = false
		player.twirling = 20
		player.mo.state = S_PLAY_NASYA_TWIRL
		//default star particle effects
		local starcount = 3
		local stardist = 20
		local starelement = S_STARAURAN
		local starsize = FRACUNIT
		local staraurasize = FRACUNIT
		local angleincrement = ANGLE_90
		local painchance = 0
		local starspeed = 20
		//Weird shit caused by shields
		
		if (player.powers[pw_shield] & SH_WHIRLWIND) then
			starelement = S_STARAURAWIND
			staraurasize = FRACUNIT*2
			player.mo.momz = $1+FRACUNIT
		end
		
		if (player.powers[pw_shield] & SH_PROTECTWATER) then
			starelement = S_STARAURABUBBLE
			staraurasize = FRACUNIT
			starsize = starsize/2
			starcount = 7
			angleincrement = ANGLE_45
			stardist = 20
			starspeed = 30
		end
		
		if (player.powers[pw_shield] & SH_PROTECTELECTRIC) then
			starelement = S_STARAURAELECTRIC
			staraurasize = FRACUNIT/4
			stardist = 20
			starspeed = 0
		end
		
		if (player.powers[pw_shield] & SH_PROTECTFIRE) then
			starelement = S_STARAURAFIRE
			staraurasize = FRACUNIT
			starsize = starsize*2
			angleincrement = ANGLE_90
			starcount = 3
			stardist = 20
			starspeed = 30
		end
		
		if (player.powers[pw_shield] & SH_FORCE) then
			painchance = 1
			starcount = 7
			angleincrement = ANGLE_45
			starsize = FRACUNIT/2
			player.mo.state = S_PLAY_NASYA_FLY
			player.drawangle = player.cmd.angleturn<<16 + R_PointToAngle2(0, 0, player.cmd.forwardmove*FRACUNIT, -player.cmd.sidemove*FRACUNIT)
			P_InstaThrust(player.mo, player.drawangle, FRACUNIT*35)
			S_StartSound(player.mo,sfx_thok,player)
			
		end
		
		if (player.powers[pw_shield] == SH_ARMAGEDDON) then
			staraurasize = FRACUNIT
			starcount = 7
			angleincrement = ANGLE_45
			stardist = 60
			starspeed = 60
			P_BlackOw(player)
		end
		
		
		if (player.powers[pw_super]) then
			staraurasize = FRACUNIT
			starsize = starsize*2
			starcount = 7
			angleincrement = ANGLE_45
			stardist = 30
			starspeed = 30
		end
		
		for i = 0, starcount do
			local starspinner = P_SpawnMobj(player.mo.x,player.mo.y+(player.mo.height/3),player.mo.z,MT_STARSPIN)
			starspinner.target = player.mo
			starspinner.angle = angleincrement*i
			starspinner.reactiontime = stardist
			starspinner.scale = starsize
			starspinner.mass = staraurasize
			starspinner.raisestate = starelement 
			starspinner.painchance = painchance
			starspinner.speed = starspeed
		end
	end
	
end, false)



addHook("MobjLineCollide", function(player, line) 
	player.lastline = line
	return nil

end, MT_PLAYER)


addHook("MobjMoveBlocked", function(player) 
		if (player.player == nil) then
			return
		end
		if player.skin ~= "nasya" then
			return
		end
		if (player.lastline) then
			if (player.lastline.frontsector) then
				if (player.lastline.frontsector.ceilingpic == "F_SKY1") then
					if (player.z > player.lastline.frontsector.ceilingheight) then
						return
					end
				end
			end
			if (player.lastline.backsector) then
				if (player.lastline.backsector.ceilingpic == "F_SKY1") then
					if (player.z > player.lastline.backsector.ceilingheight) then
						return
					end
				end
			end
			if (player.lastline.flags & ML_NOCLIMB) then
				return
			end
				if ((player.z - player.floorz) > 10*FRACUNIT) then
					if player.state != S_PLAY_NASYA_TUMBLE then
						local cpx,cpy = P_ClosestPointOnLine(player.x,player.y,player.lastline)
						player.drawangle = R_PointToAngle2(player.x,player.y,cpx,cpy)
						player.skipready = true
						player.momz = 0
						player.momx = 0
						player.momy = 0
						player.steppause = 5
						player.state = S_PLAY_CLING
					end
			end
		end
		return nil
end, MT_PLAYER)

addHook("MobjDeath", function(player) 
	player.state = S_PLAY_DEAD
end, MT_PLAYER)

function A_StarAura(actor, var1, var2)
			for rover in actor.subsector.sector.ffloors()
				if rover.flags & FF_BUSTUP and rover.flags & FF_EXISTS then
					if (rover.bottomheight < actor.z+(actor.height*2)) and (rover.topheight > actor.z-(actor.height*2)) then
						EV_CrumbleChain(rover)
					end
				end
			end
			actor.momz = FRACUNIT*-1
			actor.flags = MF_NOGRAVITY|MF_MISSILE|MF_RUNSPAWNFUNC
			actor.state = actor.reactiontime
end

local function PlanetoidSearch(refmob, foundmob) 
	if not (foundmob) then //Why can this happen exactly???
		return nil
	end
	if not (
	( (foundmob.flags & MF_SHOOTABLE) or (foundmob.flags2 & MF2_INVERTAIMABLE) )and 
	( (foundmob.flags & MF_ENEMY) or (foundmob.flags & MF_BOSS) ) and 
	foundmob.markedfordeath == nil and 
	foundmob.health > 0) then
		return nil
	end
	if (refmob.tracer == nil) then
		refmob.tracer = foundmob
		foundmob.markedfordeath = true
//	elseif (R_PointToDist2(refmob.x, refmob.y, foundmob.x,foundmob.y) < R_PointToDist2(refmob.x, refmob.y, refmob.tracer.x,refmob.tracer.y))
//		refmob.tracer = foundmob
	end

end

addHook("MobjDamage", function(target, inflictor, source, damage, damagetype)
	target.markedfordeath = nil
return nil
end)

function A_PlanetoidThink(actor, var1, var2)
	if not (actor.target and actor.target.valid and actor.target.player) then
		actor.state = S_NULL
		return
	end
	if (actor.target.player.powers[pw_super] == 0 and not actor.target.player.mysticsuper) then
		actor.state = S_NULL
		return
	end
	if (actor.tracer and actor.tracer.valid) then
		if (actor.tracer.markedfordeath) then
			local staraura = P_SpawnMobj(actor.x+(P_RandomRange(actor.radius/-2,actor.radius/2)*FRACUNIT),
			actor.y+(P_RandomRange(actor.radius/-2,actor.radius/2)*FRACUNIT),
			actor.z+(P_RandomRange(actor.radius/-2,actor.radius/2)*FRACUNIT), MT_STARAURA)
				staraura.target = actor.target
				staraura.reactiontime = S_STARAURAPLANET
				staraura.scale = FRACUNIT*4
			actor.angle = R_PointToAngle2(actor.x, actor.y, actor.tracer.x, actor.tracer.y)
			actor.momx = (actor.tracer.x-actor.x)/5
			actor.momy = (actor.tracer.y-actor.y)/5
			actor.momz = (actor.tracer.z-actor.z)/5
		else
			actor.tracer = nil
		end

	else
		local searchrange = 1024*FRACUNIT
		searchBlockmap("objects", PlanetoidSearch, actor, actor.target.x-searchrange, actor.target.x+searchrange, actor.target.y-searchrange, actor.target.y+searchrange)
		local targetx = actor.target.x+(actor.target.momx*20)
		local targety = actor.target.y+(actor.target.momy*20)
		local targetangle = R_PointToAngle2(actor.x, actor.y, targetx, targety)
		
		if (targetangle-actor.angle < 0) then
			actor.angle = $1-(ANG1*actor.reactiontime)
		else
			actor.angle = $1+(ANG1*actor.reactiontime)
		end
		
		actor.momz = ((actor.target.z+actor.target.height)-actor.z)/5
		P_InstaThrust(actor,  actor.angle, FRACUNIT*20)
		local targetDist = R_PointToDist2(actor.x,actor.y, targetx, targety) 
		P_Thrust(actor, targetangle, targetDist/50)
	end
end


function A_StarSpinner(actor, var1, var2)
if not (actor.target) then
	return
end
	actor.angle = $1-ANG20
	local flydist = (actor.speed-actor.reactiontime)*5
	if (actor.painchance) then
	
		P_TeleportMove(actor,
		actor.target.x + FixedMul(flydist*sin(actor.angle), cos(actor.target.player.drawangle+ANGLE_90) ),
		actor.target.y + FixedMul(flydist*sin(actor.angle), sin(actor.target.player.drawangle+ANGLE_90) ),
		actor.target.z + flydist*cos(actor.angle) +(32*FRACUNIT) )
	else
		P_TeleportMove(actor,
		actor.target.x + cos(actor.angle)*flydist,
		actor.target.y + sin(actor.angle)*flydist,
		actor.target.z + 32*FRACUNIT)
	end
	actor.reactiontime = $1-1
	local staraura = P_SpawnMobj(actor.x+(P_RandomRange(-10,10)*FRACUNIT),
	actor.y+(P_RandomRange(-10,10)*FRACUNIT), 
	actor.z+(P_RandomRange(-10,10)*FRACUNIT), 
	MT_STARAURA)
	staraura.target = actor.target
	staraura.raisetate = actor.raisestate
	staraura.reactiontime = actor.raisestate
	staraura.scale = actor.mass

	if actor.reactiontime == 0 then
		actor.state = S_NULL
	end
end


addHook("ShouldDamage", function(p, inflictor, source, damage, damagetype)
	if (p.player == nil) then
		return
	end
	if p.skin ~= "nasya" then 
		return nil
	end
	if not (inflictor) or not (source) then
		return nil
	end
	if (p.player.transtime) then
		return false
	end
	if (inflictor ~= source) then
		return nil
	end
	if (p.player.twirling > 0) then
		P_DamageMobj(inflictor, p, p, 1)
		return false
	end
		return nil
	
	
	
end, MT_PLAYER)