
#include "./default_system/MS_Index.txt"

let objBoss;

let BossX; 
let BossY;
let stage = 0;

SetCommonData("BossAlpha",255);

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

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(15000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(120);
	}
	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);
	yield;
} 

@Finalize {
} 

task Staging{
let HPTreshold = 12500;
wait(90);
ObjEnemy_SetDamageRate(objBoss, 80, 40);
	loop{
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < HPTreshold){
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/death2.wav", 100);
		HPTreshold-=2500;
		stage++;
		}
	yield;
	}
}

task mainTask { 
SpellCard("&quot;Solitude&quot;", [10,10,255], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/kan.png", 25, "Kana");
Staging;
Pattern1;
while(stage==0){yield;}
Pattern2;
while(stage==1){yield;}
Pattern3;
while(stage==2){yield;}
Pattern4;
while(stage==3){yield;}
Pattern5;
while(stage==4){yield;}
Pattern6;

}

task Pattern1{
	loop{
	FireShotA1(BossX, BossY, rand(1, 2), rand(0,360), SCALE_RED, 10);
	wait(6);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	}
}

task Pattern2{
	loop{
	let random = rand(0,360);
	ascent(j in 0..3){
		ascent(i in 0..12){
		let obj = FireShotA1(BossX, BossY, 1, random+i*360/11, BILL_RED, 10);
		ObjMove_AddPatternA2(obj, 60, NO_CHANGE, NO_CHANGE, 0.01*j, 0, 10);
		ObjMove_AddPatternA2(obj, 90, NO_CHANGE, NO_CHANGE, 0, 0, 10);
		}
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	PlaySoundTime(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 80, 60);
	wait(60);
	}
}

task Pattern3{
	loop{
	let random = rand(0,360);
		ascent(i in 0..12){
		let obj = FireShotA1(BossX, BossY, 2, random+i*360/12, SNOWFLAKE_RED, 10);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 80);
	wait(80);
	}
}
task Pattern4{
	loop{
	let random = rand(0,360);
	let random1 = rand(-50, 50);
	let random2 = rand(-50, 50);
		ascent(i in 0..8){
		let obj = FireShotA1(BossX+random1, BossY+random2, 2, random+i*360/8, FIREBALL_RED, 25);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(40);
	}
}
task Pattern5{
	loop{
		let red = 33.5;
		ascent(i in 0..5){
		FireShotA1(BossX, BossY, 1.5, GetAngleToPlayer(objBoss)+red-i*red/2, KUNAI_S_PURPLE, 15);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(60);
	}
}

task Pattern6{
let count = 0;
	loop{
		let red = 33.5;
		ascent(i in 0..5){
		FireShotA1(BossX, BossY, 4, 45+GetAngleToPlayer(objBoss)+45*sin(count), ARROW_PURPLE, 15);
		FireShotA1(BossX, BossY, 4, 45-GetAngleToPlayer(objBoss)-45*sin(count)+90, ARROW_PURPLE, 15);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 40);
	count++;
	wait(5);
	}
}

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", [10, 10, 255], 10);
	ExplodeEffectT(BossX, BossY, rand(1, 20), 1, "Cherry", [155, 10, 155], 10);
	yield;
	}
	SetCommonData("BossX", BossX);
	SetCommonData("BossY", BossY);
	SetCommonData("KanaIsDed", 1);
	StopSlow(TARGET_ALL);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 