#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 5 L"]
#Text["Wooooooop"]

let objBoss;
#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtSpeed(objBoss,384/2,150,7);
	
	mainTask;	
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);
        }
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

let BossX = 0;
let BossY = 0;

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

@Finalize {

} 

task mainTask { 
	renderdiancie(objBoss);
	BottomEnemyMarker(objBoss, objBoss);
	end;
	action;
	BossShotSound(objBoss, 75, 300);
} 

task action{
wait(90);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 100);
ConcentrationA1(objBoss,"Star",210,4,150,[255,150,255]);
Charge(210);
wait(240);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/explosion.wav", 100);
Explosion;
shockwave(objBoss);
FlameAura(objBoss,[255,150,255],3);
wait(15);
Mega = true;
MegaEvolutionSymbol(objBoss);
wait(150);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
wait(50);
Attack;
wait(90);
ObjEnemy_SetDamageRate(objBoss,60,40);
}

task Attack{
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
	let angle = rand(0,360);
	let mod = 0;
	loop(15){
	loop(4){
  let obj = CreateShotA1(ObjMove_GetX(objBoss)+50*cos(angle), ObjMove_GetY(objBoss)+50*sin(angle), 3.5, angle, BALL_S_PINK, 0);
  Reflection(obj, mod);
  angle += 360/4;
}
mod += 0.5;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 60);
wait(3);
}
mod = 0;
wait(40);
}
}

task Reflection(obj, ang){
	let angle = ang;
	while(!Obj_IsDeleted(obj)){		
		if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
		loop(16){
		CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, ObjMove_GetAngle(obj)+angle, ICE_PINK, 0);
		angle += 22.5;
		}Obj_Delete(obj);SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);}
		if(trunc(ObjMove_GetX(obj))<0){
		loop(16){
		CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, ObjMove_GetAngle(obj)+angle, ICE_PINK, 0);
		angle += 22.5;
		}Obj_Delete(obj);SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);}
		yield;
		if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){Obj_Delete(obj);}
		if(trunc(ObjMove_GetY(obj))<0){
		loop(16){
		CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, ObjMove_GetAngle(obj)+angle, ICE_PINK, 0);
		angle += 22.5;
		}Obj_Delete(obj);SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);}
		yield;
	}
}

task Explosion{
let angle = rand(0,360);
let speed = 4;
loop(24){
loop(24){
  let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), speed, angle, BALL_S_GRAY, 0);
  angle += 360/24;
}
angle += 6;
speed -= 0.15;
}
}

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

task Charge(frames){
	let angle = 0;
	loop(frames){
	let obj = CreateStraightLaserA1(ObjMove_GetX(objBoss)+25*cos(angle),ObjMove_GetY(objBoss)+25*sin(angle),angle, 25, 12, 80,LASER_GRAY, 0);
	ObjShot_SetIntersectionEnable(obj, 0);
	lengh(obj);
	rotate(obj, angle);
	angle += rand(0,360);
	wait(1);
	}
	task lengh(tar){
	let len = 140;
	loop{
	ObjLaser_SetLength(tar, len);
	len-=2.1;
	yield;
	}
	}
	task rotate(tar, ang){
	let num = 0;
	loop{
	ObjMove_SetPosition(tar, ObjMove_GetX(objBoss)+25*cos(ang+num), ObjMove_GetY(objBoss)+25*sin(ang+num));
	ObjStLaser_SetAngle(tar, GetAngleTo(tar, objBoss)+180);
	num++;
	yield;
	}
	}
}

