#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP3"]
#Text["Duet[r]&quot;Dance Under the Rain&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, 0, 0]);
	
	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(4000);
     	}
	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 {
if(GetCommonData("IsStage", false)==true){
	if(GetCommonData("Underwater", false)==true){
		ascent(i in 0..90){
		SetCommonData("CameraHeight", GetCommonData("CameraHeight", 0)+2);
		yield;
		} 
	}
}
wait(90);
let bub = BubbleRed(GetPlayerX, GetPlayerY, 0.75);
Move(bub);
BubbleMani(bub);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/bubble.wav", 90, 45);
task Move(bub){
loop{
ObjMove_SetDestAtWeight(bub, GetPlayerX, GetPlayerY, 5, 0.5);
yield;
}
}

wait(120);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/meg2.png";
SpellCard(210, "Duet &quot;Dance Under the Rain&quot;", [255,5,5], path, path2, 25, 100, 1, "Megumi");
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
ShootTop;
ShootHer;
Movement;
}

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

task ShootHer{
wait(120);
loop{
ascent(j in 0..5){
FireShotA1(BossX, BossY, 2, GetAngleToPlayer(objBoss)-45+j*22.5, ORB_L2_RED_ADD, 15);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 0);
wait(90);
ascent(j in 0..5){
FireShotA1(BossX, BossY, 2, GetAngleToPlayer(objBoss)-45+j*22.5, ORB_L2_PURPLE_ADD, 15);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 0);
wait(90);
}
}

task ShootTop{
loop{
ascent(i in 0..33){
FireShotA1(0+i*18, -10, 1+0.05*sin(i*360/6), 90, RICE_S_RED, 10);
FireShotA1(0+i*18, -10, 0.90+0.05*sin(i*360/6), 90, DOT_PURPLE, 25);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
wait(1);
}
wait(180);
descent(i in 0..33){
FireShotA1(0+i*18, -10, 1+0.05*sin(i*360/6+180), 90, RICE_S_RED, 10);
FireShotA1(0+i*18, -10, 0.90+0.05*sin(i*360/6+180), 90, DOT_PURPLE, 25);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
wait(1);
}
wait(180);
}
}

task BubbleMani(obj){
	loop{
	let bul = GetShotIdInCircleA2(GetX(obj), GetY(obj), 90, TARGET_ENEMY);
		ascent(i in 0..length(bul)){
			if(ObjShot_GetImageID(bul[i]) == RICE_S_RED && Obj_GetValueD(bul[i], "Moved", 0) == 0){
			ObjMove_AddPatternA2(bul[i], 0, NO_CHANGE, GetAngleToPlayer(bul[i]), 0.01, 0, 10);
			Obj_SetValue(bul[i], "Moved", 1);
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
			}
			if(ObjShot_GetImageID(bul[i]) == ORB_L2_RED_ADD && Obj_GetValueD(bul[i], "Moved", 0) == 0){
			ObjMove_AddPatternA2(bul[i], 0, ObjMove_GetSpeed(bul[i])/2, GetAngleToPlayer(bul[i]), 0.01, 0, 10);
			ascent(j in 0..12){
			FireShotA2(GetX(bul[i]), GetY(bul[i]), 0.5, j*360/12, 0.01, 10, ORB_S_RED_ADD, 10);
			}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
			Obj_Delete(bul[i]);
			}
		}
	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());
	
} 


