
#include "./default_system/MS_Index.txt"

let objBoss;

let BossX; 
let BossY;

SetCommonData("BossAlpha",255);
SetCommonData("ForceLifebar", 1);

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjMove_SetPosition(objBoss, GetCommonData("BossX", GetStgFrameWidth/2),	GetCommonData("BossY", GetStgFrameHeight/2));
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 0);
	DrawName("Ellen", [255,122,122], 12.7);
	MagicRing(objBoss,true);
	FlameAura(objBoss,[199, 5, 5],3);
	RenderEllen(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	BackgroundEllen;
	}
	
	mainTask;
	end;
} 

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

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

@Finalize {
} 


task mainTask { 
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/death.wav", 90);
	loop(120){ExplodeEffectT(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(0.5, 10), 0.6, "Cherry", [255, 10, 10], 4);}
	ascent(i in 0..6){ExplodeCircleT(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 60, i*12, 0);}
	SetCommonData("BossAlpha",0);
	wait(120);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/chargelong.wav", 80);
	ascent(i in 0..30){
	Concentrate(BossX, BossY, 0, 6, 4, 1, "Cherry", 200, -2, [255, 15, 15]);
	Concentrate(BossX, BossY, 0, 6, 4, 1, "Cherry", 200, 2, [255, 15, 15]);
	SetCommonData("BossAlpha",i*4);
	wait(4);
	}
	SpellCard("Experience &quot;Tabula Rasa&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/ell.png", 25, "Ellen");
	
	Shots;
}
let off = 12;
let spin = 4;

task Shots{
loop{
let obj = CreateShotA1(BossX, BossY, rand(0.5, 3), rand(0,360), MIKO_ORB_RED, 20);
ObjRender_SetAlpha(obj, 122);
ObjShot_SetIntersectionEnable(obj, 0);
Boop(obj);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80);
wait(180);
}
task Boop(obj){
	while(!Obj_IsDeleted(obj)){
	if(ObjMove_GetY(obj)<GetStageUp){top(obj);}
	if(ObjMove_GetY(obj)>GetStageDown){bot(obj);}
	if(ObjMove_GetX(obj)<GetStageLeft){left(obj);}
	if(ObjMove_GetX(obj)>GetStageRight){right(obj);}
	yield;
	}
}
task top(obj){
let X = ObjMove_GetX(obj);
let count = 0;
Obj_Delete(obj);
ascent(i in 0..64){
let obj = CreateShotA1(X+i*off, -15, 1, 90-i*spin, BALL_M_RED, 20);
let obj2 = CreateShotA1(X-i*off, -15, 1, 90+i*spin, BALL_M_RED, 20);
FireShotA1(X+i*off, -15, rand(1, 2), rand(90-90,90+90), BALL_S_YELLOW_INV, 20);
FireShotA1(X-i*off, -15, rand(1, 2), rand(90-90,90+90), BALL_S_YELLOW_INV, 20);
ReflectDown(obj, "Down"); ReflectDown(obj2, "Down"); 
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
count++;
if(count==3){yield; count=0;}
}
}

task bot(obj){
let X = ObjMove_GetX(obj);
let count = 0;
Obj_Delete(obj);
ascent(i in 0..64){
let obj = CreateShotA1(X+i*off, GetStageDown+15, 1, 270+i*spin, BALL_M_RED, 20);
let obj2 = CreateShotA1(X-i*off, GetStageDown+15, 1, 270-i*spin, BALL_M_RED, 20);
FireShotA1(X-i*off, GetStageDown+15, rand(1, 2), rand(270-90,270+90), BALL_S_YELLOW_INV, 20);
FireShotA1(X+i*off, GetStageDown+15, rand(1, 2), rand(270-90,270+90), BALL_S_YELLOW_INV, 20);
ReflectUp(obj, "Up"); ReflectUp(obj2, "Up"); 
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
count++;
if(count==3){yield; count=0;}
}
}

