Beispiel #1
0
        //move a single unit only
        IEnumerator SingleUnitRoutine(Unit unit)
        {
            GameControl.DisplayMessage("AI's Turn");

            yield return(new WaitForSeconds(0.1f));

            if (!unit.IsStunned())
            {
                Faction faction      = FactionManager.GetFaction(unit.factionID);
                _AIMode activeAIMode = !faction.useDefaultAIMode ? faction.aiMode : mode;

                while (unit.moveRemain > 0 || unit.CanAttack())
                {
                    StartCoroutine(MoveUnitRoutine(unit, activeAIMode));
                    while (movingUnit)
                    {
                        yield return(null);
                    }
                    if (unit == null)
                    {
                        break;
                    }
                    if (unit.attackRemain > 0 || unit.CanAttack())
                    {
                        yield return(new WaitForSeconds(.1f));
                    }
                }

                //~ StartCoroutine(MoveUnitRoutine(unit, activeAIMode));
                //~ while(movingUnit) yield return null;
                //~ yield return new WaitForSeconds(0.25f);
            }

            GameControl.EndTurn();
        }
Beispiel #2
0
        public float _NewTurn()
        {
            if (!generateInGame)
            {
                return(0);
            }
            if (activeItemList.Count >= activeItemLimit)
            {
                return(0);
            }

            bool spawned = false;

            for (int i = 0; i < spawnPerTurn; i++)
            {
                if (activeItemList.Count >= activeItemLimit)
                {
                    break;
                }
                if (Random.value > spawnChance)
                {
                    continue;
                }

                Tile tile = GetRandomTile();
                if (tile == null)
                {
                    continue;
                }

                int        rand    = Random.Range(0, itemList.Count);
                GameObject itemObj = (GameObject)Instantiate(itemList[rand].gameObject);

                PlaceItemAtTile(itemObj, tile);

                spawned = true;

                if (spawnEffect != null)
                {
                    if (!autoDestroySpawnEffect)
                    {
                        ObjectPoolManager.Spawn(spawnEffect, tile.GetPos(), Quaternion.identity);
                    }
                    else
                    {
                        ObjectPoolManager.Spawn(spawnEffect, tile.GetPos(), Quaternion.identity, spawnEffectDuration);
                    }
                }
            }

            GameControl.DisplayMessage("New Collectible!");

            return(spawned ? 2 : 0);
        }
Beispiel #3
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();
        }
Beispiel #4
0
        //public static void AbilityTargetSelected(Tile tile){ instance._AbilityTargetSelected(tile); }
        public void AbilityTargetSelected(Tile tile)
        {
            if (targetModeTileList.Count > 0 && !targetModeTileList.Contains(tile))
            {
                GameControl.DisplayMessage("Out of Range");
                return;
            }

            bool invalidFlag = false;

            if (targetModeType == _TargetType.AllUnit)
            {
                invalidFlag = (tile.unit == null);
            }
            else if (targetModeType == _TargetType.HostileUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID == currentFacID);
            }
            else if (targetModeType == _TargetType.FriendlyUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID != currentFacID);
            }
            else if (targetModeType == _TargetType.EmptyTile)
            {
                invalidFlag = (tile.unit != null || !tile.walkable);
            }
            else if (targetModeType == _TargetType.AllTile)
            {
            }

            if (invalidFlag)
            {
                GameControl.DisplayMessage("Invalid target");
            }
            else
            {
                if (targetSelectedCallBack != null)
                {
                    targetSelectedCallBack(tile, abilityIndex);
                }

                TBTK.OnAbilityActivated();

                ExitAbilityTargetMode();
            }
        }