task TShadow
	{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "../system/img/WhiteSquare.png");	
	ObjSprite2D_SetSourceRect(obj,0,0,1,1);
	ObjSprite2D_SetDestRect(obj,-64,-64,GetStgFrameWidth+64,GetStgFrameHeight+64);
	ObjRender_SetColorHSV(obj,0,0,0);
	Obj_SetRenderPriority(obj,0.3);
	ascent(t in 1..36)
		{
		ObjRender_SetAlpha(obj,t*255/35);
		yield;
		}
	while(SpellSwitch == false){yield;}
	loop(25){yield;}
	descent(t in 0..20)
		{
		ObjRender_SetAlpha(obj,t*255/20);
		yield;
		}
	Obj_Delete(obj);
	}

task TKoiSpell
{
	let spell = GetSpellManageObject();
	let path = PlayerPath;
	let scaleX = ObjRender_GetScaleX(objPlayer);
	let scaleY = ObjRender_GetScaleY(objPlayer);
	ObjRender_SetScaleXYZ(objPlayer,1,1,0);
	PlayerPath = GetCurrentScriptDirectory ~ "./pl1/Sprite.png";
	SpellSwitch = false;
	ShotPermit = false;
	SetPlayerSpeed(7.5,7.5);
	TShadow;
	let spread = 3;
	SetPlayerInvincibilityFrame(6*5*10+120);
	let alpha = 255;
	ascent(t in 0..6)
		{
		ascent(i0 in 0..5)
			{
			ascent(i1 in 0..spread+1)
				{
				TSpam(GetStgFrameWidth+8,(i1+i0*0.15+t*0.05)*GetStgFrameHeight/spread,180,0);
				TSpam((i1+i0*0.15+t*0.05)*GetStgFrameWidth/spread,-8,90,1);
				}
			PlaySound("se_PlayerShot2",120);
			loop(10)
				{
				if(alpha > 0)
					{
					alpha-=255/36;
					ObjRender_SetAlpha(objPlayer,alpha);
					}
				yield;
				}
			}
		}
	loop(30){yield;}
	PlaySound("se_Die5",120);
	SpellSwitch = true;
	ShotPermit = true;
	SetPlayerSpeed(PlayerSpeed[0],PlayerSpeed[1]);
	ascent(t in 1..21)
		{
		ObjRender_SetAlpha(objPlayer,t*255/20);
		yield;
		}
	ObjRender_SetScaleXYZ(objPlayer,scaleX,scaleY,0);
	PlayerPath = path;
	Obj_Delete(spell);

	task TSpam(x,y,angle,graph)
		{
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		Obj_SetRenderPriority(obj,0.5);
		let scale = 8;
		let scaleM = 64;	
		let damage = false;
		let alpha = 255;
		while(!Obj_IsDeleted(obj) && x > -9 && x < GetStgFrameWidth+9 && y > -9 && y < GetStgFrameHeight+9)
			{
			if(GetDistance(GetPlayerX,GetPlayerY,x,y) < 64 && SpellSwitch == false)
				{
				if(scale < scaleM)
					{
					scale+=scaleM/7;
					}
				else
					{
					PlaySound("se_Shot5",100);
					scale=scaleM;
					}
				damage = true;
				ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "pl0/Sprite.png");
				ObjSprite2D_SetSourceRect(obj,graph*64,176,(graph+1)*64,240);
				ObjRender_SetColorHSV(obj,graph,0,255);
				}
			else
				{
				if(scale > 8)
					{
					scale-=(scaleM-8)/7;
					}
				else
					{
					scale = 8;
					ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "../system/img/WhiteCircleAlpha.png");
					ObjSprite2D_SetSourceRect(obj,0,0,64,64);
					}
				damage = false;
				ObjRender_SetColorHSV(obj,graph*240,155,255);
				}
			if(SpellSwitch == true)
				{	
				damage = true;
				alpha-=255/20;
				ObjRender_SetAlpha(obj,alpha);
				scale+=scaleM/20;
				}
			if(damage == true)
				{
				let array = GetAllEnemyID;
				ascent(i in 0..length(array))
					{
					let enemy = array[i];
					if(!Obj_IsDeleted(enemy) && Obj_GetValueD(enemy,"PLAYER",false) == false && GetDistance(x,y,ObjMove_GetX(enemy),ObjMove_GetY(enemy)) <= scale && IsPermitPlayerShot == true)
						{
						let shot = CreatePlayerShotA1(ObjMove_GetX(enemy),ObjMove_GetY(enemy),0,0,0.75,100,0);
						Obj_DelayDelete(shot,2);
						}
					}
				array = GetShotIdInCircleA2(x,y,scale,TARGET_ENEMY);
				ascent(i in 0..length(array))
					{
					let enemy = array[i];
					if(!Obj_IsDeleted(enemy) && ObjShot_IsSpellResist(enemy) == false)
						{		
						ObjShot_ToItem(enemy);
						}
					}
				}
			x+=4*cos(angle);
			y+=4*sin(angle);
			ObjRender_SetPosition(obj,x,y,0);
			ObjSprite2D_SetDestRect(obj,-scale,-scale,scale,scale);
			yield;
			}
		Obj_Delete(obj);
		}
}


