Esempio n. 1
0
 public static Location InterceptLocation(this Elf source, MapObject target)
 {
     if (target is GameObject)
     {
         return(LastPosition.GetInterceptLocation(source, (GameObject)target));
     }
     else
     {
         return(target.GetLocation());
     }
 }
Esempio n. 2
0
 public static void MoveToIntercept(this Elf elf, MapObject target)
 {
     if (target is GameObject)
     {
         Location interceptLocation = LastPosition.GetInterceptLocation(elf, (GameObject)target);
         elf.MoveTo(interceptLocation);
     }
     else
     {
         elf.MoveTo(target);
     }
 }
Esempio n. 3
0
        public static bool IsHeadingTowards(this GameObject gameObject, MapObject target, float certainty)
        {
            if (target is GameObject)
            {
                //is the gameObject heading towards the target or the target's intercept location????
                if (target is Elf)
                {
                    if (LastPosition.IsHeadingTowards(gameObject, ((Elf)gameObject).InterceptLocation((GameObject)target), certainty))
                    {
                        return(true);
                    }
                }

                return(LastPosition.IsHeadingTowards(gameObject, target, certainty));
            }
            else
            {
                return(LastPosition.IsHeadingTowards(gameObject, target, certainty));
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
 public static LocationF GetVelocity(this GameObject source)
 {
     return(LastPosition.GetVelocity(source));
 }
Esempio n. 7
0
 public static LocationF GetDirection(this GameObject source)
 {
     return(LastPosition.GetDirection(source));
 }