//�X�y���ƃ_�~�[�X�y��
task TSpell
{//�d��u�����߂Ȃ��P���_�v 
	OnSpell=true;
	SetPlayerSpeed(1.5,0.6);
	SetPlayerInvincibilityFrame_Special(285);//���G���Ԃ�ݒ�
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);

	PlayVol(SE_SPELL1, 56);
	PlayVol(SE_SPELL2, 56);
	Rod;
	OperationEffect;

	loop(255){yield;}
	OnSpell=false;
	SetPlayerSpeed(4.5,2.0);

	task Rod
	{
		let RodAngle=[0,34,61,85,106,120,135,147,156,163,168,172,175,177,178,179,179.5,179.75,179.875,179.9375];
		loop(4)
		{
		RodAttack(1);
		Twist(1);
		descent(i in 0..20)
		{
		RodEffect(360-RodAngle[i],1,0);
		RodAttack_Erase(360-RodAngle[i]);
		yield;
		}
		ShockEffect;
		TShake();
		loop(10)
		{
		RodEffect(360,1,1);
		yield;
		}
		RodAttack(-1);
		Twist(-1);
		descent(i in 0..20)
		{
		RodEffect(180-RodAngle[i],-1,0);
		RodAttack_Erase(180+RodAngle[i]);
		yield;
		}
		ShockEffect;
		TShake();
		loop(10)
		{
		RodEffect(180,-1,1);
		yield;
		}
		}
	}

	task Twist(dir)
	{
		loop(12)
		{
			SpellMove+=1*dir;
			ObjRender_SetX(objPlayer,GetPlayerX+3/12*dir);
			yield;
		}
		SpellMove=0;
		loop(8)
		{
			SpellMove-=1+dir;
			ObjRender_SetX(objPlayer,GetPlayerX-15/8*dir);
			yield;
		}
		SpellMove=0;
	}

	task RodAttack(dir)
	{
		let obj = ObjSpell_Create();
		ObjSpell_Regist(obj);
		ObjSpell_SetDamage(obj, 400);
		loop(12){yield;}
		ObjSpell_SetIntersectionCircle(obj,GetPlayerX+135*cos(270-70*dir),GetPlayerY+135*sin(270-70*dir),45);
		loop(3){yield;}
		ObjSpell_SetIntersectionCircle(obj,GetPlayerX,GetPlayerY-120,60);
		loop(2){yield;}
		ObjSpell_SetIntersectionCircle(obj,GetPlayerX+135*cos(270+70*dir),GetPlayerY+135*sin(270+70*dir),45);
		loop(1){yield;}
		Obj_Delete(obj);
	}

	task RodAttack_Erase(angle)
	{
		let obj = ObjSpell_Create();
		ObjSpell_Regist(obj);
		ObjSpell_SetDamage(obj, 0);
		ObjSpell_SetIntersectionLine(obj,GetPlayerX,GetPlayerY,GetPlayerX+180*cos(angle),GetPlayerY+180*sin(angle),30);
		loop(1){yield;}
		Obj_Delete(obj);
	}

	task RodEffect(Zangle,dir,StopFlag)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_ROD);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -6, -121, -0);
		ObjPrim_SetVertexPosition(obj, 1, 174, -121, -0);
		ObjPrim_SetVertexPosition(obj, 2, 174, 33, 0);
		ObjPrim_SetVertexPosition(obj, 3, -6, 33, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 102);
		ObjPrim_SetVertexUVT(obj, 1, 180, 102);
		ObjPrim_SetVertexUVT(obj, 2, 180, 256);
		ObjPrim_SetVertexUVT(obj, 3, 0, 256);

		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAngleX(obj,90-90*dir);

		//let Zangle=-num*60;
		let Alpha=1;
		let AlphaMax=Alpha;
		let R=255;
		let G=255;
		let B=200+55*dir;
		if(StopFlag)
		{
		G/=2;B/=2;
		}
		let Scale=1.0;
		let ScaleMax=Scale;
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		loop(8)
		{
			//
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			if(StopFlag)
			{
			G-=255/16;
			}
			else
			{
			G-=255/8;
			}
			Alpha-=1/8;
		//	Scale-=ScaleMax/12;
			yield;
		}
		Obj_Delete(obj);	
	}

	task ShockEffect
	{
		PlayVol(SE_SPELL3, 60);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOCK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

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

		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

		//let Zangle=-num*60;
		let Alpha=1;
		let AlphaMax=Alpha;
		let R=255;
		let G=96;
		let B=96;
		let Scale=0;
		let ScaleSpeed=0.09;
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		loop(20)
		{
			//
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			Alpha-=1/20;
			Scale+=ScaleSpeed;
			ScaleSpeed-=ScaleSpeed/20;
			yield;
		}
		Obj_Delete(obj);
	}

	task TShake()
	{
		loop(8)
		{
			Set2DCameraFocusX(GetStgFrameWidth / 2 + 10*rand_degree);
			Set2DCameraFocusY(GetStgFrameHeight / 2 + 10*rand_degree);
			yield;
		}
		Reset2DCamera();
	}
}

task OperationEffect
{
	ShockEffect;
	task ShockEffect
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOCK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

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

		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

		//let Zangle=-num*60;
		let Alpha=0.2;
		let AlphaMax=Alpha;
		let R=255;
		let G=50;
		let B=50;
		let Scale=0;
		let ScaleSpeed=0.005;
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		loop(180)
		{
			//
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		//	Alpha-=1/20;
			Scale+=ScaleSpeed;
			ScaleSpeed+=0.0005;
			yield;
		}
		loop(75){yield;}
		Obj_Delete(obj);
	}
}

task DummySpell
{//���ꖳ�G�V�X�e���p
	SetPlayerInvincibilityFrame(0);//���G���Ԃ�ݒ�
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	if(OnSpell)
	{
		SetPlayerSpeed(1.5*2,0.6*2);	
	}
	else
	{
		SetPlayerSpeed(4.5*2,2.0*2);
	}
	yield;
	if(OnSpell)
	{
		SetPlayerSpeed(1.5,0.6);	
	}
	else
	{
		SetPlayerSpeed(4.5,2.0);
	}
}