/// <summary>
 /// 询问用户从若干牌堆中选择卡牌,例如顺手牵羊,观星等等。
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="sourceDecks"></param>
 /// <param name="resultDeckNames"></param>
 /// <param name="resultDeckMaximums"></param>
 /// <param name="verifier"></param>
 /// <param name="answer">用户选择结果。对应resultDeckNames,每个选出的牌堆占用一个list。</param>
 /// <returns>False if user cannot provide an answer.</returns>
 public static bool AskForCardChoice(this Player p, Prompt prompt,
                                     List<DeckPlace> sourceDecks,
                                     List<string> resultDeckNames,
                                     List<int> resultDeckMaximums,
                                     ICardChoiceVerifier verifier,
                                     out List<List<Card>> answer,
                                     AdditionalCardChoiceOptions helper = null,
                                     CardChoiceRearrangeCallback callback = null)
 {
     return Game.CurrentGame.UiProxies[p].AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, helper, callback);
 }
 /// <summary>
 /// 询问用户从若干牌堆中选择卡牌,例如顺手牵羊,观星等等。
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="sourceDecks"></param>
 /// <param name="resultDeckNames"></param>
 /// <param name="resultDeckMaximums"></param>
 /// <param name="verifier"></param>
 /// <param name="answer">用户选择结果。对应resultDeckNames,每个选出的牌堆占用一个list。</param>
 /// <returns>False if user cannot provide an answer.</returns>
 public static bool AskForCardChoice(this Player p, Prompt prompt,
                                     List <DeckPlace> sourceDecks,
                                     List <string> resultDeckNames,
                                     List <int> resultDeckMaximums,
                                     ICardChoiceVerifier verifier,
                                     out List <List <Card> > answer,
                                     AdditionalCardChoiceOptions helper   = null,
                                     CardChoiceRearrangeCallback callback = null)
 {
     return(Game.CurrentGame.UiProxies[p].AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, helper, callback));
 }
Exemple #3
0
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     answerPending = new Semaphore(0, 1);
     proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, TimeOutSeconds, options, callback);
     answer = null;
     if (answerPending.WaitOne(TimeOutSeconds * 1000))
     {
         answer = answerCardsOfCards;
     }
     if (answer == null)
     {
         return false;
     }
     else
     {
         return (verifier.Verify(answer) == VerifierResult.Success);
     }
 }
Exemple #4
0
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback)
 {
     answerPending = new Semaphore(0, 1);
     proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, TimeOutSeconds, rearrangeable, ref windowId, callback);
     if (answerPending.WaitOne(TimeOutSeconds * 1000))
     {
         answer = answerCardsOfCards;
     }
     else
     {
         answer = null;
     }
     if (verifier.Verify(answer) == VerifierResult.Success)
     {
         return true;
     }
     return false;
 }
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options = null, CardChoiceRearrangeCallback callback = null)
 {
     Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id);
     TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, options, callback);
     SimulateReplayDelay();
     NextQuestion();
     if (TryAnswerForCardChoice(prompt, verifier, out answer, options, callback))
     {
         uiProxy.Freeze();
         if (answer == null || answer.Count == 0)
         {
             return false;
         }
     #if DEBUG
         Trace.Assert(verifier.Verify(answer) == VerifierResult.Success);
     #endif
         return true;
     }
     uiProxy.Freeze();
     return false;
 }
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback)
 {
     Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id);
     TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, rearrangeable, ref windowId, callback);
     if (active)
     {
         NextQuestion();
     }
     else
     {
         Trace.TraceInformation("Not active player, defaulting.");
     }
     if (TryAnswerForCardChoice(prompt, verifier, out answer, callback))
     {
         proxy.Freeze();
     #if DEBUG
         Trace.Assert(verifier.Verify(answer) == VerifierResult.Success);
     #endif
         return true;
     }
     proxy.Freeze();
     return false;
 }
