#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2"]
#Text["Disease &quot;Viral Outbreak&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);
	DiseaseBoss(objBoss, 4, 70);
	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(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_PLAYER_REBIRTH){
		SetCommonData("Stacks",0);
	}
} 

@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 { 
Diseasecontroller;
wait(60);
SpellCard("Disease &quot;Viral Outbreak&quot;");
ObjEnemy_SetDamageRate(objBoss, 100, 100);
Pattern1;
wait(180);
Pattern2;
wait(180);
Pattern3;
}

task Pattern1{
	ascent(j in 0..50){
		ascent(i in 0..8){
		let obj = CreateShotA1(AttackX, AttackY, 0.6, j*25+i*360/8, LARGE_PURPLE, 5);
		Disease(obj, 1.75, 30);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
	wait(120);
	}
}

task Pattern2{
	loop{
	let angle = 0;
	let random = rand(0,360);
		ascent(j in 0..50){
			ascent(i in 0..2){
			let obj = CreateShotA2(AttackX+(j*2)*cos(angle), AttackY+(j*2)*sin(angle), 0, random+j*25+i*360/12, 0, 100, ICE_PURPLE, 5);
			Redirect(obj);
			Disease(obj, 1, 20);
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		angle+=32;
		wait(2);
		}
	wait(120);
	}
	task Redirect(obj){
	wait(60);
	ObjMove_SetAcceleration(obj, 0.01);
	}
}

task Pattern3{
	loop{
	let obj = CreateShotA2(AttackX, AttackY, 1, GetAngleToPlayer(objBoss), 0.01, 100, ORB_PURPLE, 5);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Disease(obj, 3, 60);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(120);
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Yam2.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);
	GetCommonData("LeftoverStacks",GetCommonData("Stacks",0));
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
