#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell7"]
#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 {

} 

let glAng = 90;

task Maintask{
wait(60);
SpellCard("Wind Sign &quot;wooshy wooshy upwards wind&quot;");
Wooshy;
revolve = true;
attack = true;
wait(60);
Pattern;
wait(270);
Pattern2;
}

task Pattern2{
	loop{
	let obj = KillyStick(rand(0,GetStgFrameWidth), 0, 270);
	Shoot(obj);
	wait(30);
	}
	task Shoot(obj){
	wait(30);
		ascent(j in 0..24){
		CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj)+80, 0+(j/3), 90, 0.005, 10, AMULET_RED, 25);
		}
	wait(30);
	ObjMove_SetAcceleration(obj, 0.05);
	ObjMove_SetMaxSpeed(obj, 5);
	wait(60);
	Obj_Delete(obj);
	}
}

task Pattern{
	ascent(i in 0..14){
		ascent(j in 0..16){
		let obj = CreateShotB2(0, 0+i*35, 1+j/2, 0, 0, -0.01, 5, -5, KNIFE_RED, 5);
		}
		ascent(j in 0..16){
		let obj = CreateShotB2(GetStgFrameWidth, 0+i*35, -1-j/2, 0, 0, -0.01, 5, -5, KNIFE_BLUE, 5);
		}
	wait(20);
	}
	loop{
	let random = rand(0,1);
		ascent(j in 0..16){
		let obj = CreateShotB2(0, GetStgFrameHeight-10, random+j/2, 0, 0, -0.01, 5, -5, KNIFE_PURPLE, 5);
		}
	wait(25);
	random = rand(0,1);
		ascent(j in 0..16){
		let obj = CreateShotB2(GetStgFrameWidth, GetStgFrameHeight-10, -random-j/2, 0, 0, -0.01, 5, -5, KNIFE_PURPLE, 5);
		}
	wait(25);
	}
}


task Wooshy{
let obj = WooshyWind(270);
	loop{
	ObjMove_SetPosition(GetPlayerObjectID,GetPlayerX, GetPlayerY-1);
	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());
} 
