#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell3"]
#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 wind&quot;");
Boom;
attack=true;
wait(120);
revolve=true;
Pattern;
Wooshy;
}

task Boom{
	ascent(i in 0..129){
	let obj = CreateShotB2(BossX, BossY, rand(-3, 3), rand(-5, -3), 0, 0, 5, 5, FIRE_GREEN, 5);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
}

task Pattern{
	loop{
	ascent(j in 0..9){
			ascent(i in 0..9){
			let obj = CreateShotA2(-18+j*6+i*49, -10, 4, 90, -0.05, 0, FIRE_GREEN, 5);
			Move(obj);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		wait(35);
	}
	}
	task Move(obj){
	wait(120);
	let yes = 0;
	if(GetPlayerY<100){yes = 180;}
		if(!Obj_IsDeleted(obj)){
		let a1 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, glAng+yes, 0.007, 10, FIRE_RED, 5);
		ObjRender_SetBlendType(a1, BLEND_ADD_ARGB);
		let a2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, 180 - glAng+yes, 0.007, 10, FIRE_BLUE, 5);
		ObjRender_SetBlendType(a2, BLEND_ADD_ARGB);
		Obj_Delete(obj);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
		}
	}
}

task Wooshy{
let obj = WooshyWind(90);
let count = 0;
Move;
	loop{
	ObjMove_SetAngle(obj, glAng);
	glAng=90+60*sin(count/3);
	count++;
	yield;
	}
	task Move{
	let WindStrength = 0.6;
		loop{
		ObjMove_SetPosition(GetPlayerObjectID,ObjMove_GetX(GetPlayerObjectID)+WindStrength*cos(glAng),ObjMove_GetY(GetPlayerObjectID)+WindStrength*sin(glAng));
		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());
} 
