#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["JunkoNon3"]
#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(), 120, 40); //moves boss to destination

	TDrawLoop; //calls TDrawLoop task
	TFinalize; //calls TFinalize task
	MainTask; //calls MainTask task
	SetCommonData("Card",true);
	//SetSpellText("&quot;Primordial Divine", "Spirit World&quot;",20);
	//RenderBG;
	
}

@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(55);
	ObjEnemy_SetDamageRate(objBoss, 45, 34);
	fireA;
}

task fireA {
	let s = 2.3;
	let n = 10;
	let angle = 0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		angle = 90;
		junkoattack;
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 0){return;}
		loop(n){
			let bullet = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), s, angle, 311, 0);
			ObjRender_SetBlendType(bullet, BLEND_ADD_ARGB);
			ObjRender_SetScaleXYZ(bullet, 1.2, 1.2, 1);
			ObjShot_SetAutoDelete(bullet, false);
			enddelete(bullet);
			explode(bullet);
			angle += 360/n;
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(shot1, shot1v);}
		}
		wait(80);
		bmovement(40, 50, 5, 10, 30);
		wait(180);
	}
}

task explode(bullet){
	let m = 5;
	while(!Obj_IsDeleted(bullet)){
		ObjShot_SetIntersectionCircleA1(bullet, 11);
		let x = ObjMove_GetX(bullet);
		let y = ObjMove_GetY(bullet);
		if( x < -m || x > GetStgFrameWidth() + m || y > GetStgFrameHeight() +m){
			let n = 36;
			let s = 1.1;
			let angle = ObjMove_GetAngle(bullet);
			loop(n){
				let bullet2 = CreateShotA2(x, y, 0, angle, 0.02, s,539, 0);
				Obj_SetRenderPriorityI(bullet2, Obj_GetRenderPriorityI(bullet2)+1);
				enddelete(bullet2);
				angle += 360/n;
			}
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(kira3, kira3v);}
			wait(20);
			Obj_Delete(bullet);
		}
		if(y < -m){
			wait(20);
			Obj_Delete(bullet);
		}
		wait(1);
	}
}