Exemple #7
0
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     answer = null;
     bool ret = true;
     if (!TryAskForCardChoice(sourceDecks, resultDeckMaximums, verifier, out answer, options, callback))
     {
         SendNoAnswer();
         ret = false;
     }
     else
     {
         SendCardChoice(verifier, answer, options);
     }
     NextQuestion();
     if (answer == null)
     {
         answer = new List<List<Card>>();
         foreach (var v in resultDeckMaximums)
         {
             answer.Add(new List<Card>());
         }
     }
     return ret;
 }
        public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks,
                                     List<string> resultDeckNames,
                                     List<int> resultDeckMaximums,
                                     ICardChoiceVerifier verifier,
                                     int timeOutSeconds,
                                     AdditionalCardChoiceOptions options,
                                     CardChoiceRearrangeCallback callback)
        {
            if (ViewModelBase.IsDetached) return;
            Trace.Assert(!Player.IsDead);
            if (this != GameModel.MainPlayerModel && (verifier.Helper == null || !verifier.Helper.ShowToAll))
            {
                TimeOutSeconds = timeOutSeconds;
                CardChoiceAnsweredEvent(null);
                return;
            }
            Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count);

            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                GameModel.CurrentActivePlayer = this;
                if (!IsPlayable)
                {
                    Trace.Assert(currentUsageVerifier == null);
                    TimeOutSeconds = timeOutSeconds;
                    CardChoiceAnsweredEvent(null);
                }
                if (GameModel.MainPlayerModel != this)
                {
                    prompt.ResourceKey = prompt.ResourceKey + Prompt.NonPlaybleAppendix;
                    prompt.Values.Insert(0, Player);
                }
                if (options != null && options.IsWuGu)
                {
                    // Trace.Assert(GameModel.WuGuModel != null);
                    TimeOutSeconds = timeOutSeconds;
                    // @todo: Fix this to show wugu on reconnection
                    if (GameModel != null && GameModel.WuGuModel != null)
                    {
                        GameModel.WuGuModel.IsEnabled = IsPlayable;
                        GameModel.WuGuModel.Prompt = LogFormatter.Translate(prompt);
                    }
                }
                else if (options != null && options.IsTwoSidesCardChoice)
                {
                    if (GameModel != null && GameModel.TwoSidesCardChoiceModel != null)
                    {
                        GameModel.TwoSidesCardChoiceModel.IsEnabled = IsPlayable;
                        GameModel.TwoSidesCardChoiceModel.Prompt = LogFormatter.Translate(prompt);
                        bool isMainPlayer =
                            GameModel.TwoSidesCardChoiceModel.GroupOfPlayer[GameModel.MainPlayerModel.Id] == GameModel.TwoSidesCardChoiceModel.GroupOfPlayer[Id];
                        if (isMainPlayer)
                        {
                            GameModel.TwoSidesCardChoiceModel.TimeOutSeconds1 = timeOutSeconds;
                        }
                        else
                        {
                            GameModel.TwoSidesCardChoiceModel.TimeOutSeconds2 = timeOutSeconds;
                        }
                    }
                }
                else
                {
                    _currentChoiceOptions = options;
                    _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback);
                    CardChoiceModel.Prompt = LogFormatter.Translate(prompt);
                    if (!IsPlayable)
                    {
                        CardChoiceModel.DisplayOnly = true;
                        prompt.Values.Insert(0, Player);
                        CurrentCardChoiceRearrangeCallback = null;
                    }
                    else
                    {
                        CurrentCardChoiceRearrangeCallback = callback;
                    }
                    IsCardChoiceQuestionShown = true;
                }
            });
        }
Exemple #9
0
 bool IUiProxy.AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback)
 {
     answer = null;
     return false;
 }
