public override object ToClient() { var client = new { playerCups = PlayerCups.Select(pc => pc.ToClient()), quantity = Quantity, dice = Dice.ToClient(), hasLock = HasLock, actualQuantity = ActualQuantity, endActionName = EndAction?.Name, diceLoserName = DiceLoser?.Name, diceWinnerName = DiceWinner?.Name }; return(client.Merge(base.ToClient())); }
public GameChangeResult End(GameAction endAction) { IsEnded = true; EndAction = endAction; // transition lock status if (HasLock) { PlayerCups.First(pc => pc.LockStatus == LockStatus.Locking).LockStatus = LockStatus.Unavailable; } // highlight matching dices foreach (var matchingDice in PlayerCups.SelectMany(pc => pc.Dices).Where(d => d.Value == Dice.Value || d.Value == 1)) { matchingDice.IsHighlighted = true; } // check if table ends var playersWithDices = PlayerCups.Where(pc => pc.DicesQuantity > 0).Select(pc => pc.Player); if (playersWithDices.Count() == 1) { Table.End(playersWithDices); } var gameEndResult = new GameChangeResult(new { actualQuantity = ActualQuantity, playerCups = PlayerCups.Select(pc => pc.ToClient()), table = new { status = Table.Status.ToString(), activePlayerName = Table.ActivePlayer?.Name, stats = Table.GetStats(), winnerNames = Table.Winners.Select(p => p.Name) }, isEnded = IsEnded, winnerNames = Winners.Select(p => p.Name), endActionName = EndAction?.Name, diceLoserName = DiceLoser?.Name, diceWinnerName = DiceWinner?.Name }); return(gameEndResult); }