//#TouhouDanmakufu
#ScriptVersion[3]
#Title["AliceS1_H"]
#Text["Bullets"]
let white = GetCurrentScriptDirectory~"sprites/white.png";

#include"./../lib/SHOT_REPLACE/shot_replace.dnh"
#include"./../includes/BossIncludes.txt"
let color2 = 1;
let color = 0;
let wave = 0;
let spawneddolls = 0;
let objEnemy;
let duration = 0;
let dollsarray = [];
let stopstuff = false;
let angle = 0;
let angle2 = 0;
let one = 1;
let type = 0;
let animframe = 0;
let frame = 0;
let objlasers = [];
let GetSpeedX = 0;
let variable = 0;
let thunder = GetCurrentScriptDirectory~"sfx/thunder.wav";
let n = 0;
let shotrate = 35;
let bombrate = 25;
let reimucut = GetCurrentScriptDirectory~"sprites/cirnocut.png";

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
	SetScriptResult(1000);
	}
	case(EV_REQUEST_TIMER){
	SetScriptResult(999);
	}
	case(EV_REQUEST_SPELL_SCORE){
	SetScriptResult(10000000);
	}
	case(EV_GAIN_SPELL)
	{
	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));	
	}
}

@Initialize{
	//Resource Loading
	shotinit;
	
	
	
	
	
	
	
	LoadTexture(reimucut);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	Invuln(600, shotrate, bombrate);
	//BottomEnemyMarker(objEnemy, objEnemy);
	let Reimu = GetCurrentScriptDirectory~"sprites/cirno.png";
	ObjPrim_SetTexture(objEnemy, Reimu); 
	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 128, 128);
	ascent(x in 0..3){
	ObjAnim_AddFrameA2(objEnemy, ANIM_IDLE, 0, 0+x*128, 128, 128+x*128, 0, 0);
	}
	ascent(x in 0..2){
	ObjAnim_AddFrameA2(objEnemy, ANIM_IDLE, 128, 0+x*128, 256, 128+x*128, 0, 0);
	}
	ascent(x in 0..2){ObjAnim_AddFrameA2(objEnemy, ANIM_MOVE_LEFT, 256, 128*x, 256+128, 128*x+128, 1, 0);}
	
	
	ascent(x in 2..4){ObjAnim_AddFrameA2(objEnemy, ANIM_MOVE_RIGHT, 256, 128*x, 256+128, 128*x+128, 0, 0);}
	
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_RIGHT, 256, 128*2, 128*3, 128*2+128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_RIGHT, 0, 0, 128, 128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_LEFT, 256, 0, 128*3, 128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_LEFT, 0, 0, 128, 128, 0, 0);
	
	ascent(x in 0..3){ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACK, 128*3, 128*x, 128*4, 128*x+128, 0, 0);}
	ascent(x in 0..3){ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACKEND, 128*3, 128*2-128*x, 128*4, 128*3-128*x, 0, 0);}
	
	ObjAnim_SetSpeedA1(objEnemy, ANIM_IDLE, 12);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_LEFT, 8);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_RIGHT, 8);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_ATTACK, 8);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_RIGHT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_LEFT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_ATTACK, 2);
	ObjAnim_StartAnimationA2(objEnemy, 0, 0);
		ObjSprite2D_SetDestCenter(objEnemy);  
	
	
	
LoadTexture(white);
	delayedstart;
	SetShotAutoDeleteClip(30, 100, 30, 30);
	
	
}



task delayedstart{
ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 60);
wait(60);

ObjEnemyBossScene_StartSpell(objScene);
ObjEnemyBossScene_SetSpellTimer(objScene, 60*32.75);

PlaySoundEffect("cardcall", 90, GetCenterX);
ObjAnim_SetAttackA2(objEnemy, 75);
ObjCutin_SetSpellcardS4("Ice Sign &quot;Icicle Crash&quot;", reimucut, "NAZRIN", 135, 206, 250);
ObjCutin_LaunchS3("NAZRIN", reimucut, "Hard");
NotifyEventAll(EV_SPELLBG, 4);
wait(75);
attack1;
attack2;
}




@MainLoop{
	
	
	SetCommonData("sakuyax", ObjMove_GetX(objEnemy));
	SetCommonData("sakuyay", ObjMove_GetY(objEnemy));
	if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <=0 && stopstuff==false){stopstuff=true;}

		
