//スペルとダミースペル
task TSpell
{//妖器「ダークスパーク」  
	OnSpell=true;
	PlayerType*=-1;
	//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	
	SetCommonData("PlayerIconR",255);
	SetCommonData("PlayerIconG",255);
	SetCommonData("PlayerIconB",255);
	PlaySE(SE_SPELL1);
	ShakeSpell(1);
	if(PlayerType==1)
	{
		
		RebirthSound(340);
		ShowBombName(IMG_YABUSAME_BOMNAME,200);
		DELETE(260,80);
		BUTTERFLY;
		loop(340){yield;}
	}
	else
	{
		RebirthSound(300);
		ShowBombName(IMG_TSUBAKURA_BOMNAME,200);
		DELETE(250,50);
		PlaySE(SE_SPELL2);	
		CHARGE;
		loop(300){yield;}
	}
	

	OnSpell=false;
	
}
task ShakeSpell(scale2)
{
	let scale = 1;
	loop(30)
	{
		SetCommonData("ShakePlayer",scale*scale2);
		scale-=1/30;
		yield;
	}
	SetCommonData("ShakePlayer",scale);
}
task DELETE(frames,Invince)
{
	loop(frames)
	{
		CollectAllItems;
		SetPlayerInvincibilityFrame_Special(2);
		DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,GetPlayerX,GetPlayerY,9999*256);
		yield;
	}
	loop(Invince)
	{
		SetPlayerInvincibilityFrame_Special(2);
		yield;
	}
}
task ShowBombName(IMAGE,stay)
{
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj,IMAGE);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	Obj_SetRenderPriorityI(obj,52);
	ObjPrim_SetDestCenter(obj,0,0,510,80);
	let scale = 3;
	let alpha = 0;
	ObjRender_SetPosition(obj,GetStgFrameWidth-(510/(1.75*2)),GetStgFrameHeight-(80/(1.75*2)),0);
	loop(50)
	{
		ObjRender_SetScaleXYZ(obj,scale/1.75,scale/1.75,scale);
		ObjRender_SetAlpha(obj,alpha);
		alpha+=255/50;
		scale-=2/50;
		yield;
	}
	ObjRender_SetScaleXYZ(obj,scale/1.75,scale/1.75,scale);
	ObjRender_SetAlpha(obj,alpha);
	loop(stay){yield;}
	loop(30)
	{
		ObjRender_SetScaleXYZ(obj,scale/1.75,scale/1.75,scale);
		ObjRender_SetAlpha(obj,alpha);
		alpha-=255/30;
		yield;
	}
	Obj_Delete(obj);
}
task CHARGE
{
	let RANDER = 5;
	FLASH;
	CHARGER(255,255,255,30);
	CHARGER(0,0,0,0);
	
	let ang = 0;
	let ang2= 0;
	let dist = 0;
	loop(70)
	{
		loop(6)
		{
			let id = 157;
		
			let obj = CreatePlayerShotA1(GetPlayerX,GetPlayerY,45,-90,4,99999,id);
			Mover(obj,ang,dist);
			
			let obj2 = CreatePlayerShotA1(GetPlayerX,GetPlayerY,45,-90,4,99999,id);
			Mover(obj2,ang2,dist);
			
			let obj3 = CreatePlayerShotA1(GetPlayerX,GetPlayerY,45,-90,4,99999,id);
			Mover(obj3,0,dist);
			ObjShot_SetSpellFactor(obj,true);
			ObjShot_SetSpellFactor(obj2,true);
			ObjShot_SetSpellFactor(obj3,true);

		}
		dist+=500/70;
		ang+=180/70;
		ang2-=180/70;
		

		yield;
	}
	
	loop(100+30+20-70){yield;}
	PlaySE(SE_SPELL4);
	loop(70)
	{
		Set2DCameraFocusX(GetStgFrameWidth / 2 + 2*rand_degree);
		Set2DCameraFocusY(GetStgFrameHeight / 2 + 2*rand_degree);
		yield;
	}
	Reset2DCamera;
	loop(275-(100+30+20+70)){yield;}
	task Mover(obj,angr,dist)
	{
		ObjShot_SetIntersectionEnable(obj,false);
		ObjRender_SetScaleXYZ(obj,0.5,5,1);
		ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
		let x = GetPlayerX+200*sin(angr)+rand(10,-10);
		if(x<0){x=0;}
		if(x>GetStgFrameWidth){x=GetStgFrameWidth}
		ObjMove_SetDestAtFrame(obj,x,GetPlayerY-dist+rand(10,-10),10);
		loop(10){yield;}
		ObjRender_SetScaleXYZ(obj,2,2,1);
		loop(70+100+30+20-70){yield}
		ObjShot_SetIntersectionEnable(obj,true);
		ObjMove_SetSpeed(obj,rand(20,40));
		ObjMove_SetAngle(obj,rand(0,360));
		let scale =0.5;
		while(!Obj_IsDeleted(obj))
		{
			ObjShot_SetIntersectionCircleA1(obj,7*3);
			ObjRender_SetScaleXYZ(obj,2,5,1);
			scale+=0.3;
			yield;
		}
	}
}
task BUTTERFLY
{
	PlaySE(SE_SPELL7);
	let x = GetPlayerX;
	let y = GetPlayerY-30;
	ascent(o in 0..3)
	{
		FLASH;
		ascent(i in 0..11)
		{
			Net(360/11*i,32,5+o);
		}
		loop(32){yield;}
		ascent(i in 0..11)
		{
			Net(360/11*i,0,5+o);
		}
		loop(32){yield;}
	}
	task Net(ang,deley,addah)
	{
		let vertexcount = 128;
		let objBoom = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(objBoom, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(objBoom, 128);
		Obj_SetRenderPriorityI(objBoom, 49);
		ObjPrim_SetTexture(objBoom, IMG_PIXEL);
		ObjRender_SetBlendType(objBoom,BLEND_INV_DESTRGB);
		let angle = 0;
		let dis =  0;
		ObjRender_SetPosition(objBoom,x,y,0);
		let am = 1;
		let yp = 0;
		ascent (i in 0..vertexcount/2)
		{
			let indexvert = i*2;
			ObjPrim_SetVertexColor(objBoom,indexvert,0,0,0);
			ObjPrim_SetVertexColor(objBoom,indexvert+1,0,0,0);
			let angle = (360/(vertexcount/2-1)*i);
			ObjPrim_SetVertexPosition(objBoom,indexvert+0,dis*cos(angle+ang),dis/5*sin(angle+ang)+yp,0);
			ObjPrim_SetVertexPosition(objBoom,indexvert+1,(dis*1)*cos(angle-20+ang),(dis/5)*sin(angle-20+ang)+yp,0);
			angle+=4;
			dis+=addah*am;
			am-=1/62;
			yp-=1;
		}
		dis = 0;
		am = 1;
		let c = 0;
		yp = 0;
		ascent (i in 0..vertexcount/2)
		{		
			let indexvert = i*2;
			let left = i*(128/6);
			let ranag = rand(0,360);
			if(c%8==0)
			{
				let obj = CreatePlayerShotA1(x+dis*cos(ranag),y+dis/5*sin(ranag)+yp,rand(5,10)/6,-90,3,99999,179);
				ObjShot_SetSpellFactor(obj,true);
				ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
				Renderin(obj);
			}
			yp-=1;
			dis+=(addah-1)*am;
			am-=1/62;
			c++;
			ObjPrim_SetVertexColor(objBoom,indexvert,255,255,255);
			ObjPrim_SetVertexColor(objBoom,indexvert+1,255,255,255);
			ObjPrim_SetVertexUVT(objBoom,indexvert,-left,0);
			ObjPrim_SetVertexUVT(objBoom,indexvert+1,-left,128);
			yield;
		}
		loop(64+deley)
		{
			yield;
		}
		task Renderin(obj)
		{
			let scale = 0;
			loop(20)
			{
				ObjShot_SetDamage(obj,0.14*scale);
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				scale+=1/19;
				yield;
			}
			ObjMove_SetMaxSpeed(obj,45);
			ObjMove_SetAcceleration(obj,0.3);
			while(!Obj_IsDeleted(obj))
			{
				ObjShot_SetDamage(obj,0.14*scale);
				scale+=0.3;
				yield;
			}
		}
		Obj_Delete(objBoom);
	}
	
}
task FLASH
{
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj,IMG_WHITECIRCLE);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	Obj_SetRenderPriorityI(obj,42);
	ObjRender_SetAngleZ(obj,0);
	let ALF=0;
	ObjRender_SetAlpha(obj,ALF);
	let scale =10;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjPrim_SetDestCenter(obj,0,0,256,256);
	loop(20)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF+=255/20;
		yield;
	}
	loop(20)
	{
		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
		ObjRender_SetAlpha(obj,ALF);
		ALF-=255/20;
		yield;
	}
	Obj_Delete(obj);
}
task CHARGER(R,G,B,DELEY)
{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_WHITECIRCLE);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,51);
		ObjRender_SetAngleZ(obj,0);
		let ALF=0;
		ObjRender_SetAlpha(obj,ALF);
		let scale =10;
		ObjRender_SetColor(obj,R,G,B);
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjPrim_SetDestCenter(obj,0,0,256,256);
		loop(30)
		{
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,-20,0);
			ObjRender_SetAlpha(obj,ALF);
			ALF+=255/30;
			yield;
		}
		ObjRender_SetAlpha(obj,ALF);
		loop(DELEY+70)
		{
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,-20,0);
			yield;
		}
		PlaySE(SE_SPELL3);
		loop(20)
		{
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,-20,0);
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			scale-=11/20;
			yield;
		}
		Obj_Delete(obj);
}
task DummySpell
{//特殊無敵システム用
	SetPlayerInvincibilityFrame(0);//無敵時間を設定
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	if(OnSpell)
	{
	//	SetPlayerSpeed(1.0*2,0.4*2);	
	}
	else
	{
		//SetPlayerSpeed(5.0*2,2.0*2);
	}
	yield;
	if(OnSpell)
	{
	//	SetPlayerSpeed(1.0,0.4);	
	}
	else
	{
	//	SetPlayerSpeed(5.0,2.0);
	}
}