#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["JunkoNon2"]
#Text["By Lusus"]
#include ".\Functions.dnh"
#Background[".\JunkoBackground.dnh"]
#BGM[".\se/junko.ogg"]
#System[".\default_system/Default_System.txt"]

let objBoss; //global variable, can be used anywhere
let objScene = GetEnemyBossSceneObjectID(); //declares global variable enemy boss scene object


@Event{
	alternative(GetEventType())
    case(EV_REQUEST_LIFE){ //Sets boss's life
        SetScriptResult(2000);
    }
    case(EV_REQUEST_TIMER){ //Sets attack time
        SetScriptResult(40);
    }
    case(EV_REQUEST_SPELL_SCORE){ //Spellcard bonus
        SetScriptResult(1000000);
    }
}

@Initialize{
	toggleaura(1);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS); //gives the variable a value, object ID that makes it a boss
	ObjEnemy_Regist(objBoss); //registers it as an enemy
	ObjMove_SetDestAtFrame(objBoss, GetCenterX(), 110, 40); //moves boss to destination

 //declares spellcard
	TDrawLoop; //calls TDrawLoop task
	TFinalize; //calls TFinalize task
	MainTask; //calls MainTask task
}

@MainLoop{
	ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
	// CircleToShot means any player shoot hitting this will damage the boss, CircleToPlayer kills the player on colission
	yield; //necessary for task functions to work
}

task MainTask {
	wait(50);
	chargeeffect;
	wait(60);
	ObjEnemy_SetDamageRate(objBoss, 45, 34);
	fireA;
}

task fireA {
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		let n = 55;
		let s = 4;
		let c = 0;
		loop(2){ 
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 0){return;}
			let angleT = rand(0, 360);
			loop(n){
				let bullet = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), s, angleT, -0.04, 0, 539, 0);
				commands(bullet,c);
				angleT += 360/n;
				c+= 1;	
			}
			c = 0;
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(shot1, shot1v);}
			wait(70);
		}
		c = 0;
		bmovement(30, 50, 5, 10, 30);
	}
}

task commands(bullet,c){
	ObjShot_SetAutoDelete(bullet, false);
	enddelete(bullet);
	wait(80);
	ObjMove_AddPatternA2(bullet, 0, 0, 90, 0.15, 0, 3);
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0 && c == 0){SE_Play(kira3, kira3v);}
	wait(200);
	ObjShot_SetAutoDelete(bullet, true);
}