if(stopstuff==true && popped==false){
DestroyBoss;
}	
	
	GetEnemyX = ObjMove_GetX(objEnemy);
	GetEnemyY = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetEnemyX, GetEnemyY, 25);//当たり判定(自機弾用)登録
	type++;
	if(type>=600){
	Invuln(0, shotrate, bombrate);
	if(GetCommonData("timestop", false)==true){
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetEnemyX, GetEnemyY, 600);
	ObjEnemy_SetDamageRate(objEnemy, 0, bombrate);
	}
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetEnemyX, GetEnemyY, 17);//当たり判定(体当たり用)登録
	}
	frame++;
	yield;
	GetSpeedX = ObjMove_GetSpeed(objEnemy)*cos(ObjMove_GetAngle(objEnemy));
}

task attack2{
wait(300);
loop{

	loop(19){
	PlaySoundEffect("shot2", 75, GetEnemyX);
loop(6){
	ascent(i in 0..3){
		CreateDNHShotA2(GetEnemyX, GetEnemyY, 4, angle+(i*1.875*one*-1), -0.15, 1+(i/3), BLUE23, 10);
		}
		angle+=360/6;
		}
		angle+=22.78372983*one;
wait(12);
if(popped==true){ return; }
}

wait(30);
one*=-1;

if(popped==true){ return; }
}
}

task attack1{	
let one = -1;
let cascadex = 0;
wait(90);
ChangeToAttack1;
let angle2 = 0;
let color = 0;
let angle3 = 0;
if(popped==true){return;}
PlaySoundEffect("charge2", 85, -1);
TCharge01(objEnemy, 3, 45, 155, 155, 255);
wait(45);
if(popped==true){ return; }
loop{

ObjAnim_SetAttackA1(objEnemy, true);
wait(10);
if(popped==true){ return; }

cascadex = GetPlayerX;

ascent(i in 0..180){
PlaySoundEffect("ping", 60, cascadex,);
	loop(2){
CreateDNHShotA1(cascadex+rand(-5-(i/3), 5+(i/3)), rand(-5, 5), rand(2, 4)+(i/90), rand(88, 92), WHITE23, rand(1, 15));
	}
	if(popped==true){ return; }
yield;
}

if(popped==true){ return; }
one*=-1;
ObjAnim_SetAttackA1(objEnemy, false);
wait(20);
if(popped==true){ return; }
ExMove(GetClipMinY+120, rand(-5, 5), rand(20, 30));
wait(100);
angle = rand(0, 360);
if(popped==true){ return; }
color++;
wave++;
}
}

task CreateExplodingThing(x, y, v, angle, acc, minmax, graphic, delay){
let objpop = CreateDNHShotA2(x, y, v, angle, acc, minmax, graphic, delay);
let graphicarray = [RED12, ORANGE12, YELLOW12, GREEN12, AQUA12, BLUE12, PURPLE12];
let angle2 = angle-180;
if(wave%2==0){ angle2 = angle; }
loop(45){
if(Obj_IsDeleted(objpop)){ return; }
yield;
}
PlaySoundEffect("ping", 82.5, GetCenterX);
if(Obj_IsDeleted(objpop)){ return; }
loop(5){
let objugh = CreateDNHShotA2(ObjMove_GetX(objpop), ObjMove_GetY(objpop), 0.05, angle2, 0, 2, graphicarray[(graphic+2)%7], 10);
ObjMove_AddPatternA2(objugh, 1, NO_CHANGE, NO_CHANGE, 0, 0, 2);
ObjMove_AddPatternA2(objugh, 45, NO_CHANGE, NO_CHANGE, 0.02, 0, 2.35);
angle2+=360/5;
} 
Obj_Delete(objpop);
}

task ChangeToAttack1{
ascent(x in 0..3){ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACK, x, 128*4, 128*x, 128*5, 128*x+128, 0, 0);}
	ascent(x in 0..3){ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, x, 128*4, 128*2-128*x, 128*5, 128*3-128*x, 0, 0);}
}

task DestroyBoss{
NotifyEventAll(EV_SPELLBGEND, 1);
SetCommonData("timestop", false);
SetCommonData("petals", false);
popped=true;
StopSlow(TARGET_ALL);
loop(10){ yield; }
Obj_Delete(objEnemy);
loop(45){ yield; }
		CloseScript(GetOwnScriptID());
		return;
}
