#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell4"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

let AttackX;
let AttackY;

#include "./Functions/Index.txt"
Diseasecontroller;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderyamame(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[255,25,25],2);
	BottomEnemyMarker(objBoss, objBoss);
	MagicRing(objBoss,false);
	DiseaseBoss(objBoss, 4, 70);
	DrawName("Yamame Kurodani", [200, 200, 20], 11);
	SetCommonData("BossAngle",0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/4, 5, 4);
	mainTask;
	end;

} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(40);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	AttackX = BossX+10;
	AttackY = BossY-20;
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
wait(70);
ConcentrationA1(objBoss,"Nothing",40,2.2,120,[255, 122, 255]);
wait(90);
DiseaseBoss(objBoss, 6, 120);
ExplosionA2(objBoss,"CHERRY",[255, 122, 255],[255, 122, 255]);
wait(60);
Movement;
	loop{
	loop(5){
			ascent(i in 0..16){
			let random = truncate(rand(0,6));
			let obj = CreateShotA1(BossX+20, BossY, 2+(i/10), 90+20-(i*6), SMALL_BLUE, 5);
			let obj2 = CreateShotA1(BossX-20, BossY, 2+(i/10), 90-20+(i*6), SMALL_BLUE, 5);
				if(random>4){
				Disease(obj, 1.2, 24); 
				Disease(obj2, 1.2, 24); 
				Redirect(obj);
				Redirect(obj2);
				}
			}
				SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		wait(40);
		}
		wait(190);
	}
}

task Movement{
let sinner = 0;
let radius = 0;
	loop{
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+radius*cos(sinner),GetStgFrameHeight/4+(radius/2)*sin(sinner), 5, 4);
	if(radius<140){radius+=0.6;}
	sinner++;
	yield;
	}
}

	
	task Redirect(obj){
	while(!Obj_IsDeleted(obj)){
	yield;
	if(ObjMove_GetY(obj)>GetStgFrameHeight-1){break;}
	}
	ObjMove_SetSpeed(obj,0);
		if(!Obj_IsDeleted(obj)){
		let shotObj = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, GetAngleToPlayer(obj), SMALL_RED, 10);
		Disease(shotObj, 1.2, 24); 
		Go(shotObj);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
		}
	Obj_Delete(obj);
	}

	task Go(obj){
	wait(60);
	ObjMove_AddPatternA3(obj, 0, 0, GetAngleToPlayer(obj), 0.01, 0, 5, NO_CHANGE);
	}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
