#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["JunkoSpell3"]
#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(500);
    }
    case(EV_REQUEST_TIMER){ //Sets attack time
        SetScriptResult(65);
    }
    case(EV_REQUEST_SPELL_SCORE){ //Spellcard bonus
        SetScriptResult(1000000);
    }
}

@Initialize{
	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
	toggleaura(1);
	ObjMove_SetDestAtFrame(objBoss, GetCenterX(), 130, 40); //moves boss to destination

	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 {
	chargeeffect;
	wait(55);
	spellcutin("\"Self Reflective Impurity\"");
	ObjEnemy_SetDamageRate(objBoss,7.3, 3);
	junkoattack;
	fireA;
}

task fireA {
	let n = 26;
	let t = 13;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		let angleT = GetAngleToPlayer(objBoss);
		let c = 1;
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){SE_Play(shot1, shot1v);}
		loop(n){
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 0){return;}
			loop(2){
				let bullet = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3.5, angleT, -0, 0.4, 335, 0);
				enddelete(bullet);
				if(c==2){speed(bullet); c = 0;}
				c+= 1;
			}
			angleT += 360/n;
		}
		if(t > 0){t+= -0.7;}
		wait(20+t);
	}
}

task speed(bullet){
	ObjMove_AddPatternA2(bullet, 10, 3.5, NO_CHANGE, -0.1, 0, 0.85);
}