コード例 #1
0
        IEnumerator DelayEndTurn()
        {
            yield return(new WaitForSeconds(1f));

            while (!TurnControl.ClearToProceed())
            {
                yield return(null);
            }
            GameControl.EndTurn();
        }
コード例 #2
0
        //clear movingUnit flag so the next unit can be moved
        IEnumerator EndMoveUnitRoutine()
        {
            while (!TurnControl.ClearToProceed())
            {
                AIDebug("Waiting for all sequence to complete");
                yield return(null);
            }
            yield return(null);

            movingUnit = false;
        }
コード例 #3
0
        //end the turn, called when EndTurn button are pressed or when a unit has used up all its move(in FactionUnitPerTurn & UnitPerTurn mode)
        public static void EndTurn()
        {
            if (!TurnControl.ClearToProceed())
            {
                return;
            }

            //if(onIterateTurnE!=null) onIterateTurnE();	//listen by EffectTracker and AbilityManager to iterate effect and cd duration
            //listen by tile in for tracking forceVisible(scan)

            instance.StartCoroutine(instance._EndTurn());
        }
コード例 #4
0
        public void OnEndTurnButton()
        {
            if (!TurnControl.ClearToProceed())
            {
                return;
            }
            OnGameInAction(true);

            endTurnButton.imgHighlight.gameObject.SetActive(false);

            //GameControl.EndTurn();
            UIMainControl.EndTurn();
        }
コード例 #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);
		}
コード例 #6
0
ファイル: CameraControl.cs プロジェクト: Hengle/TBTKPrototype
        IEnumerator ActionCamRoutine(Unit srcUnit, Vector3 tgtPos)
        {
            TurnControl.ActionCommenced();

            actionCamInProgress = true;

            Vector3    rootPosOrigin = thisT.position;
            Quaternion rootRotOrigin = thisT.rotation;

            Vector3 posOrigin  = camT.localPosition;
            float   zoomOrigin = camT.localPosition.z;

            Vector3 centerPos = srcUnit.GetTargetT().position + (tgtPos - srcUnit.GetTargetT().position) * 0.35f;

            centerPos.y = thisT.position.y;

            Quaternion wantedRot = Quaternion.LookRotation(centerPos - srcUnit.GetTargetT().position);

            wantedRot *= Quaternion.Euler(10, 15, 0);
            wantedRot  = Quaternion.Euler(wantedRot.eulerAngles.x, wantedRot.eulerAngles.y, 0);

            float dist = Vector3.Distance(centerPos, srcUnit.GetTargetT().position);

            float duration = 0;

            while (duration < 1)
            {
                thisT.rotation = Quaternion.Euler(thisT.rotation.eulerAngles.x, thisT.rotation.eulerAngles.y, 0);

                camT.localPosition = Vector3.Lerp(new Vector3(0, 0, zoomOrigin), new Vector3(0, 0, -dist - GridManager.GetTileSize() * 2), duration);
                thisT.position     = Vector3.Lerp(rootPosOrigin, centerPos, duration);
                thisT.rotation     = Quaternion.Lerp(rootRotOrigin, wantedRot, duration);

                duration += Time.deltaTime * 1f;
                yield return(null);
            }
            thisT.rotation = wantedRot;

            TurnControl.ActionCompleted();

            yield return(null);

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

            TurnControl.ActionCommenced();

            duration = 0;
            while (duration < 1)
            {
                thisT.rotation = Quaternion.Euler(thisT.rotation.eulerAngles.x, thisT.rotation.eulerAngles.y, 0);

                camT.localPosition = Vector3.Lerp(new Vector3(0, 0, -dist - GridManager.GetTileSize() * 2), new Vector3(0, 0, zoomOrigin), duration);
                thisT.position     = Vector3.Lerp(centerPos, rootPosOrigin, duration);
                thisT.rotation     = Quaternion.Lerp(wantedRot, rootRotOrigin, duration);

                duration += Time.deltaTime * 1f;
                yield return(null);
            }

            thisT.position     = rootPosOrigin;
            thisT.rotation     = rootRotOrigin;
            camT.localPosition = posOrigin;

            TurnControl.ActionCompleted();

            actionCamInProgress = false;
        }
