#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell4"]
#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(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(60);
SpellCard("Wind Sign &quot;wooshy wooshy wind v2&quot;");
GuaranteedWoosh;
wait(180);
WooshyWooshy;
wait(60);
revolve=true;
Pattern;
wait(60);
Pattern2;
Move;
}

task Move{
loop{
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-50, 50), GetStgFrameHeight/4+rand(-25, 25), 10, 2);
wait(210);
}
}

task Pattern2{
loop{
		ascent(i in 0..12){
			ascent(j in 0..12){
			let obj = CreateShotA1(BossX, BossY, 1+(j/2), 0+(i*360/24), AMULET_BLUE, 5);
			ObjMove_AddPatternA2(obj, 60, 0, NO_CHANGE, 0.01, 0, 3);
			}
			wait(3);
		}
		ascent(i in 0..12){
			ascent(j in 0..12){
			let obj = CreateShotA1(BossX, BossY, 1+(j/2), 180+7.5-(i*360/24), AMULET_BLUE, 5);
			ObjMove_AddPatternA2(obj, 60, 0, NO_CHANGE, 0.01, 0, 1);
			}
			wait(3);
		}
		
		wait(120);
		ascent(i in 0..32){
		let obj = CreateShotA1(BossX, BossY, 1, 0+(i*360/32), BUBBLE_RED, 5);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
		ascent(i in 0..32){
		let obj = CreateShotA1(BossX, BossY, 0.8, 5.625+(i*360/32), BUBBLE_RED, 5);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		}
		wait(60);
	}
}

task Pattern{
	loop{
		ascent(j in 0..8){
		let obj = CreateShotA2(BossX+60, BossY-20, 3, -70+(j*10), 0.08, 15, ICE_GREEN, 10);
		let obj2 = CreateShotA2(BossX-60, BossY-20, 3, 180+70-(j*10), 0.08, 15, ICE_GREEN, 10);
		}
		wait(4);
	}
}

task GuaranteedWoosh{
		let duration = 60;
		let delay = 60;
		let random = 270;
		let obj = WooshyTempest(GetStgFrameWidth/2-150, GetStgFrameWidth/2, random, duration, delay); 
		MoveWoshy(obj, random, duration, delay);

		let obj2 = WooshyTempest(GetStgFrameWidth/2, GetStgFrameWidth/2, random, duration, delay); 
		MoveWoshy(obj2, random, duration, delay);
	
		let obj3 = WooshyTempest(GetStgFrameWidth/2+150, GetStgFrameWidth/2, random, duration, delay);
		MoveWoshy(obj3, random, duration, delay);
		
		wait(60);
		ScreenShake(210+64,4);
		
		task MoveWoshy(obj, dir, dur, del){
		let direction;
		wait(del);
		wait(32);
		if(dir==90){direction="up";}
		if(dir==270){direction="down";}
		loop(dur){
		if(GetPlayerX<ObjMove_GetX(obj)+65 && GetPlayerX>ObjMove_GetX(obj)-65 && direction=="up"){ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY+4);}
		if(GetPlayerX<ObjMove_GetX(obj)+65 && GetPlayerX>ObjMove_GetX(obj)-65 && direction=="down"){ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY-4);}
		yield;
		}
		}
	}

task WooshyWooshy{
	loop{
	let yes = 0;
		if(truncate(rand(1,4))==3){
		let random = truncate(rand(1,3));
		let duration = 120;
		let delay = 60;
			if(random==1){random=90;}
			else{random=270;}
		let obj = WooshyTempest(GetStgFrameWidth/2-150, GetStgFrameWidth/2, random, duration, delay); 
		MoveWoshy(obj, random, duration, delay);
		yes++;
		}
	
		if(truncate(rand(1,4))==3){
		let random = truncate(rand(1,3));
		let duration = 120;
		let delay = 60;
			if(random==1){random=90;}
			else{random=270;}
		let obj = WooshyTempest(GetStgFrameWidth/2, GetStgFrameWidth/2, random, duration, delay); 
		MoveWoshy(obj, random, duration, delay);
		yes++;
		}
	
		if(truncate(rand(1,4))==3){
		let random = truncate(rand(1,3));
				let duration = 120;
		let delay = 60;
			if(random==1){random=90;}
			else{random=270;}
		let obj = WooshyTempest(GetStgFrameWidth/2+150, GetStgFrameWidth/2, random, duration, delay);
		MoveWoshy(obj, random, duration, delay);
		yes++;
		}
	if(yes>0){Shake;}
	if(yes>0){wait(210+64+5);}
	task Shake{
	wait(60);
	ScreenShake(210+64,4);
	}
	}
	
	task MoveWoshy(obj, dir, dur, del){
	let direction;
	wait(del);
	wait(32);
	if(dir==90){direction="up";}
	if(dir==270){direction="down";}
	loop(dur){
	if(GetPlayerX<ObjMove_GetX(obj)+65 && GetPlayerX>ObjMove_GetX(obj)-65 && direction=="up"){ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY+4);}
	if(GetPlayerX<ObjMove_GetX(obj)+65 && GetPlayerX>ObjMove_GetX(obj)-65 && direction=="down"){ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, GetPlayerY-4);}
	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());
} 