Exemple #10
0
 public void TryAskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     List<List<Card>> answer;
     if (!active)
     {
         proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback);
         return;
     }
     if (!proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) ||
         answer == null)
     {
         Trace.TraceInformation("Invalid answer");
         client.AnswerNext();
         client.AnswerItem(0);
     }
     else
     {
         client.AnswerNext();
         client.AnswerItem(1);
         client.AnswerItem(answer.Count);
         foreach (var subList in answer)
         {
             client.AnswerItem(subList.Count);
             foreach (Card c in subList)
             {
                 client.AnswerItem(c);
             }
         }
         if (options != null && options.Options != null)
         {
             client.AnswerItem(options.OptionResult);
         }
     }
     client.Flush();
 }
Exemple #11
0
        public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks,
                                     List<string> resultDeckNames,
                                     List<int> resultDeckMaximums,
                                     ICardChoiceVerifier verifier,
                                     int timeOutSeconds,
                                     AdditionalCardChoiceOptions options,
                                     CardChoiceRearrangeCallback callback)
        {
            Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count);

            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                if (!IsPlayable)
                {
                    Trace.Assert(currentUsageVerifier == null);
                    TimeOutSeconds = timeOutSeconds;
                    CardChoiceAnsweredEvent(null);
                    return;
                }

                lock (verifierLock)
                {
                    _currentChoiceOptions = options;
                    _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback);
                    CardChoiceModel.Prompt = PromptFormatter.Format(prompt);
                    IsCardChoiceQuestionShown = true;
                }
            });
        }
Exemple #12
0
        public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks,
                                     List<string> resultDeckNames,
                                     List<int> resultDeckMaximums,
                                     ICardChoiceVerifier verifier,
                                     int timeOutSeconds,
                                     AdditionalCardChoiceOptions options,
                                     CardChoiceRearrangeCallback callback)
        {
            Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count);

            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                lock (verifierLock)
                {
                    GameModel.CurrentActivePlayer = this;
                    if (!IsPlayable)
                    {
                        Trace.Assert(currentUsageVerifier == null);
                        TimeOutSeconds = timeOutSeconds;
                        CardChoiceAnsweredEvent(null);
                        prompt.ResourceKey = prompt.ResourceKey + Prompt.NonPlaybleAppendix;
                        prompt.Values.Insert(0, Player);
                    }
                    if (options != null && options.IsWuGu)
                    {
                        Trace.Assert(GameModel.WuGuModel != null);
                        TimeOutSeconds = timeOutSeconds;
                        GameModel.WuGuModel.IsEnabled = IsPlayable;
                        GameModel.WuGuModel.Prompt = PromptFormatter.Format(prompt);
                    }
                    else
                    {
                        _currentChoiceOptions = options;
                        _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback);
                        CardChoiceModel.Prompt = PromptFormatter.Format(prompt);
                        if (!IsPlayable)
                        {
                            CardChoiceModel.DisplayOnly = true;
                            prompt.Values.Insert(0, Player);
                            CurrentCardChoiceRearrangeCallback = null;
                        }
                        else
                        {
                            CurrentCardChoiceRearrangeCallback = callback;
                        }
                        IsCardChoiceQuestionShown = true;
                    }
                }
            });
        }
Exemple #13
0
 public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null)
 {
     throw new NotImplementedException();
 }
 public void TryAskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     List<List<Card>> answer;
     if (!IsPlayable)
     {
         if (IsUiDetached) return;
         uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback);
         return;
     }
     if (IsUiDetached || !uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) ||
         answer == null)
     {
         Trace.TraceInformation("Invalid answer");
         client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, null, 0, client.SelfId));
     }
     else
     {
         client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, answer, options == null ? 0 : options.OptionResult, client.SelfId));
     }
 }
 public void AskForCardChoice(Prompt prompt, List<Cards.DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     currentChoiceOptions = options;
     CurrentQuestionState = QuestionState.AskForCardChoice;
     Gamer.ReceiveAsync();
     if (Gamer.OnlineStatus != OnlineStatus.Online) AnswerCardChoice(null);
 }
