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

let objBoss;
let objBossFake;

let BossX; 
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	HitSound(objBoss, 80, 450);
	EnemyMarker(objBoss);
	DamageReduction(objBoss, 0);
	DrawName("Aunn Komano", [40,140,90], 12.7);
	MagicRing(objBoss,true);
	FlameAura(objBoss,[199, 5, 5],3);
	RenderCharacter(objBoss);
	ObjMove_SetPosition(objBoss, -100, -100);
	
	objBossFake = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objBossFake);
	MagicRing(objBossFake,true);
	EnemyMarker(objBossFake);
	FlameAura(objBossFake,[199, 5, 5],3);
	RenderCharacter(objBossFake);
	ObjMove_SetPosition(objBossFake, GetStgFrameWidth, 0);
	ObjMove_SetDestAtWeight(objBossFake, GetStgFrameWidth/2, GetStgFrameHeight/4, 10, 5);
	
	if(GetCommonData("IsStage", false)==false){
	StageBackground;
	}
	
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(105);
	}
	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 { 
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage.wav", 255);
wait(120);
loop(3){
SetCommonData("BossAlpha", 0);
wait(5);
SetCommonData("BossAlpha", 255);
wait(5);
}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/barrage2.wav", 255);
ObjMove_SetPosition(objBossFake, -100, -100);
yield;
SetCommonData("BossAlpha", 255);
wait(10);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/4, 10, 8);
wait(50);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/charge.wav", 255);
	loop(8){
	Concentrate(BossX, BossY, 0, 4, 4, 1, "Cherry", 200, -2, [125, 15, 125]);
	Concentrate(BossX, BossY, 0, 4, 4, 1, "Cherry", 200, 2, [255, 255, 255]);
	wait(5);
	}
Pattern;
}

////SpellCard("Spell background test!", [200,200,200], GetCurrentScriptDirectory ~ "./default_system/img/Ingame/Kaoru.png", 25);


task Pattern{
loop{
Attack(5*9);
ascent(i in 0..7){
	ascent(j in 0..32){
	let obj = CreateShotA2(BossX+85*cos(j*360/32+i*4), BossY+85*sin(j*360/32+i*4), 2, j*360/32+i*4, -0.05, 0,  89, 5);
	Redirect(obj, j*360/32, i);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(10);
}
wait(70);
Attack(5*9);
descent(i in 0..7){
	ascent(j in 0..32){
	let obj = CreateShotA2(BossX+85*cos(j*360/32+i*4), BossY+85*sin(j*360/32+i*4), 2, j*360/32+i*4, -0.05, 0,  84, 5);
	Redirect(obj, j*360/32-180, i);
	}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 80);
	wait(10);
}
wait(70);
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2+rand(-50, 50), GetStgFrameHeight/4+rand(-25, 25), 15, 3);
}


task Redirect(obj, off, i){
let ang = ObjMove_GetAngle(obj);
wait(60-i);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
ObjMove_AddPatternA2(obj, 0, 2, GetAngleToPlayer(obj), -0.02, 0, 0);
wait(110);
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 60);
ObjMove_AddPatternA2(obj, 0, 2, ang+off, 0.01, 0, 10);
}

}

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