//スペルとダミースペル
task TSpell{	//幻符「殺人ドール」 
	OnSpell = true;
	SetPlayerInvincibilityFrame_Special(210);//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	
//	PlaySE(SE_EXPLODE);
	PlaySE(SE_EXPLODE2);
	
//	OperationEffect;
	Vanish;
	loop(180){	yield;	}
	OnSpell = false;
	
	task Vanish{
		let ang = 0;
		let way = 2;
		let dDamage = 1.5;
		let ids = [30,31];
		let type = 0;
		
		loop(60){
			loop(way){
				DollShot(ang,dDamage,ids[type],0);
				DollShot(ang,dDamage,ids[type],1);
				ang += 360 / way;
			}
			ang -= 3;
			ang %= 360;
			type++;
			type %= 2;
			yield;
		}
	}
	
	task DollShot(ang,damage,id,type){
		let speed = 22.5;
		let obj = CreatePlayerShotA1(GetPlayerX(),GetPlayerY(),0,ang,0,500,id);
		let dmy = CreatePlayerShotA1(GetPlayerX(),GetPlayerY(),0,ang,0,1,id);
		Obj_SetRenderPriorityI(obj,40);
		ObjShot_SetSpellFactor(obj,true);
		ObjShot_SetEraseShot(obj,true);
		Obj_SetRenderPriorityI(dmy,40);
		ObjShot_SetSpellFactor(dmy,true);
		ObjRender_SetAlpha(dmy,0);
//		let scale = 1.0;
//		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let count = 0;
		let AngleZ = 270;
		let spd = [1.5,1.8][type];
		loop(60){
			if(Obj_IsDeleted(obj)){	return;	}
			AngleZ += 12;
			ObjMove_SetAngle(obj,AngleZ);
			ObjMove_SetPosition(obj,ObjMove_GetX(obj)+spd*cos(ang),ObjMove_GetY(obj)+spd*sin(ang));
			ObjMove_SetPosition(dmy,ObjMove_GetX(obj),ObjMove_GetY(obj));
			yield;
		}
		ObjShot_SetDamage(obj,damage);
		ObjShot_SetDamage(dmy,damage);
		let EnemyObjectArray=GetIntersectionRegistedEnemyID;
		if(length(EnemyObjectArray) != 0){
			let dPos = [-9,9][type];
			ascent(i in 0..length(EnemyObjectArray)){
				ang = atan2(ObjMove_GetY(EnemyObjectArray[i])-ObjMove_GetY(obj)+dPos*cos(ang),ObjMove_GetX(EnemyObjectArray[i])-ObjMove_GetX(obj)+dPos*sin(ang));
			}
		}
		ObjMove_SetAngle(obj,ang);
		ObjMove_SetSpeed(obj,speed);
		while(!Obj_IsDeleted(obj)){
			if(Obj_IsDeleted(dmy)){
				HitEffect(ObjMove_GetX(obj),ObjMove_GetY(obj),speed,ang);
				HitEffect2(ObjMove_GetX(obj),ObjMove_GetY(obj),speed,ang);
				break;
			}
			ObjMove_SetPosition(dmy,ObjMove_GetX(obj),ObjMove_GetY(obj));
			yield;
		}
	}
	
	task HitEffect(x,y,speed,angle){
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,angle+90);
		
		ObjPrim_SetDestCenter(obj,144,96,160,128);
//		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}
		
		ObjRender_SetPosition(obj,x,y,0);
		speed/=8;
		let Scale=1;
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
		loop(3){
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
//		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		loop(3){
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,32,160,64);
//		if(id==10){ObjPrim_SetDestCenter(obj,160,32,176,64);}
		
		loop(3){
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		Obj_Delete(obj);
	}
	
	task HitEffect2(x,y,speed,angle){
		angle+=180+rand(-90,90);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		
		ObjPrim_SetDestCenter(obj,144,96,160,128);
//		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}
		
		ObjRender_SetPosition(obj,x,y,0);
		speed=rand(2.5,5);
		let Scale=1;
		let Alpha=0.5;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=angle+90;
		let ZanglePlus=rand(10,20)*rand_dir;
		loop(10){
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
//		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		
		loop(5){
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obj);
	}
}

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);
	}
}