示例#1
0
    private IEnumerator SpecialAttackDamageDelay(float a_timer)
    {
        //wait for timer before runing code
        yield return(new WaitForSeconds(a_timer));

        //go though each tile and deal damage to the enemy
        foreach (Hex x in specialTiles)
        {
            //if there is a unit
            if (x.CurrentUnit != null)
            {
                //make sure we arent damaging the player or team
                if (x.CurrentUnit.Team != TEAM.player)
                {
                    //deal damage to that unit
                    x.CurrentUnit.TakeDamage(specialDamage[HexUtility.Distance(specialTiles[0], x) - 1], this);
                }
            }
        }

        //change the position of the camera to the position of the unit
        cameraController.transform.position = transform.position;



        //call the finished call back function
        specialFinishedFunc();
    }
示例#2
0
    public static List <Hex> FindPath(Hex a_starting, Hex a_target)
    {
        List <Hex>    openSet   = new List <Hex>();
        HashSet <Hex> closedSet = new HashSet <Hex>();

        openSet.Add(a_starting);

        while (openSet.Count > 0)
        {
            Hex current = openSet[0];
            current.HScore = HexUtility.Distance(current, a_target);
            for (int i = 1; i < openSet.Count; i++)
            {
                if (openSet[i].FScore < current.FScore || (openSet[i].FScore == current.FScore && openSet[i].FScore < current.FScore))
                {
                    current = openSet[i];
                }
            }

            closedSet.Add(current);
            openSet.Remove(current);

            if (current == a_target)
            {
                foreach (Hex node in closedSet)
                {
                    node.GScore = 0;
                }

                return(RetracePath(a_starting, a_target));
            }

            foreach (Hex neighbour in current.Neighbours)
            {
                if (!neighbour.IsTraversable || closedSet.Contains(neighbour))
                {
                    continue;
                }

                float newMovemntCostToNeighour = current.GScore + HexUtility.Distance(current, neighbour);
                if (newMovemntCostToNeighour < neighbour.GScore || !openSet.Contains(neighbour))
                {
                    neighbour.GScore = newMovemntCostToNeighour;
                    neighbour.HScore = HexUtility.Distance(neighbour, a_target);
                    neighbour.Parent = current;

                    if (!openSet.Contains(neighbour))
                    {
                        openSet.Add(neighbour);
                    }
                }
            }
        }

        return(null);
    }
示例#3
0
    public Hex[] GetHexLine(Hex a_lhs, Hex a_rhs)
    {
        List <Hex> hexs = new List <Hex>();

        int distance = HexUtility.Distance(a_lhs, a_rhs);

        float scale = HexUtility.outerRadius;

        for (int i = 0; i < distance; i++)
        {
            hexs.Add(GetHexFromPosition(Vector3.Lerp(a_lhs.transform.position, a_rhs.transform.position, scale / distance * i)));
        }

        return(hexs.ToArray());
    }
示例#4
0
    // returns a tiles within range of landing tiles
    private void GetTilesAffectByEarthSpecialAttack(Hex a_targetTile)
    {
        foreach (Hex tile in tilesAffectByAction)
        {
            tile.MouseExit();
        }

        tilesAffectByAction.Clear();

        foreach (Unit unit in enemiesAffectByAction)
        {
            unit.PreviewDamage(0);
        }

        enemiesAffectByAction.Clear();

        tilesAffectByAction.Add(a_targetTile);

        List <Hex> tilesInRange = grid.GetTilesWithinDistance(a_targetTile, earthUnit.SpecialDamageArea, false);

        for (int i = 0; i < tilesInRange.Count; i++)
        {
            tilesAffectByAction.Add(tilesInRange[i]);
        }

        foreach (Hex tile in tilesAffectByAction)
        {
            if (tile.CurrentUnit != null && tile.CurrentUnit.CompareTag("Enemy"))
            {
                enemiesAffectByAction.Add(tile.CurrentUnit);
            }

            tile.MouseEnter(currentRuleset.HighlightColour);
        }

        foreach (Unit unit in enemiesAffectByAction)
        {
            int damageIndex = HexUtility.Distance(a_targetTile, unit.CurrentTile) - 1;
            unit.PreviewDamage(earthUnit.GetSpecialDamage(damageIndex));
        }
    }
