Esempio n. 1
0
    /// <summary>
    /// Notify this controller than the current unit has finished its current move order.
    /// </summary>
    protected override void UnitDoneMoving(UnitMoveResponse response)
    {
        if (currentPhase != TurnPhase.MovingUnit) {
            Debug.LogWarning(
                string.Format("UnitDoneMoving unexpectedly called while {0} was in state {1}",
                            this.name, currentPhase.ToString()));

        } else if (!response.validMove) {
            string debugString =
                string.Format ("{0} received a report that {1}'s move was invalid (\"{2}\").",
                    this.name, currentUnit.name, response.responseMessage);
            Debug.Log(debugString);

            // We don't allow another move request if this one was invalid!
            currentPhase = TurnPhase.Attacking;
            // TODO: Allow the AI to retry?

        } else {
            string debugString =
                string.Format ("{0} received a report that {1} finished moving.", this.name, currentUnit.name);
            Debug.Log(debugString);

            currentPhase = TurnPhase.Attacking;
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Called when the unit has finished moving.
 /// </summary>
 public void DoneMoving(UnitMoveResponse response)
 {
     if (currentState == State.Moving) {
         string LogMsg = "{0} is done moving.";
         Debug.Log (string.Format(LogMsg, this.name));
         currentState = State.WaitingOrders;
         response.caller.SendMessage("UnitDoneMoving", response, SendMessageOptions.RequireReceiver);
         playerController.SendMessage("ChangeGUIState", "StartTurn");
         BroadcastMessage("HideMovementRadius", SendMessageOptions.RequireReceiver);
     } else {
         string LogMsg = "RequestMove unexpectedly called on {0} while it is in state \"{1}\"";
         Debug.LogWarning(string.Format(LogMsg, this.name, currentState.ToString()));
     }
 }
Esempio n. 3
0
    /// <summary>
    /// Notify this controller than the current unit has finished its current move order.
    /// </summary>
    protected override void UnitDoneMoving(UnitMoveResponse response)
    {
        if (!response.validMove) {
            string debugString =
                string.Format ("{0} received a report that {1}'s move was invalid (\"{2}\").",
                    this.name, currentUnit.name, response.responseMessage);
            Debug.Log(debugString);

            // We allow another move request if this one was invalid.
            // TODO: notify the user that the move was illegal.
            player.SendMessage("ChangeGUIState", "StartTurn");

        } else {
            hasAlreadyMoved = true;
            string debugString =
                string.Format ("{0} received a report that {1} finished moving.", this.name, currentUnit.name);
            Debug.Log(debugString);
        }
    }
Esempio n. 4
0
    // Move a unit. If successful returns the new GameState after unit has moved
    public async Task <UnitMoveResponse> SendAsync(UnitMoveRequest req)
    {
        var unit               = req.GameState.Units[req.UnitIndex];
        var unitPos            = unit.Pos;
        var hasChangedTileType = false;

        foreach (Vector p in req.Path)
        {
            // unit cannot move after entering/exiting water
            if (hasChangedTileType)
            {
                UnityEngine.Debug.Log("hasChangedTileType");
                return(UnitMoveResponse.Failure(req.GameState));
            }
            // unit can only move one step at a time
            if (!unitPos.IsAdjacent(p))
            {
                UnityEngine.Debug.Log("unit can only move one step at a time");
                return(UnitMoveResponse.Failure(req.GameState));
            }
            // unit cannot move outside of the world
            if (req.GameState.GetTile(p) == Tile.Invalid)
            {
                UnityEngine.Debug.Log("unit cannot move outside of the world");
                return(UnitMoveResponse.Failure(req.GameState));
            }
            // remember if we crossed a water boundary
            if (req.GameState.GetTile(p) != req.GameState.GetTile(unitPos))
            {
                hasChangedTileType = true;
            }
            // everything looked good! move unit
            unitPos = p;
        }
        // apply the verified destination to the unit
        unit.Pos = unitPos;

        // return success with a new GameState that describe the world
        return(new UnitMoveResponse {
            IsSuccess = true,
            GameState = req.GameState
        });
    }
Esempio n. 5
0
 /// <summary>
 /// Notify this controller than the current unit has finished its current move order.
 /// </summary>
 protected abstract void UnitDoneMoving(UnitMoveResponse response);