/// <summary> /// Runs away from any ice trolls if it needs to. Returns true if it needs to run away, false otherwise /// </summary> /// <param name="elf"></param> /// <returns> If is running away from ice troll true, else false</returns> public static bool RunAwayFromIceTrolls(this Elf elf) { IceTroll[] iceTrolls = Constants.GameCaching.GetEnemyIceTrolls(); foreach (IceTroll iceTroll in iceTrolls) { Location elfDirection = LastPosition.GetDirection(elf).GetIntLocation(); Location nextLocation = elf.GetLocation().Add(elfDirection); if (iceTroll.CurrentHealth - Constants.Game.IceTrollSuffocationPerTurn * iceTroll.Distance(nextLocation) > 0 && // if ice troll going to die when they meet iceTroll.Distance(nextLocation) < Constants.Game.IceTrollAttackRange) // if the ice troll is going to reach the elf { float angle = Mathf.GetAngle(elf, iceTroll); Location runAwayLocation = Mathf.GetNewLocationFromLocation(iceTroll, angle, 2000); elf.MoveTo(runAwayLocation); return(true); } } return(false); }
public static LocationF GetDirection(this GameObject source) { return(LastPosition.GetDirection(source)); }