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


let objBoss;

let BossX;
let BossY;

let speed = 0.5;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[255,255,255],3);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/2,2,6);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(68);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	yield;
} 

@Finalize {

} 

task mainTask { 
	wait(60);
	SpellCard("&quot;Phobia of the Unknown&quot;");
	attack=true;
	ConcentrationA1(objBoss,"CHERRY",60,3,120,[255,255,255]);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/charge.wav", 70);
	wait(60);
	ObjRender_SetAlpha(objBoss, 120);
	ascent(j in 0..10){
		ascent(i in 0..24){
		let obj = DarknessCloud(BossX,BossY);
		ObjMove_SetAngle(obj, (j*10)+(i*360/24));
		ObjMove_SetSpeed(obj, 2+(j/8));
		ObjMove_SetAcceleration(obj, -0.01);
		ObjMove_SetMaxSpeed(obj, 0);
		stop(obj);
		}
	}
	attack=false;
	wait(20);
	Letsdoit;
	wait(40);
	Pattern1;
	Pattern2;
	Pattern3;
	Pattern4;
	task stop(obj){
	while(ObjMove_GetSpeed(obj)!=0){yield;}
	wait(30);
	ObjMove_SetAngle(obj, ObjMove_GetAngle(obj)+180);
	ObjMove_SetAcceleration(obj, 0.0001);
	ObjMove_SetMaxSpeed(obj, 0.03);
	}
}

task Letsdoit{
let elps = 0;
let movespeed = 2;
	loop{
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+255*cos(elps), GetStgFrameHeight/2+255*sin(elps), 5, movespeed);
	elps+=speed;
	if(movespeed!=14){movespeed+=0.2;}
	yield;
	}
}

function Pattern1{
let count = 0;
	loop{
		ascent(i in 0..26){
		let obj = CreateShotA1(BossX, BossY, 1, GetAngleToPlayer(objBoss)+(i*360/26), PELLET_RED, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	if(count==22){break;}
	count++;
	wait(40);
	}
}
function Pattern2{
let count = 0;
speed=2;
	loop{
		ascent(i in 0..26){
		let obj = CreateShotA1(BossX, BossY, 1, GetAngleToPlayer(objBoss)+(i*360/26), PELLET_RED, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	loop(7){
	let obj = CreateShotA1(BossX, BossY, 1, GetAngleToPlayer(objBoss), PELLET_YELLOW, 5);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(3);
	}
	if(count==30){break;}
	count++;
	wait(15);
	}
}

function Pattern3{
let count = 0;
	loop{
	loop(9){
		ascent(i in 0..26){
		let obj = CreateShotA1(BossX, BossY, 1, GetAngleToPlayer(objBoss)+(i*360/26), PELLET_PURPLE, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(3);
	}
	if(count==15){break;}
	count++;
	wait(15);
	}
}

function Pattern4{
let count = 0;
speed=1;
	loop{
	let angle = GetAngleToPlayer(objBoss);
	loop(9){
		ascent(i in 0..26){
		let obj = CreateShotA1(BossX, BossY, 1, angle+(i*360/26), PELLET_GRAY, 5);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(12);
	}
	}
}


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

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