Esempio n. 1
0
    public override Steering Apply()
    {
        if (IsFinished())
        {
            callback(true);
        }

        Steering st = new Steering();

        //Comprobar si se ha matado a la unidad
        if (attack == null || Util.HorizontalDist(targetEnemy.position, center) > rangeRadius + agent.militar.attackRange + followRangeExtra)
        {
            AgentUnit closerEnemy = Info.GetUnitsFactionArea(center, rangeRadius + agent.militar.attackRange, Util.OppositeFaction(agent.faction))
                                    .OrderBy(enemy => Util.HorizontalDist(agent.position, enemy.position))
                                    .FirstOrDefault();
            AttackEnemy(closerEnemy);
        }

        SetCenter(agent.position);
        if (attack != null)
        {
            st = attack.Apply();
        }
        else
        {
            st = followPath.Apply();
        }

        return(st);
    }
Esempio n. 2
0
    public override Steering Apply()
    {
        if (IsFinished())
        {
            callback(true);
        }

        Steering st = new Steering();

        //Comprobar si se ha matado a la unidad
        if (attack == null || Util.HorizontalDist(targetEnemy.position, center) > rangeRadius + agent.militar.attackRange + followRangeExtra)
        {
            AgentUnit closerEnemy = Info.GetUnitsFactionArea(center, rangeRadius + agent.militar.attackRange, Util.OppositeFaction(agent.faction))
                                    .OrderBy(enemy => Util.HorizontalDist(agent.position, enemy.position))
                                    .FirstOrDefault();


            AttackEnemy(closerEnemy);

            //if it does not find any target that it returns back to the center

            if (closerEnemy == null && !returning && Util.HorizontalDist(agent.position, center) > rangeRadius / 2)
            {
                goTo.SetNewTarget(center);
                goTo.SetVisiblePath(true);
                returning = true;
            }
        }

        if (attack != null)
        {
            st = attack.Apply();
        }
        else if (returning)
        {
            st = goTo.Apply();
        }

        return(st);
    }
Esempio n. 3
0
        public void Handle(Selector selector, Player p1, Player p2, Field p1Field, Field p2Field,
                           KeyboardState state, KeyboardState previousState)
        {
            // Handles left and right
            HandleLeftRightWithMaxIndex(selector, state, previousState, 4);
            if (p2Field.monsterZone[selector.index].sprite == null)
            {
                selector.defaultPosition = p2Field.monsterPositions[selector.index];
            }
            selector.selected = p2Field.monsterZone[selector.index];

            // Handle Attack
            if (state.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter) &&
                (p1.currentPhase.Equals(Phase.MAIN) || p1.currentPhase.Equals(Phase.BATTLE)))
            {
                selector.state           = SelectedState.P2_MONSTER_ZONE;
                selector.selected        = p2Field.monsterZone[selector.index];
                selector.defaultPosition = p2Field.monsterPositions[selector.index];
                if (selector.selected is MonsterCard) // Can't attack empty field spaces
                {
                    Attack.Apply(p1, p2, p1Field, p2Field, selector.attacking, (MonsterCard)selector.selected, selector.index);
                }
                else if (!p2Field.HasMonsters() || selector.attacking.canAttackDirectly) // Attack directly
                {
                    Attack.Apply(p1, p2, p1Field, p2Field, selector.attacking, null, selector.index);
                }
                selector.attacking = null;
            }
            else if (state.IsKeyDown(Keys.Back) && previousState.IsKeyUp(Keys.Back))
            {
                selector.state           = SelectedState.BATTLE_SELECT;
                selector.action          = SelectedAction.ATTACK;
                selector.selected        = selector.attacking;
                selector.index           = 0;
                selector.defaultPosition = selectorPositions[0];
            }
        }