Exemple #16
0
        public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            answer = null;
            bool ret = true;

            if (!TryAskForCardChoice(sourceDecks, resultDeckMaximums, verifier, out answer, options, callback))
            {
                SendCardChoice(null, null, null);
                ret = false;
            }
            else
            {
                SendCardChoice(verifier, answer, options);
            }
            NextQuestion();
            if (answer == null)
            {
                answer = new List <List <Card> >();
                foreach (var v in resultDeckMaximums)
                {
                    answer.Add(new List <Card>());
                }
            }
            return(ret);
        }
Exemple #17
0
        public bool TryAskForCardChoice(List <DeckPlace> sourceDecks, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            answer = null;
            int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0);

            Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, timeOut);
            var answerReady = new Semaphore(0, Int16.MaxValue);
            CardChoiceAnsweredEventHandler handler = (c) =>
            {
                choiceAnswer = c;
                answerReady.Release(1);
            };

            proxy.CardChoiceAnsweredEvent += handler;
            proxy.AskForCardChoice(new Prompt(), sourceDecks, new List <string>(), resultDeckMaximums, verifier, timeOut, options, callback);
            bool noAnswer = false;

            if (!answerReady.WaitOne(timeOut * 1000))
            {
                noAnswer = true;
            }
            proxy.CardChoiceAnsweredEvent -= handler;
            proxy.Freeze();
            if (noAnswer)
            {
                return(false);
            }

            answer = choiceAnswer;
            if (answer != null)
            {
                foreach (var list in answer)
                {
                    foreach (var item in list)
                    {
                        if (item == null)
                        {
                            return(false);
                        }
                        bool exist = false;
                        foreach (var v in sourceDecks)
                        {
                            if (Game.CurrentGame.Decks[v].Contains(item))
                            {
                                exist = true;
                                break;
                            }
                        }
                        if (options != null && options.DefaultResult != null)
                        {
                            foreach (var dk in options.DefaultResult)
                            {
                                if (dk.Contains(item))
                                {
                                    exist = true;
                                    break;
                                }
                            }
                        }
                        if (!exist)
                        {
                            Trace.TraceWarning("Client DDOS!");
                            return(false);
                        }
                    }
                }
            }
            else
            {
                answer = new List <List <Card> >();
            }
            while (answer.Count < resultDeckMaximums.Count)
            {
                answer.Add(new List <Card>());
            }
            if (verifier.Verify(answer) != VerifierResult.Success)
            {
                Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
                answer = null;
                return(false);
            }
            return(true);
        }
Exemple #18
0
        public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            answerPending = new Semaphore(0, 1);
            int timeOut = _GetActualTimeoutSecond(verifier.Helper);

            proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, timeOut, options, callback);
            answer = null;
            if (answerPending.WaitOne(timeOut * 1000 /* + GameDelays.UiDelayCompensation*/))
            {
                answer = answerCardsOfCards;
            }
            if (answer == null)
            {
                return(false);
            }
            else
            {
                return(verifier.Verify(answer) == VerifierResult.Success);
            }
        }
Exemple #19
0
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback)
 {
     throw new NotImplementedException();
 }
        public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, CardChoiceRearrangeCallback callback)
        {
            answer = null;
            Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, TimeOutSeconds);
            int? count;
            if (!server.ExpectNext(clientId, TimeOutSeconds))
            {
                return false;
            }

            count = server.GetInt(clientId, 0);
            if (count == null || count == 0)
            {
                return false;
            }
            if (count == null)
            {
                return false;
            }
            answer = new List<List<Card>>();

            count = server.GetInt(clientId, 0);
            while (count-- > 0)
            {
                int? subCount = server.GetInt(clientId, 0); ;
                var theList = new List<Card>();
                answer.Add(theList);
                while (subCount-- > 0)
                {
                    Card item = server.GetCard(clientId, 0);
                    if (item == null)
                    {
                        return false;
                    }
                    bool exist = false;
                    foreach (var v in sourceDecks)
                    {
                        if (Game.CurrentGame.Decks[v].Contains(item))
                        {
                            exist = true;
                            break;
                        }
                    }
                    if (!exist)
                    {
                        Trace.TraceWarning("Client DDOS!");
                        return false;
                    }
                    theList.Add(item);
                }
            }

            if (verifier.Verify(answer) != VerifierResult.Success)
            {
                Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
                answer = null;
                return false;
            }
            return true;
        }
