#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["RingoNon2"]
#Text["By Lushie/Lusushime"]
#include ".\Functions.dnh"
#Background[".\Stage2bg.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

 //declares spellcard
 	bossanimation("ringo");
	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);
	bmoveto(GetCenterX, 120, 20);
	wait(61);
	startattacking;
	
}

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

task fireA(pdc){
	let s = 5;
	
	let ms = 3.1;
	let n = 22;
	let n2 = 50;
	let t = 5;
	let d = 20;
	let c = 0;
	let posneg = 1;
	let posneg2 = 1;
	let angle = rand(0,360);
	let ap = -2;
	let ap2 = 0.5;
	
	let map2 = 3.5;
	

	if(diff == 2){
		n = 26;
		ap2 = 0.5;
		map2 = 4.5;
		ms = 3.3;
	}
	if(diff == 3){
		
		n = 32;
		ap2 = 0.35;
		map2 = 5;
		ms = 3.5;
	}
	let acc = -(s-ms)/30;
	let map1 = -map2;
	while(lifecheck(pdc) == true){
		let graphic = 88;
		move = 3;
		loop(n2){
			if(lifecheck(pdc) == false){return;}
			let array = [];
			loop(n){
				let bullet = CreateShotA2(BossX + d * cos(angle), BossY + d * sin(angle), s, angle, acc, ms, graphic, 0);
				angle += 360/n;
				array = array ~ [bullet];
				if(graphic == 88){graphic = 87;}
				else{graphic = 88;}
			}
			spawncustomarray2(array, 1, 1.5, 70, 255, 12, 0);
			SE_Play(shot1, shot1v);
			angle += ap * posneg;
			ap += ap2 * posneg2;
			if(ap > map2 || ap < map1){posneg2 *= -1;}
			if(ap < map1){}

			wait(t);
		}
		posneg *= -1;
		if(lifecheck(pdc) == false){return;}
		bmovement(15, 30, 5, 15, 55);
		wait(70);
		
	}
}

