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

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


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death2.wav", 90);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtSpeed(objBoss,384/2,200,4);
	
	mainTask;	
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1500);
        }
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	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 SpellCall {
	bspell = true;
	TCallBg2;
}
let Diancie = GetCurrentScriptDirectory ~ "Functions/img/Cutin/DiancieCutin.png";
task action{
wait(60);
ObjCutin_SetSpellcardS3("Earth's Crystals &quot;Stone Edge&quot;", 255, 15, 200);
ObjCutin_LaunchS3("KANAKO", Diancie,"Normal");
SpellCall;
let objScene = GetEnemyBossSceneObjectID();
ObjEnemyBossScene_StartSpell(objScene);
wait(180);
Attack;
wait(50);
ObjEnemy_SetDamageRate(objBoss,50,30);
}

task Attack {
	let angle = 0;
	wait(20);
	loop(2){
	let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, angle, ICEBREAKER_PINK, 20);
	ObjShot_SetSpellResist(obj, 1);
	IndicationLaser(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),angle,40);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 90);
	angle += 180;
	Crystal(obj);
	}
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
	wait(30);
	let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0, 90, ICEBREAKER_PINK, 20);
	ObjShot_SetSpellResist(obj, 1);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 90);
	Crystal(obj);
	let angle = GetAngleToPlayer(objBoss);
	IndicationLaser(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),angle,70);
	ObjMove_SetDestAtWeight(obj,ObjMove_GetX(objBoss)+35*cos(angle),ObjMove_GetY(objBoss)+35*sin(angle),10,5);
	wait(30);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/charge.wav", 100);
	ConcentrationA1(objBoss,"MAGIC",60,3,120,[255,150,255]);
	ConcentrationA1(obj,"MAGIC",60,4,120,[255,150,255]);
	wait(70);
	Shootthings(obj);
	wait(20);
	ObjMove_SetAngle(obj, angle);
	ObjMove_SetAngle(objBoss, angle);
	ObjMove_SetAcceleration(obj, 0.2);
	ObjMove_SetAcceleration(objBoss, 0.2);
	ObjMove_SetMaxSpeed(obj, 666);
	ObjMove_SetMaxSpeed(objBoss, 666);
	loop{
	if(!Obj_IsDeleted(obj)){yield;}
	else{break;}
	}
	ObjMove_SetSpeed(objBoss, 0);
	ObjMove_SetAcceleration(objBoss, 0);
	ObjMove_SetMaxSpeed(objBoss, 0);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/death.wav", 100);
	ScreenShake(122,15);
}
}

task Shootthings(obj){
	let angle = ObjMove_GetAngle(obj)-61;
	while(!Obj_IsDeleted(obj)){
	loop(4){
	CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1,angle+90,ICE_ROSE,5);
	angle += 360/4;
	}
	angle += 5;
	wait(3);
	}
}


task IndicationLaser(x,y,angle,g){
	let obj = CreateStraightLaserA1(x,y,angle,1024,50,0,416,1111);
	wait(g);
	Obj_Delete(obj);
}


task Crystal(obj){
    while(!Obj_IsDeleted(obj)){
	let spd = ObjMove_GetSpeed(obj)/2;
	let radius = 1;
	if(trunc(ObjMove_GetX(obj))<0){
	let woop = ObjMove_GetX(obj);
	let woop2 = ObjMove_GetY(obj);
	let angle = ObjMove_GetAngle(obj)+180;
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 50);
		ascent(i in 0..150){
		let las1 = CreateStraightLaserA1(woop,woop2+(i*radius),angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las1,255,80,235);
		let las2 = CreateStraightLaserA1(woop,woop2-(i*radius),angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las2,255,80,235);
		ObjShot_SetDeleteFrame(las1,170);
		ObjShot_SetDeleteFrame(las2,170);
		Obj_Delete(obj);
		wait(1);
		}
	}
	if(trunc(ObjMove_GetX(obj))>GetStgFrameWidth){
	let woop = ObjMove_GetX(obj);
	let woop2 = ObjMove_GetY(obj);
	let angle = ObjMove_GetAngle(obj)+180;
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 50);
		ascent(i in 0..150){
		let las1 = CreateStraightLaserA1(woop,woop2+(i*radius),angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las1,255,80,235);
		let las2 = CreateStraightLaserA1(woop,woop2-(i*radius),angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las2,255,80,235);
		ObjShot_SetDeleteFrame(las1,170);
		ObjShot_SetDeleteFrame(las2,170);
		Obj_Delete(obj);
		wait(1);
		}
	}
	if(trunc(ObjMove_GetY(obj))<0){
	let woop = ObjMove_GetX(obj);
	let woop2 = ObjMove_GetY(obj);
	let angle = ObjMove_GetAngle(obj)+180;
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 50);
		ascent(i in 0..150){
		let las1 = CreateStraightLaserA1(woop+(i*radius),woop2,angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las1,255,80,235);
		let las2 = CreateStraightLaserA1(woop-(i*radius),woop2,angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las2,255,80,235);
		ObjShot_SetDeleteFrame(las1,170);
		ObjShot_SetDeleteFrame(las2,170);
		Obj_Delete(obj);
		wait(1);
		}
	}
	if(trunc(ObjMove_GetY(obj))>GetStgFrameHeight){
	let woop = ObjMove_GetX(obj);
	let woop2 = ObjMove_GetY(obj);
	let angle = ObjMove_GetAngle(obj)+180;
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser2.wav", 50);
		ascent(i in 0..150){
		let las1 = CreateStraightLaserA1(woop+(i*radius),woop2,angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las1,255,80,235);
		let las2 = CreateStraightLaserA1(woop-(i*radius),woop2,angle+rand(-45,45), 200-(i*1.5), 15,15000, ICE_ROSE, 0);
		ObjRender_SetColor(las2,255,80,235);
		ObjShot_SetDeleteFrame(las1,170);
		ObjShot_SetDeleteFrame(las2,170);
		Obj_Delete(obj);
		wait(1);
		}
	}
yield;
}
}

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

