#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP4"]
#Text["Dance and Song[r]&quot;Three-Styled Performance&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_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	OxigenController;
	WorldBG;
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	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 {
} 
task Main {
wait(90);
let bub = Bubble(GetCenterX, GetCenterY, 1.5);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 35);
wait(120);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg2.png";
SpellCard(210, "Dance and Song &quot;Three-Styled Performance&quot;", [122, 122, 122], path, path2, 25, 100, 1, "Megumi");
wait(60);
BubShot(bub);
ascent(j in 0..12){
let obj = FireShotA1(BossX, BossY, 0, 0, ORB_M_WHITE_ADD, 15);
ObjShot_SetSpellResist(obj, true);
Rotate(obj, j*360/12);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+200*cos(GetAngleToPlayer(objBoss)+180), GetStgFrameHeight/2+200*sin(GetAngleToPlayer(objBoss)+180), 5, 4);
ascent(i in 0..7){
let bub2 = Bubble(GetCenterX+200*cos(i*360/7), GetCenterY+200*sin(i*360/7), 0.15);
Rotate2(bub2, i*360/7);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
Movement;
}

task Movement{
loop{
ObjMove_SetDestAtWeight(objBoss, GetPlayerX+rand(-50, 50), GetStgFrameHeight/2-150-rand(-25, 25), 5, 4);
wait(120);
}
}

task Rotate2(obj, off){
let rot = 0;
wait(30);
loop{
ObjMove_SetPosition(obj, GetCenterX+200*cos(off), GetCenterY+200*sin(off));
if(rot<0.5){rot+=0.01;}
off += 1*rot;
yield;
}
}

task BubShot(obj){
wait(120);
loop{
let random = rand(0,360);
ascent(i in 0..8){
FireShotA1(GetCenterX+140*cos(random+i*360/8), GetCenterY+140*sin(random+i*360/8), 1, random+i*360/8+180, RICE_S_WHITE, 30);
}
ascent(i in 0..24){
FireShotA1(GetCenterX+160*cos(random+i*360/24), GetCenterY+160*sin(random+i*360/24), 2, random+i*360/24, RICE_S_WHITE, 30);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90,30);
wait(60);
}
}

task Rotate(obj, off){
let rad = 0;
let rot = 0;
let ret = 0;
let ret2 = 0;
loop{
ObjMove_SetPosition(obj, GetCenterX+rad*cos(off), GetCenterY+rad*sin(off));
if(rot<1){rot+=0.01;}
if(ret2<0.25){ret2+=0.0005;}
off += 1*rot/2;
rad = 0+140*sin(ret);
ret+=1*ret2;
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());
	
} 


