Exemplo n.º 1
0
        private void CallDoDamagePhysicalProjectile(LivingEntity attacker, LivingEntity victim)
        {
            if (attacker is Hero)
            {
                var hero = attacker as Hero;
                var fi   = ActivateFightItem(FightItemKind.PlainArrow, hero);
                var wpn  = GenerateEquipment <Weapon>("Bow");
                Assert.True(SetHeroEquipment(wpn));
                Assert.True(UseFightItem(hero, victim, fi));
            }
            else
            {
                var en  = attacker as Enemy;
                var pfi = en.ActiveFightItem as ProjectileFightItem;

                if (attacker.DistanceFrom(victim) <= 1)
                {
                    return;
                }

                Assert.True(game.GameManager.ApplyAttackPolicy(attacker, victim, pfi, null, (p) => { }));
            }
        }
Exemplo n.º 2
0
        public void MakeHeroAllyMove(LivingEntity ally)
        {
            if (!ally.Alive)
            {
                return;
            }

            if (ally.Stats.HealthBelow(0.5f))
            {
                var allyCasted = ally as Ally;
                if (allyCasted != null)
                {
                    if (allyCasted.LastingEffects.Any(i => i.Type == Effects.EffectType.Poisoned))
                    {
                        var anty = allyCasted.Inventory.Items.FirstOrDefault(i => i is Potion pot && pot.Kind == PotionKind.Antidote);
                        if (anty != null)
                        {
                            allyCasted.Consume(anty as Consumable);
                            return;
                        }
                    }
                    var food = allyCasted.Inventory.Items.FirstOrDefault(i => i is Consumable);
                    if (food != null)
                    {
                        allyCasted.Consume(food as Consumable);
                        return;
                    }
                }
            }

            //if (ally.FixedWalkTarget != null)
            //{
            //  if (ally.PathToTarget != null && ally.PathToTarget.Count == 1)
            //  {
            //    ally.FixedWalkTarget = null;
            //  }
            //  if (!MakeMoveOnPath(ally, ally.FixedWalkTarget.point, true))
            //    MakeRandomMove(ally);
            //  return;
            //}

            if (ally.AllyModeTarget != null)
            {
                var found = enemiesManager.AllEntities.Where(i => i == ally.AllyModeTarget).FirstOrDefault();
                if (found == null)//dead?
                {
                    ally.AllyModeTarget = null;
                }
            }

            if (ally.AllyModeTarget == null || ally.AllyModeTarget.DistanceFrom(ally) >= MaxEntityDistanceToToChase)
            {
                ally.AllyModeTarget = enemiesManager.AllEntities.Where(i => i.DistanceFrom(ally) < MaxEntityDistanceToToChase).OrderBy(i => i.DistanceFrom(ally)).ToList().FirstOrDefault();
            }

            bool moveCloserToHero = false;

            if (ally.AllyModeTarget == null)
            {
                moveCloserToHero = true;
            }
            else
            {
                if (attackStrategy.AttackIfPossible(ally, ally.AllyModeTarget))
                {
                    return;
                }
                if (ShallChaseTarget(ally, ally.AllyModeTarget))                               //, MaxAllyDistToEnemyToChase))
                {
                    moveCloserToHero = !MakeMoveOnPath(ally, ally.AllyModeTarget.point, true); //, true);
                }
            }

            if (moveCloserToHero)
            {
                if (ally.DistanceFrom(context.Hero) > 2)//do not block hero moves
                {
                    //user false here as forHeroAlly as we want to find a hero on path
                    MakeMoveOnPath(ally, context.Hero.point, false);
                }
                else
                {
                    ally.AllyModeTarget = null;//find a new target
                    if (RandHelper.Random.NextDouble() > .5f)
                    {
                        MakeRandomMove(ally);
                    }
                }
            }
        }