示例#1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
示例#2
0
        public void _SelectNextUnitInFaction()
        {
            if (selectedFactionID < 0)
            {
                selectedFactionID = 0;
            }

            if (TurnControl.GetMoveOrder() == _MoveOrder.Free)
            {
                bool unitAvailable = factionList[selectedFactionID].SelectFirstAvailableUnit();
                if (!unitAvailable)
                {
                    _SelectNextFaction();
                }
            }
            else
            {
                //pass true to SelectNextUnitInQueue() so when the all unit in the faction has been selected before, the function will return true
                bool allUnitCycled = factionList[selectedFactionID].SelectNextUnitInQueue(true);
                //original line
                //bool allUnitCycled=factionList[selectedFactionID].SelectNextUnitInQueue(true);
                if (allUnitCycled)
                {
                    _SelectNextFaction();
                }
            }
        }
示例#3
0
文件: Unit.cs 项目: ghrguse/ss
        public IEnumerator AttackRoutine(Tile targetTile, Unit targetUnit /*, AttackInstance attInstance*/)
        {
            while (!TurnControl.ClearToProceed())
            {
                yield return(null);
            }
            TurnControl.ActionCommenced();

            //play animation
            if (unitAnim != null)
            {
                unitAnim.Attack();
            }
            if (unitAudio != null)
            {
                unitAudio.Attack();
            }

            //TODO attack
            //target fight back?

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

            FinishAction();
        }
示例#4
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
        }
示例#5
0
文件: Unit.cs 项目: ghrguse/ss
 void FinishAction()
 {
     //if (isAIUnit)
     //    return;
     if (!IsAllActionCompleted())
     {
         BattleControl.SelectUnit(this);
     }
     else
     {
         TurnControl.NextUnit();
     }
 }
示例#6
0
 public List <Unit> _GetAllUnit()
 {
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         return(allUnitList);
     }
     else
     {
         List <Unit> list = new List <Unit>();
         for (int i = 0; i < factionList.Count; i++)
         {
             for (int n = 0; n < factionList[i].allUnitList.Count; n++)
             {
                 list.Add(factionList[i].allUnitList[n]);
             }
         }
         return(list);
     }
 }
示例#7
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
            //    }
            //}
        }
示例#8
0
文件: BattleUI.cs 项目: ghrguse/ss
 public void OnEndUnitButton()
 {
     BattleControl.selectedUnit.FinishAllAction();
     TurnControl.NextUnit();
 }
示例#9
0
文件: Unit.cs 项目: ghrguse/ss
        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();
        }