#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sariel Phase2 Spell1"]
#Text[""]
#BGM["script/bgm/shugen.mp3"]

#include "script/shot/ZUNShot_Const.txt"
#include"./Cutin.txt"
#include "script/default_system/Default_Effect.txt"

let objBoss;
let objScene=GetEnemyBossSceneObjectID();

let se_shot = GetCurrentScriptDirectory ~ "se/shot.wav";
let se_shot2 = GetCurrentScriptDirectory ~ "se/shot2.wav";
let se_kira = GetCurrentScriptDirectory ~ "se/kira.wav";
let se_kill = GetCurrentScriptDirectory ~ "se/kill.wav";


@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(40500);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(135.6);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}

@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
    ObjMove_SetDestAtFrame(objBoss, GetCenterX, 120, 60);

    TDrawLoop;
    TFinalize;
    MainTask;
    StartSpell;
}

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

task MainTask{
	wait(200);
	LoadSound(se_shot);
	LoadSound(se_shot2);
	LoadSound(se_kira);
	LoadSound(se_kill);
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
	wait(65);
	fireA;
	wait(35);
	fireB;
	wait(60);
	fireC;
	fireD;
	wait(120);
	fireE;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireF;
	wait(120);
	fireA;
	wait(35);
	fireB;
	wait(35);
	fireA;
	wait(35);
	fireB;
	wait(30);
	fireC;
	fireD;
	wait(120);
	fireE;
	fireF;
}


task fireA{
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = 40;
	let num = 1;//how many rings/bullets are launched each time the task is ran
		let loop_number = 20;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),6,angleT+a*360/num,74,5);
			}
			angleT+=9;//number the bullets rotate every time
			PlaySE(se_shot);
			wait(1);//delay
		}
}

task fireB{
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = 120;
	let num = 1;//how many rings/bullets are launched each time the task is ran
		let loop_number = 20;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),6,angleT+a*360/num,74,5);
			}
			angleT-=9;//number the bullets rotate every time
			PlaySE(se_shot);
			wait(1);//delay
		}
}

task fireC{
	let randX = rand(0, 360);
	let randY = rand(90, 120);
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = 90;
	let num = 10;//how many rings/bullets are launched each time the task is ran
		let loop_number = 60;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,angleT+a*360/num,74,5);
			}
			angleT-=15;//number the bullets rotate every time
			PlaySE(se_kira);
			wait(1);//delay
		}
}

task fireD{
	let randX = rand(0, 360);
	let randY = rand(90, 120);
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = 90;
	let num = 10;//how many rings/bullets are launched each time the task is ran
		let loop_number = 60;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,angleT+a*360/num,74,5);
			}
			angleT+=15;//number the bullets rotate every time
			PlaySE(se_kira);
			wait(1);//delay
		}
}

task fireE{
	let randX = rand(0, 360);
	let randY = rand(90, 120);
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = GetAngleToPlayer(objBoss);
	let num = 5;//how many rings/bullets are launched each time the task is ran
		let loop_number = 100;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,angleT+a*360/num,138,5);
			}
			angleT+=16;//number the bullets rotate every time
			PlaySE(se_shot2);
			wait(2);//delay
		}
}

task fireF{
	let randX = rand(0, 360);
	let randY = rand(90, 120);
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
	let angleT = GetAngleToPlayer(objBoss);
	let num = 5;//how many rings/bullets are launched each time the task is ran
		let loop_number = 100;//how many times it loops
		ascent(i in 0..loop_number){
			ascent(a in 0..num){
				CreateShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,angleT+a*360/num,138,5);
			}
			angleT-=16;//number the bullets rotate every time
			PlaySE(se_shot2);
			wait(2);//delay
		}
}

task TDrawLoop {
    wait(250);
    let imgBoss = GetCurrentScriptDirectory() ~ "img/anm03.png";
    ObjPrim_SetTexture(objBoss, imgBoss);
    ObjSprite2D_SetSourceRect(objBoss, 150, 150, 0, 0);
    ObjSprite2D_SetDestCenter(objBoss);
}

task TFinalize {
    PlaySE(se_kill);
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
            +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
        AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    }
    TExplosionA(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 64, 64);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
    return;
}

function GetCenterX(){
    return GetStgFrameWidth() / 2;
}
function GetCenterY(){
    return GetStgFrameHeight() / 2;
}

function wait(n){
    loop(n){yield;}
}

@Finalize{}

task StartSpell{
	let objEnemy = GetEnemyBossObjectID[0];
	loop(90){yield;}
	
	let sekibanki = GetCurrentScriptDirectory~"sariel.png";
	let kyouko = GetCurrentScriptDirectory~"sariel.png";
	ObjCutin_SetSpellcardS4("We Shall Die Together ~ Civilization Of Magic", sekibanki, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(YABUSAME, sekibanki, "Lunatic");

	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);

	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)>0){
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 32);
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 24);
		yield;
	}
	Obj_Delete(objEnemy);
}


