コード例 #1
0
        private void EventReceivedHandler(object sender, EvmChainEventArgs e)
        {
            //Debug.Log("Event: " + e.EventName);
            switch (e.EventName)
            {
            case "RoomCreated":
            {
                RoomCreatedEventData eventDto = e.DecodeEventDto <RoomCreatedEventData>();
                this.eventActions.Enqueue(() => RoomCreated?.Invoke((Address)eventDto.Creator, eventDto.RoomId));
                break;
            }

            case "PlayerJoined":
            {
                PlayerJoinedEventData eventDto = e.DecodeEventDto <PlayerJoinedEventData>();
                this.eventActions.Enqueue(() => PlayerJoined?.Invoke(eventDto.RoomId, (Address)eventDto.Player));
                break;
            }

            case "GameStageChanged":
            {
                GameStageChangedEventData eventDto = e.DecodeEventDto <GameStageChangedEventData>();
                this.eventActions.Enqueue(() => GameStageChanged?.Invoke(eventDto.RoomId, eventDto.Stage));
                break;
            }

            case "CurrentPlayerIndexChanged":
            {
                CurrentPlayerIndexChangedEventData eventDto = e.DecodeEventDto <CurrentPlayerIndexChangedEventData>();
                this.eventActions.Enqueue(() => CurrentPlayerIndexChanged?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address)eventDto.PlayerAddress));
                break;
            }

            case "PlayerDecisionReceived":
            {
                PlayerDecisionReceivedEventData eventDto = e.DecodeEventDto <PlayerDecisionReceivedEventData>();
                this.eventActions.Enqueue(() => PlayerDecisionReceived?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address)eventDto.PlayerAddress, eventDto.PlayerDecision));
                break;
            }
            }
        }
コード例 #2
0
 private void EventReceivedHandler(object sender, EvmChainEventArgs e)
 {
     lock (this.roomIdToRoomEventActionsMap)
     {
         switch (e.EventName)
         {
             case "RoomCreated":
             {
                 RoomCreatedEventData eventDto = e.DecodeEventDto<RoomCreatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     -1,
                     () => RoomCreated?.Invoke((Address) eventDto.Creator, eventDto.RoomId)
                     );
                 break;
             }
             case "PlayerJoined":
             {
                 PlayerRelatedEventData eventDto = e.DecodeEventDto<PlayerRelatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerJoined?.Invoke(eventDto.RoomId, (Address) eventDto.Player)
                 );
                 break;
             }
             case "PlayerLeft":
             {
                 PlayerRelatedEventData eventDto = e.DecodeEventDto<PlayerRelatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerLeft?.Invoke(eventDto.RoomId, (Address) eventDto.Player)
                 );
                 break;
             }
             case "PlayerBetted":
             {
                 PlayerBettedEventData eventDto = e.DecodeEventDto<PlayerBettedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerBetted?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.Bet)
                 );
                 break;
             }
             case "PlayerReadyForNextRoundChanged":
             {
                 PlayerReadyForNextRoundChangedEventData eventDto = e.DecodeEventDto<PlayerReadyForNextRoundChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerReadyForNextRoundChanged?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.Ready)
                 );
                 break;
             }
             case "GameStageChanged":
             {
                 GameStageChangedEventData eventDto = e.DecodeEventDto<GameStageChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => GameStageChanged?.Invoke(eventDto.RoomId, eventDto.Stage)
                 );
                 break;
             }
             case "CurrentPlayerIndexChanged":
             {
                 CurrentPlayerIndexChangedEventData eventDto = e.DecodeEventDto<CurrentPlayerIndexChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => CurrentPlayerIndexChanged?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address) eventDto.PlayerAddress)
                 );
                 break;
             }
             case "PlayerDecisionReceived":
             {
                 PlayerDecisionReceivedEventData eventDto = e.DecodeEventDto<PlayerDecisionReceivedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerDecisionReceived?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.PlayerDecision)
                 );
                 break;
             }
             case "GameRoundResultsAnnounced":
             {
                 GameRoundResultsAnnouncedEventData eventDto = e.DecodeEventDto<GameRoundResultsAnnouncedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => GameRoundResultsAnnounced?.Invoke(
                         eventDto.RoomId,
                         eventDto.DealerOutcome,
                         eventDto.Players.Select(p => (Address) p).ToArray(),
                         eventDto.PlayerOutcome.ToArray())
                 );
                 break;
             }
             case "Log":
             {
                 break;
             }
             default:
                 throw new ArgumentOutOfRangeException($"Unknown event {e.EventName}");
         }
     }
 }