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


let objBoss;

let BossX;
let BossY;


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


@Initialize {
	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);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	if(invisible==false){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	}
	
	if(GetPlayerInvincibilityFrame<=0){invisible=false;}
	else{invisible=true;}
	
	yield;
} 

@Finalize {

} 

let glAng = 90;

task Maintask{
wait(90);
SpellCard("Snek Sign &quot;circly sneks of immortality&quot;");
Rings;
}

task Rings{
	
	let obj2 = CreateCurveLaserA1(BossX, BossY, 3, 270, 200, 20, LARGE_RED, 5);
	ObjCrLaser_SetTipDecrement(obj2, 0);
	ObjLaser_SetInvalidLength(obj2, 5,5);
	Curve(obj2, -1);
	Shoot2(obj2);
	wait(210);
	
	let obj3 = CreateCurveLaserA1(BossX, BossY, 4, 270, 200, 20, LARGE_GREEN, 5);
	ObjCrLaser_SetTipDecrement(obj3, 0);
	ObjLaser_SetInvalidLength(obj3, 5,5);
	Curve(obj3, 1);
	Shoot3(obj3);
	wait(210);
	
	let obj5 = CreateCurveLaserA1(BossX, BossY, 6, 270, 200, 20, LARGE_BLUE, 5);
	ObjCrLaser_SetTipDecrement(obj5, 0);
	ObjLaser_SetInvalidLength(obj5, 5,5);
	Curve(obj5, -1);
	Shoot5(obj5);
	wait(210);

	task Curve(obj, mul){
	ObjMove_SetAngularVelocity(obj, 3*mul);
	wait(60);
	ObjMove_SetAngularVelocity(obj, 1.5*mul);
	}
	
	task Shoot2(obj){
	wait(120);
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 1, ObjMove_GetAngle(obj)+count, 0.01, 4, AMULET_RED, 5);
		count-=12;
		wait(2);
		}
	}
	task Shoot3(obj){
	wait(120);
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		ascent(i in 0..4){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, ObjMove_GetAngle(obj)+count*10-(i-5)+(i*5), 0.005, 4, PELLET_GREEN, 5);
		count++;
		}
		wait(12);
		}
	}
	task Shoot5(obj){
	wait(120);
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		ascent(i in 0..2){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, ObjMove_GetAngle(obj)+90+(i*180)+rand(-10,10), 0.01, 4, FIRE_BLUE, 5);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
		count++;
		}
		wait(6);
		}
	}
}

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());
} 
