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


let objBoss;

let BossX;
let BossY;


#include "./Functions/Index.txt"
#include "./Functions/Dialogue.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkanako(objBoss);
	BossShotSound(objBoss, 100, 600);
	KanakoAura(objBoss, false);
	Sticks(objBoss, false);
	BottomEnemyMarker(objBoss, objBoss);
	DrawName("Kanako Yasaka", [20, 20, 200], 11);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 5);
	Maintask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	if(invisible==false){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	}
	
	if(GetPlayerInvincibilityFrame<=0){invisible=false;}
	else{invisible=true;}
	
	yield;
} 

@Finalize {

} 


task Maintask{
wait(80);
	loop{
	Pattern1;
	wait(150);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/6, 10, 5);
	wait(60);
	Pattern2;
	wait(190);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 5);
	wait(10);
	}
}

task Pattern1{
	ascent(i in 0..60){
	let randomang = rand(-5, 5);
	let randomspd = rand(-1, 1);
	let obj = CreateShotA1(BossX, BossY, 3+randomspd, 0-randomang, KNIFE_BLUE, 5);
	let obj2 = CreateShotA1(BossX, BossY, 3+randomspd, 180+randomang, KNIFE_BLUE, 5);
	Warp(obj);
	Warp(obj2);
	yield;
	}
	ascent(i in 0..120){
	let randomang = rand(-5, 5);
	let randomspd = rand(-1, 1);
	let obj = CreateShotA1(BossX, BossY, 3+randomspd, 0-(i*2)-randomang, KNIFE_BLUE, 5);
	let obj2 = CreateShotA1(BossX, BossY, 3+randomspd, 180+(i*2)+randomang, KNIFE_BLUE, 5);
	Warp(obj);
	Warp(obj2);
	wait(1);
	}
	
	task Warp(obj){
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj)<0 && count == 0){ObjMove_SetX(obj, GetStgFrameWidth); count++;}
		if(ObjMove_GetX(obj)>GetStgFrameWidth && count == 0){ObjMove_SetX(obj, 0); count++;}
		if(ObjMove_GetY(obj)<0 && count == 0){ObjMove_SetY(obj, GetStgFrameHeight); count++;}
		if(ObjMove_GetY(obj)>GetStgFrameHeight && count == 0){ObjMove_SetY(obj, 0); count++;}
		yield;
		}
	}
}

task Pattern2{
	ascent(i in 0..60){
	let randomang = rand(-5, 5);
	let randomspd = rand(-1, 1);
	let obj = CreateShotA1(BossX, BossY, 3+randomspd, 11+(i*1.2)+randomang, KNIFE_ORANGE, 5);
	Warp(obj);
	wait(1);
	}
	ascent(i in 0..60){
	let randomang = rand(-5, 5);
	let randomspd = rand(-1, 1);
	let obj2 = CreateShotA1(BossX, BossY, 3+randomspd, 180-11-(i*1.2)-randomang, KNIFE_ORANGE, 5);
	Warp(obj2);
	wait(1);
	}
	task Warp(obj){
	let count = 0;
		while(!Obj_IsDeleted(obj)){
		if(ObjMove_GetX(obj)<0 && count == 0){ObjMove_SetX(obj, GetStgFrameWidth); count++;}
		if(ObjMove_GetX(obj)>GetStgFrameWidth && count == 0){ObjMove_SetX(obj, 0); count++;}
		if(ObjMove_GetY(obj)<0 && count == 0){ObjMove_SetY(obj, GetStgFrameHeight); count++;}
		if(ObjMove_GetY(obj)>GetStgFrameHeight && count == 0){ObjMove_SetY(obj, 0); count++;}
		yield;
		}
	}
}

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());
} 
