#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["MidSpell"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkisume(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[25,25,255],2);
	BottomEnemyMarker(objBoss, objBoss);
	DrawName("Kisume", [25, 25, 122], 11);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/3, 5, 4);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	mainTask;
	end;

} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	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,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
wait(70);
SpellCard("Well Bucket &quot;Well Demon Spirit&quot;");
ObjEnemy_SetDamageRate(objBoss, 100, 100);
Dive;
}

task Dive{
	loop{
	WarningLaser;
	loop(120){
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX,GetStgFrameHeight/3, 15, 5);
	wait(1);
	}
	ObjMove_SetDestAtFrame(objBoss,BossX, BossY, 1);
	wait(10);
	ConcentrationA1(objBoss,"CHERRY",60,4,120,[122,122,255]);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/charge.wav", 70);
	wait(60);
	
	ObjMove_SetAngle(objBoss, 90);
	ObjMove_SetAcceleration(objBoss, 0.1);
	ObjMove_SetMaxSpeed(objBoss, 10);
	
	loop{
	if(ObjMove_GetY(objBoss)>GetStgFrameHeight){break;}
	yield;
	}
	ObjMove_SetDestAtFrame(objBoss,BossX, BossY, 1);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/splash.wav", 70);
	Splash;
	wait(70);
	ObjMove_SetDestAtWeight(objBoss,BossX,-60, 15, 1.8);
	Dip;
	Follow;
	wait(350);
	ObjMove_SetPosition(objBoss, GetPlayerX, BossY);
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX,GetStgFrameHeight/3, 5, 4);
	ascent(i in 0..9){
	CreateLooseLaserA1(BossX, BossY, 4, 0+(i*10),300, 25, LARGE_RED, 10);
	CreateLooseLaserA1(BossX, BossY, 4, 180-(i*10),300, 25, LARGE_RED, 10);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 70);
	wait(90);
	}
}

task Follow{
	loop(280){
	if(BossY<GetPlayerY){ObjMove_SetDestAtWeight(objBoss,GetPlayerX,-60, 15, 1.8);}
	yield;
	}
}

task Dip{
	loop(160){
	let obj = CreateShotB2(BossX+rand(-10,15), BossY+rand(-10,10), rand(-0.2, 0.2), 0, 0, rand(0.01, 0.03), 0, 10, FIRE_BLUE, 2);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	let obj2 = CreateShotB2(BossX+rand(-10,15), BossY+rand(-10,10), rand(-1, 1), 0, 0, rand(0.01, 0.03), 0, 10, FIRE_BLUE, 2);
	ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	wait(2);
	}
}

task Splash{
	loop(100){
	let obj = CreateShotB2(BossX, BossY, rand(-2, 2), rand(-1,-6), 0, rand(0.03, 0.08), 0, 5, FIRE_BLUE, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	}
}

task WarningLaser{
let obj =  CreateStraightLaserA1(BossX, BossY, 90, 1000, 25, 10,ST_LASER_GRAY, 9999);
ObjStLaser_SetSource(obj, false);
	loop(120){
	ObjMove_SetPosition(obj, BossX, BossY);
	yield;
	}
	wait(90);
	Obj_Delete(obj);
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Kisume.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 122);
	ObjCutin_LaunchS3("BYAKUREN", Cutin, "Normal");
	TCallBg1;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 100);
	loop(9){
	SpellBurstA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),"Cherry",[15, 15, 155]);
	wait(7);
	}
	StopSlow(TARGET_ALL);
	wait(1);
	SetCommonData("BossX", ObjMove_GetX(objBoss));
	SetCommonData("BossY", ObjMove_GetY(objBoss));
	SetCommonData("Hedied", objBoss);
    Obj_Delete(objBoss);
	SetCommonData("Died",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
