#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell1"]
#Text["Web Weaving &quot;Kurodani's Nest&quot;"]


let objBoss;

let BossX;
let BossY;

let AttackX;
let AttackY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderyamame(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[255,25,25],2);
	BottomEnemyMarker(objBoss, objBoss);
	MagicRing(objBoss,false);
	DrawName("Yamame Kurodani", [200, 200, 20], 11);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/4, 5, 4);
	mainTask;
	end;

} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(70);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	AttackX = BossX+10;
	AttackY = BossY-20;
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
wait(20);
SpellCard("Web Weaving &quot;Kurodani's Nest&quot;");
ObjEnemy_SetDamageRate(objBoss, 100, 100);
let count = 0;
	loop{
	let Player = GetAngleToPlayer(objBoss);
	attack=true;
	wait(20);
		ascent(j in 0..25){
			ascent(i in 0..6){
			CreateShotA1(AttackX, AttackY, 4, Player+2+(i*360/6), OVAL_YELLOW, 5);
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
		wait(3);
		}
		ascent(i in 0..6){
		let obj = CreateShotA1(AttackX, AttackY, 4, Player+2+(i*360/6), OVAL_YELLOW, 5);
		WebCreate(obj);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
		wait(3);
		ascent(j in 0..50){
			ascent(i in 0..6){
			CreateShotA1(AttackX, AttackY, 4, Player+2+(i*360/6), OVAL_YELLOW, 5);
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
		wait(3);
		}
	attack=false;
	wait(100);
	if(count==0){Spiral; Spiral; count++;}
	wait(80);
	}
}

task Spiral{
let angle = 0;
let offset = 0;
	loop{
	let obj = CreateShotA2(AttackX+rand(75,125)*cos(offset), AttackY+rand(75,125)*sin(offset), 0.2, angle+180, 0.01, 5, ICE_RED, 5);
	ObjMove_SetAngularVelocity(obj, rand(-0.1, 0.1));
	offset+=7;
	angle+=7;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(2);
	}
}

task WebCreate(obj){
	while(!Obj_IsDeleted(obj)){
	Strings(obj);
	wait(20);
	}
}

task Strings(obj){
let X = ObjMove_GetX(obj);
let Y = ObjMove_GetY(obj);
let angle = ObjMove_GetAngle(obj);
	ascent(i in 0..35){
	CreateShotA2(X, Y, 0.2, angle+90, 0.06, 59, PELLET_GRAY, 15);
	CreateShotA2(X, Y, 0.2, angle-90, 0.06, 59, PELLET_GRAY, 15);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
	wait(3);
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Yam1.png";
	ObjCutin_SetSpellcardS3(name, 200, 200, 12);
	ObjCutin_LaunchS3("BYAKUREN", Cutin, "Normal");
	TCallBg2;
	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());
} 
