//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Arrowmance"]
#include "./../ZUNShot/ZUNShot_Const.txt"
#include "./sharedfuncMario.dnh"


let objBoss;
let width = 384;
let height = 448;
let life = 4000;
let scene = GetEnemyBossSceneObjectID();


@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(70);
    }
	case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	Indicator(objBoss);
	ObjEnemyBossScene_StartSpell(scene);
	
	animSpell(objBoss);
	
	TFinalizeSpell(scene, objBoss);
    ObjMove_SetDestAtFrame(objBoss, rand(width/5, 4*width/5), rand(3*height/20, 80)+15, 60);
	Maint;
}


@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);
    yield;
}


task Maint{
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "../SFX/SPELLCARD.WAV", 100));
	Spell("Arrowmance", scene, objBoss);
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 10, 0);
	wait(140);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "../SFX/POWER UP.WAV", 100));
	wait(40);
    Approach;
	wait(60);
	ObjEnemy_SetDamageRate(objBoss, 60, 20);
	wait(60);
	let shot1 = LoadEffect(GetCurrentScriptDirectory~ "../SFX/ATTACK5.WAV", 65);
	let shot2 = LoadEffect(GetCurrentScriptDirectory~ "../SFX/ATTACK2.WAV", 65);
	let shot3 = LoadEffect(GetCurrentScriptDirectory~ "../SFX/ATTACK3.WAV", 65);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    let time= 0;
		let col1 = truncate(rand(410, 412));
		let col2 = truncate(rand(414, 416));
		let col3 = truncate(rand(384, 390));
		let speedini = rand(3.5,4);
		let speed = speedini;
		let numBul;
		let i =1;
		while(time< 200){
		    ObjSound_Play(shot1);
		    let theta = rand(0,360); 
			if(time< 50){numBul = 80;} else if(time < 100){numBul= 60; speed= speedini-0.25;} else{numBul = 30; speed = speedini-0.5;}
		    if(i%2 ==1){
				loop(numBul){
				    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
					CreateShotA1(ObjMove_GetX(objBoss) + 30*cos(theta), ObjMove_GetY(objBoss)+15*sin(theta)-10,speed, theta, col1, 0);
					theta+=360/numBul;
				}
			}
			else if(i%2==0){
			    loop(numBul){
				    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
					CreateShotA1(ObjMove_GetX(objBoss) + 15*cos(theta), ObjMove_GetY(objBoss)+30*sin(theta)-10,speed, theta, col2, 0);
					theta+=360/numBul;
				}
			}
			wait(20);
			time+=20;
			i+=1;
		}
		wait(60);
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)< life/2){
		    ObjSound_Play(shot3);
		    ascent(i in 0..45){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			                   let obj=CreateShotA1(ObjMove_GetX(objBoss) + 20*cos(9*i), ObjMove_GetY(objBoss)+ 20*sin(9*i), 0, 9*i, col3, 30);
		                       ObjMove_AddPatternA2(obj, 30, NO_CHANGE, NO_CHANGE, 0.1, 0, 10);}
		}
		ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "../SFX/Charge.WAV", 90));
		wait(60);
		time = 0;
		let col4 = truncate(rand(124,130));
		let col5 = truncate(rand(131, 136));
		shotSound(shot2, 40, 65, 15, objBoss);
		while(time<40){
		     ascent(i in -1..2){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;} CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss)-15, 6, rand(GetAngleToPlayer(objBoss) +30*i-5, GetAngleToPlayer(objBoss)+30*i+5), col4, 0);}
			 ascent(i in -1..2){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;} CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss)-15, 6, rand(GetAngleToPlayer(objBoss) +30*i-5, GetAngleToPlayer(objBoss)+30*i+5), col5, 0);}
			 time++;
			 yield;
		}
		wait(120);
	}
}

task Approach{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    let x = GetPlayerX;
        ObjMove_SetDestAtFrame(objBoss, x, rand(80, 100), 60);
		wait(120);
	    ObjMove_SetDestAtFrame(objBoss, rand(x-30, x+30), 9*height/10, 300);
		wait(300);
		ObjMove_SetDestAtFrame(objBoss, rand(ObjMove_GetX(objBoss)-100, ObjMove_GetX(objBoss)+100), 9*height/10, 60);
		wait(60);
	}
}
    
			