#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 05 - Stalker \"ICU, I Kill U\""]
#Text[""]
#Background["./../BG.txt"]
#Player["./../player/lenen/YabuKura.txt", "./../player/lenen/TenkaBami.txt", "./../player/gt_medicine/PracticeP.txt"]
#System["./../System/Default_System.txt"]

#include "./../lib/Shot/Shotconstants.dnh"
//#include "./../lib/Shot/LenenShot/JINXShot_Const.txt"

//#include "./../lib/Render/EnemyMark.txt"
#include "./../lib/FxnSFX.dnh"
#include "./../lib/Funcs.dnh"
#include "./../lib/FXLib.dnh"
#include "./../lib/Render/MagicCircle.txt"
#include "./../lib/Patterns.dnh"

//#include "./../lib/Render/Gizmo's Touhou Boss Sprite Library/GizmoSpriteLibrary.txt"
#include "./../lib/Render/LenenBossRender/RenderLenen.txt"
#include "./../lib/Render/MakeEye.txt"
#include "./../lib/RMTCLenenCutinLib/RMTCLenenCutin.txt"

let objBoss;
let objScene = GetEnemyBossSceneObjectID();

let count = 0;

let fam = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/Special04.wav");
let diss = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/Special02.wav");

let laser = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/Laser02.wav");
let charge = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/Charge01.wav");

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(3600);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(62);
    }
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}

@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	
	LoadEye();
	if(GetCommonData("music", false) == false){BGM_Play("Boss", 75); SetCommonData("music", true);}
	
    ObjMove_SetDestAtFrameWeight(objBoss, gx(), 150, 50);
	StartSpell;
	TDrawLoop;
    TFinalize;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
    if(count == 0){
        phases;
        count = 0;
    } 
	
    count++;
    yield;
}

task StartSpell{
wait(60*1);
	ObjEnemyBossScene_StartSpell(objScene);
	
	let objEnemy = GetEnemyBossObjectID[0];
	wait(30);
	
	let rumia = GetCurrentScriptDirectory() ~ "../img/save.png";
	TRMTCLenenCutin(rumia, "Stalker \"ICU, I Kill U\"", false, 115, 30, 153);
}

task TDrawLoop{
	renderBoss(objBoss, "Haiji", 1.12, 60*1/2, false);
	magiccircle(objBoss, 1.6, false);
}

task phases{
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(60*4.5); PlaySFX_V(charge, 65);
	Concentration(bx, by, 60, 300, 3, 2, 3, BLEND_ADD_RGB, 115, 30, 153, 1); 
	ChargeCircle(bx, by, 75, 115, 30, 153, BLEND_ADD_RGB);
	wait(65);
	renderAura(objBoss, "Haiji", 1.12, 60*1/2, 200, [115, 30, 153]);
	ObjEnemy_SetDamageRate(objBoss, 75, 20);

	egg();
}

task egg{
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;} //Default kill to prevent (0,0) spawning
	//{
		let a; let r = 30; 

	//}
	
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		ascent(i in 0..10){
			a = r + 360/10*i;
			let L = eye(bx + 260*cos(a), by + 70*sin(a), 0.3); ateez(L);
			
			PlaySFX_V(fam, 62);
			wait(5);
		}
		
		r += 90; 
		wait(60*7.23);
		
		descent(i in 0..10){
			a = r + 360/10*i;
			let L = eye(bx + 260*cos(a), by + 70*sin(a), 0.3); ateez(L);
			PlaySFX_V(fam, 62);
			
			wait(7);
		}
		
		r += 90; 
		wait(60*7.32);
	}
	
	task ateez(L){
		wait(5);
		blink(L, [2, 21], 1); //20
		wait(30); 
		ascent(i in 0..8){ExplodeCircle(getrx(L), getry(L), 10+i*5, 255, 51, 204, BLEND_ADD_ARGB);}
		ObjRender_SetAlpha(L, 255);
		ObjRender_SetBlendType(L, BLEND_SUBTRACT);
		ey_unzan(L);
	}
	
}

task TFinalize {
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) + ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
		SetCommonData("extend", true);
		
		SetPlayerLife(GetPlayerLife() + 1);
		AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    }
	
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
    return;
}