//---------------------------------------------------------------------------------
// Boss Functions
//---------------------------------------------------------------------------------

function GetBossX{ return ObjMove_GetX(objBoss); }

function GetBossY{ return ObjMove_GetY(objBoss); }

function GetBossLife{ return ObjEnemy_GetInfo(objBoss,INFO_LIFE); }

function ObjEnemy_IsAlive(let objTarget){ return ObjEnemy_GetInfo(objTarget,INFO_LIFE) > 0; }

task ObjEnemy_SetCollision(let objTarget, let shotRadius, let realRadius){
	while(!Obj_IsDeleted(objTarget)){
		let eX = ObjMove_GetX(objTarget);
		let eY = ObjMove_GetY(objTarget);
		ObjEnemy_SetIntersectionCircleToShot(objTarget,eX,eY,shotRadius);
		ObjEnemy_SetIntersectionCircleToPlayer(objTarget,eX,eY,realRadius);
		yield;
	}
}

task ObjEnemy_WaitDamageRate(let objTarget, let shotDamage, let bombDamage, let wtTime){
	wait(wtTime);
	while(IsPlayerSpellActive){ yield; }
	ObjEnemy_SetDamageRate(objTarget,shotDamage,bombDamage);
}

task ObjMove_SetDestAtRand(let objTarget, let dX, let dY, let LTRB, let mvTime){
	let pX = ObjMove_GetX(objTarget);
	let pY = ObjMove_GetY(objTarget);
	let rArray = [GetInverser,GetInverser];
	let mX = pX+dX*rArray[0];
	let mY = pY+dY*rArray[1];
	if(mX < LTRB[0]){
		mX = pX+dX;
		if(mX > LTRB[2]){
			mX = LTRB[2];
		}
	}else if(mX > LTRB[2]){
		mX = pX-dX;
		if(mX < LTRB[0]){
			mX = LTRB[0];
		}
	}
	if(mY < LTRB[1]){
		mY = pY+dY;
		if(mY > LTRB[3]){
			mY = LTRB[3];
		}
	}else if(mY > LTRB[3]){ 
		mY = pY-dY;
		if(mY < LTRB[1]){
			mY = LTRB[1];
		}
	}
	ObjMove_SetDestAtBrake(objTarget,mX,mY,mvTime);
}

task ObjMove_SetDestAtPlayerX(let objTarget, let dX, let dY, LTRB, let mvTime){
	let eX = ObjMove_GetX(objTarget);
	let eY = ObjMove_GetY(objTarget);
	let pX = GetPlayerX;
	let difDist = eX-pX;
	if(!difDist){
		difDist = GetInverser;
	}else if(absolute(difDist) < dX){ 
		dX = absolute(difDist);
	}
	let mX = eX+dX*-sgn(difDist);
	let mY = eY+dY*GetInverser;
	if(mX < LTRB[0]){
		mX = eX+dX;
	}else if(mX > LTRB[2]){
		mX = eX-dX;
	}
	if(mY < LTRB[1]){
		mY = eY+dY;
	}else if(mY > LTRB[3]){ 
		mY = eY-dY;
	}
	ObjMove_SetDestAtBrake(objTarget,mX,mY,mvTime);
}

task ObjMove_SetDestAtBrake(let objTarget, let mX, let mY, let mvTime){
	let pX = ObjMove_GetX(objTarget);
	let pY = ObjMove_GetY(objTarget);
	let rX = mX-pX;
	let rY = mY-pY;
	let sinRate = 90/mvTime;
	ObjMove_SetDestAtSpeed(objTarget,mX,mY,0);
	ascent(let a in 1..mvTime+1){
		ObjMove_SetX(objTarget,GetGapY(pX,rX,a*sinRate));
		ObjMove_SetY(objTarget,GetGapY(pY,rY,a*sinRate));
		yield;
	}
}

task ObjMove_SetDestAtSmoothStep(let objTarget, let mX, let mY, let mvTime){
	let pX = ObjMove_GetX(objTarget);
	let pY = ObjMove_GetY(objTarget);
	ObjMove_SetDestAtSpeed(objTarget,mX,mY,0);
	ascent(let a in 1..mvTime+1){
		let tRatio = a*1/mvTime;
		let dT = power(tRatio,2)*(3-2*tRatio);
		let rX = pX+dT*(mX-pX);
		let rY = pY+dT*(mY-pY);
		ObjMove_SetPosition(objTarget,rX,rY);
		yield;
	}
}

task ObjMove_SetDestAtHermite(
	let objTarget, 
	let mX, 
	let mY, 
	let aDist, 
	let aAngle, 
	let zDist, 
	let zAngle, 
	let mvTime 
	){
	let pX = ObjMove_GetX(objTarget);
	let pY = ObjMove_GetY(objTarget);
	let aX = aDist*cos(aAngle);
	let aY = aDist*sin(aAngle);
	let zX = zDist*cos(zAngle);
	let zY = zDist*sin(zAngle);
	ascent(let a in 1..mvTime+1){
		let distRate = a/mvTime;
		let hX = (2*pX+aX-2*mX+zX)*distRate^3+
				 (-3*pX-2*aX+3*mX-zX)*distRate^2+
				 (aX)*distRate^1+(1*pX);
		let hY = (2*pY+aY-2*mY+zY)*distRate^3+
				 (-3*pY-2*aY+3*mY-zY)*distRate^2+
				 (aY)*distRate^1+(1*pY);
//		ObjMove_SetPosition(objTarget,hX,hY);
		ObjMove_SetDestAtFrame(objTarget,hX,hY,1);
		yield;
	}
}