Exemple #21
0
 public void AskForCardChoice(Prompt prompt, List <Cards.DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     currentChoiceOptions = options;
     CurrentQuestionState = QuestionState.AskForCardChoice;
     Gamer.ReceiveAsync();
     if (Gamer.OnlineStatus != OnlineStatus.Online)
     {
         AnswerCardChoice(null);
     }
 }
 public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     object o = client.Receive();
     int opt;
     answer = (o as AskForCardChoiceResponse).ToAnswer(client.SelfId, out opt);
     if (options != null) options.OptionResult = opt;
     return true;
 }
Exemple #23
0
        public void TryAskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            List <List <Card> > answer;

            if (!IsPlayable)
            {
                if (IsUiDetached)
                {
                    return;
                }
                uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback);
                return;
            }
            if (IsUiDetached || !uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) ||
                answer == null)
            {
                Trace.TraceInformation("Invalid answer");
                client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, null, 0, client.SelfId));
            }
            else
            {
                client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, answer, options == null ? 0 : options.OptionResult, client.SelfId));
            }
        }
Exemple #24
0
        public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options = null, CardChoiceRearrangeCallback callback = null)
        {
            Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id);
            TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, options, callback);
            SimulateReplayDelay();
            NextQuestion();
            if (TryAnswerForCardChoice(prompt, verifier, out answer, options, callback))
            {
                uiProxy.Freeze();
                if (answer == null || answer.Count == 0)
                {
                    return(false);
                }
#if DEBUG
                Trace.Assert(verifier.Verify(answer) == VerifierResult.Success);
#endif
                return(true);
            }
            uiProxy.Freeze();
            return(false);
        }
Exemple #25
0
        private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, List<bool> rearrangeable, int timeOutSeconds, CardChoiceRearrangeCallback callback)
        {
            if (resultDeckMaximums.Sum() != 1)
            {
                throw new NotImplementedException();
            }

            CardChoiceModel.CardStacks.Clear();

            int numLines = sourceDecks.Count;

            foreach (var deck in sourceDecks)
            {
                if (Game.CurrentGame.Decks[deck].Count == 0)
                {
                    continue;
                }
                CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                line.DeckName = deck.DeckType.Name;
                int i = 0;
                int numCards = Game.CurrentGame.Decks[deck].Count;
                int maxColumns = Math.Max(numCards / 2 + 1, 5);
                bool firstRow = true;
                foreach (var card in Game.CurrentGame.Decks[deck])
                {
                    if (numLines == 1 && i >= maxColumns && firstRow)
                    {
                        Trace.Assert(CardChoiceModel.CardStacks.Count == 0);
                        CardChoiceModel.CardStacks.Add(line);
                        line = new CardChoiceLineViewModel();
                        line.DeckName = deck.DeckType.Name;
                        firstRow = false;
                    }
                    CardViewModel model = new CardViewModel()
                    {
                        Card = card,
                        IsSelectionMode = true,
                        IsEnabled = true
                    };
                    model.OnSelectedChanged += cardChoice_OnSelectedChanged;
                    line.Cards.Add(model);
                    i++;
                }
                CardChoiceModel.CardStacks.Add(line);
            }

            CardChoiceModel.TimeOutSeconds = timeOutSeconds;
        }
