#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 2"]
#Text[""]
#Background["./../BG.txt"]
#Player["./../player/ln/YK.txt", "./../player/ln/YS.txt", "./../player/gt_medicine/PracticeP.txt"]
#System["./../System/Default_System.txt"]

#include "./../lib/LenenShot/JINXShot_Const.txt"

#include "./../FxnSFX.dnh"
#include "./../lib/Funcs.dnh"
#include "./../lib/FXLib.dnh"
#include "./../lib/Render/MagicCircle.txt"

#include "./../lib/Render/LenenBossRender/RenderLenen.txt"

let objBoss;

let count = 0;

let shot  = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/e_shot_01.wav");
let shot2 = SoundSFX(GetCurrentScriptDirectory ~ "./../lib/SFX/e_shot_00.wav");

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(3000);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(66);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}

@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	
	if(GetCommonData("set_dif", false) == false){Difficulty(3); SetCommonData("set_dif", true);}
	if(GetCommonData("music", false) == false){BGM_Play("wwafawdwg", 75); SetCommonData("music", true);}
	
    ObjMove_SetDestAtFrame(objBoss, gx(), 100, 30);
	TDrawLoop;
    TFinalize;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
    if(count == 0){
        round_bullets;
        count = 0;
    } 
    count++;
    yield;
}

task TDrawLoop{
	renderBoss(objBoss, "Kurohebi", 1, 30, false);
}

task round_bullets{
ObjEnemy_SetDamageRate(objBoss, 0, 0);
wait(65);
ObjEnemy_SetDamageRate(objBoss, 50, 25);
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;} //Default kill to prevent (0,0) spawning
    let rang = 0;
	
	//{
		let ang; let r = 0;
	//}
	
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		aimedknivu();
		ascent(j in 0..9999999){
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}
			
			PlaySFX(shot); ObjSound_SetVolumeRate(shot, 55);
			ascent(i in 0..40){
				ang = r + 360/40*i;
				
				let beetch = CreateShotA1(bx + 0*cos(ang), by + 80*sin(ang), 0, ang, 1, 5);
				let bitch = CreateShotA1(bx + 80*cos(ang), by + 0*sin(ang), 0, ang, 1, 5);
				killdahoe(beetch, "y"); killdahoe(bitch, "x");
			}
			
			r = rand(0,360);
			wait(60*1);
		}
		wait(60 * 999);
    }
	
	task killdahoe(eu, str){
		wait(5); if(Obj_IsDeleted(eu)){return;} ObjShot_SetSpellResist(eu, true);
		ascent(i in 0..3){
			if(Obj_IsDeleted(eu)){return;}
			CreateShotA1(getx(eu), gety(eu), 2 + i/6, geta(eu), 36+i, 1);
		}
		Obj_Delete(eu);
	}
	
	task aimedknivu(){
		let ang = angtoP(objBoss);
		while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		
			ang = angtoP(objBoss);
			PlaySFX(shot2); ObjSound_SetVolumeRate(shot2, 65);
			ascent(i in -2..2){
				ascent(j in 0..10){
					let g = CreateShotA1(bx, by, 3+j/5, ang+i*4, 95, 5); ObjRender_SetBlendType(g, BLEND_ADD_ARGB);
				}
			}
			
			ObjMove_SetDestAtFrame(objBoss, rand(gx-80, gx+80), rand(70, 100), 60*1.5);
			wait(60*3);
		}
	}
}
task DelayLaser(x, y, ang, l, w, dt, graph, delay){
	let objlaser = CreateStraightLaserA1(x, y , ang, l, w, dt, graph, delay);
	ObjStLaser_SetSource(objlaser, false);
	//ObjStLaser_SetAngle(objlaser, angtoP(objBoss));
	
	loop(delay-1){
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){Obj_Delete(objlaser); return;}
		yield;
	}
	Obj_Delete(objlaser);
}

task TFinalize {
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}

    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	//ObjItem_SetRenderScoreEnable()
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
    return;
}