#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dialogue - Tricky and Drek"]
#Text[""]
#Player["./../TrickyPlayer/Tricky.dnh"]
#Background["./../BG.txt"]
#System["./../system/Default_System.dnh"]

//{
  let objBoss; let dir = GetCurrentScriptDirectory();
  let b = "Boss"; let p = "Player"; let s = "Sub";
//}

#include "./TalkFunctions.txt"
//{
  #include "./../lib/Render/EnemyMarker.dnh"

  #include "./../lib/Render/Gizmo's Touhou Boss Sprite Library/GizmoSpriteLibrary.txt"
  #include "./../lib/Render/Gizmo's Touhou Boss Sprite Library/HinaAura.txt"
//}

@Initialize{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS); ObjEnemy_Regist(objBoss);
  ObjMove_SetPosition(objBoss, -150, -150); NotifyEventAll(EV_USER_SYSTEM + 4, false);
  TTDrawLoop; TMain; TEnd;
}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(0.001); 
	}
}

@MainLoop{yield;}

task TTDrawLoop{
	renderKagerouDDC(objBoss); renderSeigaAura(objBoss);
  EnMarikin(objBoss);
  ObjRender_SetScaleXYZ(objBoss, 1, 1, 0);
}

task TMain{
  SetCommonData("end", false); Start();
  wait(60*1);

	Talk("The \"[font bc=(255,0,0)]Bear[font clear]ly a Day Off\" Incident[r](September, 20XX)", s);

  CutinPlayer;
  Talk("Finally, I'm free.", p);
	Talk("Meowstic is sleeping and my work is done.", p);
	Talk("I should go back to Drugs' house to recieve my[r]daily snuggle.", p);
	Talk("...", p);
	Talk("...", p);
	Talk("...", p);

  Talk("Why did you stopped talking?", b);
	Talk("Why are you stalking me?", p);
	Talk("Ah.", b);
	
	ObjMove_SetDestAtFrameWeight(objBoss, GetStgFrameWidth()/2, GetStgFrameHeight()/2-110, 60*1); wait(60*1);

	CutinBoss;
  title("[Drekareen, Demon Bear]", 145, 8, 8);
  Talk("I messed it up. Hi Tricky!", b);
  Talk("Why in the seven hells are you here, you[r]dendrophile?", p);
  Talk("Oh, and hi I guess?", p);
	Talk("That's quite evil, I did nothing yet.", b);
	Talk("Hmm, you seem kinda busy. What's the matter?", b);
	Talk("I am going to a place where I can mind my own[r]business, what about you?", p);
	Talk("F-Fucking Hell...", b);
	Talk("You know what? Maybe, I should use some trees[r]as scratching poles.", b);
	Talk("I don't have time to waste.", p);

	NotifyEventAll(EV_USER_STAGE + 10, true);

	Talk("You are, once again, obstructing my work. I[r]suppose it's time for punishment.", p);
	Talk("There's a lasagna with garlic bread waiting for me[r]I will punish you for tree harassment later.", p);
	Talk("One punishment at a time.", p);
	Talk("Now you want to fight? I will try my best to not[r]be unfair!", b);
	Talk("I would be pleased if this didn't took long.", p);
	Talk("Okay, it's a deal!", b);
	Talk("Time for my famous catchphrase:", p);
	Talk("Die.", p);

  SetCommonData("end", true);
	
	wait(60*2);
	
	ObjEnemy_SetLife(objBoss, 0);
}

task TEnd{
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
		
		yield;
	}
  Obj_Delete(objBoss);
	SetAutoDeleteObject(true);
	DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
	NotifyEventAll(EV_USER_SYSTEM + 4, true);
	CloseScript(GetOwnScriptID());
}

function CreateEffectObject(obj_x, obj_y, img, left, top, right, bottom){
  LoadTexture(img);

	let obj = ObjPrim_Create(OBJ_SPRITE_2D); ObjPrim_SetTexture(obj, img);
	ObjSprite2D_SetSourceRect(obj, left, top, right, bottom);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj, obj_x, obj_y, 0);
	ObjMove_SetPosition(obj, obj_x, obj_y);
	return obj;
}

function getDotAngle(x1, y1, x2, y2){let angle = atan2(y1-y2, x1-x2); return angle;}
task ObjMove_SetDestAtFrameWeight(tt, fin_x, fin_y, flame){
	let x = ObjMove_GetX(tt);
	let y = ObjMove_GetY(tt);
	let rx = fin_x - x;
	let ry = fin_y - y;
	let t_rate = 90/flame;
	let s = 0.1;
	ObjMove_SetAngle(tt, getDotAngle(fin_x, fin_y, ObjMove_GetX(tt), ObjMove_GetY(tt)));
	ascent(time in 1..flame+1){
		s -= 0.1/(flame-1);
		ObjMove_SetSpeed(tt, s);
		ObjMove_SetX(tt, x + rx * sin(t_rate * time));
		ObjMove_SetY(tt, y + ry * sin(t_rate * time));
		yield;
	}
	ObjMove_SetSpeed(tt, 0);
}