예제 #1
0
    /// <summary>
    /// Check if hexagon can be cast on with the current ability
    /// </summary>
    protected bool HexagonCastable(Hexagon hex, AbilityDescription.TargetType targetType)
    {
        if (hex == null)
        {
            return(false);
        }

        if (hex.CurrentHexType == Hexagon.HexType.Null)
        {
            return(false);
        }

        switch (targetType)
        {
        case AbilityDescription.TargetType.TargetAlly: {
            if (hex.OccupiedUnit is PlayerControlledBoardUnit)
            {
                return(true);
            }
            break;
        }

        case AbilityDescription.TargetType.TargetEnemy: {
            if (hex.OccupiedUnit is NonPlayerControlledBoardUnit)
            {
                return(true);
            }
            break;
        }

        case AbilityDescription.TargetType.TargetUnit: {
            if (hex.OccupiedUnit is NonPlayerControlledBoardUnit || hex.OccupiedUnit is PlayerControlledBoardUnit)
            {
                return(true);
            }
            break;
        }

        case AbilityDescription.TargetType.TargetHexagon: {
            return(true);
        }
        }
        return(false);
    }
예제 #2
0
    /// <summary>
    /// Highlights all the hexagons in a distance of the designated type
    /// </summary>
    public void HighlightLOSNeighbors(Hexagon currentlyOccupiedHexagon, int distance, AbilityDescription.TargetType targetType, bool TemplateUse)
    {
        visited.Clear();
        frontier.Clear();
        distanceQueue.Clear();
        frontier.Enqueue(currentlyOccupiedHexagon);          //Starting hex
        visited.Add(currentlyOccupiedHexagon);
        TemplateManager.instance.TargetHexagons.Clear();
        currentlyOccupiedHexagon.DisableLOSCollider();

        Queue <Hexagon> activeQueue   = frontier;
        Queue <Hexagon> inactiveQueue = distanceQueue;

        while (activeQueue.Count > 0 && distance > 0)           //Breadth first search
        {
            Hexagon curr = activeQueue.Dequeue();
            foreach (Hexagon h in GetNeighborsAbilityCast(curr))
            {
                if (inLOS(currentlyOccupiedHexagon, h) && !visited.Contains(h))
                {
                    inactiveQueue.Enqueue(h);
                    visited.Add(h);
                }
            }

            if (activeQueue.Count == 0)               //Switching between active and inactive queues to track distance
            {
                Queue <Hexagon> t = activeQueue;
                activeQueue   = inactiveQueue;
                inactiveQueue = t;
                distance--;
            }
        }

        foreach (Hexagon h in visited)           //Highlight the hexagons we found
        {
            if (HexagonCastable(h, targetType))
            {
                h.Highlight();
                HighlightedHexagons.Add(h);
                if (TemplateUse)
                {
                    TemplateManager.instance.TargetHexagons.Add(h);
                }
            }
            else
            {
                h.EnableLOSCollider();              //If we cant cast on this hex, reenable the collider so we know its not a valid target
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Highlights all the hexagons in a distance of the designated type
    /// </summary>
    public List <PlayerControlledBoardUnit> GetEnemiesInRange(Hexagon currentlyOccupiedHexagon, int distance, AbilityDescription.TargetType targetType)
    {
        visited.Clear();
        frontier.Clear();
        distanceQueue.Clear();
        frontier.Enqueue(currentlyOccupiedHexagon);          //Starting hex
        visited.Add(currentlyOccupiedHexagon);
        currentlyOccupiedHexagon.DisableLOSCollider();

        Queue <Hexagon> activeQueue   = frontier;
        Queue <Hexagon> inactiveQueue = distanceQueue;

        while (activeQueue.Count > 0 && distance > 0)           //Breadth first search
        {
            Hexagon curr = activeQueue.Dequeue();
            foreach (Hexagon h in GetNeighborsAbilityCast(curr))
            {
                if (inLOS(currentlyOccupiedHexagon, h) && !visited.Contains(h))
                {
                    inactiveQueue.Enqueue(h);
                    visited.Add(h);
                }
            }

            if (activeQueue.Count == 0)               //Switching between active and inactive queues to track distance
            {
                Queue <Hexagon> t = activeQueue;
                activeQueue   = inactiveQueue;
                inactiveQueue = t;
                distance--;
            }
        }

        List <PlayerControlledBoardUnit> targets = new List <PlayerControlledBoardUnit>();

        foreach (Hexagon h in visited)           //Highlight the hexagons we found
        {
            if (HexagonTargettable(h))
            {
                targets.Add(h.OccupiedUnit as PlayerControlledBoardUnit);
            }
            h.EnableLOSCollider();
        }
        return(targets);
    }