/*
     * -------------------------------------------------------------------------
     * MARK: LIFECYCLE FUNCTIONS
     * -------------------------------------------------------------------------
     */

    void Awake()
    {
        terrainController = GameObject.FindGameObjectWithTag("Terrain").GetComponent <TerrainController>();
        GameObject[] groundTiles = GameObject.FindGameObjectsWithTag("Ground Tile");
        tileRenderers = groundTiles.Select((tile) => tile.GetComponent <Renderer>())
                        .Cast <Renderer>()
                        .ToArray();
        tileControllers = groundTiles.Select((tile) => tile.GetComponent <GroundTileController>())
                          .Cast <GroundTileController>()
                          .ToArray();

        foreach (GameObject tile in groundTiles)
        {
            if (tile.transform.position.x + 1 > gridSizeX)
            {
                gridSizeX = (int)tile.transform.position.x + 1;
            }
            if (tile.transform.position.z + 1 > gridSizeZ)
            {
                gridSizeZ = (int)tile.transform.position.z + 1;
            }
        }

        groundHashtable = new GroundHashtable(this);
        groundGraph     = new GroundGraph(this);
        groundGraph.ConstructGraph();
    }
    /*
     * -------------------------------------------------------------------------
     * MARK: MOVE MENU SERVICE FUNCTIONS
     * -------------------------------------------------------------------------
     */

    // Handle creating move menu and shows move map for selected party member.
    public void HandleMoveSelection()
    {
        EntityController memberController = guiController.BattleController.ActiveSelection;

        Assert.IsTrue(memberController.EntityType == Utils.EntityType.PartyMember);

        GroundGraph groundGraph = guiController.BattleController.TerrainController.GroundController.groundGraph;

        groundGraph.ShowMoveMap();
    }
示例#3
0
    /*
     * -------------------------------------------------------------------------
     * MARK: UNIT SELECTION FUNCTIONS
     * -------------------------------------------------------------------------
     */

    /*
     * Handles switching active unit selections.
     * Constructs menu maps and updates valid menus.
     */
    public void SetActiveSelection(EntityController nextActiveSelection)
    {
        activeSelection = nextActiveSelection;

        if (activeSelection != EntityController.Empty &&
            activeSelection.EntityType == Utils.EntityType.PartyMember)
        {
            GroundGraph groundGraph  = terrainController.GroundController.groundGraph;
            bool        hasValidMove = groundGraph.ConstructMoveMap(activeSelection.transform.position, activeSelection.Movement, activeSelection.EntityType);
            guiController.ValidMoveMenu = !activeSelection.Moved && hasValidMove;

            bool hasValidAttack = groundGraph.ConstructAttackMap(activeSelection.transform.position, activeSelection.MinRange, activeSelection.MaxRange, activeSelection.EntityType);
            guiController.ValidAttackMenu = !activeSelection.Tapped && hasValidAttack;

            if (!hasValidMove && !hasValidAttack)
            {
                activeSelection.Tapped = true;
            }
        }
    }