#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["JunkoSpell6"]
#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
let frame = 0; 
	let frame2 = 0;
	let angle = 0;
	let angleAcc = 0;
	let radius = 0;

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

@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

	//ObjEnemyBossScene_StartSpell(objScene); //declares spellcard

	TDrawLoop; //calls TDrawLoop task
	TFinalize; //calls TFinalize task
	MainTask; //calls MainTask task
	SetCommonData("Card",true);
}

@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(60);
	chargeeffect;
	wait(50);
	ObjMove_SetDestAtFrame(objBoss, GetCenterX(), GetCenterY(), 90);
	ObjRender_SetAlpha(objBoss, 170);
	toggleaura(0);
	spellcutin("\"Overwhelming Purity\"");
	fireA;
}

task fireA {
	let graphic = 539;
	let s = 0.85;
	let t = 24;

	let n1 = 135;
	let c = 10;
	let angle1 = 90 + 360/8/3;

	let angle2 = 105;
	let n2 = 19;
	let c2 = 0;
	junkoattack;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		loop(n1-c){
			let b = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), s, angle1, graphic, 0);
			enddelete(b);
			angle1 += 360/n1;
		}
		SE_Play(shot1, shot1v);
		loop(n1-c){
			angle1 += -360/n1;
		}
		angle1 += 45;
		if(c2==5){n2=24; SE_Play(change, changev);}
		if(c2==12){n2=29; SE_Play(change, changev);}
		//if(c2 == 0){n2 +=1; c2 = -1;}
		wait(t);
		loop(4){
			loop(n2){
				let b2 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), s, angle2, graphic, 0);
				enddelete(b2);
				angle2 += 360/n2;
			}
			SE_Play(shot1, shot1v);
			angle2 += 360/n2/2;
			wait(t);
		}
		c2 +=1;
	}
}