示例#5
0
    private bool WithinDistanceAboslute(Hex a_hex, Hex a_tileLocation)
    {
        int distance = 0;

        switch (distanceCheckType)
        {
        case DistanceCheck.attackRange:
            distance = a_hex.CurrentUnit.GetComponent <Unit>().AttackRange;
            return(HexUtility.Distance(a_hex, a_tileLocation) <= distance);

        case DistanceCheck.specialAttackRange:
            distance = a_hex.CurrentUnit.GetComponent <Unit>().SpecialAttackRange;
            return(HexUtility.Distance(a_hex, a_tileLocation) <= distance);

        case DistanceCheck.movementRange:
            distance = a_hex.CurrentUnit.GetComponent <Unit>().MoveRange;
            return(HexUtility.Distance(a_hex, a_tileLocation) <= distance);

        case DistanceCheck.custom:
            return(HexUtility.Distance(a_hex, a_tileLocation) <= minDistance);
        }

        return(false);
    }
示例#6
0
    protected override void DoBasicAttack(Hex[] targetTiles, System.Action start, System.Action finished)
    {
        start();

        CanAttack = false;

        basicFinishedFunc = finished;


        if (AIController == null)
        {
            AIController = GameObject.FindGameObjectWithTag("AI_Controller").GetComponent <AI_Controller>();
        }

        basicEnemies = AIController.Agents;

        basicFinalTargets.Add(this);

        basicFinalTargets.Add(targetTiles[0].CurrentUnit);


        for (int i = 1; i < basicAmountOfBounces; i++)
        {
            foreach (var enemy in basicEnemies)
            {
                if (i < basicFinalTargets.Count)
                {
                    if (enemy != basicFinalTargets[i])
                    {
                        if (HexUtility.Distance(basicFinalTargets[i].CurrentTile, enemy.CurrentTile) <= basicRange)
                        {
                            basicSortedList.Add(enemy);
                        }
                    }
                }
            }



            basicSortedList.Sort((a, b) => (HexUtility.Distance(basicFinalTargets[i].CurrentTile, a.CurrentTile).CompareTo(HexUtility.Distance(basicFinalTargets[i].CurrentTile, b.CurrentTile))));

            if (basicRehitEnemies == false)
            {
                foreach (var x in basicSortedList)
                {
                    if (!basicFinalTargets.Contains(x))
                    {
                        basicFinalTargets.Add(x);
                        break;
                    }
                }
            }
            else
            {
                if (basicSortedList.Count > 1)
                {
                    if (basicSortedList[0] == basicFinalTargets[i - 1])
                    {
                        basicFinalTargets.Add(basicSortedList[1]);
                    }
                    else
                    {
                        basicFinalTargets.Add(basicSortedList[0]);
                    }
                }
                else if (basicSortedList.Count != 0)
                {
                    basicFinalTargets.Add(basicSortedList[0]);
                }
            }

            basicSortedList.Clear();
        }

        Vector3 tilePos = basicFinalTargets[1].transform.position;

        tilePos.y = transform.position.y;


        StartCoroutine(BasicAttackDamageDelay(basicDelayTime, basicLightningLifeTime));
    }
