#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Minoriko Spell 03"]

#include"./../Functions/Cutin/Cutin.txt"
#include"./LoadGraphics.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
let global = 0;

let card = GetCurrentScriptDirectory ~ "./../Sounds/se_cat00.wav";
let kira = GetCurrentScriptDirectory ~ "./../Sounds/se_kira02.wav";
let sho = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
#include"./DrawBoss.txt"

@Initialize{
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	SetCommonData("Aura",0);
	SetCommonData("End",0);
	LoadShotData;
	animateBossM;
	mainTask;
	TEnd;

	LoadSound(sho);
	LoadSound(card);
	LoadSound(kira);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(600);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../System/Minoriko_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 10, 5);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{wait(1);TEtama;PlaySE(card);
	THarvesterWreathC(0.7,1);
	THarvesterWreathC(1,-1);
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY,5,3);
	ObjCutin_SetSpellcardS4("Plenty Sign \"Exotic Dance of Harvest Gods\"", cutin2, "KANAKO", 255, 64, 0);
	ObjCutin_LaunchS3("KANAKO", cutin2, "normal");
	TSpellBG;wait(120);
		TShotBanana(0);
		TShotBanana(180);
	wait(300);damage=1;}

task TShotBanana(ang){
	let m = 0; let time = 90;
	while(!Obj_IsDeleted(bossObj)){PlaySE(sho);
		let banana = CreateFruit(bossX,bossY,0,ang+m,1);
		if(time<=17){time=17;}
		TSpeed(banana);
	m+=18.5;time-=10;
	wait(time);}}

task TSpeed(obj){
	let move = 0;
	loop(360){
		ObjMove_SetSpeed(obj,2*sin(move));
	move++;yield;}
	Obj_Delete(obj);}

function CreateFruit(x,y,speed,angle,graphic){
	let spirit = CreateEnemy(100);
	ObjMove_SetPosition(spirit,x,y);
	ObjMove_SetSpeed(spirit,speed);
	ObjMove_SetAngle(spirit,angle);
	DrawEnemy(spirit,graphic);
	return spirit;}

function CreateEnemy(objlife){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjEnemy_SetLife(obj,objlife);
	return obj;}

task DrawEnemy(id,gr){
	let enemyX;
	let enemyY;
	let angleZ = rand(0,180);
	DrawEnemyEffect(id);
	Obj_SetRenderPriorityI(id,32);
	ObjPrim_SetTexture(id,akishot);
	ObjRender_SetScaleXYZ(id,0.6,0.6,0);
	while(!Obj_IsDeleted(id)){
		enemyX = ObjMove_GetX(id);
		enemyY = ObjMove_GetY(id);
		ObjSprite2D_SetDestCenter(id);
		ObjSprite2D_SetSourceRect(id,154,52,190,104);
		ObjEnemy_SetIntersectionCircleToPlayer(id,enemyX,enemyY,10);
		ObjRender_SetAngleZ(id,angleZ);
		if(GetCommonData("End",0)!=0){
			DisappearBulletEffect(enemyX,enemyY,id,255,25,25);}
		angleZ+=2;yield;}}

task DrawEnemyEffect(obj){
	while(!Obj_IsDeleted(obj)){
		let id = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(id,akishot);
		ObjRender_SetScaleXYZ(id,0.6,0.6,0);
		ObjSprite2D_SetSourceRect(id,154,52,190,104);
		ObjSprite2D_SetDestCenter(id);
		Obj_SetRenderPriorityI(id,31);
		ObjRender_SetColor(id,64,255,64);
		ObjRender_SetBlendType(id,BLEND_ADD_ARGB);
		ObjRender_SetAngleZ(id,ObjRender_GetAngleZ(obj));
		ObjRender_SetPosition(id,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
		TAlphaENC(id);
	wait(3);}
	task TAlphaENC(object){
		let alpha = 255;
		loop(15){
			ObjRender_SetAlpha(object,alpha);
			alpha-=255/10;yield;}
		Obj_Delete(object);}}
