/** Manages when the user releases the mouse and tries to make a move */ public void ConfirmMovePawn(object sender, object args) { PlayerController localPlayer = matchController.localPlayer; GameObject obj = ((Draggable)sender).gameObject; PawnData pawn = obj.GetComponent <PawnData>(); Tile initialTile = pawn.GetContainingTile(); // gets the pawn previous position (Tile) Vector3 finalPos = (Vector3)args; Tile finalTile = gameBoard.GetTileNearWorldPosition(finalPos); // finds the Tile where the user wants to move the pawn Vector3 oldPos = ((Draggable)sender).oldPos; Vector3 realFinalPos = oldPos; if (finalTile != null) { Move move = new Move(pawn.pawnType, initialTile.x, initialTile.z, finalTile.x, finalTile.z); if (game.IsMoveValid(move)) { realFinalPos = finalTile.transform.localPosition; localPlayer.UpdatePawnCoordinates(pawn, finalTile.x, finalTile.z); localPlayer.PawnMoved(move); } } realFinalPos.y = oldPos.y; obj.transform.localPosition = realFinalPos; // moves the pawn locally (client side) localPlayer.PlayerMovesThePawn(pawn.gameObject, realFinalPos); // moves the pawn over the network }
/** Manages when the user releases the mouse and tries to make a move */ public void ConfirmMovePawn(object sender, object args) { GameObject obj = ((Draggable)sender).gameObject; PawnData pawn = obj.GetComponent <PawnData>(); Tile initialTile = pawn.GetContainingTile(); // gets the pawn previous position (Tile) Vector3 finalPos = (Vector3)args; Tile finalTile = gameBoard.GetTileNearWorldPosition(finalPos); // finds the Tile where the user wants to move the pawn Vector3 oldPos = ((Draggable)sender).oldPos; Vector3 realFinalPos = oldPos; if (finalTile != null) { Move move = new Move(pawn.pawnType, initialTile.x, initialTile.z, finalTile.x, finalTile.z); if (game.IsMoveValid(move)) { realFinalPos = finalTile.transform.localPosition; pawn.x = finalTile.x; pawn.z = finalTile.z; game.MovePawn(move); } } realFinalPos.y = oldPos.y; obj.transform.localPosition = realFinalPos; // moves the pawn locally (graphically) }