Exemple #1
0
        /// <summary>
        /// Runs away from any elfs 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 elfs true, else false</returns>
        public static bool RunAwayFromElfs(this Elf elf)
        {
            Elf[] elfs = Constants.GameCaching.GetEnemyLivingElves();

            LocationF myNextLocation = elf.GetLocation().GetFloatLocation() + LastPosition.GetVelocity(elf);

            foreach (Elf enemyElf in elfs)
            {
                LocationF enemyNextLocation = enemyElf.GetLocation().GetFloatLocation() + LastPosition.GetVelocity(enemyElf);

                if (enemyElf.InRange(elf, enemyElf.AttackRange * 2) || enemyNextLocation.InRange(elf, enemyElf.AttackRange * 2)) // if the ice troll is going to reach the elf
                {
                    float    angle           = Mathf.GetAngle(elf, enemyElf) + 10;
                    Location runAwayLocation = Mathf.GetNewLocationFromLocation(enemyElf, angle, enemyElf.AttackRange * 2);
                    elf.MoveTo(runAwayLocation);

                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
 public static LocationF GetVelocity(this GameObject source)
 {
     return(LastPosition.GetVelocity(source));
 }