#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Practise Defeated anim"]
#Text["Practise Defeated anim"]

#include "script/thdcs/system/shotlibrary.txt"
#include "script/thdcs/functions/function_common.txt"
#include "script/thdcs/functions/function_global.txt"
#include "script/thdcs/functions/function_bosseff.txt"

@Initialize {
    SetCommonData("isDialogue", true);
	// Check which stage and card is played previously and define death animation
	let getStage = GetCommonData("tryStage", 0);
	let getCard = GetCommonData("tryCard", 0);
	let typeBoss = 0;
	let typeBoss2 = 0;
	let isDuo = false;

	if(getStage == 0) {
		if(getCard == 0) { typeBoss = 11; }
		if(getCard > 0 && getCard < 4) { typeBoss = 1; }
		if(getCard == 4) { isDuo = true; typeBoss = 1; typeBoss2 = 10; }			
	} 
	if(getStage == 1) {
		if(getCard == 0) { isDuo = true; typeBoss = 23; typeBoss2 = 24; }
		if(getCard > 0 && getCard < 7) { typeBoss = 2; }
		if(getCard == 7) { isDuo = true; typeBoss = 2; typeBoss2 = 20; }			
	} 	
	if(getStage == 2) {
		if(getCard == 0) { isDuo = true; typeBoss = 31; typeBoss2 = 32; }
		if(getCard == 1) { isDuo = true; typeBoss = 33; typeBoss2 = 34; }
		if(getCard > 1 && getCard < 8) { typeBoss = 3; }
		if(getCard == 8) { isDuo = true; typeBoss = 3; typeBoss2 = 30; }
	} 

	// Draw based on previous values
	renderBoss(typeBoss);
	SetCommonData("bossAttackType", 0);
	SetCommonData("bossCircleType", 0);
	if(isDuo) {
		SetCommonData("isDuet", true);
		renderBoss2(typeBoss2);
		bossMagicCircle2;
		dyingDuoBreath;
	}
	else {
		SetCommonData("isDuet", false);
		dyingBreath;
	}
	SetAutoDeleteObject(true);
}

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

@MainLoop { yield; } 
@Finalize { } 

// movement task
task dyingBreath {
	ObjMove_SetPosition(bossObj, bossX, bossY);
	ObjMove_SetDestAtSpeed(bossObj, bossX-60, bossY-60, 1);
	explosionspray(bossObj);
	wait(70);
	ObjRender_SetScaleXYZ(bossObj, 0, 0, 0);
	wait(30);
	ObjEnemy_SetLife(bossObj, -1);
	Obj_Delete(bossObj);	
	wait(180);	
	CloseScript(GetOwnScriptID());
}

 // movement task
task dyingDuoBreath {
	ObjMove_SetPosition(bossObj, bossX, bossY);
	ObjMove_SetPosition(boss2Obj, GetCommonData("boss2X", boss2X), GetCommonData("boss2Y", boss2Y));
	ObjMove_SetDestAtSpeed(bossObj, bossX-60, bossY-60, 1);
	ObjMove_SetDestAtSpeed(boss2Obj, boss2X-60, boss2Y-60, 1);
	explosionspray(bossObj);
	explosionspray(boss2Obj);
	wait(70);
	ObjRender_SetScaleXYZ(bossObj, 0, 0, 0);
	ObjRender_SetScaleXYZ(boss2Obj, 0, 0, 0);
	wait(30);
	ObjEnemy_SetLife(bossObj, -1);
	Obj_Delete(bossObj);
	Obj_Delete(boss2Obj);	
	wait(180);	
	CloseScript(GetOwnScriptID());
}