#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["DoremyNon2"]
#Text["By Lushie/Lusushime"]
#include ".\Functions.dnh"
#Background[".\Stage3bg.dnh"]
#System[".\default_system/Default_System.txt"]
#Player[".\player/LoLK Marisa (Lushie)/MarisaH.dnh"]

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(spelllife);
    }
    case(EV_REQUEST_TIMER){ //Sets attack time
        SetScriptResult(spelltime);
    }
    case(EV_REQUEST_SPELL_SCORE){ //Spellcard bonus
        SetScriptResult(1000000);
    }
    case(EV_PLAYER_SHOOTDOWN){
    	pdreset(spelltime,spelllife);
    }
}

let spelltime = 35;
let spelllife = 3000;

@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
	bossanimation("doremy");
 //declares spellcard
	TDrawLoop; //calls TDrawLoop task
	TFinalize; //calls TFinalize task
	MainTask; //calls MainTask task
}

@MainLoop{
	ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), bosshitbox); 
	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{
	startingposition(GetCenterX, 120);
	wait(61);
	startattacking;
	
}

task startattacking{
	pointdevicepositions;
	pdplayerx = GetCenterX;
	pdplayery = 400;
	pdcount2 = pdcount;
	let pdc = pdcount;
	
	wait(50);
	setauracolor("purple");
	chargeeffect2("red");
	wait(45);
	if(pdc == pdcount){
		spelldamage(30, 130, 13);
		fireA(pdc);
	}
}

task fireA(pdc) {
	let d = 70;
	let n = 27;
	let wt = 120;
	let t = 10;
	let n2 = 4;
	let n3 = 4;
	let ap2 = 9;
	let posneg = -1;
	let sp = 0.025;
	let app = 0.5;

	let graphic1 = 293;
	let graphic2 = 295;
	let graphic = 293;
	while(lifecheck(pdc) == true){
		let angle = rand(0,360);
		let angle2 = angle;
		let s = 1.8;
		let ap = 35;
		let acc = 0.1;
		let ms = 2.3;
		
		if(diff == 2){
			d=  70;
			n = 30;
			t = 9;
			n2 = 4;
			n3 = 5;
			s = 1.8;
			ms = 2.4;
			ap = 35;
			app = 0.5;
			ap2 = 9;
			acc = 0.1;
		}
		if(diff == 3){
			d=  70;
			n = 30;
			t = 8;
			n2 = 4;
			n3 = 6;
			s = 1.8;
			ms = 2.6;
			ap = 35;
			app = 0.5;
			ap2 = 9;
			acc = 0.1;
		}
		move = 3;
		loop(n){
			if(lifecheck(pdc) == false){return;}
			loop(n2){
				loop(n3){
					let bullet = CreateShotA2(BossX + d * cos(angle), BossY + d * sin(angle), s, angle2, acc, ms, graphic, 0);
					spawncustom2(bullet, 1, 1.5, 0, 255, 8, 0);
					angle += 360/n3 * posneg;
				}
				if(graphic == graphic1){graphic = graphic2;}
				else{graphic = graphic1;}
				angle2 += 360/n2 * posneg;
			}
			SE_Play2(shot1, shot1v);
			ms += sp;
			ap += app;
			angle += ap * posneg;
			angle2 += ap2 * posneg;
			wait(t);
		}
		if(lifecheck(pdc) == false){return;}
		bmovement(15, 30, 5, 15, 55);
		wait(wt);
		posneg *= -1;
	}
	
}