#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell1"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	FlameAura(objBoss,[255,255,255],3);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjMove_SetDestAtWeight(objBoss,384/2,150,2,6);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	yield;
} 

@Finalize {

} 

task mainTask { 
	wait(60);
	SpellCard("Nue Sign &quot;Mysterious Non-bendy Snake Rain&quot;");
	attack=true;
	wait(20);
		loop(2){
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 70);
			ascent(i in 0..45/2){
			CreateLooseLaserA1(BossX, BossY-40, 7, 270-45+(i*4), 100, 15, C_LASER_GREEN, 5);  
			yield;
			}
			
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 70);
			ascent(i in 0..45/2){
			CreateLooseLaserA1(BossX, BossY-40, 7, 270+45-(i*4), 100, 15, C_LASER_GREEN, 5);  
			yield;
			}
			
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 70);
			ascent(i in 0..45/2){
			CreateLooseLaserA1(BossX, BossY-40, 7, 270-45+(i*4), 100, 15, C_LASER_GREEN, 5);  
			CreateLooseLaserA1(BossX, BossY-40, 7, 270+45-(i*4), 100, 15, C_LASER_GREEN, 5);  
			yield;
			}
		wait(10);
		}
	attack=false;
	wait(20);
	Subfire;
		loop{
		let random = rand(0,45);
			ascent(i in 0..60){
			let obj = CreateLooseLaserA1(-200+random+(i*45), -25, 2.5, 90-10, 150, 15, C_LASER_GREEN, 5);  
			ObjMove_SetAcceleration(obj, 0.03);
			ObjMove_SetMaxSpeed(obj, 25);
			yield;
			}
			ascent(i in 0..60){
			let obj = CreateLooseLaserA1(GetStgFrameWidth+200-random-(i*45), -25, 2.5, 90+10, 150, 15, C_LASER_GREEN, 5);  
			ObjMove_SetAcceleration(obj, 0.03);
			ObjMove_SetMaxSpeed(obj, 25);
			yield;
			}
			let random2 = [rand(5,15), rand(-5,-15)];
			ascent(i in 0..60){
			let obj = CreateLooseLaserA1(GetStgFrameWidth+200-random-(i*45), -25, 2, 90+random2[0], 150, 15, C_LASER_GREEN, 5);  
			ObjMove_SetAcceleration(obj, 0.03);
			ObjMove_SetMaxSpeed(obj, 25);
			let obj2 = CreateLooseLaserA1(-200+random+(i*45), -25, 2, 90+random2[1], 150, 15, C_LASER_GREEN, 5);  
			ObjMove_SetAcceleration(obj2, 0.03);
			ObjMove_SetMaxSpeed(obj2, 25);
			yield;
			ObjEnemy_SetDamageRate(objBoss, 60, 60);
			}
		}
	}
	
task Subfire{
wait(210);
	while(!Obj_IsDeleted(objBoss)){
	let angle = rand(0, 360);
	attack=true;
	wait(20);
	loop(7){
		ascent(i in 0..6){
		let obj = CreateShotA2(BossX+(20*(i*0.9))*cos(angle), BossY+(20*(i*0.9))*sin(angle), 0.2, GetAngleToPlayer(objBoss), 0.01, 15, FIRE_BLUE, 10*i);  
		ObjMove_SetAcceleration(obj, 0.06);
		ObjMove_SetMaxSpeed(obj, 5);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		angle+=360/7;
		}
	}	
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 70);
	wait(20);
	attack=false;
	wait(140);
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Cutin.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 25);
	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());
} 
