#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 4"]
#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,180,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("Clear Body &quot;Diamond Storm&quot;", 255, 15, 200);
ObjCutin_LaunchS3("KANAKO", Diancie,"Normal");
SpellCall;
let objScene = GetEnemyBossSceneObjectID();
ObjEnemyBossScene_StartSpell(objScene);
wait(180);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 100);
ConcentrationA1(objBoss,"MAGIC",150,2,120,[255,150,255]);
wait(150);
Attack;
wait(50);
ObjEnemy_SetDamageRate(objBoss,60,30);
}

task Attack{
	wait(50);
	Diamonds;
	wait(300);
	Diamonds2;
	wait(200);
	loop{
	Diamonds;
	wait(500);
	}
}

task Diamonds{	
        let angleT = rand(0, 360);
		let sinmod = 1;
        let objcount = 0;
        loop(100){
           loop(6){
				let AngleToPlayer = GetAngleToPlayer(objBoss);
				SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 90);
                let obj = CreateShotA1(ObjMove_GetX(objBoss)+25*sin(sinmod), ObjMove_GetY(objBoss)+25*cos(sinmod), 2, angleT, ICE_PINK, 15);
				ObjMove_AddPatternA3(obj,0,5+1+1*sin(sinmod),angleT,-0.04,5.5,0,NO_CHANGE);
				ObjMove_AddPatternA3(obj,110,0,GetAngleToPlayer(obj),0.3,0,5+3*sin(sinmod),NO_CHANGE);
				DelayInd(sinmod, AngleToPlayer);
                angleT += 360/6;
            }
			wait(1);
			sinmod += 6;
            angleT += sin(objcount) * 30;
            objcount++;
            yield;
        }
}

task Diamonds2{	
	let angleT = rand(0, 360);
    loop{
    let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, angleT, BALL_S_RED, 5);
	ObjMove_AddPatternA3(obj,0,1,angleT,0.01,0.5,5,NO_CHANGE);
	let obj2 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, angleT, BALL_S_VIOLET, 5);
	ObjMove_AddPatternA3(obj2,0,1,angleT,0.01,-0.5,5,NO_CHANGE);
	angleT += 360/24;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/glow.wav", 30);
	wait(5)
	}
}

task DelayInd(si, ang){
wait(55);
IndicationLaser(ObjMove_GetX(objBoss)+100*sin(si),ObjMove_GetY(objBoss)+100*cos(si), ang, 100);
wait(55);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 60);
}

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

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

