#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP5"]
#Text["&quot;Dance of Snow, Moon and Flowers&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);
	Aura(objBoss, [25, 25, 25]);
	
	SetCommonData("ForceLifebar", 1);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-120, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(1);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	yield;
} 

@Finalize {
}


task Main {
wait(90);
let bub = Bubble(BossX, BossY, 0.5);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 40);
let bub2 = Bubble(GetPlayerX, GetPlayerY, 0.75);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
wait(120);
Movebub(bub2);
Move2(bub);
Move;
let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg2.png";
SpellCard(210, "&quot;Dance of Snow, Moon and Flowers&quot;", [5, 5, 5], path, path2, 25, 100, 1, "Megumi");
wait(60*4);
Current;
wait(120);
BubbleMaker;
}


let scale = 0.75;
let spd = 0; 
let maxspd = 1;
task BubbleMaker{
let a = 0;
loop{
let objScene = GetEnemyBossSceneObjectID();
let time = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);

let obj = InstantBubble(GetCenterX+rand(-200, 200), GetStageDown+50, scale);
Movebub(obj);
StayPlayer(obj, scale);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 5);
if(time<30){
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 5);
BubbleRings(obj, scale);
}

if(time<30 && a == 0){
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 90, 0);
maxspd = 1.5;
scale = 0.60;
a++;
}
if(time<15 && a == 1){
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 90, 0);
maxspd = 2;
scale = 0.50;
a++;
}
wait(210-(75*spd));
}
}

task BubbleRings(obj, scale){
ascent(i in 0..(scale*10)){
let shot = CreateShotA1(0, 0, 0, 0, ORB_R_WHITE_ADD, 0);
ObjShot_SetAutoDelete(shot, 0);
ObjShot_SetSpellResist(shot, 0);
Rotate(shot, obj, i*360/(scale*10), scale);
}

task Rotate(shot, obj, off, rad){
rad = rad*100;
while(!Obj_IsDeleted(obj)){
ObjMove_SetPosition(shot, GetX(obj)+rad*cos(off), GetY(obj)+rad*sin(off));
off++;
yield;
}
Obj_Delete(shot);
}
}

task StayPlayer(obj, scale){
while(!Obj_IsDeleted(obj)){
let rad = GetObjectDistance(obj, GetPlayerObjectID);
if(rad<scale*100){
ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY+spd);
}

if(GetY(obj) < -50){Obj_Delete(obj);}
yield;
}
}

task Current{
loop{
if(spd<maxspd){spd+=0.02;}
FireShotA1(GetCenterX+rand(-2000*spd, 2000*spd), GetStageDown+10, rand(spd/2, spd*2), rand(270+11, 270-11), ORB_S_INV_WHITE, 10);
ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY-spd);
yield;
}
}

task Movebub(obj){
loop{
ObjMove_SetPosition(obj, GetX(obj), GetY(obj)-spd);
yield;
}
}

task Move2(obj){
loop{
ObjMove_SetDestAtWeight(obj, BossX, BossY, 5, 5);
yield;
}
}

task Move{
let rad = 0;
let a = 0;
loop{
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rad*cos(a), GetStgFrameHeight/2-100+(rad/2)*sin(a)-a, 5, 7);
a++;
if(rad<150){rad+=1;}
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("BossAlpha",255);
	SetCommonData("ForceLifebar", 0);
	SetCommonData("UnderwaterSpell", false);
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("RipSpell", 1);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	
} 


