Beispiel #1
0
    public static bool CanMoveAndAttack(BattleActor actor, BattleObject target, out Vector2 movePattern, out Vector2 attackPattern)
    {
        List <Vector2> moveLocations = actor.Type.Pattern.GetLocationsForFlags(PatternFlags.Movement);

        moveLocations.Add(Vector2.zero);

        List <Vector2> attackLocations = actor.Type.Pattern.GetLocationsForFlags(PatternFlags.Attack);
        Vector2        actorPos        = actor.Position;
        Vector2        targetPos       = target.Position;

        foreach (Vector2 movePos in moveLocations)
        {
            foreach (Vector2 attackPos in attackLocations)
            {
                if (movePos + attackPos + actorPos == targetPos &&
                    actor.CanMoveTo(actor.Position + movePos))
                {
                    movePattern   = movePos;
                    attackPattern = attackPos;
                    return(true);
                }
            }
        }

        movePattern   = Vector2.zero;
        attackPattern = Vector2.zero;
        return(false);
    }
Beispiel #2
0
    bool DoMovement()
    {
        Debug.Log("Moving");

        if (currentActor.CanMoveTo(movementPosition))
        {
            currentActor.SetPosition(movementPosition);
            performedMovement = true;

            if (attackPosition != Vector2.zero && currentTarget != null)
            {
                NextAction = ThinkerActions.ATTACK;
            }
            return(true);
        }

        return(false);
    }
Beispiel #3
0
    bool FindTarget()
    {
        Debug.Log("Finding target");

        bool performed = false;

        foreach (BattleActor actor in GameData.CurrentBattle.PlayerB.AvailableActors)
        {
            foreach (BattleObject obj in GameData.CurrentBattle.PlayerA.AvailableActors)
            {
                Vector2 movePattern;
                Vector2 attackPattern;
                if (BattleUtils.CanMoveAndAttack(actor, obj, out movePattern, out attackPattern))
                {
                    if (movePattern == Vector2.zero) // doesn't need to move
                    {
                        performedMovement = true;
                        NextAction        = ThinkerActions.ATTACK;
                    }
                    else
                    {
                        movementPosition = actor.Position + movePattern;
                        NextAction       = ThinkerActions.MOVE;
                    }

                    currentActor   = actor;
                    currentTarget  = obj;
                    attackPosition = movementPosition + attackPattern;
                    performed      = true;
                    break;
                }
            }

            if (performed)
            {
                break;
            }
        }

        if (!performed)
        {
            // no one could attack anyone, just find some random guy to move randomly
            List <BattleActor> actors = new List <BattleActor>();
            foreach (BattleObject obj in GameData.CurrentBattle.PlayerB.AvailableActors)
            {
                if (obj is BattleActor)
                {
                    actors.Add(obj as BattleActor);
                }
            }
            actors.Shuffle();

            while (actors.Count > 0)
            {
                BattleActor actor = actors[0];
                actors.RemoveAt(0);

                List <Vector2> moveLocations = actor.Type.Pattern.GetLocationsForFlags(PatternFlags.Movement);
                moveLocations.Shuffle();

                bool moved = false;
                while (moveLocations.Count > 0)
                {
                    Vector2 move = moveLocations[0];
                    moveLocations.RemoveAt(0);

                    if (actor.CanMoveTo(actor.Position + move))
                    {
                        moved            = true;
                        performed        = true;
                        currentActor     = actor;
                        movementPosition = move;
                        NextAction       = ThinkerActions.MOVE;
                        break;
                    }
                }

                if (moved)
                {
                    break;
                }
            }
        }

        return(performed);
    }