#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 1"]
#Text["Woop"]

let objBoss;
let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderorin(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	
	ObjMove_SetDestAtWeight(objBoss,384/2-24,150,5,5);
	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,24);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,24);
	yield;
} 

@Finalize {

} 

task SpellCall {
	bspell = true;
	TCallBg;
}

let orin = GetCurrentScriptDirectory ~ "Functions/img/orin.png";

task mainTask { 
	wait(30);
	ObjCutin_SetSpellcardS3("Corpse Sign &quot;Roadway of Vengeful Sprits&quot;", 200, 00, 00);
	ObjCutin_LaunchS3("KANAKO", orin, "Normal");
	SpellCall;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	
wait(130);
let reverse = 1;
attack = true;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 80);
wait(60);
RingSpread;

loop{
let angle = 0;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/water.wav", 90);
	loop(2){
		let obj = SummonGhost(ObjMove_GetX(objBoss)+24, ObjMove_GetY(objBoss)-35,50,270, false,true);
		MoveFunction(obj, 1, angle, 0.01, 5);
		Shoot(obj);
		angle+=180;
	}
		if(reverse==-1){reverse=1;}
		else{reverse=-1;}
	wait(60);
	}
}

task RingSpread{
	let angle = rand(0,360);
	loop{
		ascent(i in 0..4){
		let obj = CreateShotA1(BossX+24, BossY-35, rand(1.2,1.5), angle+(i*(360/4)), R_DOT_BLUE, 5);
	}
	angle +=2;
	wait(2);
	}
}

task Shoot(tar){
let speed = 1;
let angle = 90;
let X = 0;
let Y = 0;
while(ObjEnemy_GetInfo(tar, INFO_LIFE)>0){
	X = ObjMove_GetX(tar);
	Y = ObjMove_GetY(tar);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		loop(10){
			ascent(i in 0..2){
			let obj = CreateShotA2(X, Y, speed, angle+(i*180),0.005, 10, SMALL_RED, 10);
			}
		speed += 0.05;
		wait(1);
	}
	speed = 1;
	wait(40);
}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
