#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP6"]
#Text["&quot;Fantasy Diva&quot;"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	HitSound(objBoss, 80, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120+210+90);
	EnemyMarker(objBoss);
	Aura(objBoss, [25, 25, 25]);
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetPosition(objBoss, GetCenterX, GetStageUp-50);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-50, 5, 2);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(8000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(90);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	yield;
} 

@Finalize {
} 

let fireball = [1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120];
let stage = 0;


task Main {
wait(180);
let obj = Bubble(GetPlayerX, GetPlayerY, 0.20);
BubbleMovement(obj);

let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg2.png";
SpellCard(210, "&quot;Fantasy Diva&quot;", [255, 255, 255], path, path2, 25, 100, 1, "MegumiRainbow");
Staging;
BubblesLoop;
}

let scale = 1;
task BubblesLoop{
loop{
if(stage == 0){
	ascent(i in 0..1){
	let obj = Bubble(GetCenterX, GetCenterY-100, scale);
	Destroy(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
	}
}
if(stage == 1){
	ascent(i in 0..2){
	let obj = Bubble(GetCenterX-100+100*(i*2), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 1){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 40);
	wait(30);
	}
}
if(stage == 2){
	ascent(i in 0..3){
	let obj = Bubble(GetCenterX-100+50*(i*2), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 2){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 35);
	wait(30);
	}
}
if(stage == 3){
	ascent(i in 0..4){
	let obj = Bubble(GetCenterX-100+25*(i*3), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 3){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 30);
	wait(30);
	}
}
Ring;
wait(180);
if(stage == 0){
	ascent(i in 0..1){
	let obj = Bubble(GetCenterX, GetCenterY-100, scale);
	Destroy(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
	}
}
if(stage == 1){
	ascent(i in 0..2){
	let obj = Bubble(GetCenterX+100-100*(i*2), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 1){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 40);
	wait(30);
	}
}
if(stage == 2){
	ascent(i in 0..3){
	let obj = Bubble(GetCenterX+100-50*(i*2), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 2){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 35);
	wait(30);
	}
}
if(stage == 3){
	ascent(i in 0..4){
	let obj = Bubble(GetCenterX+100-25*(i*3), GetCenterY-100, scale);
	Destroy(obj);
	if(stage != 3){wait(90);break;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 30);
	wait(30);
	}
}
Ring;
wait(180);
}
}

task Ring{
ascent(i in 0..stage+1){
let random = rand(0,360);
	ascent(i in 0..12){
	let obj = DualShotA1(BossX, BossY, 1, random+i*360/12, ORB_L2_WHITE_ADD, 15, BLEND_ADD_ARGB, BLEND_SUBTRACT);
	Color(obj);
	}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 5);
wait(30);
}

task Color(obj){
let a = 0;
loop{
ObjRender_SetColorHSV(obj, a, 255, 255);
a+=2;
yield;
}
}
}

task Destroy(obj){
wait(120);
let rad = scale*100;
let random = rand(0,360);
ascent(k in 0..8){
	ascent(i in 0..(32*scale*1.5)){
	FireShotA2(GetX(obj)+rad*cos(random+i*360/(32*scale*1.5)), GetY(obj)+rad*sin(random+i*360/(32*scale*1.5)), 0, random+i*360/(32*scale*1.5), 0.01+0.01*k, 10, fireball[k], 10);
	}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 10);
}
Obj_Delete(obj);
}



task Staging{
let HPTreshold = 6000;
wait(90);
ObjEnemy_SetDamageRate(objBoss, 80, 40);
	loop{
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < HPTreshold){
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/death2.wav", 100, 0);
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		HPTreshold-= 8000/4;
		stage++;
		scale-=0.25;
		}
	yield;
	}
}








task BubbleMovement(obj){
loop{
ObjMove_SetDestAtWeight(obj, GetPlayerX, GetPlayerY, 5, 10);
yield;
}
}

task end{
	/*
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("UnderwaterSpell", false);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	*/

    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("UnderwaterSpell", false);
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 0);
	StartSlow(TARGET_ALL, 15);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/death.ogg", 90, 0);
	loop(45){
	ParticleT(BossX, BossY, rand(1, 20), rand(0,360), 1, rand(0,360), "Cherry", [255, 10, 10], 10);
	ParticleT(BossX, BossY, rand(1, 20), rand(0,360), 1, rand(0,360), "Cherry", [155, 10, 155], 10);
	yield;
	}
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("BossIsDed", 1);
	StopSlow(TARGET_ALL);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	
} 


