//スペルとダミースペル
task TSpell
{//マジックアブソーバー 
	OnSpell=true;
	SetPlayerInvincibilityFrame_Special(200);//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);

	PlaySE(SE_SPELL1);
	PlaySE(SE_SPELL2);
	Absorber;

	loop(520){yield;}
	OnSpell=false;

	task Absorber
	{
		let AbsorberX=GetPlayerX;
		let AbsorberY=GetPlayerY;
		AbsorberEffect(AbsorberX,AbsorberY,0.625,1);
		AbsorberEffect(AbsorberX,AbsorberY,0.500,-1);
		AbsorberEffect(AbsorberX,AbsorberY,0.375,1);
		Erase;
		loop(5){yield;}
		WaveEffect(AbsorberX,AbsorberY);
		loop(25){yield;}

		Aura(AbsorberX,AbsorberY,1);
		Aura(AbsorberX,AbsorberY,-1);
		loop(30){yield;}

		let Speed=0;
		let SpeedPlus=0;
		loop(460)
		{
			Speed+=(2*256/460)/460;
			AbsorberY-=Speed;
			
			yield;
		}

		task Erase
		{
			let obj = ObjSpell_Create();
			ObjSpell_Regist(obj);
			ObjSpell_SetDamage(obj, 4.5);
			let Range=0;
			loop(30)
			{
				Range+=72/30;
				ObjSpell_SetIntersectionCircle(obj,AbsorberX,AbsorberY,Range);
				yield;
			}
			loop(490)
			{
				ObjSpell_SetIntersectionCircle(obj,AbsorberX,AbsorberY,Range);
				yield;
			}
		}

		task Aura(x,y,dir)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_ABSORBER);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,38);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);

		ObjPrim_SetDestCenter(obj,0,0,256,256);

		ObjRender_SetPosition(obj,x,y,0);


		let Zangle=0;
		let ZanglePlus=10.5;
		let Alpha=50;
		let AlphaMax=Alpha;
		let R=230;
		let G=180;
		let B=34;

		let distance=0;
		let Scale=0;

		loop(30)
		{
			Scale+=1/30;
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R,G,B);
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		loop(460)
		{
			ObjRender_SetY(obj,AbsorberY);
		//	ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		loop(20)
		{
			Scale-=1/20;
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R,G,B);
			ObjRender_SetAlpha(obj,Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		Obj_Delete(obj);
		}

		task AbsorberEffect(x,y,BaseScale,dir)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_ABSORBER);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,39);

		let ZanglePlus=0;
		if(BaseScale==0.625)
		{
		//	ObjRender_SetBlendType(obj, BLEND_MULTIPLY);
			ZanglePlus=4.5;
		}
		if(BaseScale==0.500)
		{
			ObjRender_SetBlendType(obj, BLEND_ALPHA);
			ZanglePlus=7.5;
		}
		if(BaseScale==0.375)
		{
			ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
		}
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,256,256);

		ObjRender_SetPosition(obj,x,y,0);

		ObjRender_SetAngleZ(obj,0);

		let Zangle=0;
		let Alpha=1;
		let AlphaMax=Alpha;
		let R=255;
		let G=255;
		let B=255;

		let distance=0;
		let Scale=0;
		let Scale2=0.4;

		loop(15)
		{
			Scale+=BaseScale*1.25/15;
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		loop(5)
		{
			Scale-=BaseScale*0.25/5;
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		loop(500)
		{
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			if(BaseScale==0.375)
			{
			Scale=BaseScale*(0.6+Scale2);
			Scale2+=0.02;
			if(Scale2>0.4){Scale2=0;}
			}
			yield;
		}
		loop(20)
		{
			Scale-=BaseScale*1.0/20;
			ObjRender_SetY(obj,AbsorberY);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus*dir;
			yield;
		}
		Obj_Delete(obj);
		}

		task WaveEffect(x,y)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOCK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,79);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,512,512);

		ObjRender_SetPosition(obj,x,y,0);

		let Alpha=1.0;
		let Scale=0;
		let ScalePlus=0;
		let ScalePlusSpeed=0.0125/8*1.33;
		let R=235;
		let G=136;
		let B=16;
		ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		loop(46)
		{
			ScalePlus+=ScalePlusSpeed;
			Scale+=ScalePlus;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		loop(14)
		{
			yield;
		}
		loop(45)
		{
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1/45;
			yield;
		}
		Obj_Delete(obj);
		}
	}
}

task DummySpell
{//特殊無敵システム用
	SetPlayerInvincibilityFrame(0);//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	if(OnSpell)
	{
		SetPlayerSpeed(5.0*2,2.0*2);	
	}
	else
	{
		SetPlayerSpeed(5.0*2,2.0*2);
	}
	yield;
	if(OnSpell)
	{
		SetPlayerSpeed(5.0,2.0);	
	}
	else
	{
		SetPlayerSpeed(5.0,2.0);
	}
}