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


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"
#include "./Functions/Dialogue.txt"


@Initialize {
SetCommonData("ShowLifebar", 1);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkanako(objBoss);
	BossShotSound(objBoss, 100, 600);
	KanakoAura(objBoss, false);
	Sticks(objBoss, false);
	BottomEnemyMarker(objBoss, objBoss);
	DrawName("Kanako Yasaka", [20, 20, 200], 11);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 10, 5);
	Maintask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(70);
	}
	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 {

} 

let spd = 2;
let number = 1;
let del = 30;
let fire = 2;
let graph = 0;
let spinspd = 0;

task Maintask{
invisible = true;
SpellCard("&quot;a survival yey!&quot;");
wait(20);
	ascent(i in 0..12){
	let obj = RegularStick(BossX+250*cos(i*360/12+180), BossY+250*sin(i*360/12+180), i*360/12+180);
	ObjRender_SetAlpha(obj, 122);
	Shoot(obj);
	Kill(obj, i);
	GO(obj,i);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(5);
	}
wait(30);
revolve=true;
Move;
spinspd = 2;
wait(600);
del=0;
spd=5;
fire=2;
wait(360);
number=2;
graph++;
del=0;
fire=5;
spd=2;
spinspd = 0;
ascent(i in 0..64){
spinspd+=0.1;
yield;
}
let count = 0;
number=1;
fire=17;
loop(120+(360*2)){
spd=3+2*sin(count);
count++;
yield;
}
ascent(i in 0..52){
spinspd-=0.1;
yield;
}
spd=2;
number=3;
del=30;
fire=3.5;
graph+=2;
wait(200);
	ascent(i in 0..12){
	let obj = RegularStick(BossX+250*cos(i*360/12+180), BossY+250*sin(i*360/12+180), i*360/12+180);
	ObjRender_SetAlpha(obj, 122);
	Shoot2(obj);
	Kill(obj, i);
	GO2(obj,i);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(5);
	}
spd=3;
wait(400);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 0.10);
wait(200);


	task Move{
	let count = 0;
	let radius = 0;
	loop(540){
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+radius*cos(count), GetStgFrameHeight/2+radius*sin(count), 10, 5);
	radius+=0.1;
	count++;
	yield;
	}
	radius = 150;
	loop(450){
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+radius*cos(count), GetStgFrameHeight/2+radius*sin(count), 10, 5);
	count+=1;
	yield;
	}
	wait(120);
	loop(360*2){
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+radius*cos(count), GetStgFrameHeight/2+radius*sin(count), 10, 5);
	count+=0.5;
	yield;
	}
	}
	task Shoot(obj){
	wait(210);
		loop{
		ascent(j in 0..4){
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		let ObjAng = ObjMove_GetAngle(obj);	
			ascent(i in 0..number){
			CreateShotA1(ObjX-85*cos(ObjAng), ObjY-85*sin(ObjAng), spd, ObjAng-10+(i*2)+180, AMULET_RED+graph, 15);
			}
		wait(fire);
		}
		wait(del);
		}
	}
	task Shoot2(obj){
	wait(290);
		loop{
		ascent(j in 0..4){
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		let ObjAng = ObjMove_GetAngle(obj);	
			ascent(i in 0..number){
			CreateShotA1(ObjX-85*cos(ObjAng), ObjY-85*sin(ObjAng), spd, ObjAng-10+(i*2)+180, AMULET_RED+graph, 15);
			}
		wait(fire);
		}
		wait(del);
		}
	}
	task GO(obj,i){
	wait(120-(i*5));
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetDestAtWeight(obj, BossX+40*cos(i*360/12+count), BossY+40*sin(i*360/12+count), 10, 5);
		count+=1+spinspd;
		yield;
		}
	}
	task GO2(obj,i){
	wait(210-(i*5));
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetDestAtWeight(obj, BossX+125*cos(i*360/12+count), BossY+125*sin(i*360/12+count), 10, 5);
		count-=1+spinspd;
		yield;
		}
	}
	task Kill(obj, i){
	wait(210-(i*5));
	let alpha = 122;
		let ObjX = ObjMove_GetX(obj);
		let ObjY = ObjMove_GetY(obj);
		let ObjAng = ObjMove_GetAngle(obj);
		let las = CreateStraightLaserA1(ObjX, ObjY, ObjMove_GetAngle(obj), 180, 70, 99999999, ST_LASER_GRAY, 10);
		ObjShot_SetAutoDelete(las, 0);
		Obj_SetVisible(las, 0);
		while(!Obj_IsDeleted(obj)){
		ObjX = ObjMove_GetX(obj);
		ObjY = ObjMove_GetY(obj);
		ObjAng = ObjMove_GetAngle(obj);	
		ObjRender_SetAlpha(obj, alpha);
		ObjStLaser_SetAngle(las, angleToObject(las,obj));
		ObjMove_SetPosition(las, ObjX-85*cos(ObjAng), ObjY-85*sin(ObjAng));
		alpha++;
		yield;
		}
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Kan1.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 255);
	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());
} 
