#include"./system/Load_AllTexture.dnh"

/*
	(引数:2)
	1)ゲージの増減
	  0:ゲージ量の多い方
	  1:ゲージ量の少ない方
	  2:分割無し
	2)開幕処理
	  0:回復無し
	  1:回復有り
	3)分割場所
	  0:初期値
	  数値：1〜301
	  上記以外の数値を入力するとエラー
*/

task Hpb(type,heel,place,alpha){
	let obj1			= ObjPrim_Create(OBJ_SPRITE_2D);
	let obj2			= ObjPrim_Create(OBJ_SPRITE_2D);
	let obj3			= ObjPrim_Create(OBJ_SPRITE_2D);
	let obj4			= ObjPrim_Create(OBJ_SPRITE_2D);
	let pc1				= 0;
	let pc2				= 1;
	let i1				= 0;
	let i2				= 1;
	let riy				= 69;
	let id				= 0;
	let EnmX			= ObjMove_GetX(enm);
	let EnmY			= ObjMove_GetY(enm);
	let GetEnemyLife	= ObjEnemy_GetInfo(enm,INFO_LIFE);
	let GEL				= ObjEnemy_GetInfo(enm,INFO_LIFE);
	let i				= 0;
	let h				= 0;
	let obj_ac			= [60.25-3/5,12.5,72.5];
	let GELMX;
	
	alternative(type)
	case("Normal"){
		id=0;
	}
	case("Spell"){
		id=1;
	}
	case("NotSplit"){
		id=2;
	}
	
	GELMX = (GetEnemyLife*10)/(GEL/obj_ac[id]);
	
	ObjRender_SetPosition(obj1,CenX,CenY,0);
	ObjPrim_SetTexture(obj1,effect_tex[2]);
	Obj_SetRenderPriorityI(obj1,riy);
	ObjPrim_SetPrimitiveType(obj1,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetBlendType(obj1,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj1,0,0,180);
	ObjRender_SetScaleXYZ(obj1,1,1,0);
	ObjRender_SetColor(obj1,255,255,255);
	ObjPrim_SetVertexCount(obj1,722);
	
	ObjRender_SetPosition(obj2,CenX,CenY,0);
	ObjPrim_SetTexture(obj2,effect_tex[2]);
	Obj_SetRenderPriorityI(obj2,riy);
	ObjPrim_SetPrimitiveType(obj2,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetBlendType(obj2,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj2,0,0,180);
	ObjRender_SetScaleXYZ(obj2,1,1,0);
	ObjRender_SetColor(obj2,255,255,255);
	ObjPrim_SetVertexCount(obj2,722);
	
	ObjRender_SetPosition(obj3,CenX,CenY,0);
	ObjPrim_SetTexture(obj3,effect_tex[2]);
	Obj_SetRenderPriorityI(obj3,riy);
	ObjPrim_SetPrimitiveType(obj3,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetBlendType(obj3,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj3,0,0,180);
	ObjRender_SetScaleXYZ(obj3,1,1,0);
	ObjRender_SetColor(obj3,255,255,255);
	ObjPrim_SetVertexCount(obj3,722);
	
	ObjRender_SetPosition(obj4,CenX,CenY,0);
	ObjPrim_SetTexture(obj4,effect_tex[2]);
	Obj_SetRenderPriorityI(obj4,riy);
	ObjPrim_SetPrimitiveType(obj4,PRIMITIVE_TRIANGLESTRIP);
	ObjRender_SetBlendType(obj4,BLEND_ALPHA);
	ObjRender_SetScaleXYZ(obj4,1.25,2,0);
	ObjRender_SetColor(obj4,255,255,255);
	ObjSprite2D_SetSourceRect(obj4,1,2,6,8);
	ObjSprite2D_SetDestCenter(obj4);
	ObjRender_SetAlpha(obj4,alpha);
	
	loop(722){
		ObjPrim_SetVertexPosition(obj1,i1,64*sin(pc1),64*cos(pc1),0);
		ObjPrim_SetVertexPosition(obj1,i2,60*sin(pc2),60*cos(pc2),0);
		ObjPrim_SetVertexUVT(obj1,i1,0+pc1,9);
		ObjPrim_SetVertexUVT(obj1,i2,0+pc2,13);
		ObjRender_SetAlpha(obj1,0);
		if(heel==true&&type=="NotSplit"){
			ObjRender_SetAlpha(obj1,0);
		}else if(type=="NotSplit"){
			ObjRender_SetAlpha(obj1,255);
		}
		ObjPrim_SetVertexPosition(obj2,i1,64*sin(pc1),64*cos(pc1),0);
		ObjPrim_SetVertexPosition(obj2,i2,60*sin(pc2),60*cos(pc2),0);
		ObjPrim_SetVertexUVT(obj2,i1,0+pc1,9);
		ObjPrim_SetVertexUVT(obj2,i2,0+pc2,13);
		ObjPrim_SetVertexAlpha(obj2,i1,0);
		ObjPrim_SetVertexAlpha(obj2,i2,0);

		ObjPrim_SetVertexPosition(obj3,i1,64*sin(pc1),64*cos(pc1),0);
		ObjPrim_SetVertexPosition(obj3,i2,60*sin(pc2),60*cos(pc2),0);
		ObjPrim_SetVertexUVT(obj3,i1,0+pc1,14);
		ObjPrim_SetVertexUVT(obj3,i2,0+pc2,18);
		ObjRender_SetAlpha(obj3,255);
		pc1+=1;
		pc2+=1;
		i1+=2;
		i2+=2;
	}
	pc1=0;
	pc2=0;
	i1=0;
	i2=0;
	
	while(h<GELMX&&type=="Spell"){
		ObjPrim_SetVertexAlpha(obj1,0+h,255);
		h++;
	}
	h=0;
	
	if(type=="Normal"){
		loop(GELMX){
			ObjPrim_SetVertexAlpha(obj2,0+h/4.51,255);
			h++;
		}
		h=0;
	}else{
		Obj_Delete(obj2);
	}
	
	while(!Obj_IsDeleted(enm)){
		let EnmX			= ObjMove_GetX(enm);
		let EnmY			= ObjMove_GetY(enm);
		let pri				= (GetEnemyLife*10)/(GEL/obj_ac[id]);
		let GEL2			= GELMX-pri;
		
		GetEnemyLife = ObjEnemy_GetInfo(enm,INFO_LIFE);
		
		alternative(type)
		case("Normal"){
			let ang	= -128;
			ObjRender_SetPosition(obj4,EnmX+63*sin(ang+10),EnmY+63*cos(ang+10),0);
			ObjRender_SetAngleXYZ(obj4,0,0,ang*-1);
			ObjRender_SetAngleXYZ(obj1,0,0,115);
			if(heel==true&&h<pri){
				loop(10){
					ObjPrim_SetVertexAlpha(obj1,0+h,255);
					h++;
				}
			}
			if(GetEnemyLife>0){
				ObjPrim_SetVertexAlpha(obj1,0+pri,0);
			}
			if(pri<=GELMX){
				ObjRender_SetAlpha(obj4,alpha);
				loop(GEL2+10){
					ObjPrim_SetVertexAlpha(obj1,0+pri+i,0);
					i++;
				}
				i=0;
			}
		}
		case("Spell"){
			let ang	= -128;
			ObjRender_SetPosition(obj4,EnmX+63*sin(ang+10),EnmY+63*cos(ang+10),0);
			ObjRender_SetAngleXYZ(obj4,0,0,ang*-1);
			if(heel==true&&h<pri){
				loop(10){
					ObjPrim_SetVertexAlpha(obj1,0+h,255);
					h++;
				}
			}
			if(GetEnemyLife>0){
				ObjPrim_SetVertexAlpha(obj1,0+pri,0);
			}
			if(pri<=GELMX){
				ObjRender_SetAlpha(obj2,alpha);
				ObjRender_SetAlpha(obj4,alpha);
				loop(GEL2+5){
					ObjPrim_SetVertexAlpha(obj1,0+pri+i,0);
					i++;
				}
				i=0;
			}
		}
		case("NotSplit"){
			if(heel==true&&h<pri){
				loop(10){
					ObjPrim_SetVertexAlpha(obj1,0+h,255);
					h++;
				}
			}
			if(GetEnemyLife>0){
				ObjPrim_SetVertexAlpha(obj1,0+pri,0);
				ObjRender_SetAlpha(obj4,0);
			}
			if(pri<=GELMX){
				loop(GEL2){
					ObjPrim_SetVertexAlpha(obj1,0+pri+i,0);
					i++;
				}
				i=0;
			}
		}
		
		ObjRender_SetPosition(obj1,EnmX,EnmY,0);
		ObjRender_SetPosition(obj2,EnmX,EnmY,0);
		ObjRender_SetPosition(obj3,EnmX,EnmY,0);
		yield;
	}
	Obj_Delete(obj1);
	Obj_Delete(obj2);
	Obj_Delete(obj3);
	Obj_Delete(obj4);
}