Exemple #26
0
        private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames,
                                               List<int> resultDeckMaximums,
                                               AdditionalCardChoiceOptions options,
                                               ICardChoiceVerifier verifier,
                                               int timeOutSeconds,
                                               CardChoiceRearrangeCallback callback)
        {
            bool isSingleResult = (resultDeckMaximums.Sum() == 1);

            var choiceModel = new CardChoiceViewModel();

            int numLines = sourceDecks.Count;

            foreach (var deck in sourceDecks)
            {
                if (Game.CurrentGame.Decks[deck].Count == 0)
                {
                    continue;
                }
                CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                line.DeckName = deck.DeckType.Name;
                line.IsResultDeck = false;
                int i = 0;
                int numCards = Game.CurrentGame.Decks[deck].Count;
                int maxColumns = Math.Max(numCards / 2 + 1, 5);
                bool firstRow = true;
                foreach (var card in Game.CurrentGame.Decks[deck])
                {
                    if (numLines == 1 && isSingleResult && i >= maxColumns && firstRow)
                    {
                        Trace.Assert(choiceModel.CardStacks.Count == 0);
                        choiceModel.CardStacks.Add(line);
                        line = new CardChoiceLineViewModel();
                        line.DeckName = deck.DeckType.Name;
                        line.IsResultDeck = false;
                        firstRow = false;
                    }
                    CardViewModel model = new CardViewModel()
                    {
                        Card = card,
                        IsSelectionMode = isSingleResult,
                        IsEnabled = true
                    };

                    line.Cards.Add(model);
                    i++;
                }
                choiceModel.CardStacks.Add(line);
            }

            if (!isSingleResult)
            {
                int k = 0;
                foreach (var deckName in resultDeckNames)
                {
                    CardChoiceLineViewModel line = new CardChoiceLineViewModel();
                    line.DeckName = deckName;
                    if (options != null)
                    {
                        if (options.Rearrangeable != null)
                        {
                            line.Rearrangable = options.Rearrangeable[k];
                        }
                        if (options.DefaultResult != null)
                        {
                            foreach (var card in options.DefaultResult[k])
                            {
                                line.Cards.Add(new CardViewModel() { Card = card });
                            }
                        }
                    }
                    line.Capacity = resultDeckMaximums[k++];
                    line.IsResultDeck = true;
                    choiceModel.CardStacks.Add(line);
                }
            }

            if (options != null && options.Options != null)
            {
                for (int i = 0; i < options.Options.Count; i++)
                {
                    MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                    {
                        CanExecuteStatus = false,
                        ChoiceKey = options.Options[i],
                        ChoiceIndex = i
                    };
                    choiceModel.MultiChoiceCommands.Add(command);
                }
            }
            else
            {
                MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand)
                {
                    CanExecuteStatus = false,
                    ChoiceKey = new OptionPrompt("Confirm")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }
            if (options != null && options.IsCancellable)
            {
                MultiChoiceCommand command = new MultiChoiceCommand(CancelCardChoiceCommand)
                {
                    IsCancel = true,
                    ChoiceKey = new OptionPrompt("Cancel")
                };
                choiceModel.MultiChoiceCommands.Add(command);
            }

            choiceModel.Verifier = verifier;
            choiceModel.TimeOutSeconds = timeOutSeconds;
            CardChoiceModel = choiceModel;
        }
Exemple #27
0
 public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     answer = null;
     object o = client.Receive();
     if (o == null)
     {
         return false;
     }
     if ((int)o == 0)
     {
         return false;
     }
     answer = new List<List<Card>>();
     o = client.Receive();
     int count = (int)o;
     while (count-- > 0)
     {
         o = client.Receive();
         if (o == null)
         {
             return false;
         }
         int subCount = (int)o;
         var theList = new List<Card>();
         answer.Add(theList);
         while (subCount-- > 0)
         {
             o = client.Receive();
             if (o == null)
             {
                 return false;
             }
             theList.Add((Card)o);
         }
     }
     if (options != null && options.Options != null)
     {
         options.OptionResult = (int)client.Receive();
     }
     return true;
 }
