#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["And Something else."]
#Text["Baaaaaaaaaap"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;

let BossX; 
let BossY;

SetCommonData("BossAlpha",255);
SetCommonData("ForceLifebar", 0);

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 1);
	DrawName("No joke up here, go away.", [255,25,25], 12.7);
	MagicRing(objBoss,true);
	FlameAura(objBoss,[199, 5, 5],3);
	RenderCharacter(objBoss);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;
	StageBackground;
	}
	
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(52);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

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

@Finalize {
} 

task mainTask { 
SetCommonData("Flare",1);
SetCommonData("FlareIntensity", 2);
SetPlayerLife(0);
SpellCard("Solar Energy &quot;Nuclear Fusion Beam&quot;", [255,10,0], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Emotions/uts.png", 100, "Utsuho");
Pattern;
}

task Pattern{
	loop(1){
	Attack(60);
	let obj = Sun3d(BossX, BossY-28, 0.5, 0.1, 125);
	Circle(BossX, BossY-28);
	Explosion(BossX, BossY-28, 2);
	Beam(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	}
wait(60*4);
	loop(3){
	Attack(60);
	let obj = Sun3d(BossX+rand(-200, 200), BossY+rand(-100, 100), 0.5, 0.1, 125);
	Beam(obj);
	Circle(ObjMove_GetX(obj), ObjMove_GetY(obj));
	Explosion(ObjMove_GetX(obj), ObjMove_GetY(obj), 2);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	wait(120);
	}
wait(60*3);
	loop(1){
	Attack(60);
	let obj = Sun3d(BossX, BossY-180, 3, 0.05, 125);
	Circle(BossX, BossY-28);
	Explosion(BossX, BossY-28, 2);
	Beam2(obj);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explosion.wav", 80);
	wait(120*5);
	ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2, 10000, 10, 1);
	}
}

	task Beam2(obj){
	wait(120);
	fire;
	loop(4){
	ascent(j in 0..32){
	let aaa = NuclearLaser(ObjMove_GetX(obj)+150*cos(j*360/42), ObjMove_GetY(obj)+150*sin(j*360/42), GetAngleToPlayer(objBoss), 600, 50, 120, 100, 120);
	}
	wait(120);
	fire;
	DEADLYLASER;
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spark.wav", 120);
	}
		wait(120);
	}
	
	task fire{
			ascent(i in 0..120){
			let random = rand(0,360);
			FireShotA1(BossX, BossY-120, 5, random, MIKO_ORB_YELLOW, 20);

			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
			wait(1);
		}
	}
	
	task DEADLYLASER{
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/sunlaser.wav", 120);
	}

	
	task Beam(obj){
	wait(60);
	ascent(j in 0..12){
	NuclearLaser(ObjMove_GetX(obj)+45*cos(j*360/12), ObjMove_GetY(obj)+45*sin(j*360/12), j*360/12, 600, 50, 120, 100, 120);
	}
	wait(120);
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/sunlaser.wav", 80);
		ascent(i in 0..4){
		let random = rand(0,360);
			ascent(j in 0..24){
			FireShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, j*360/24+random, MIKO_ORB_YELLOW, 20);
			}
			PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
			wait(30);
		}
		wait(60);
		Obj_Delete(obj);
	}

task Movement{ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-150, 150), GetStgFrameHeight/3+rand(-25, 25), 10, 4);}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 