示例#7
0
    protected virtual IEnumerator DoTurn(GridManager a_grid)
    {
        AI_Action  bestAction     = null;
        int        playerToAttack = 0;
        float      bestScore      = int.MinValue;
        List <Hex> path           = null;

        players[0] = Manager.instance.PlayerController.EarthUnit;
        players[1] = Manager.instance.PlayerController.LightningUnit;

        ScoringInfo[] scoringInfo = new ScoringInfo[2];
        scoringInfo[0] = (players[0] == null || players[0].IsDead) ? null : new ScoringInfo(a_grid, this, players[0]);
        scoringInfo[1] = (players[1] == null || players[1].IsDead) ? null : new ScoringInfo(a_grid, this, players[1]);

        foreach (AI_Action action in actions)
        {
            for (int i = 0; i < 2; i++)
            {
                if (scoringInfo[i] == null)
                {
                    continue;
                }

                float score = action.GetScore(scoringInfo[i]);
                if (scoringInfo[i].Path != null)
                {
                    if (score > bestScore)
                    {
                        bestAction     = action;
                        playerToAttack = i;
                        bestScore      = score;
                        path           = scoringInfo[i].Path;
                    }
                }
            }
        }

        if (bestAction == null)
        {
            Debug.Log("No valid actions found", gameObject);
            turnComplete = true;
            yield break;
        }

        // Remove the path that is out of the movement range
        if (path.Count > MoveRange)
        {
            path.RemoveRange(MoveRange, path.Count - MoveRange);
        }

        // Path find and wait for it to finish
        isPerformingAction = true;
        finishedWalking    = FinishedAction;
        StartCoroutine(Walk(path));
        yield return(new WaitUntil(() => isPerformingAction == false));

        // Attack the player, checking if it is in range && if we have a clear shot
        if (HexUtility.Distance(currentTile, players[playerToAttack].CurrentTile) <= attackRange && HasClearShot(players[playerToAttack]))
        {
            isPerformingAction = true;
            BasicAttack(new Hex[] { players[playerToAttack].CurrentTile }, null, FinishedAction);
            yield return(new WaitUntil(() => isPerformingAction == false));
        }

        turnComplete = true;
        yield break;
    }
示例#8
0
    public List <Hex> GetTilesWithinDistance(Hex centerTile, int range, bool CheckIfTraversable = true, bool addOccupiedTiles = false, bool addOutofBounds = false)
    {
        List <Hex> openList   = new List <Hex>();
        List <Hex> returnList = new List <Hex>();
        Hex        currentTile;

        centerTile.GScore = 0;

        openList.Add(centerTile);

        while (openList.Count != 0)
        {
            currentTile = openList[0];
            openList.Remove(currentTile);

            foreach (Hex neighbour in currentTile.Neighbours)
            {
                if (CheckIfTraversable)
                {
                    if (addOccupiedTiles == true)
                    {
                        if ((neighbour.IsTraversable && !returnList.Contains(neighbour)))
                        {
                            neighbour.GScore = HexUtility.Distance(currentTile, neighbour) + currentTile.GScore;
                            if (neighbour.GScore < range + 1)
                            {
                                openList.Add(neighbour);
                                returnList.Add(neighbour);
                            }
                        }
                        else if ((neighbour.CurrentUnit != null && !returnList.Contains(neighbour)))
                        {
                            neighbour.GScore = HexUtility.Distance(currentTile, neighbour) + currentTile.GScore;
                            if (neighbour.GScore < range + 1)
                            {
                                //openList.Add(neighbour);
                                returnList.Add(neighbour);
                            }
                        }
                    }
                    else
                    {
                        if (neighbour.IsTraversable && !returnList.Contains(neighbour))
                        {
                            neighbour.GScore = HexUtility.Distance(currentTile, neighbour) + currentTile.GScore;
                            if (neighbour.GScore < range + 1)
                            {
                                openList.Add(neighbour);
                                returnList.Add(neighbour);
                            }
                        }
                    }
                }
                else if (!returnList.Contains(neighbour))
                {
                    if (addOutofBounds == false)
                    {
                        if (neighbour.HexState != HexState.OutOfBounds)
                        {
                            neighbour.GScore = HexUtility.Distance(currentTile, neighbour) + currentTile.GScore;
                            if (neighbour.GScore < range + 1)
                            {
                                openList.Add(neighbour);
                                returnList.Add(neighbour);
                            }
                        }
                    }
                    else
                    {
                        neighbour.GScore = HexUtility.Distance(currentTile, neighbour) + currentTile.GScore;
                        if (neighbour.GScore < range + 1)
                        {
                            openList.Add(neighbour);
                            returnList.Add(neighbour);
                        }
                    }
                }
            }

            openList.Sort((x, y) => x.GScore.CompareTo(y.GScore));
        }

        foreach (Hex hex in returnList)
        {
            hex.GScore = 0;
        }

        return(returnList);
    }