Exemple #1
0
        protected override Transition HandleResponseMessage(IResponseMessage responseMessage)
        {
            if (responseMessage is KnowledgeExchangeRequestMessage knowledgeExchangeRequest)
            {
                var initiatorId = knowledgeExchangeRequest.SenderPlayerId;
                //Console.WriteLine($"Player #{initiatorId} requested communication in state {this}");
                IMessage knowledgeExchangeResponse =
                    new RejectKnowledgeExchangeMessage(PlayerStrategyInfo.PlayerId, initiatorId,
                                                       PlayerStrategyInfo.PlayerGuid);

                if (IsExchangeWantedWithPlayer(initiatorId))
                {
                    knowledgeExchangeResponse =
                        DataMessage.FromBoardData(
                            PlayerStrategyInfo.Board.ToBoardData(PlayerStrategyInfo.PlayerId, initiatorId), false,
                            PlayerStrategyInfo.PlayerGuid);
                }

                return(new LoopbackTransition(this, new List <IMessage> {
                    knowledgeExchangeResponse
                }));
            }

            if (responseMessage is DataMessage dataMessage && dataMessage.GoalFields.Length > 1)
            {
                HandleSuccessfulKnowledgeExchange();
                return(new LoopbackTransition(this, new List <IMessage>()));
            }

            return(base.HandleResponseMessage(responseMessage));
        }