#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Training: Spell Card 1-6"]
#Player["./resource/player/Marisa by plasmaflame22/Marisa_A.txt","./resource/player/Marisa by plasmaflame22/Marisa_B.txt","./resource/player/Marisa by plasmaflame22/Marisa_C.txt"]
#Background["./resource/bg/stg01.txt"]
#System["./system/system.txt"]

#include"./resource/cutin/cutin.txt"
#include"./system/effects.txt"
#include"./resource/[library] effects.txt"
#include"./resource/[library] boss.txt"
#include"./resource/[library] se.txt"
let bossObj = 0;
let bossX = 0;
let bossY = 0;
let attack = 0;
let damage = 0;
let csd = GetCurrentScriptDirectory;
let cutin = csd ~ "./resource/img/cutinstg02.png";

@Initialize{
	SetCommonData("BOSS","Nemuno");
	InstallFont(GetCurrentScriptDirectory ~ "./resource/blogger sans.ttf");

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);

	animateBossSakata;
	TEtama;
	LoadShot;
	MainTask;
	TEndScript;
	AddGraze(-GetGraze);
	
	SetPlayerLife(1);
	SetAutoDeleteObject(true);
	SetForbidPlayerSpell(true);
}

@Loading{
	LoadTexture(cutin);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1000);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(120);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(11000000);
	}
}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 10, 0);}
	ObjEnemy_SetIntersectionCircleToShot(bossObj, bossX, bossY, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj, bossX, bossY, 24);
	yield;
}

@Finalize{
}

task MainTask{
	ObjMove_SetDestAtWeight(bossObj,192,120,6,4);
	loop(90){yield;} if(!Obj_IsDeleted(bossObj)){SE(se_spell);}
	CutIn_Right(cutin,"Murderer Sign \"Exhausted Prisoner\"");
	loop(150){yield;}
	damage = 1;
	attack = 1;
	loop(30){yield;}
	let move = rand(0,30);
	let move2 = rand(0,30);
	let count = 0;
	while(!Obj_IsDeleted(bossObj)){
		if(count >= 120){count = 0;}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 1000){
			if(count%30 == 0){ SE(se_slash);
				ascent(i in 0..8){
					ascent(a in -1..2){
						CreateShotOA1(bossObj,3,i*45+a*2+move,300,0);
					}
				}
				move+=5;
			}
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 800){
			if(count%120 == 15){ SE(se_slash);
				let y = rand(120,240);
				ascent(i in 0..8){
					ascent(a in -1..2){
						CreateShotA1(-50+i*60+a*6,y-i*20-a*2,2,acos(1/3),305,30);
						CreateShotA1(-50+i*60+a*6,y-i*20-a*2,2,acos(1/3)+180,305,30);
					}
				}
			}
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 600){
			if(count%120 == 75){ SE(se_slash);
				let y = rand(30,120);
				ascent(i in 0..8){
					ascent(a in -1..2){
						CreateShotA1(-50+i*60+a*6,y+i*20+a*2,2,-acos(1/3),304,30);
						CreateShotA1(-50+i*60+a*6,y+i*20+a*2,2,-acos(1/3)+180,304,30);
					}
				}
			}
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 400){
			if(count%120 == 45){ SE(se_slash);
				let r = rand(0,30);
				ascent(i in 0..12){
					ascent(a in -1..2){
						let obj = CreateShotA1(bossX,bossY,2,i*30+a*2+r,302,0);
						TReflect(obj);
					}
				}
			}
		}
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 200){
			if(count%20 == 0){ SE(se_slash);
				ascent(a in -1..2){
					let obj = CreateShotA1(0,0,2,0,301,0);
					ObjMove_SetPosition(obj,bossX+90*cos(move2)+a*6*cos(GetAngleToPlayer(obj)+90),bossY+90*sin(move2)+a*6*sin(GetAngleToPlayer(obj)+90));
					ObjMove_SetAngle(obj,atan2(GetPlayerY-ObjMove_GetY(obj)+a*6*sin(GetAngleToPlayer(obj)+90),GetPlayerX-ObjMove_GetX(obj)+a*6*cos(GetAngleToPlayer(obj)+90)));
				}
				move2+=25;
			}
		}
		yield;
		count++;
	}
}


task TReflect(shot){
	while(!Obj_IsDeleted(shot)){
		if(ObjMove_GetX(shot) <= 0){
			ObjMove_SetAngle(shot,0);
			ObjShot_SetDelay(shot,10);
			ObjMove_SetAngularVelocity(shot,ObjMove_GetY(shot)/650);
			break;}
		if(ObjMove_GetX(shot) >= 384){
			ObjMove_SetAngle(shot,180);
			ObjShot_SetDelay(shot,10);
			ObjMove_SetAngularVelocity(shot,-ObjMove_GetY(shot)/650);
			break;}
	yield;}
}