#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP9"]
#Text["Blep"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

let stage = 0;
let season = 0;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	EnemyMarker(objBoss);
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 320);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-110, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(10000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(55);
	}
	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(120);
	let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/cutin.png";
	SpellCard(210, "", [255, 60, 60], path, path, 20, 0.75, "Okina");
	
	season = GetCommonData("Season", 0);
	
	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;}
}

task Pattern4{
let a = 0;
loop{
ascent(i in 0..6){
FireShotA1(BossX, BossY, 2, a, scale[1], 10+5*i)
}
a+=12;
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 90, 0);
wait(6);
}
}

task Pattern3{
loop{
let a = rand(0,360);
ascent(j in 0..24){
let obj = FireShotA2(BossX, BossY, 4, a+j*360/24, -0.07, 0.5, pellet[3], 10);
ObjMove_AddPatternB2(obj, 60, NO_CHANGE, NO_CHANGE, 0, 0.01, 10, 10);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/labullet.wav", 90, 0);
wait(60);
}
}

task Pattern2{
let a = 0;
loop{
FireShotB2(BossX, BossY, 0+3*sin(a), -2, 0, 0.04, 10, 10, ice[2], 10);
a+=5;
wait(2);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
}
}

task Pattern1{
let a = 0;
loop{
	ascent(i in 0..3){
	FireShotA1(BossX, BossY, 3, a+i*360/3, fireball[0], 10);
	}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
a+=25;
wait(5);
}
}

task Staging{
let HPTreshold = 8000;
wait(90);
ObjEnemy_SetDamageRate(objBoss, 80, 40);
	loop{
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) < HPTreshold){
		PlaySound(GetCurrentScriptDirectory ~ "default_system/se/death2.wav", 100, 0);
		HPTreshold-= 10000/4;
		stage++;
		}
	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/death.ogg", 90, 0);
	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("OkinaIsDed", 1);
	StopSlow(TARGET_ALL);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
}


