Beispiel #1
0
    EnviromentTile FindClosestTileforSpawner(CardObject cardObject, Mage mageSpawner)
    {
        AttackArea = mageSpawner.FindAttackRangeAround(mageSpawner.GetCurrentTile, cardObject.MaxAttackDistance);
        int            minDistancePlayer   = 100;
        EnviromentTile ClosestSpawnerrTile = null;

        foreach (EnviromentTile tile in AttackArea)
        {
            if (tile.cardType == CardType.Open)
            {
                int Distance = cardObject.FindTileDistance(tile);
                // If Distance is 0 then a path is not available
                if (Distance < minDistancePlayer && Distance > 0)
                {
                    minDistancePlayer   = Distance;
                    ClosestSpawnerrTile = tile;
                }
            }
        }
        return(ClosestSpawnerrTile);
    }
Beispiel #2
0
    // Control the card object to attack the closest object thats attackable
    void SelectObject(CardObject cardObject)
    {
        index++;
        Debug.Log("Selected " + SelectedCardObject.name + " " + index);
        cardObject.MoveChangeObservers   += SelectedObjectMoveStateChange;
        cardObject.CombatChangeObservers += SelectedObjectCombatChange;

        Range = cardObject.FindMoveRange();

        EnviromentTile ClosestPlayerTile  = null;
        EnviromentTile ClosestSpawnerTile = null;

        // if in attack range of the spawner attack it
        AttackArea = mageSpawner.FindAttackRangeAround(mageSpawner.GetCurrentTile, cardObject.MaxAttackDistance);
        if (AttackArea.Contains(cardObject.GetCurrentTile))
        {
            CheckforAttackAvailable(cardObject);
            return;
        }


        // check if there are any player objects out on the field
        if (playerCardObjectsOut.Count > 0)
        {
            // Find the closest player Object to attack
            int minDistancePlayer = 100;

            foreach (CardObject cardObjectplayer in playerCardObjectsOut)
            {
                AttackArea             = cardObjectplayer.FindAttackRangeAround(cardObjectplayer.GetCurrentTile, cardObject.MaxAttackDistance);
                AttackAreaAroundPlayer = AttackArea;

                // CheckforPlayerinAttackArea
                if (AttackArea.Contains(cardObject.GetCurrentTile))
                {
                    CheckforAttackAvailable(cardObject);
                    return;
                }

                int            Distance = 100;
                EnviromentTile tile     = FindClosestTileforCard(cardObject, cardObjectplayer);
                Debug.Log(tile);
                //Make sure a tile is available to make a path
                if (tile != null)
                {
                    Distance = cardObject.FindTileDistance(tile);
                }
                if (Distance < minDistancePlayer)
                {
                    //Set new minDistance and new closest tile
                    minDistancePlayer = Distance;
                    ClosestPlayerTile = tile;
                }
            }
            //  Debug.Log(ClosestPlayerTile);
            //   Debug.Log(minDistancePlayer);
            // If there is no path to an available object to attack dont move

            if (ClosestPlayerTile != null)
            {
                int minDistanceSpawner = 100;
                ClosestSpawnerTile = FindClosestTileforSpawner(cardObject, mageSpawner);
                //Make sure a tile is available to make a path
                if (ClosestSpawnerTile != null)
                {
                    minDistanceSpawner = cardObject.FindTileDistance(ClosestSpawnerTile);
                }
                if (minDistancePlayer < minDistanceSpawner)
                {
                    MoveToTile(cardObject, ClosestPlayerTile);
                    return;
                }
                else
                {
                    MoveToTile(cardObject, ClosestSpawnerTile);
                    return;
                }
            }
        }
        // if no path available to the player objects go for the flag/spawner
        // If no player is found then go for the spawner
        ClosestSpawnerTile = FindClosestTileforSpawner(cardObject, mageSpawner);
        if (ClosestSpawnerTile != null)
        {
            MoveToTile(cardObject, ClosestSpawnerTile);
        }
        else
        {
            StartCoroutine(SelectNextObject());
        }
    }