public void HandleMessage(RegisteredGames message) { if (message.GameInfo == null || message.GameInfo.Length == 0 || !message.GameInfo.Where(g => g.gameName == Player.Options.GameName).Any()) { Task.Run(() => { Thread.Sleep((int)Player.Settings.RetryJoinGameInterval); string xmlMessage = XmlMessageConverter.ToXml(new GetGames()); Player.Send(xmlMessage); }); } else { ConsoleDebug.Good("Games available"); if (Player.Options.GameName == null) { ConsoleDebug.Warning("Game name not specified"); return; } if (message.GameInfo.Count(info => info.gameName == Player.Options.GameName) == 1) { string xmlMessage = XmlMessageConverter.ToXml(new JoinGame() { gameName = Player.Options.GameName, playerIdSpecified = false, preferredRole = Player.Options?.PreferredRole == "player" ? PlayerType.member : PlayerType.leader, preferredTeam = Player.Options?.PreferredTeam == "red" ? Common.Schema.TeamColour.red : Common.Schema.TeamColour.blue }); Player.Send(xmlMessage); } } }
public void PlaceNewPiece(Wrapper.TaskField field) { var pieceType = rng.NextDouble() < GameMasterClient.Settings.GameDefinition.ShamProbability ? PieceType.sham : PieceType.normal; lock (BoardLock) { var newPiece = new Wrapper.Piece((ulong)Pieces.Count, pieceType, DateTime.Now); newPiece.Id = pieceid++; if (field == null) { ConsoleDebug.Warning("There are no empty places for a new Piece!"); return; //TODO BUSYWAITING HERE probably } //remove old piece if (field.PieceId != null) { var oldPiece = Pieces.Where(p => p.Id == field.PieceId.Value).Single(); Pieces.Remove(oldPiece); } field.PieceId = newPiece.Id; newPiece.Location = new Location() { x = field.X, y = field.Y }; Pieces.Add(newPiece); Board.UpdateDistanceToPiece(Pieces); ConsoleDebug.Good($"Placed new Piece at: ({field.X}, {field.Y})"); } //BoardPrinter.Print(Board); }
public async void HandleMessage(TestPiece message, Socket handler) { if (!ValidateMessage(message)) { return; } string resp = ""; await Task.Delay((int)GameMasterClient.Settings.ActionCosts.TestDelay); Wrapper.Player currentPlayer = Players.SingleOrDefault(p => p.Guid == message.playerGuid); if (currentPlayer == null) { return; } GameMasterClient.Logger.Log(message, currentPlayer); lock (BoardLock) { Wrapper.Piece piece = Pieces.SingleOrDefault( pc => pc.PlayerId == currentPlayer.Id); if (piece == null) // not carrying anything { ConsoleDebug.Warning("Not carrying a piece!"); piece = Pieces.FirstOrDefault(pc => pc.Location.Equals(currentPlayer.Location)); } if (piece == null) { ConsoleDebug.Warning("Not on a piece!"); //send empty piece collection resp = new DataMessageBuilder(currentPlayer.Id, endGame) .SetPieces(new Piece[0]) .GetXml(); } else { ConsoleDebug.Warning("On a piece!"); resp = new DataMessageBuilder(currentPlayer.Id, endGame) .AddPiece(piece.SchemaPiece) .GetXml(); } } GameMasterClient.Connection.SendFromClient(handler, resp); }
public void HandleMessage(object message) { ConsoleDebug.Warning("Unknown Type"); }
public async Task HandleMessage(PickUpPiece message, Socket handler) { if (!ValidateMessage(message)) { return; } string resp = ""; await Task.Delay((int)gameMaster.Settings.ActionCosts.PickUpDelay); Wrapper.Player currentPlayer = Players.Single(p => p.Guid == message.playerGuid); gameMaster.Logger.Log(message, currentPlayer); lock (BoardLock) { Wrapper.Piece piece = Pieces.FirstOrDefault( pc => pc.Location.x == currentPlayer.Location.x && pc.Location.y == currentPlayer.Location.y && !pc.PlayerId.HasValue); if (piece == null || Pieces.Any(pc => pc.PlayerId == currentPlayer.Id)) { ConsoleDebug.Warning("No piece here or you have already a piece!"); //send empty piece collection resp = new DataMessageBuilder(currentPlayer.Id, endGame) .SetPieces(new Piece[0]) .GetXml(); } else { ConsoleDebug.Warning("Piece picked up!"); piece.PlayerId = currentPlayer.Id; var taskField = Board.Fields[currentPlayer.X, currentPlayer.Y] as Wrapper.TaskField; if (taskField != null) //update taskField { ConsoleDebug.Warning("Updating TaskField"); taskField.PieceId = null; Board.UpdateDistanceToPiece(Pieces); //clocest neighbour to piece + 1 // taskField.DistanceToPiece = new[] // { // FieldAt(gameMaster.Board.Fields, currentPlayer.X + 1, currentPlayer.Y) // ?.DistanceToPiece, // FieldAt(gameMaster.Board.Fields, currentPlayer.X - 1, currentPlayer.Y) // ?.DistanceToPiece, // FieldAt(gameMaster.Board.Fields, currentPlayer.X, currentPlayer.Y + 1) // ?.DistanceToPiece, // FieldAt(gameMaster.Board.Fields, currentPlayer.X, currentPlayer.Y - 1) // ?.DistanceToPiece //}.Where(u => u.HasValue).Select(u => u.Value).Min() + 1; } resp = new DataMessageBuilder(currentPlayer.Id, endGame) .AddPiece(new Piece() { id = piece.Id, timestamp = piece.TimeStamp, playerId = currentPlayer.Id, playerIdSpecified = true, type = PieceType.unknown }) .GetXml(); } } GameMasterClient.Connection.SendFromClient(handler, resp); }
public static void HandleMessage(object message, CommunicationServer server, Socket handler) { ConsoleDebug.Warning("Unknown type"); }