示例#1
0
    Dictionary <string, Action <string> > MakeWebsocketActions()
    {
        var WebsocketActions = new Dictionary <string, Action <string> >();

        WebsocketActions.Add("text", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <WsChatMessage>(reply);
            Chat.MessageReceived(replyMsg.Name, replyMsg.Payload);
        });
        WebsocketActions.Add("newUser", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <WsUserMessage>(reply);
            ClientList.AddClient(replyMsg.Payload.ID, replyMsg.Payload.Name);
        });
        WebsocketActions.Add("deleteuser", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <WsUserMessage>(reply);
            ClientList.DeleteClient(replyMsg.Payload.ID);
        });
        WebsocketActions.Add("ownCards", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <WsCardsForm>(reply);
            PlayerSeatSlot.ShowCards(replyMsg.Payload);
        });
        WebsocketActions.Add("activePlayer", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <ActivePlayerForm>(reply);
            ActivePlayerBorder(replyMsg.ID);
            //TODO: consider changing to id
            if (replyMsg.Name == ClientInfo.Name)
            {
                BettingStage.ActiveBet(replyMsg.MinBet);
            }
        });
        WebsocketActions.Add("tableCards", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <TableCardsForm>(reply);
            TableCards.SetTableCards(replyMsg.Payload);
        });
        WebsocketActions.Add("startRound", (reply) => {
            Pot.ClearPot();
            TableCards.ClearTable();
            CurrentSeatStructure.ClearClientsCards();
            CurrentSeatStructure.DefaultActiveBorder();
            var replyMsg = JsonConvert.DeserializeObject <StartRoundForm>(reply);
            CurrentSeatStructure.FillSeatsWithPlayers(replyMsg.Players);
            PlayerSeatSlot.SetStack(replyMsg.Players[CurrentSeatStructure.GetClientIndex(replyMsg.Players)].Stack);
            //TODO: button player mark
        });
        WebsocketActions.Add("endRound", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <EndRoundMessageForm>(reply);
            WinnerNotifier.ShowWinnerMessage(replyMsg.Winners);
            foreach (var winner in replyMsg.Winners)
            {
                if (winner.Winner.ID == ClientInfo.ID)
                {
                    PlayerSeatSlot.ChangeStack(winner.Ammount);
                }
                else
                {
                    CurrentSeatStructure.SetClientBet(winner.Winner.ID, winner.Ammount);
                    CurrentSeatStructure.ShowClientCards(winner.Winner.ID, winner.Cards);
                }
            }
        });
        WebsocketActions.Add("bet", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <BetForm>(reply);
            if (replyMsg.ID == ClientInfo.ID)
            {
                PlayerBetField.SetBetSize(replyMsg.Ammount);
                PlayerSeatSlot.ChangeStack(-replyMsg.Ammount);
                return;
            }
            CurrentSeatStructure.SetClientBet(replyMsg.ID, replyMsg.Ammount);
        });
        WebsocketActions.Add("endBetStage", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <EndBetStageForm>(reply);
            PlayerBetField.ClearBet();
            CurrentSeatStructure.ClearAllBets();
            Pot.AddToPot(replyMsg.Pot);
        });
        WebsocketActions.Add("fold", (reply) => {
            var replyMsg = JsonConvert.DeserializeObject <PlayerInfo>(reply);
            ActivePlayerBorder(replyMsg.ID);
            if (replyMsg.ID == ClientInfo.ID)
            {
                //TODO: hiding cards instead of deleting them, show them on hover
                PlayerSeatSlot.ClearCards();
            }
            else
            {
                CurrentSeatStructure.SetClientFoldCue(replyMsg.ID);
            }
        });
        return(WebsocketActions);
    }