Exemplo n.º 1
0
        //for when selected unit is destroyed during counter attack
        public IEnumerator AutoEndTurn()
        {
            while (!ClearToProceed())
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(0.5f));

            if (GameControl.GetGamePhase() != _GamePhase.Over)
            {
                GameControl.EndTurn();
            }
        }
Exemplo n.º 2
0
        //move the whole faction, unit by unit
        IEnumerator FactionRoutine(Faction faction)
        {
            GameControl.DisplayMessage("AI's Turn");
            yield return(new WaitForSeconds(0.3f));

            //create a new list so no unit will be skipped is one of them is somehow destroyed (by counter attack);
            List <Unit> unitList = new List <Unit>(faction.allUnitList);

            for (int i = 0; i < unitList.Count; i++)
            {
                AIDebug("Start moving unit " + unitList[i].gameObject.name);

                yield return(new WaitForSeconds(unitInterval));

                if (unitList[i].IsStunned())
                {
                    continue;
                }

                _AIMode activeAIMode = !faction.useDefaultAIMode ? faction.aiMode : mode;

                while (unitList[i].moveRemain > 0 || unitList[i].CanAttack())
                {
                    AIDebug("Moving unit " + unitList[i].gameObject.name + "     (move remain:" + (unitList[i].moveRemain > 0) + ", can attack:" + unitList[i].CanAttack() + ")");
                    StartCoroutine(MoveUnitRoutine(unitList[i], activeAIMode));
                    while (movingUnit)
                    {
                        yield return(null);
                    }
                    if (unitList[i] == null)
                    {
                        break;
                    }
                    if (unitList[i].moveRemain > 0 || unitList[i].CanAttack())
                    {
                        yield return(new WaitForSeconds(.1f));
                    }
                }

                //~ StartCoroutine(MoveUnitRoutine(unitList[i], activeAIMode));
                //~ while(movingUnit) yield return null;
                //~ yield return new WaitForSeconds(0.25f);

                if (GameControl.GetGamePhase() == _GamePhase.Over)
                {
                    yield break;
                }
            }

            GameControl.EndTurn();
        }
Exemplo n.º 3
0
        public IEnumerator _EndTurn()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                yield break;
            }

            yield return(new WaitForSeconds(0.2f));

            currentTurnID += 1;

            if (turnMode == _TurnMode.FactionPerTurn)
            {
                if (moveOrder == _MoveOrder.Free)
                {
                    FactionManager.EndTurn_FactionPerTurn();
                }
                else
                {
                    if (FactionManager.SelectNextUnitInFaction_NotFree())
                    {
                        TBTK.OnNewTurn(IsPlayerTurn());
                        yield break;
                    }
                    else
                    {
                        FactionManager.EndTurn_FactionPerTurn();
                    }
                }
            }
            else if (turnMode == _TurnMode.FactionUnitPerTurn)
            {
                CheckPlayerMoveFlag(false);
                FactionManager.EndTurn_FactionUnitPerTurn();
            }

            IterateEndTurn();
            if (turnMode == _TurnMode.UnitPerTurn)
            {
                FactionManager.EndTurn_UnitPerTurn();
            }


            TBTK.OnNewTurn(IsPlayerTurn());
        }
Exemplo n.º 4
0
        //call by unit when all action is depleted
        public static void SelectedUnitMoveDepleted()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                return;
            }

            if (instance.turnMode == _TurnMode.FactionPerTurn)
            {
                //if not in free move order, cant switch to next unit without end turn
                if (instance.moveOrder != _MoveOrder.Free)
                {
                    TBTK.OnAllUnitOutOfMove();
                    if (GameControl.GetSelectedUnit().HP <= 0)
                    {
                        instance.StartCoroutine(instance.AutoEndTurn());
                    }
                }
                else
                {
                    if (!FactionManager.SelectNextUnitInFaction_Free())
                    {
                        TBTK.OnAllUnitOutOfMove();
                    }
                }
            }
            else if (instance.turnMode == _TurnMode.FactionUnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
            else if (instance.turnMode == _TurnMode.UnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
        }
Exemplo n.º 5
0
		public void _OnCursorDown(int cursorID=-1){
			//Debug.Log("_OnCursorDown");
			
			if(hoveredTile==null) return;
			
			if(TBTK.IsCursorOnUI(cursorID)) return;
			
			if(!TurnControl.ClearToProceed()) return;
			
			if(GameControl.GetGamePhase()==_GamePhase.Over) return;
			
			if(GameControl.GetGamePhase()==_GamePhase.UnitDeployment){
				if(hoveredTile.unit==null) FactionManager.DeployUnitOnTile(hoveredTile);
				else if(hoveredTile.unit!=null) FactionManager.UndeployUnit(hoveredTile.unit);
				return;
			}
			
			if(AbilityManager.InTargetMode()){
				Debug.Log("AbilityTargetSelected");
				targetModeTargetSelected(hoveredTile);
			}
			else OnTile(hoveredTile);
		}
Exemplo n.º 6
0
        IEnumerator OnLeftCursorDown(int pointer = -1)
        {
            yield return(null);

            if (UI.IsCursorOnUI(pointer))
            {
                yield break;
            }

            Tile tile = GridManager.GetHoveredTile();

            if (tile != null)
            {
                if (GameControl.GetGamePhase() == _GamePhase.UnitDeployment)
                {
                    GridManager.OnCursorDown();
                    yield break;
                }

                if (AbilityManager.InTargetMode())
                {
                    GridManager.OnCursorDown();
                    yield break;
                }

                heldTile        = tile;
                holdStartedTime = Time.time;

                if (touchMode && GridManager.CanAttackTile(GridManager.GetHoveredTile()))
                {
                    NewClickTile(tile);
                }
                else if (touchMode && GridManager.CanMoveToTile(GridManager.GetHoveredTile()))
                {
                    NewClickTile(tile);
                }
                else
                {
                    if (!GridManager.CanPerformAction(tile))
                    {
                        //ClearLastClickTile();     dont call last click tile, we dont want to hide unit info if there's any
                        lastClickTile = null;
                        UIInputOverlay.SetNewHoveredTile(null);
                    }
                    else
                    {
                        GridManager.OnCursorDown();                             //ClearLastClickTile() will be called as soon as unit move or attack or cast ability
                    }
                }
            }
            else
            {
                ClearLastClickTile();
            }

            //~ if(tile!=null){
            //~ if(tile.unit!=null){
            //~ if(!GameControl.CanSelectUnit(tile.unit)) UIUnitInfo.Show(tile);
            //~ else{
            //~ GridManager.OnCursorDown();
            //~ UIUnitInfo.Hide();
            //~ return;
            //~ }
            //~ }
            //~ else UIUnitInfo.Hide();

            //~ if(touchMode && GridManager.CanAttackTile(GridManager.GetHoveredTile())){
            //~ NewClickTile(tile);
            //~ }
            //~ else if(touchMode && GridManager.CanMoveToTile(GridManager.GetHoveredTile())){
            //~ NewClickTile(tile);
            //~ }
            //~ else{
            //~ if(!GridManager.CanPerFormAction(tile)){
            //~ //ClearLastClickTile();     dont call last click tile, we dont want to hide unit info if there's any
            //~ lastClickTile=null;
            //~ UIInputOverlay.SetNewHoveredTile(null);
            //~ }
            //~ else GridManager.OnCursorDown();	//ClearLastClickTile() will be called as soon as unit move or attack or cast ability
            //~ }
            //~ }
            //~ else ClearLastClickTile();
        }