Ejemplo n.º 1
0
        public void _OnTile(Tile tile)
        {
            //if (!FactionManager.IsPlayerTurn()) return;

            if (tile.unit != null)
            {
                //select the unit if the unit belong's to current player in turn
                if (FactionManager.GetSelectedFactionID() == tile.unit.factionID)
                {
                    if (TurnControl.GetMoveOrder() != _MoveOrder.Free)
                    {
                        return;
                    }
                    //    if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn) return;

                    if (!BattleControl.AllowUnitSelect())
                    {
                        return;
                    }
                    if (BattleControl.selectedUnit != null && BattleControl.selectedUnit.tile == tile)
                    {
                        return;
                    }
                    BattleControl.SelectUnit(tile.unit);
                }
                //if the unit in the tile can be attack by current selected unit, attack it
                else if (attackableTileList.Contains(tile))
                {
                    BattleControl.selectedUnit.Attack(tile.unit);
                }
            }
            //if the tile is within the move range of current selected unit, move to it
            else
            {
                if (walkableTileList.Contains(tile))
                {
                    if (onExitWalkableTileE != null)
                    {
                        onExitWalkableTileE();
                    }

                    BattleControl.selectedUnit.Move(tile);
                    ClearAllTile();
                }
                else
                {
                    BattleControl.ClearSelectedUnit();
                }
            }


            ClearHoveredTile(); //clear the hovered tile so all the UI overlay will be cleared
        }
Ejemplo n.º 2
0
        //call by unit when all action is depleted
        public static void NextUnit()
        {
            //if (GameControl.GetGamePhase() == _GamePhase.Over)
            //    return;
            BattleControl.UnlockUnitSelect();

            if (instance.turnMode == _TurnMode.FactionPerTurn)
            {
                FactionManager.SelectNextUnitInFaction();
            }
            //else if (instance.turnMode == _TurnMode.FactionUnitPerTurn)
            //{
            //    EndTurn();
            //}
            //else if (instance.turnMode == _TurnMode.UnitPerTurn)
            //{
            //    EndTurn();
            //}
        }
Ejemplo n.º 3
0
        //called by GameControl to initiate the factions,
        //load from data when needed, spawn the startingUnit,
        //initiate the unit, check if unit deployment is required....
        public void Init()
        {
            if (instance == null)
            {
                instance = this;
            }

            //setup all the unit in the game
            for (int i = 0; i < factionList.Count; i++)
            {
                for (int n = 0; n < factionList[i].allUnitList.Count; n++)
                {
                    factionList[i].allUnitList[n].isAIUnit = false;
                }
            }

            Vector3    pos = new Vector3(0, 99999, 0);
            Quaternion rot = Quaternion.identity;

            for (int i = 0; i < factionList.Count; i++)
            {
                Faction fac = factionList[i];

                //if load from data, then load the list from data and then put it to startingUnitList
                //if (fac.loadFromData)
                //{
                //    fac.startingUnitList = new List<Unit>();
                //    fac.dataList = Data.GetLoadData(fac.dataID);
                //    if (fac.dataList == null)
                //    {
                //        Debug.LogWarning("TBTK faction's data not setup properly", this);
                //        continue;
                //    }
                //    Debug.Log("unit from data: " + fac.dataList.Count);
                //    for (int n = 0; n < fac.dataList.Count; n++) fac.startingUnitList.Add(fac.dataList[n].unit);

                //    //put the data list back into the end data first, to save the current starting lineup for next menu loading
                //    //in case the player didnt finish the level and GameOver is not called
                //    Data.SetEndData(fac.dataID, fac.dataList);
                //}
                //else
                {
                    //if using default startingUnitList, make sure none of the element in startingUnitList is empty
                    for (int n = 0; n < fac.startingUnitList.Count; n++)
                    {
                        if (fac.startingUnitList[n] == null)
                        {
                            fac.startingUnitList.RemoveAt(n);
                            n -= 1;
                        }
                    }
                }

                for (int n = 0; n < fac.startingUnitList.Count; n++)
                {
                    GameObject unitObj = (GameObject)Instantiate(fac.startingUnitList[n].gameObject, pos, rot);
                    fac.startingUnitList[n]  = unitObj.GetComponent <Unit>();
                    unitObj.transform.parent = transform;
                    unitObj.SetActive(false);
                }
            }



            //if (!BattleControl.EnableManualUnitDeployment())
            {
                for (int i = 0; i < factionList.Count; i++)
                {
                    if (factionList[i].startingUnitList.Count <= 0)
                    {
                        continue;
                    }

                    AutoDeployFaction(i);
                }
            }
        }