Exemple #28
0
        public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            answer = null;
            int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0);
            Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, timeOut);
            int? count;
            if (!server.ExpectNext(clientId, timeOut))
            {
                return false;
            }

            count = server.GetInt(clientId, 0);
            if (count == null || count == 0)
            {
                return false;
            }
            if (count == null)
            {
                return false;
            }
            answer = new List<List<Card>>();

            count = server.GetInt(clientId, 0);
            while (count-- > 0)
            {
                int? subCount = server.GetInt(clientId, 0); ;
                var theList = new List<Card>();
                answer.Add(theList);
                while (subCount-- > 0)
                {
                    Card item = server.GetCard(clientId, 0);
                    if (item == null)
                    {
                        return false;
                    }
                    bool exist = false;
                    foreach (var v in sourceDecks)
                    {
                        if (Game.CurrentGame.Decks[v].Contains(item))
                        {
                            exist = true;
                            break;
                        }
                    }
                    if (options != null && options.DefaultResult != null)
                    {
                        foreach (var dk in options.DefaultResult)
                        {
                            if (dk.Contains(item))
                            {
                                exist = true;
                                break;
                            }
                        }
                    }
                    if (!exist)
                    {
                        Trace.TraceWarning("Client DDOS!");
                        return false;
                    }
                    theList.Add(item);
                }
            }
            if (options != null && options.Options != null)
            {
                int? opr = server.GetInt(clientId, 0);
                if (opr == null) return false;
                if (opr < 0 || opr >= options.Options.Count) return false;
                options.OptionResult = (int)opr;
            }

            if (verifier.Verify(answer) != VerifierResult.Success)
            {
                Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
                answer = null;
                return false;
            }
            return true;
        }
Exemple #29
0
        public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            object o = client.Receive();
            int    opt;

            answer = (o as AskForCardChoiceResponse).ToAnswer(client.SelfId, out opt);
            if (options != null)
            {
                options.OptionResult = opt;
            }
            return(true);
        }
Exemple #30
0
 bool IUiProxy.AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     answer = null;
     return false;
 }
        public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
        {
            answer = null;
            int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0);
            Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, timeOut);
            var answerReady = new Semaphore(0, Int16.MaxValue);
            CardChoiceAnsweredEventHandler handler = (c) =>
            {
                choiceAnswer = c;
                answerReady.Release(1);
            };
            proxy.CardChoiceAnsweredEvent += handler;
            proxy.AskForCardChoice(new Prompt(), sourceDecks, new List<string>(), resultDeckMaximums, verifier, timeOut, options, callback);
            bool noAnswer = false;
            if (!answerReady.WaitOne(timeOut * 1000)) noAnswer = true;
            proxy.CardChoiceAnsweredEvent -= handler;
            proxy.Freeze();
            if (noAnswer) return false;

            answer = choiceAnswer;
            if (answer != null)
            {
                foreach (var list in answer)
                {
                    foreach (var item in list)
                    {
                        if (item == null)
                        {
                            return false;
                        }
                        bool exist = false;
                        foreach (var v in sourceDecks)
                        {
                            if (Game.CurrentGame.Decks[v].Contains(item))
                            {
                                exist = true;
                                break;
                            }
                        }
                        if (options != null && options.DefaultResult != null)
                        {
                            foreach (var dk in options.DefaultResult)
                            {
                                if (dk.Contains(item))
                                {
                                    exist = true;
                                    break;
                                }
                            }
                        }
                        if (!exist)
                        {
                            Trace.TraceWarning("Client DDOS!");
                            return false;
                        }
                    }
                }
            }
            else
            {
                answer = new List<List<Card>>();
            }
            while (answer.Count < resultDeckMaximums.Count)
            {
                answer.Add(new List<Card>());
            }
            if (verifier.Verify(answer) != VerifierResult.Success)
            {
                Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
                answer = null;
                return false;
            }
            return true;
        }
Exemple #32
0
 public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null)
 {
     throw new NotImplementedException();
 }
 bool IPlayerProxy.AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback)
 {
     answer = null;
     return(false);
 }