Esempio n. 1
0
    /// <summary>
    /// Moves the unit that this controller is currently controlling.
    /// </summary>
    protected override void SendMoveOrderToUnit(Vector3 target)
    {
        string debugString =
            string.Format("Target move position: {0},{1},{2}", target.x, target.y, target.z);
        Debug.Log(debugString);

        UnitMoveRequest request = new UnitMoveRequest(this.gameObject, target);

        Debug.Log("Sending move order to " + currentUnit.name);
        currentUnit.SendMessage("RequestMove", request, SendMessageOptions.RequireReceiver);
    }
Esempio n. 2
0
    /// <summary>
    /// Moves the unit that this controller is currently controlling.
    /// </summary>
    protected override void SendMoveOrderToUnit(Vector3 target)
    {
        if (currentPhase != TurnPhase.MovingUnit) {
            Debug.LogWarning(
            string.Format("SendMoveOrderToUnit unexpectedly called while {0} was in state {1}",
                            this.name, currentPhase.ToString()));
        } else {

            string debugString =
                string.Format("Target move position: {0},{1},{2}", target.x, target.y, target.z);
            Debug.Log(debugString);

            player.SendMessage("AutoMoveCameraTo", target, SendMessageOptions.DontRequireReceiver);
            UnitMoveRequest request = new UnitMoveRequest(this.gameObject, target);

            Debug.Log("Sending move order to " + currentUnit.name);
            currentUnit.SendMessage("RequestMove", request, SendMessageOptions.RequireReceiver);
        }
    }
Esempio n. 3
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. 4
0
 /// <summary>
 /// Requests that this unit move toward the target point. The unit will ignore incoming requests until
 /// it is done moving.
 /// </summary>
 /// <param name='target'>
 /// The target point, in world coordinates.
 /// </param>
 /// <param name='controller'>
 /// The controller object that is sending the movement request.
 /// </param>
 public void Move(UnitMoveRequest request)
 {
     if (!hasTarget) {
         this.target = request.targetPosition;
         this.origin = transform.position;
         this.moveRequest = request;
         if (!WithinRange(target)) {
             string debugString = string.Format
                 ("Move was of distance {0}, but unit's max distance is {1}",
                     (this.transform.position - target).magnitude,
                     unitInfo.CalculateWalkingDistance());
             Debug.Log(debugString);
             BroadcastMessage("DoneMoving", OutOfRangeResponse(), SendMessageOptions.RequireReceiver);
             playerController.SendMessage("ChangeGUIState", "StartTurn");
         } else {
             animation.Play("Walk");
             this.hasTarget = true;
             //transform.LookAt(target);
             transform.LookAt(new Vector3(target.x, transform.position.y, target.z));
             rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Requests that the unit move to a certain location.
 /// </summary>
 public void RequestMove(UnitMoveRequest request)
 {
     if (currentState == State.WaitingOrders) {
         playerController.SendMessage("ChangeGUIState", "WaitingForEnemyTurn");
         currentState = State.Moving;
         BroadcastMessage("Move", request, SendMessageOptions.RequireReceiver);
     } else if (currentState == State.Moving) {
         string LogMsg = "RequestMove called on {0}, but it's already moving (called by {1})";
         Debug.Log(string.Format(LogMsg, this.name, request.caller.name));
     } else {
         string LogMsg = "RequestMove unexpectedly called on {0} while it is in state \"{1}\" (called by {2})";
         Debug.LogWarning(string.Format(LogMsg, this.name, currentState.ToString(), request.caller.name));
     }
 }