Exemple #1
0
        public void _EndTurn()
        {
            //if (GameControl.GetGamePhase() == _GamePhase.Over)
            //    return;
            BattleControl.UnlockUnitSelect();
            currentTurnID += 1;

            if (turnMode == _TurnMode.FactionPerTurn)
            {
                if (moveOrder == _MoveOrder.Free)
                {
                    ;// FactionManager.SelectNextFaction();
                }
                //else if (moveOrder == _MoveOrder.StatsBased)
                //    FactionManager.SelectNextUnitInFaction();
            }
            //else if (turnMode == _TurnMode.FactionUnitPerTurn)
            //{
            //    FactionManager.SelectNextUnitInNextFaction();
            //}
            //else if (turnMode == _TurnMode.UnitPerTurn)
            //{
            //    FactionManager.SelectNextUnit();
            //}
        }
Exemple #2
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Exemple #3
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
        }
Exemple #4
0
        public void Move(Tile targetTile)
        {
            if (moveRemain <= 0)
            {
                return;
            }

            moveRemain -= 1;

            BattleControl.LockUnitSelect();

            StartCoroutine(MoveRoutine(targetTile));
        }
Exemple #5
0
 void FinishAction()
 {
     //if (isAIUnit)
     //    return;
     if (!IsAllActionCompleted())
     {
         BattleControl.SelectUnit(this);
     }
     else
     {
         TurnControl.NextUnit();
     }
 }
Exemple #6
0
 //for FactionPerTurn mode, breakWhenExceedLimit is set to true, where selectUnitID resets when it reachs end
 public bool SelectNextUnitInQueue(bool breakWhenExceedLimit = true)
 {
     selectedUnitID += 1;
     if (selectedUnitID >= allUnitList.Count)
     {
         if (breakWhenExceedLimit)
         {       //for FactionPerTurn mode, reset the ID
             selectedUnitID = -1;
             return(true);
         }
         selectedUnitID = 0;
     }
     allUnitList[selectedUnitID].ResetUnitTurnData();
     BattleControl.SelectUnit(allUnitList[selectedUnitID]);
     return(false);
 }
Exemple #7
0
        public void Attack(Unit targetUnit)
        {
            if (attackRemain == 0)
            {
                return;
            }
            attackRemain -= 1;

            BattleControl.LockUnitSelect();

            //AttackInstance attInstance = new AttackInstance(this, targetUnit);
            //attInstance.Process();


            StartCoroutine(AttackRoutine(targetUnit.tile, targetUnit /*, attInstance*/));
        }
Exemple #8
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();
            //}
        }
Exemple #9
0
        public int selectedUnitID = -1; //used when move-order are not free, cycle through allUnitList

        //[HideInInspector]
        //public bool foldSpawnInfo = false;	//for editor use only, show or hide spawnInfoList
        //public List<FactionSpawnInfo> spawnInfoList = new List<FactionSpawnInfo>();

        //used in FactionPerTurn, FreeMove order only
        public bool SelectFirstAvailableUnit()
        {
            int index = -1;

            for (int i = 0; i < allUnitList.Count; i++)
            {
                if (!allUnitList[i].IsAllActionCompleted())
                {
                    index = i;
                    break;
                }
            }

            if (index >= 0)
            {
                selectedUnitID = index;
                BattleControl.SelectUnit(allUnitList[selectedUnitID]);
                return(true);
            }

            return(false);
        }
Exemple #10
0
        public void _SelectNextFaction()
        {
            BattleControl.ClearSelectedUnit();

            selectedFactionID += 1;
            if (selectedFactionID >= factionList.Count)
            {
                selectedFactionID = 0;
            }
            factionList[selectedFactionID].ResetFactionTurnData();

            if (true) //if it's a player's faction
            {
                if (TurnControl.GetMoveOrder() == _MoveOrder.Free)
                {
                    factionList[selectedFactionID].SelectFirstAvailableUnit();
                }
                else
                {
                    factionList[selectedFactionID].SelectNextUnitInQueue(true);
                }
            }
            //else
            //{//if it's a AI's faction, execute AI move
            //    Debug.Log("AIManager.MoveFaction ------------------------");
            //    BattleControl.DisplayMessage("AI's Turn");
            //    if (TurnControl.GetMoveOrder() == _MoveOrder.Free)
            //    {
            //        AIManager.MoveFaction(factionList[selectedFactionID]);
            //    }
            //    else
            //    {
            //        SelectNextUnitInFaction();	//when an AI unit pass to BattleControl.Select(), AI routine will be called
            //    }
            //}
        }
Exemple #11
0
        public IEnumerator MoveRoutine(Tile targetTile)
        {
            tile.unit = null;

            byte[,] grid = TileManager.GetTiledMap().GetCostGrid(TileManager.TerrainToCost);
            List <Tile> path = AStar.SearchWalkableTile(grid, tile, targetTile);

            while (!TurnControl.ClearToProceed())
            {
                yield return(null);
            }

            TurnControl.ActionCommenced();

            if (unitAnim != null)
            {
                unitAnim.Move();
            }
            if (unitAudio != null)
            {
                unitAudio.Move();
            }


            while (path.Count > 0)
            {
                while (true)
                {
                    float dist = Vector3.Distance(transform.position, path[0].GetPos());
                    if (dist < 0.05f)
                    {
                        break;
                    }

                    //Quaternion wantedRot = Quaternion.LookRotation(path[0].GetPos() - transform.position);
                    //transform.rotation = Quaternion.Slerp(transform.rotation, wantedRot, Time.deltaTime * moveSpeed * 3);

                    unitAnim.Direction(path[0].GetPos().x - transform.position.x,
                                       path[0].GetPos().y - transform.position.y);
                    Vector3 dir = (path[0].GetPos() - transform.position).normalized;
                    transform.Translate(dir * Mathf.Min(moveSpeed * Time.deltaTime, dist), Space.World);
                    yield return(null);
                }

                tile = path[0];

                //FactionManager.UpdateHostileUnitTriggerStatus(this);

                path.RemoveAt(0);
            }

            if (unitAnim != null)
            {
                unitAnim.StopMove();
            }

            tile.unit          = this;
            transform.position = tile.GetPos();

            TurnControl.ActionCompleted(0.15f);

            BattleControl.UnlockUnitSelect();

            FinishAction();
        }