#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 3"]
#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, 300);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	BottomEnemyMarker(objBoss, objBoss);
	
	ObjMove_SetDestAtWeight(objBoss,384/2-24,150,5,5);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(90);
	}
	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("Spirit &quot;Ferris Wheel of a Former Hell&quot;", 200, 00, 00);
	ObjCutin_LaunchS3("KANAKO", orin, "Normal");
	SpellCall;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	
wait(130);
let angle = 360/12;
let speed = 0;
let reverse = 1;
loop{
attack = true;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/water.wav", 90);
	loop(3){
		loop(8){
			let dir = 0; 
			//I couldn't think of another way.
			let obj = SummonGhost(ObjMove_GetX(objBoss)+24, ObjMove_GetY(objBoss)-35,250000,3000, false, true);
			ObjMove_SetAngle(obj, angle);
			ObjMove_SetSpeed(obj, 0);
			ObjMove_SetAngularVelocity(obj, 1*reverse);
			ObjMove_SetAcceleration(obj, 0.001+speed);
			ObjMove_SetMaxSpeed(obj, 100);
			Prime(obj);
			speed += 0.0011;
			}
		angle+=360/3;
		speed = 0.0;
		}
if(reverse==-1){reverse=1;}
else{reverse=-1;}
wait(60);
attack = false;
	loop(3){
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-30,30),120+rand(-20,20),10,5);
	wait(180);
	ObjEnemy_SetDamageRate(objBoss,40,40);
	}
}
}

task Prime(tar){
let count = 1;
	while(!Obj_IsDeleted(tar)){
	if(count>32){ObjShot_FadeDelete(tar); break;}
	let obj = CreateShotA2(ObjMove_GetX(tar), ObjMove_GetY(tar), 0, ObjMove_GetAngle(tar),0.008, 3, SMALL_BLUE, 10);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 90);
	wait(count);
	count+=1;
	}
	let angle = 0;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 80);
	loop(16){
	let obj = CreateShotA2(ObjMove_GetX(tar), ObjMove_GetY(tar), 0, angle,0.008, 3, SMALL_BLUE, 10);
	angle+=360/16;
	}
	ObjEnemy_SetLife(tar, 0);
}
		
	
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());
} 
