

// w フレームだけ待つ
function wait(w) 
{
    loop(w) { yield; }
}

function WaitForZeroEnemy()//敵数が0になるまで待機する関数
{
	while(GetEnemyNum() != 0){yield;}
}

function MSDSetCollisionB(x,y,Radius)
{
	if(GetCommonData("BURSTLEVEL")==0)
	{
		SetCollisionB(x,y,Radius);
	}
}

function GetDistanceToPlayer
{
	let dis=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	return(dis);
}

task OutDamageRateZero
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			SetDamageRate(110,110);
		}
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
		{
			SetDamageRate(105,105);
		}
		else
		{
			SetDamageRate(100,100);
		}
	}

yield;
}

}

task OutDamageRateZeroOnSet(ShotDamage,BombDamage)
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			SetDamageRate(ShotDamage*1.10,BombDamage*1.10);
		}
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
		{
			SetDamageRate(ShotDamage*1.05,BombDamage*1.05);
		}
		else
		{
			SetDamageRate(ShotDamage,BombDamage);
		}
	}

yield;
}

}

task GetDamege
{
GetDamegeItem;
loop
{
	if(GetHitCount!=0)
	{
		ZakoColor=[150,150,255];
		SetColor(150,150,255);
		wait(10);
	}
	else
	{
		ZakoColor=[255,255,255];
		SetColor(255,255,255);
	}
yield;
}
}

task GetDamegeItem
{
loop
{
		if(GetHitCount!=0 && GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			if(GetCommonData("BURSTLEVEL")==0)
			{
			ItemSet(GetX,GetY,2);
			ItemSet(GetX,GetY,2);
			}
			if(GetCommonData("BURSTLEVEL")==3)
			{
			ItemSet(GetX,GetY,8);
			ItemSet(GetX,GetY,8);
			}
		}
yield;
}
}

function FinalizeItemSet(num)
{
let type;
alternative(GetCommonData("BURSTLEVEL"))
case(0)
{
	type=3;
}
case(3)
{
	type=5;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
			if(GetCommonData("MAGICCOUNTER")>=10000)
			{
				ItemSet(GetX,GetY,type);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonData("MAGICPOWER")>=1000)
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
			{
				ItemSet(GetX,GetY,9);
			}
		}
		}
}

function ItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ItemXY",XY);//共通データに変更後の配列を渡す
}

function ExtendItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ExtendItem",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ExtendItem",XY);//共通データに変更後の配列を渡す
}


task Lissajous(R,G,B)
{
let a=5;
let b=6;
let RA=50;
let RB=40;
let angle=0;
let X;
let Y;
let t=0;
loop
{
	X=RA*cos(a*t);
	Y=RB*sin(b*t+angle);
	LissajousEffect1(GetX+X,GetY+Y,R,G,B);
	LissajousEffect1(GetX-X,GetY+Y,R,G,B);
	t+=0.75;
	yield;
}

}


task LissajousEffect1(X,Y,R,G,B)
{
		let randrect=5;
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[48/2+rand(-randrect,randrect)];
	}
	if(GetCommonDataDefault("LightMode",0)==1){return;}

		let scax=0.3;
		let scay=0.3;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=50;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);


		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetScale(obj, scax,scay);

		ObjEffect_SetLayer(obj,2);

		loop(10)
		{
		Obj_SetY(obj,Obj_GetY(obj)-1);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.2/10;
			scay+=0.2/10;
			alpha-=50/10;
			yield;
		}
		Obj_Delete(obj);
}

function MoveToPlayer02(xMove, yAdd, frame, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition02(x, y, frame);
	SetAction(ACT_MOVE,60);
}

function MoveToPlayer03(xMove, yAdd, weight,maxspeed, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition03(x, y, weight,maxspeed);
	SetAction(ACT_MOVE,60);
}


///////////////////////////////////////////////////////////////////////////////////////////
	let csd = GetCurrentScriptDirectory;
	let imgLetter =csd ~ "img/border.png"; 
	let BulletNum;
	let ZakoColor=[255,255,255];
	let ZakoMagicColor=[255,255,255];
////////////////////////////////////////////////////////////////////////////////////////////
task Concentration03(x,y,frame,R,G,B)
{
//Concentration03CircleEffect(frame,R,G,B);

if(frame<31){return;}
loop(frame-30)
{
	Concentration03Effect(x,y,R,G,B);
	Concentration03Effect(x,y,R,G,B);
	yield;
}

}

task Concentration03Effect(x,y,R,G,B)
{
		let Rudius=rand(100,250);
		let StandardRudius=Rudius;
		let Angle=rand(0,360);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let MinScale=0.5;
		let Scale=rand(0.5,2.0);
		let StandardScale=Scale;
		let Alpha=40;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"..\img/effect_tiny.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX+Rudius*cos(Angle),GetY+Rudius*sin(Angle));
		Obj_SetAngle(obj,Angle);

		ascent(let i in 0..30)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			Obj_SetPosition(obj,x+Rudius*cos(Angle),y+Rudius*sin(Angle));
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale+MinScale,Scale+MinScale);
			Rudius-=StandardRudius/35;
			Zangle+=RotateAngle*dir;
			Scale-=StandardScale/35;
			if(i>20)
			{
			Alpha-=4;
			}
			yield;
		}
		Obj_Delete(obj);
}

task Concentration03CircleEffect(let frame,R,G,B)
{
		let Scale=0.8;
		let StandardScale=Scale;
		let Alpha=80;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -256, -256);
		ObjEffect_SetVertexXY(obj, 1, 256,  -256);
		ObjEffect_SetVertexXY(obj, 2, 256, 256);
		ObjEffect_SetVertexXY(obj, 3,  -256,  256);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX,GetY);

		ascent(let i in 0..frame)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/frame;
			yield;
		}
		Obj_Delete(obj);
}