#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell1"]
#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/3, 10, 5);
	Maintask;
	end;
} 

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

} 


task Maintask{
wait(60);
SpellCard("Snek Sign &quot;Snek&quot;");
attack = true;
revolve = true;
pattern;
}

task pattern{
	loop{
	let obj = CreateCurveLaserA1(GetStgFrameWidth/2-150, -10, 2.5, 90-27, 100, 25, LARGE_GREEN, 10);
	ObjCrLaser_SetTipDecrement(obj, 0);
	ObjLaser_SetInvalidLength(obj, 5,5);
	Snake(obj, 5, 90+45, AMULET_GREEN, 2, 2, 1.5);
	let obj2 = CreateCurveLaserA1(GetStgFrameWidth/2+150, -10, 2.5, 90-27, 100, 25, LARGE_GREEN, 10);
	ObjCrLaser_SetTipDecrement(obj2, 0);
	ObjLaser_SetInvalidLength(obj2, 5,5);
	Snake(obj2, 5, 90-45, AMULET_GREEN, 2, 2, 1.5);

	wait(120);

	let obj3 = CreateCurveLaserA1(GetStgFrameWidth/2, -10, 2, 90-27, 100, 25, LARGE_RED, 10);
	ObjCrLaser_SetTipDecrement(obj3, 0);
	ObjLaser_SetInvalidLength(obj3, 5,5);
	Snake(obj3, 5, 270, AMULET_RED, 2, 3, 1);
	wait(120);

	let obj5 = CreateCurveLaserA1(GetStgFrameWidth/2-150, -10, 2, 90-27-45, 100, 25, LARGE_BLUE, 10);
	ObjCrLaser_SetTipDecrement(obj5, 0);
	ObjLaser_SetInvalidLength(obj5, 5,5);
	Snake(obj5, 3, 90, AMULET_BLUE, 3, 4, 1.5);
	let obj6 = CreateCurveLaserA1(GetStgFrameWidth/2+150, -10, 2, 90-27+45, 100, 25, LARGE_BLUE, 10);
	ObjCrLaser_SetTipDecrement(obj6, 0);
	ObjLaser_SetInvalidLength(obj6, 5,5);
	Snake(obj6, 3, 90, AMULET_BLUE, 3, 4, 1.5);
	
	wait(210);
	}
}

task Snake(obj, mult, angle, graph, del, off, spd){
wait(10);
let count = 0;
let wave = rand(0,360);
Shoot(obj, mult, angle, graph, del, off, spd);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetAngle(obj, ObjMove_GetAngle(obj)+5*sin(count*10));
	count++;
	wave++;
	yield;
	}
task Shoot(obj, mult, angle, graph, del, off, spd){
	while(!Obj_IsDeleted(obj)){
	let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2*sin(wave*mult), 0, graph, 5);
	ObjMove_AddPatternA2(obj2, 180, spd, angle, 0, 0, 0);
	wait(del);
	}
}
}

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