task left(obj){
let Y = ObjMove_GetY(obj);
let count = 0;
Obj_Delete(obj);
ascent(i in 0..64){
let obj = CreateShotA1(-15, Y-i*off, 1, 0-i*spin, BALL_M_RED, 20);
let obj2 = CreateShotA1(-15, Y+i*off, 1, 0+i*spin, BALL_M_RED, 20);
FireShotA1(-15, Y+i*off, rand(1, 2), rand(0-90,0+90), BALL_S_YELLOW_INV, 20);
FireShotA1(-15, Y-i*off, rand(1, 2), rand(0-90,0+90), BALL_S_YELLOW_INV, 20);
ReflectRight(obj, "Right"); ReflectRight(obj2, "Right"); 
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
count++;
if(count==3){yield; count=0;}
}
}

task right(obj){
let Y = ObjMove_GetY(obj);
let count = 0;
Obj_Delete(obj);
ascent(i in 0..64){
let obj = CreateShotA1(GetStageRight+15, Y+i*off, 1, 180-i*spin, BALL_M_RED, 20);
let obj2 = CreateShotA1(GetStageRight+15, Y-i*off, 1, 180+i*spin, BALL_M_RED, 20);
FireShotA1(GetStageRight+15, Y-i*off, rand(1, 2), rand(180-90,180+90), BALL_S_YELLOW_INV, 20);
FireShotA1(GetStageRight+15, Y+i*off, rand(1, 2), rand(180-90,180+90), BALL_S_YELLOW_INV, 20);
ReflectLeft(obj, "Left"); ReflectLeft(obj2, "Left"); 
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
count++;
if(count==3){yield; count=0;}
}
}
}

task ReflectUp(obj, a){
	while(!Obj_IsDeleted(obj)){		
        if(trunc(ObjMove_GetY(obj))<GetStageUp){
			ObjMove_SetY(obj,-ObjMove_GetY(obj));
			ObjMove_SetAngle(obj,360 - ObjMove_GetAngle(obj));
			return;
        }
		yield;
	}
}

task ReflectDown(obj, a){
	while(!Obj_IsDeleted(obj)){		
        if(trunc(ObjMove_GetY(obj))>GetStageDown){
			ObjMove_SetY(obj,GetStageDown-ObjMove_GetY(obj)+GetStageDown);
			ObjMove_SetAngle(obj,360 - ObjMove_GetAngle(obj));
			return
        }
		yield;
	}
}

task ReflectLeft(obj, a){
	while(!Obj_IsDeleted(obj)){		
		if(trunc(ObjMove_GetX(obj))<GetStageLeft){	
			ObjMove_SetX(obj,-ObjMove_GetX(obj));
			ObjMove_SetAngle(obj,180 - ObjMove_GetAngle(obj));
			return;
		}
		yield;
	}
}

task ReflectRight(obj, a){
	while(!Obj_IsDeleted(obj)){		
		if(trunc(ObjMove_GetX(obj))>GetStageRight){
			ObjMove_SetX(obj,GetStageRight-ObjMove_GetX(obj)+GetStageRight);
			ObjMove_SetAngle(obj,180 - ObjMove_GetAngle(obj));
			return;
		}
		yield;
	}
}


task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("BossAlpha",255);
	SetCommonData("ForceLifebar", 0);
	StartSlow(TARGET_ALL, 15);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/deathstart.wav", 80);
	loop(45){
	ExplodeEffectT(BossX, BossY, rand(1, 20), 1, "Cherry", [255, 10, 10], 10);
	ExplodeEffectT(BossX, BossY, rand(1, 20), 1, "Cherry", [155, 10, 155], 10);
	yield;
	}
	SetCommonData("BossX", BossX);
	SetCommonData("BossY", BossY);
	SetCommonData("EllenIsDed", 1);
	StopSlow(TARGET_ALL);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 