예제 #1
0
    //execute move/attack for a single unit
    IEnumerator _MoveUnit(UnitTB unit)
    {
        //make sure no event is taking place
        while(GameControlTB.IsActionInProgress()) yield return null;

        if(!unit.IsStunned()){

            /*
            DateTime timeS;
            DateTime timeE;
            TimeSpan timeSpan;
            timeS=System.DateTime.Now;
            */

            Tile destinationTile=null;
            if(aIStance==_AIStance.Trigger){
                if(unit.triggered) destinationTile=Analyse(unit);
            }
            else{
                destinationTile=Analyse(unit);
            }

            //if there's target in current tile, just attack it
            if(destinationTile==unit.occupiedTile){
                if(destinationTile.AIHostileList.Count!=0){
                    //unit.Attack(destinationTile.AIHostileList[UnityEngine.Random.Range(0, destinationTile.AIHostileList.Count)]);
                    //unit will simply attack instead of move
                    if(!unit.MoveAttack(unit.occupiedTile)) NoActionForUnit(unit);
                }
                else{
                    unitInAction=false;
                }
                yield break;
            }

            if(destinationTile!=null){
                if(GameControlTB.EnableFogOfWar()){
                    bool visibleToPlayer=CheckEncounterOnPath(unit.occupiedTile, destinationTile);
                    if(visibleToPlayer){
                        if(!unit.MoveAttack(destinationTile)) NoActionForUnit(unit);
                    }
                    else{
                        if(destinationTile.AIHostileList.Count==0){
                            MoveUnitToTileInstant(unit, destinationTile);
                            unit.CompleteAllAction();
                        }
                        else{
                            if(!unit.MoveAttack(destinationTile)) NoActionForUnit(unit);
                        }
                    }
                }
                else{
                    if(!unit.MoveAttack(destinationTile)) NoActionForUnit(unit);
                }
            }
            else{
                //no action is available for the unit, simply registred it as moved
                NoActionForUnit(unit);
            }

            /*
            timeE=System.DateTime.Now;
            timeSpan=timeE-timeS;
            Debug.Log( "Time:"+timeSpan.TotalMilliseconds);
            */
        }
        else{
            NoActionForUnit(unit);
        }
    }
예제 #2
0
    //execute move/attack for a single unit
    IEnumerator _MoveUnit(UnitTB unit)
    {
        //make sure no event is taking place
        while (GameControlTB.IsActionInProgress())
        {
            yield return(null);
        }

        if (!unit.IsStunned())
        {
            /*
             * DateTime timeS;
             * DateTime timeE;
             * TimeSpan timeSpan;
             * timeS=System.DateTime.Now;
             */

            Tile destinationTile = null;
            if (aIStance == _AIStance.Trigger)
            {
                if (unit.triggered)
                {
                    destinationTile = Analyse(unit);
                }
            }
            else
            {
                destinationTile = Analyse(unit);
            }

            //if there's target in current tile, just attack it
            if (destinationTile == unit.occupiedTile)
            {
                if (destinationTile.AIHostileList.Count != 0)
                {
                    //unit.Attack(destinationTile.AIHostileList[UnityEngine.Random.Range(0, destinationTile.AIHostileList.Count)]);
                    //unit will simply attack instead of move
                    if (!unit.MoveAttack(unit.occupiedTile))
                    {
                        NoActionForUnit(unit);
                    }
                }
                else
                {
                    unitInAction = false;
                }
                yield break;
            }

            if (destinationTile != null)
            {
                if (GameControlTB.EnableFogOfWar())
                {
                    bool visibleToPlayer = CheckEncounterOnPath(unit.occupiedTile, destinationTile);
                    if (visibleToPlayer)
                    {
                        if (!unit.MoveAttack(destinationTile))
                        {
                            NoActionForUnit(unit);
                        }
                    }
                    else
                    {
                        if (destinationTile.AIHostileList.Count == 0)
                        {
                            MoveUnitToTileInstant(unit, destinationTile);
                            unit.CompleteAllAction();
                        }
                        else
                        {
                            if (!unit.MoveAttack(destinationTile))
                            {
                                NoActionForUnit(unit);
                            }
                        }
                    }
                }
                else
                {
                    if (!unit.MoveAttack(destinationTile))
                    {
                        NoActionForUnit(unit);
                    }
                }
            }
            else
            {
                //no action is available for the unit, simply registred it as moved
                NoActionForUnit(unit);
            }

            /*
             * timeE=System.DateTime.Now;
             * timeSpan=timeE-timeS;
             * Debug.Log( "Time:"+timeSpan.TotalMilliseconds);
             */
        }
        else
        {
            NoActionForUnit(unit);
        }
    }