#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2"]
#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("Stick Sign &quot;big sticks&quot;");
Pattern;
attack = true;
wait(120);
attack = false;
wait(210);
Pattern2;
revolve = true;
wait(60);
Move;

	loop{
	let obj = KillyStick(rand(GetStgFrameWidth/2-100,GetStgFrameWidth/2+100),100, 90);
	Shoot2(obj);
	Move2(obj);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(270);
	}
	task Move2(obj){
	ObjMove_SetAngle(obj, GetAngleToPlayer(obj));
	wait(30);
	ObjMove_SetAcceleration(obj, 0.05);
	ObjMove_SetMaxSpeed(obj, 5);
	wait(360);
	Obj_Delete(obj);
	}
	
	task Shoot2(obj){
	while(!Obj_IsDeleted(obj)){
	CreateShotA2(ObjMove_GetX(obj)-85*cos(ObjMove_GetAngle(obj)), ObjMove_GetY(obj)-85*sin(ObjMove_GetAngle(obj)), 0.5, ObjMove_GetAngle(obj)-90, 0.02, 5, ARROWHEAD_RED, 10);
	CreateShotA2(ObjMove_GetX(obj)-85*cos(ObjMove_GetAngle(obj)), ObjMove_GetY(obj)-85*sin(ObjMove_GetAngle(obj)), 0.5, ObjMove_GetAngle(obj)+90, 0.02, 5, ARROWHEAD_RED, 10);
	wait(8);
	}
	}
}

task Move{
	loop{
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-50, 50), GetStgFrameHeight/3-50+rand(-20, 20), 5, 3);
	wait(160);
	}
}

task Pattern2{
	loop{
	let random = rand(0,360);
		ascent(i in 0..24){
		CreateShotA2(BossX, BossY, 5, random+(i*360/24), -0.085, 1.2, PELLET_RED, 10);
		}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(60);
	}
}

task Pattern{
	ascent(i in 0..5){
	let obj = KillyStick(30+(i*80), -20, 90);
	Move(obj);
	Shoot(obj);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	task Shoot(obj){
	wait(80);
	ascent(i in 0..9){
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj)-60, 0.5, 270, 0.01, 5, ARROWHEAD_YELLOW, 5);
		Split(obj2);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		wait(10);
		}
	}
	
	task Split(obj){
	wait(20);
	CreateShotB2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0.5, 0, 0, 0.01, 5, 5, ARROWHEAD_YELLOW, 5); 
	CreateShotB2(ObjMove_GetX(obj), ObjMove_GetY(obj), -0.5, 0, 0, 0.01, 5, 5, ARROWHEAD_YELLOW, 5); 
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	Obj_Delete(obj);
	}
	
	task Move(obj){
	wait(30);
	ObjMove_SetAcceleration(obj, 0.05);
	ObjMove_SetMaxSpeed(obj, 5);
	wait(130);
	ObjMove_SetAcceleration(obj, 0);
	ObjMove_SetSpeed(obj, 0);
	ScreenShake(0.5,5);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargedown.wav", 120);
	}
}


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