#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	BossShotSound(objBoss, 100, 600);
	BottomEnemyMarker(objBoss, objBoss);
	FlameAura(objBoss,[255,255,255],3);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjMove_SetDestAtWeight(objBoss,384/2,150,2,6);
	mainTask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

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

@Finalize {

} 

task mainTask { 
	wait(60);
	SpellCard("Unidentified &quot;Rainbow UFO Invasion&quot;");
	attack=true;
	let envy = UFO(BossX, BossY, "green");
	envyufo(envy);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 50);
	wait(20);
	let terror = UFO(BossX, BossY, "yellow");
	terrorufo(terror, 0+10, 0, 0);
	let terror2 = UFO(BossX, BossY, "yellow");
	terrorufo(terror2, GetStgFrameWidth-10, 180, 180);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 50);
	wait(20);
		ascent(i in 0..4){
		let rage = UFO(BossX, BossY, "red");
		rageufo(rage, i*360/4);
		}	
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 50);
	wait(20);
		ascent(i in 0..4){
		let grief = UFO(BossX, BossY, "blue");
		griefufo(grief, i*360/4);
		}
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 50);
	wait(20);
	ObjEnemy_SetDamageRate(objBoss, 50, 50);
	}

task envyufo(obj){
ObjMove_SetDestAtWeight(obj,384/2,50,5,3);
wait(40);
move;
shoot;
	task move{
	let sinner = 0;
	let position = ObjMove_GetX(obj);
		loop{
		ObjMove_SetPosition(obj, position+(position/2*sin(sinner))*1.6,50);
		sinner+=1;
		yield;
		}
	}
	task shoot{
		while(!Obj_IsDeleted(obj)){
		wait(20);
		CreateStraightLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 91, 500, 17, 15, ST_LASER_GREEN, 60);
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 50);
		}
	}
}

task terrorufo(obj, goto, sinner, angle){
ObjMove_SetDestAtWeight(obj,goto,250,5,3);
wait(80);
move;
shoot;
	task move{
	let position = ObjMove_GetY(obj);
		loop{
		ObjMove_SetPosition(obj, goto ,position+(position/2*sin(sinner))*1.6);
		sinner+=0.7;
		yield;
		}
	}
	task shoot{
		while(!Obj_IsDeleted(obj)){
		wait(30);
		let ang = angle-90+(2*sin(sinner));
		loop(5){
			ascent(i in 1..3){
			CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 1+(i/10), ang, PELLET_YELLOW, 5);
			}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 50);
		ang+=45;
		}
		}
	}
}

task rageufo(obj, angle){
ObjMove_SetDestAtWeight(obj, BossX+50*cos(angle), BossY+75*sin(angle), 5, 2);
wait(40);
move;
shoot;
	task move{
	let sinner = 0;
	let position = ObjMove_GetX(obj);
		loop{
		ObjMove_SetPosition(obj, BossX+50*cos(angle), BossY+75*sin(angle));
		ObjMove_SetAngle(obj, angle);
		sinner+=1;
		angle++;
		yield;
		}
	}
	task shoot{
		while(!Obj_IsDeleted(obj)){
		wait(10);
		let obj2 = CreateShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0.4, angle, 0.04, 50, FIRE_RED, 5);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 50);
		}
	}
}

task griefufo(obj, angle){
ObjMove_SetDestAtWeight(obj, BossX+100*cos(angle), BossY+75*sin(angle), 5, 3);
wait(40);
move;
shoot;
	task move{
	let sinner = 0;
	let position = ObjMove_GetX(obj);
		loop{
		ObjMove_SetPosition(obj, BossX+100*cos(angle), BossY+75*sin(angle));
		ObjMove_SetAngle(obj, angle);
		sinner+=1;
		angle--;
		yield;
		}
	}
	task shoot{
		while(!Obj_IsDeleted(obj)){
		wait(20);
		let obj2 = CreateLooseLaserA1(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, angle, 100, 10, C_LASER_BLUE, 5);
		ObjCrLaser_SetTipDecrement(obj2, 0);
		ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser1.wav", 50);
		}
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Cutin.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 25);
	ObjCutin_LaunchS3("KANAKO", Cutin, "Normal");
	TCallBg;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