コード例 #7
0
        private bool movingUnit = false;                //set to true when a unit is being moved
        IEnumerator MoveUnitRoutine(Unit unit, _AIMode activeMode)
        {
            TBTK.OnUnitSelected(unit);

            movingUnit = true;
            //Debug.Log("moving unit");
            if (activeMode != _AIMode.Aggressive && !unit.trigger)
            {
                AIDebug("unit " + unit.gameObject.name + " is not triggered");
                if (!untriggeredUnitMove)
                {
                    StartCoroutine(EndMoveUnitRoutine());
                    unit.moveRemain = 0;      unit.attackRemain = 0;
                }
                else
                {
                    if (Random.value < 0.5f)
                    {
                        StartCoroutine(EndMoveUnitRoutine());
                        unit.moveRemain = 0;      unit.attackRemain = 0;
                    }
                    else
                    {
                        AIDebug("Randomly move unit " + unit.gameObject.name + " anyway");
                        List <Tile> walkableTilesInRange = GridManager.GetTilesWithinDistance(unit.tile, Mathf.Min(1, unit.GetEffectiveMoveRange() / 2), true);
                        if (walkableTilesInRange.Count > 0)
                        {
                            unit.Move(walkableTilesInRange[Random.Range(0, walkableTilesInRange.Count)]);
                        }
                    }
                }
                AIDebug("End unit " + unit.gameObject.name + " turn");
                StartCoroutine(EndMoveUnitRoutine());
                yield break;
            }

            Tile targetTile = Analyse(unit, activeMode);


            if (CameraControl.CenterOnSelectedUnit())
            {
                bool visible = false;
                if (unit.tile.IsVisible())
                {
                    visible = true;
                }
                else if (targetTile != unit.tile)
                {
                    List <Tile> path = unit.GetPathForAI(targetTile);
                    for (int i = 0; i < path.Count; i++)
                    {
                        if (path[i].IsVisible())
                        {
                            visible = true;
                            break;
                        }
                    }
                    targetTile = path[path.Count - 1];
                    Debug.DrawLine(unit.tile.GetPos(), targetTile.GetPos(), Color.red, 2);
                }

                if (visible)
                {
                    CameraControl.OnUnitSelected(unit, false);
                    while (CameraControl.IsLerping())
                    {
                        yield return(null);
                    }
                }
            }


            //first move to the targetTile
            if (targetTile != unit.tile)
            {
                unit.Move(targetTile);
                yield return(new WaitForSeconds(.1f));                  //wait until the unit has moved into the targetTile

                while (!TurnControl.ClearToProceed())
                {
                    //AIDebug("waiting, unit "+unit.gameObject.name+" is moving");
                    AIDebug("waiting while unit is moving");
                    yield return(null);
                }
            }

            if (unit == null || unit.HP <= 0)           //in case unit is destroyed by overwatch
            {
                StartCoroutine(EndMoveUnitRoutine());
                yield break;
            }

            for (int i = 0; i < targetTile.hostileInRangeList.Count; i++)
            {
                if (targetTile.hostileInRangeList[i].unit == null || targetTile.hostileInRangeList[i].unit.factionID == unit.factionID)
                {
                    targetTile.hostileInRangeList.RemoveAt(i);              i -= 1;
                }
            }

            //if there's hostile within range, attack it
            if (targetTile.hostileInRangeList.Count > 0)
            {
                if (unit.CanAttack())
                {
                    AIDebug("waiting, unit " + unit.gameObject.name + " is attacking");

                    //~ if(targetTile!=unit.tile){	//wait until the unit has moved into the targetTile
                    //~ yield return new WaitForSeconds(.25f);
                    //~ while(!TurnControl.ClearToProceed()) yield return null;
                    //~ }

                    int rand = Random.Range(0, targetTile.hostileInRangeList.Count);
                    unit.Attack(targetTile.hostileInRangeList[rand].unit);
                }
                else
                {
                    if (unit.moveRemain > 0)
                    {
                        unit.moveRemain -= 1;
                    }
                }
            }
            else
            {
                if (unit.moveRemain <= 0)
                {
                    unit.attackRemain = 0;
                }
            }

            AIDebug("End unit " + unit.gameObject.name + " turn");
            StartCoroutine(EndMoveUnitRoutine());

            yield return(null);
        }