task TNueSpell
{

	let spell = GetSpellManageObject();
	GrazeEnable = false;

	SpellSwitch = false;
	TShadow;
	SetPlayerSpeed(5.5,5.5);
		
	SetPlayerInvincibilityFrame(330);

	loop(30){yield;}
	let angle = rand(0,360);
	let dist = 0;
	let spread = 3;
	loop(15)
		{
		PlaySound("se_LaserDelay",120);
		ascent(i in 0..spread)
			{
			let angleA = angle+i*360/spread;
			TSpam(GetPlayerX,GetPlayerY,angleA+150);
			}
		angle+=31;
		dist+=GetStgFrameHeight*0.75/30;
		loop(6){yield;}
		}
	loop(90){yield;}
	SetPlayerSpeed(PlayerSpeed[0],PlayerSpeed[1]);
	PlaySound("se_Die5",100);
	SpellSwitch = true;
	loop(30){yield;}
	Obj_Delete(spell);
	GrazeEnable = true;

	task TSpam(x,y,angle)
		{
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "../system/img/WhiteCircleAlpha.png");
		ObjSprite2D_SetSourceRect(obj,0,0,64,64);
		ObjSprite2D_SetDestRect(obj,0,0,1,1);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetColorHSV(obj,0,205,255);
		Obj_SetRenderPriority(obj,0.45);	
		
		let scaleM = 32;
		let scale = 0;

		let speed = 0;
		let alpha = 0;
		let counter = 0;

		while(x > -scale-2 && x < GetStgFrameWidth+scale+2 && y > -scale-2 && y < GetStgFrameHeight+scale+2)
			{	
			counter+=1;
			if(alpha < 255)
				{
				alpha+=255/45;
				scale+=scaleM/45;
				}
			else
				{
				alpha = 255;
				scale=scaleM;
				}
			if(counter < 120)
				{
				angle+=1;
				}
			ObjRender_SetScaleXYZ(obj,scale*2.25,scale*2.25,0);
			speed+=1/30;
			x+=speed*cos(angle);
			y+=speed*sin(angle);
			ObjRender_SetAngleZ(obj,angle);
			ObjRender_SetAlpha(obj,alpha+rand(-55,0));
			ObjRender_SetPosition(obj,x,y,0);
			let array = GetAllEnemyID;
			ascent(i in 0..length(array))
				{
				let enemy = array[i];
				if(!Obj_IsDeleted(enemy) && Obj_GetValueD(enemy,"PLAYER",false) == false && GetDistance(x,y,ObjMove_GetX(enemy),ObjMove_GetY(enemy)) <= scale)
					{
					let shot = CreatePlayerShotA1(ObjMove_GetX(enemy),ObjMove_GetY(enemy),1,0,0.55,100,0);
					Obj_DelayDelete(shot,2);
					}
				}
			array = GetShotIdInCircleA2(x,y,scale,TARGET_ENEMY);
			ascent(i in 0..length(array))
				{
				let enemy = array[i];
				if(!Obj_IsDeleted(enemy) && ObjShot_IsSpellResist(enemy) == false)
					{		
					Obj_Delete(enemy);
					}
				}
			yield;
			}
		Obj_Delete(obj);
		}
}

