#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko Spell 01"]

#include"./../Functions/Cutin/Cutin.txt"
#include"./LoadGraphics.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
let global = 0;

let card = GetCurrentScriptDirectory ~ "./../Sounds/se_cat00.wav";
let kira = GetCurrentScriptDirectory ~ "./../Sounds/se_boon00.wav";
let sho = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
#include"./DrawBoss.txt"

@Initialize{
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	LoadShotData;
	animateBossM;
	mainTask;
	TEnd;

	LoadSound(sho);
	LoadSound(card);
	LoadSound(kira);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(600);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../System/Minoriko_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 15, 2);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{wait(1);TEtama;PlaySE(card);
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,5,3);
	ObjCutin_SetSpellcardS4("Goddess Sign \"Inari in a form of a Fox\"", cutin2, "KANAKO", 255, 64, 0);
	ObjCutin_LaunchS3("KANAKO", cutin2, "normal");
	TSpellBG;wait(120);damage=1;
	while(!Obj_IsDeleted(bossObj)){
		attack=1;
		TFox(0,60,1030,373);TFox(180,60,1030,373);
		wait(90);attack=0;
	ObjMove_SetDestAtWeight(bossObj,CenterX+rand(-30,30),CenterY-120,5,5);
		wait(30);}}

task TFox(angle,gr1,gr2,gr3){
	let time = 10;
	let move = 0;
	let x = bossX;
	let y = bossY;
	loop(72){PlaySE(sho);
		if(Obj_IsDeleted(bossObj)){break;}
		let fox = CreateShotA1(x,y,5,angle+move,gr3,30);
		ObjMove_AddPatternA3(fox,time,NO_CHANGE,NO_CHANGE,1,0,1,NO_CHANGE);
		ObjRender_SetColorHSV(fox,gr1,250,255);
		TSpawnLaser(fox);
	move+=8;time+=0.5;wait(3);}

	task TSpawnLaser(obj){
		while(ObjMove_GetSpeed(obj) > 1){yield;}
		wait(30); if(!Obj_IsDeleted(obj)){
		let laser = CreateLooseLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1,ObjMove_GetAngle(obj),80,20,gr2,30);
		Obj_Delete(obj);
		loop(45){ObjMove_SetSpeed(laser,ObjMove_GetSpeed(laser)+0.05);yield;}}}}