#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko NonSpell 02"]
#include"./LoadGraphics.txt"
#include"./../Functions/Enemy_Functions.txt"

let bossObj;
let bossX;
let bossY;
let dam = 0;

let short = GetCurrentScriptDirectory ~ "./../Sounds/se_ch00.wav";
let kira = GetCurrentScriptDirectory ~ "./../Sounds/se_kira02.wav";
let sho = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
let sho1 = GetCurrentScriptDirectory ~ "./../Sounds/se_tan01.wav";
#include"./DrawBoss.txt"

@Initialize{
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	SetCommonData("End",0);
	LoadShotData;
	animateBossM;
	mainTask;
	TEnd;

	LoadSound(sho);
	LoadSound(sho1);
	LoadSound(kira);
	LoadSound(short);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1200);}
	case(EV_REQUEST_TIMER){SetScriptResult(30);}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(dam==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(dam==1){ObjEnemy_SetDamageRate(bossObj, 50, 25);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	TEtama;let r = 0;
	ObjMove_SetDestAtWeight(bossObj,192,120,5,4);
	loop(80){PowerS(192+r*cos(r*15),120+r*sin(r*15));r+=1;}r = 0;
	loop(80){Point(192+r*cos(r*15+180),120+r*sin(r*15+180));r+=1;}
	ascent(i in 0..25){Fruit(192+80*cos(i*14.4),120+80*sin(i*14.4));}
	wait(90);
	THarvesterWreath(2.3,180,1);wait(30);
	THarvesterWreath(2.0,150,-1);wait(120);
	TLightAura;
	wait(30);dam=1;
	TShot;wait(180);
	while(!Obj_IsDeleted(bossObj)){
		ascent(i in -2..3){
			THelix(i*60,0);
			THelix(i*60,180);}
		wait(210);}}

task THelix(ang,turn){
	let color = 255;
	let speed = 5;
	let move = 0;
	let rad = 0;
	ShotSE();
	loop(120){
		if(Obj_IsDeleted(bossObj)){break;}
		let shot = CreateShotA1(bossX+rad*sin(move+turn+ang),bossY+rad*cos(move+turn+ang),5,0,371,10);
		ObjMove_AddPatternA1(shot,0,NO_CHANGE,GetAngleToPlayer(shot)+ang);
		ObjRender_SetColor(shot,255,color,color);
		if(rad >= 90){rad = 90;}
	rad+=2;move+=8;color-=1;yield;}}

task ShotSE{loop(40){PlaySE(sho);wait(3);}}

task TShot{
	let m = 0; let tr = 0;
	while(!Obj_IsDeleted(bossObj)){
		PlaySE(sho);
		ascent(ang in 0..12){
			CreatePotato(bossX+65*cos(ang*30+m),bossY+65*sin(ang*30+m),2,ang*30+m,1,30);
			CreatePotato(bossX+90*cos(ang*30-m),bossY+90*sin(ang*30-m),3,ang*30-m,2,30);
			let a = CreateShotA1(bossX+65*cos(ang*30+m),bossY+65*sin(ang*30+m),10,ang*30+m,1,30);
			let b = CreateShotA1(bossX+90*cos(ang*30-m),bossY+90*sin(ang*30-m),10,ang*30-m,2,30);
			ObjShot_SetDeleteFrame(a,0);
			ObjShot_SetDeleteFrame(b,0);}
			m+=5;
		wait(20);}}

function CreatePotato(x,y,speed,angle,graphic,delay){
	let spirit = CreateEnemy(100);
	ObjMove_SetPosition(spirit,x,y);
	ObjMove_SetAngle(spirit,angle);
	DrawEnemy(spirit,graphic);
	TEnemyDelay(spirit,delay,speed);
	return spirit;}

task TEnemyDelay(obj,d,s){
	ObjMove_SetSpeed(obj,0);
	Obj_SetVisible(obj,false);
	wait(d);
	ObjMove_SetSpeed(obj,s);
	Obj_SetVisible(obj,true);}

function CreateEnemy(objlife){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjEnemy_SetLife(obj,objlife);
	return obj;}

task DrawEnemy(id,gr){
	let enemyX;
	let enemyY;
	let angleZ = rand(0,180);
	ObjPrim_SetTexture(id,akishot);
	while(!Obj_IsDeleted(id)){
		enemyX = ObjMove_GetX(id);
		enemyY = ObjMove_GetY(id);
		ObjSprite2D_SetDestCenter(id);
			if(gr == 1){ObjSprite2D_SetSourceRect(id,3,209,32,239);}
			if(gr == 2){ObjSprite2D_SetSourceRect(id,1,242,32,269);}
		ObjEnemy_SetIntersectionCircleToPlayer(id,enemyX,enemyY,9);
		ObjRender_SetAngleZ(id,angleZ);
		if(GetCommonData("End",0)!=0){DisappearBulletEffect(enemyX,enemyY,id,255,25,25);}
		if(CheckOutsideScreenA2(enemyX,enemyY,64)){
			Obj_Delete(id);break;}
		angleZ+=2;yield;}}