//スペルとダミースペル
task TSpell
{//時符「デュアルバニッシュ」 
	OnSpell=true;
	SetPlayerInvincibilityFrame_Special(180);//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);

	PlaySE(SE_SPELL1);
	//PlaySE(SE_SPELL2);

	OperationEffect;
	Vanish;
	loop(120){yield;}
	OnSpell=false;

	task Vanish
	{
		Reflect;
		loop(110){yield;}
		Obj_SetValue(objPlayer,"DualVanish",true);
		DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,192,224,512);
		yield;
		Obj_SetValue(objPlayer,"DualVanish",false);
	}

	task Reflect
	{
		loop(109){yield;}
		let PreBulletArray=GetShotIdInCircleA1(GetStgFrameWidth/2,GetStgFrameHeight/2,512);
		loop(1){yield;}
		let BulletArray=GetShotIdInCircleA1(GetStgFrameWidth/2,GetStgFrameHeight/2,512);
		ascent(i in 0..length(BulletArray))
		{
			if(!ObjShot_IsSpellResist(BulletArray[i]))
			{
			if(ObjMove_GetSpeed(BulletArray[i])==0 && ObjMove_GetAngle(BulletArray[i])==0)
			{
				let Sangle=atan2(ObjMove_GetY(BulletArray[i])-ObjMove_GetY(PreBulletArray[i]),ObjMove_GetX(BulletArray[i])-ObjMove_GetX(PreBulletArray[i]));
				ReflectShot(ObjMove_GetX(BulletArray[i]),ObjMove_GetY(BulletArray[i]),Sangle,7.5,i,31);	
			}
			else
			{
			ReflectShot(ObjMove_GetX(BulletArray[i]),ObjMove_GetY(BulletArray[i]),ObjMove_GetAngle(BulletArray[i])+180,7.5,i,31);	
			}
			}
		}
	}
}

task OperationEffect
{
	CircleEffect(GetPlayerX,GetPlayerY);
	WhiteEffect;
	loop(30){yield;}
	ReverseEffect;

	task CircleEffect(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,70);
		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=184;
		let G=136;
		let B=59;
		ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		loop(60)
		{
			ScalePlus+=ScalePlusSpeed;
			Scale+=ScalePlus;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		loop(15)
		{
			Alpha-=1/15;
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			yield;
		}
		Obj_Delete(obj);
	}

	task WhiteEffect
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		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,640,640);

		ObjRender_SetPosition(obj,320,240,0);

		let Alpha=0;
		let Scale=0;
		let ScalePlus=0;
		let ScalePlusSpeed=0.0125/8*1.33;
		let R=150;
		let G=150;
		let B=150;
		ObjRender_SetColor(obj,R,G,B);
		loop(30)
		{
			Alpha+=255/30;
			ObjRender_SetAlpha(obj,Alpha);
			yield;
		}

		loop(30)
		{
			Alpha-=255/30;
			ObjRender_SetAlpha(obj,Alpha);
			yield;
		}
		loop(50){yield;}
		loop(10)
		{
			Alpha+=255/10;
			ObjRender_SetAlpha(obj,Alpha);
			yield;
		}
		loop(10)
		{
			Alpha-=255/10;
			ObjRender_SetAlpha(obj,Alpha);
			yield;
		}
		Obj_Delete(obj);
	}


	task ReverseEffect
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,78);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,640,640);

		ObjRender_SetPosition(obj,320,240,0);

		let Alpha=0;
		let Scale=0;
		let ScalePlus=0;
		let ScalePlusSpeed=0.0125/8*1.33;
		loop(90)
		{
			yield;
		}
		Obj_Delete(obj);
	}
}

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