Esempio n. 1
0
 void Run(Player owner, GameEvent gameEvent, GameEventArgs args)
 {
     while (owner.HandCards().Count > 0 && owner.DelayedTools().Count > 0)
     {
         List<List<Card>> answer;
         List<DeckPlace> sourceDeck = new List<DeckPlace>();
         sourceDeck.Add(new DeckPlace(owner, DeckType.DelayedTools));
         sourceDeck.Add(new DeckPlace(owner, DeckType.Hand));
         AdditionalCardChoiceOptions options = new AdditionalCardChoiceOptions();
         options.IsCancellable = true;
         if (owner.AskForCardChoice(new CardChoicePrompt("XiuLuo", owner),
             sourceDeck,
             new List<string>() { "XLJinNang", "XLShouPai" },
             new List<int>() { 1, 1 },
             new XiuLuoVerifier(),
             out answer,
             options))
         {
             NotifySkillUse();
             Game.CurrentGame.HandleCardDiscard(owner, answer[1]);
             Game.CurrentGame.HandleCardDiscard(owner, answer[0]);
         }
         else break;
     }
 }
Esempio n. 2
0
 /// <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);
 }
Esempio n. 3
0
        void Run(Player Owner, GameEvent gameEvent, GameEventArgs eventArgs)
        {
            var GuZhengDeck = new DeckType("GuZheng");
            foreach (Card c in new List<Card>(GuZhengCards))
            {
                if (c.Place.DeckType != DeckType.Discard)
                {
                    GuZhengCards.Remove(c);
                }
            }
            CardsMovement move = new CardsMovement();
            move.Cards = GuZhengCards;
            move.To = new DeckPlace(null, GuZhengDeck);
            Game.CurrentGame.MoveCards(move);
            List<List<Card>> answer;
            var options = new AdditionalCardChoiceOptions() { Options = new List<string>() { Prompt.MultipleChoiceOptionPrefix + "GuZhengHuoDe", Prompt.MultipleChoiceOptionPrefix + "GuZhengBuHuoDe" } };
            if (!Game.CurrentGame.UiProxies[Owner].AskForCardChoice(
                new CardChoicePrompt("GuZheng"),
                new List<DeckPlace>() { new DeckPlace(null, GuZhengDeck) },
                new List<string>() { "GuZhengFanHui" },
                new List<int>() { 1 },
                new RequireOneCardChoiceVerifier(),
                out answer,
                options))
            {
                Trace.TraceInformation("Invalid answer, choosing for you");
                answer = new List<List<Card>>();
                answer.Add(new List<Card>());
                answer[0].Add(Game.CurrentGame.Decks[null, GuZhengDeck][0]);
            }
            move = new CardsMovement();
            move.Cards = new List<Card>(answer[0]);
            move.To = new DeckPlace(Game.CurrentGame.CurrentPlayer, DeckType.Hand);
            Game.CurrentGame.MoveCards(move);
            Game.CurrentGame.PlayerAcquiredCard(Game.CurrentGame.CurrentPlayer, answer[0]);

            if (options.OptionResult == 1)
            {
                Game.CurrentGame.PlaceIntoDiscard(null, new List<Card>(Game.CurrentGame.Decks[null, GuZhengDeck]));
            }
            else
            {
                var cardsToAcquire = new List<Card>(Game.CurrentGame.Decks[null, GuZhengDeck]);
                move = new CardsMovement();
                move.Cards = new List<Card>(cardsToAcquire);
                move.To = new DeckPlace(Owner, DeckType.Hand);
                Game.CurrentGame.MoveCards(move);
                Game.CurrentGame.PlayerAcquiredCard(Owner, cardsToAcquire);
            }
            GuZhengCards = new List<Card>();
        }
Esempio n. 4
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);
     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, 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);
     }
 }
Esempio n. 6
0
        public override bool Commit(GameEventArgs arg)
        {
            GameDelays.Delay(GameDelayTypes.Awaken);

            Owner[XinZhanUsed] = 1;
            DeckType XinZhanDeck = new DeckType("XinZhan");
            CardsMovement move = new CardsMovement();
            move.Cards = new List<Card>();
            for (int i = 0; i < choiceCount; i++)
            {
                Game.CurrentGame.SyncImmutableCard(Owner, Game.CurrentGame.PeekCard(0));
                Card c = Game.CurrentGame.DrawCard();
                move.Cards.Add(c);
            }
            move.To = new DeckPlace(null, XinZhanDeck);
            move.Helper.IsFakedMove = true;
            Game.CurrentGame.MoveCards(move);
            List<List<Card>> answer;
            AdditionalCardChoiceOptions options = new AdditionalCardChoiceOptions();
            options.Rearrangeable = new List<bool>() { true, false };
            options.DefaultResult = new List<List<Card>>() { new List<Card>(Game.CurrentGame.Decks[null, XinZhanDeck]), new List<Card>() };
            if (!Game.CurrentGame.UiProxies[Owner].AskForCardChoice(new CardChoicePrompt("XinZhan", Owner),
                    new List<DeckPlace>() {},
                    new List<string>() { "PaiDuiDing", "HuoDe" },
                    new List<int>() {choiceCount, choiceCount},
                    new XinZhanVerifier(),
                    out answer,
                    options,
                    CardChoiceCallback.GenericCardChoiceCallback))
            {
                Game.CurrentGame.NotificationProxy.NotifyLogEvent(new Prompt(Prompt.LogEventPrefix + "XinZhan", Owner, Game.CurrentGame.Decks[null, XinZhanDeck].Count));
                Game.CurrentGame.InsertBeforeDeal(null, Game.CurrentGame.Decks[null, XinZhanDeck], new MovementHelper() { IsFakedMove = true });
            }
            else
            {
                Game.CurrentGame.NotificationProxy.NotifyLogEvent(new Prompt(Prompt.LogEventPrefix + "XinZhan", Owner, answer[0].Count));
                Game.CurrentGame.InsertBeforeDeal(null, answer[0], new MovementHelper() { IsFakedMove = true });
                Game.CurrentGame.HandleCardTransferToHand(null, Owner, answer[1]);
            }
            return true;
        }
 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;
 }
Esempio n. 8
0
        void Run(Player Owner, GameEvent gameEvent, GameEventArgs eventArgs)
        {
            DeckType GuanXingDeck = new DeckType("GuanXing");

            CardsMovement move = new CardsMovement();
            move.Cards = new List<Card>();
            int toDraw = Math.Min(5, Game.CurrentGame.AlivePlayers.Count);
            for (int i = 0; i < toDraw; i++)
            {
                Game.CurrentGame.SyncImmutableCard(Owner, Game.CurrentGame.PeekCard(0));
                Card c = Game.CurrentGame.DrawCard();
                move.Cards.Add(c);
            }
            move.To = new DeckPlace(null, GuanXingDeck);
            move.Helper.IsFakedMove = true;
            Game.CurrentGame.MoveCards(move, false, Core.Utils.GameDelayTypes.None);
            List<List<Card>> answer;
            AdditionalCardChoiceOptions options = new AdditionalCardChoiceOptions();
            options.Rearrangeable = new List<bool>() { true, true };
            options.DefaultResult = new List<List<Card>>() { new List<Card>(Game.CurrentGame.Decks[null, GuanXingDeck]), new List<Card>() };
            if (!Game.CurrentGame.UiProxies[Owner].AskForCardChoice(new CardChoicePrompt("GuanXing"),
                    new List<DeckPlace>() { },
                    new List<string>() { "PaiDuiDing", "PaiDuiDi" },
                    new List<int>() { toDraw, toDraw },
                    new GuanXingVerifier(Game.CurrentGame.Decks[null, GuanXingDeck]),
                    out answer,
                    options,
                    CardChoiceCallback.GenericCardChoiceCallback))
            {
                Game.CurrentGame.NotificationProxy.NotifyLogEvent(new LogEvent("GuanXing", Owner, Game.CurrentGame.Decks[null, GuanXingDeck].Count, 0), new List<Player>() { Owner }, false);
                Game.CurrentGame.InsertBeforeDeal(null, Game.CurrentGame.Decks[null, GuanXingDeck], new MovementHelper() { IsFakedMove = true });
            }
            else
            {
                Game.CurrentGame.NotificationProxy.NotifyLogEvent(new LogEvent("GuanXing", Owner, answer[0].Count, answer[1].Count), new List<Player>() { Owner }, false);
                Game.CurrentGame.InsertBeforeDeal(null, answer[0], new MovementHelper() { IsFakedMove = true });
                Game.CurrentGame.InsertAfterDeal(null, answer[1], new MovementHelper() { IsFakedMove = true });
            }
        }
Esempio n. 9
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;
 }
Esempio n. 10
0
        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;
                }
            });
        }
Esempio n. 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;
                }
            });
        }
Esempio n. 12
0
 public void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options)
 {
     for (int i = 0; i < server.MaxClients; i++)
     {
         server.SendObject(i, 1);
         server.SendObject(i, answer.Count);
         int j = 0;
         foreach (var cards in answer)
         {
             server.SendObject(i, cards.Count);
             foreach (Card c in cards)
             {
                 if (verifier.Helper != null && (verifier.Helper.RevealCards || (verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy != null && verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy[j])))
                 {
                     if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools)
                     {
                         c.RevealOnce = true;
                     }
                 }
                 server.SendObject(i, c);
             }
             j++;
         }
         if (options != null && options.Options != null) server.SendObject(i, options.OptionResult);
         server.Flush(i);
     }
 }
Esempio n. 13
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;
        }
Esempio n. 14
0
        void Run(Player Owner, GameEvent gameEvent, GameEventArgs eventArgs)
        {
            var GuZhengDeck = new DeckType("GuZheng");
            belongToCurrent = new List<Card>();
            foreach (Card c in new List<Card>(GuZhengCards))
            {
                if (c.Place.DeckType != DeckType.Discard)
                {
                    GuZhengCards.Remove(c);
                }
                else if (c.HistoryPlace1.Player == Game.CurrentGame.CurrentPlayer)
                {
                    belongToCurrent.Add(c);
                }
            }
            if (belongToCurrent.Count == 0 || !AskForSkillUse())
            {
                GuZhengCards = new List<Card>();
                belongToCurrent = new List<Card>();
                return;
            }
            NotifySkillUse();
            CardsMovement move = new CardsMovement();
            move.Cards = GuZhengCards;
            move.To = new DeckPlace(null, GuZhengDeck);
            Game.CurrentGame.MoveCards(move);
            List<List<Card>> answer;
            var options = new AdditionalCardChoiceOptions() { Options = new List<OptionPrompt>() { new OptionPrompt("GuZhengHuoDe"), new OptionPrompt("GuZhengBuHuoDe") } };
            if (!Game.CurrentGame.UiProxies[Owner].AskForCardChoice(
                new CardChoicePrompt("GuZheng", Owner, Game.CurrentGame.CurrentPlayer),
                new List<DeckPlace>() { new DeckPlace(null, GuZhengDeck) },
                new List<string>() { "GuZhengFanHui" },
                new List<int>() { 1 },
                new GuZhengVerifier(),
                out answer,
                options))
            {
                Trace.TraceInformation("Invalid answer, choosing for you");
                answer = new List<List<Card>>();
                answer.Add(new List<Card>());
                answer[0].Add(belongToCurrent[0]);
            }
            move = new CardsMovement();
            move.Cards = new List<Card>(answer[0]);
            move.To = new DeckPlace(Game.CurrentGame.CurrentPlayer, DeckType.Hand);
            Game.CurrentGame.MoveCards(move);
            Game.CurrentGame.PlayerAcquiredCard(Game.CurrentGame.CurrentPlayer, answer[0]);

            if (options.OptionResult == 1)
            {
                Game.CurrentGame.PlaceIntoDiscard(null, new List<Card>(Game.CurrentGame.Decks[null, GuZhengDeck]));
            }
            else
            {
                var cardsToAcquire = new List<Card>(Game.CurrentGame.Decks[null, GuZhengDeck]);
                move = new CardsMovement();
                move.Cards = new List<Card>(cardsToAcquire);
                move.To = new DeckPlace(Owner, DeckType.Hand);
                Game.CurrentGame.MoveCards(move);
                Game.CurrentGame.PlayerAcquiredCard(Owner, cardsToAcquire);
            }
            GuZhengCards = new List<Card>();
        }
 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));
     }
 }
Esempio n. 16
0
            public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
            {
                Pk1v1Game game = Game.CurrentGame as Pk1v1Game;

                foreach (Player pp in game.Players)
                {
                    game.HandCardVisibility.Add(pp, new List<Player>() { pp });
                }

                // Put the whole deck in the dealing deck

                foreach (Card card in game.CardSet)
                {
                    // We don't want hero cards
                    if (card.Type is HeroCardHandler)
                    {
                        game.Decks[DeckType.Heroes].Add(card);
                        card.Place = new DeckPlace(null, DeckType.Heroes);
                    }
                    else if (card.Type is RoleCardHandler)
                    {
                        card.Place = new DeckPlace(null, RoleDeckType);
                    }
                    else
                    {
                        game.Decks[DeckType.Dealing].Add(card);
                        card.Place = new DeckPlace(null, DeckType.Dealing);
                    }
                }
                if (game.Players.Count == 0)
                {
                    return;
                }
                // Await role decision
                int seed = DateTime.Now.Millisecond;
                game.Seed = seed;
                Trace.TraceError("Seed is {0}", seed);
                if (game.RandomGenerator == null)
                {
                    game.RandomGenerator = new Random(seed);
                    Random random = game.RandomGenerator;
                }
                int selectorId = game.RandomGenerator.Next(2);
                int rulerId = 0;
                bool selectorIs0 = selectorId == 0;
                game.SyncConfirmationStatus(ref selectorIs0);
                if (selectorIs0)
                {
                    selectorId = 0;
                }
                else
                {
                    selectorId = 1;
                }
                int wantToBeRuler = 0;
                game.Players[selectorId].AskForMultipleChoice(new MultipleChoicePrompt("BeRuler"), OptionPrompt.YesNoChoices, out wantToBeRuler);
                rulerId = 1 - (wantToBeRuler ^ selectorId);
                Trace.Assert(rulerId >= 0 && rulerId <= 1);
                Trace.Assert(game.Players.Count == 2);
                if (rulerId == 0)
                {
                    game.AvailableRoles.Add(Role.Ruler);
                    game.AvailableRoles.Add(Role.Defector);
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Ruler));
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Defector));
                }
                else
                {
                    game.AvailableRoles.Add(Role.Defector);
                    game.AvailableRoles.Add(Role.Ruler);
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Defector));
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Ruler));
                }

                List<CardsMovement> moves = new List<CardsMovement>();
                int i = 0;
                foreach (Player p in game.Players)
                {
                    CardsMovement move = new CardsMovement();
                    move.Cards = new List<Card>() { game.Decks[null, RoleDeckType][i] };
                    move.To = new DeckPlace(p, RoleDeckType);
                    moves.Add(move);
                    i++;
                }
                game.MoveCards(moves, null, GameDelays.GameStart);
                GameDelays.Delay(GameDelays.RoleDistribute);
                //hero allocation
                game.Shuffle(game.Decks[DeckType.Heroes]);

                List<Card> heroPool = new List<Card>();
                int toDraw = 12;
                for (int rc = 0; rc < toDraw; rc++)
                {
                    game.SyncImmutableCardAll(game.Decks[DeckType.Heroes][rc]);
                    heroPool.Add(game.Decks[DeckType.Heroes][rc]);
                }
                game.SyncImmutableCards(game.Players[rulerId], heroPool);
                DeckType tempHero = DeckType.Register("TempHero");
                game.Decks[null, tempHero].AddRange(heroPool);
                Trace.TraceInformation("Ruler is {0}", rulerId);
                game.Players[rulerId].Role = Role.Ruler;
                game.Players[1 - rulerId].Role = Role.Defector;

                List<int> heroSelectCount = new List<int>() { 1, 2, 2, 2, 2, 2, 1 };
                int seq = 0;
                int turn = rulerId;
                Dictionary<int, int> map = new Dictionary<int,int>();
                map.Add(0, 0);
                map.Add(1, 1);
                var deckPlace = new DeckPlace(null, tempHero);
                game.NotificationProxy.NotifyTwoSidesCardPickStart(new CardChoicePrompt("Pk1v1.InitHeroPick.Init"), deckPlace, map, 6, 6);
                while (heroSelectCount.Count > seq)
                {
                    List<DeckPlace> sourceDecks = new List<DeckPlace>();
                    sourceDecks.Add(new DeckPlace(null, tempHero));
                    List<string> resultDeckNames = new List<string>();
                    resultDeckNames.Add("HeroChoice");
                    List<int> resultDeckMaximums = new List<int>();
                    int numHeroes = heroSelectCount[seq];
                    resultDeckMaximums.Add(numHeroes);
                    List<List<Card>> answer;
                    var newVer = new Pk1v1HeroChoiceVerifier(1, seq + 1 == heroSelectCount.Count ? -(Game.CurrentGame.Settings.TimeOutSeconds - 2) : 0);
                    for (int j = 0; j < numHeroes; j++)
                    {
                        var option = new AdditionalCardChoiceOptions();
                        option.IsTwoSidesCardChoice = true;
                        if (!game.UiProxies[game.Players[turn]].AskForCardChoice(new CardChoicePrompt("Pk1v1.InitHeroPick", numHeroes), sourceDecks, resultDeckNames, resultDeckMaximums, newVer, out answer, option))
                        {
                            answer = new List<List<Card>>();
                            answer.Add(new List<Card>());
                            answer[0].Add(game.Decks[null, tempHero].First(h => !answer[0].Contains(h) && !game.Decks[game.Players[turn], SelectedHero].Contains(h) && !game.Decks[game.Players[1 - turn], SelectedHero].Contains(h)));
                        }
                        game.Decks[game.Players[turn], SelectedHero].AddRange(answer[0]);
                        game.NotificationProxy.NotifyTwoSidesCardPicked(turn == 0, game.Decks[deckPlace].IndexOf(answer[0][0]));
                    }
                    seq++;
                    turn = 1 - turn;
                }
                GameDelays.Delay(GameDelays.Pk1v1EndOfSelection);
                game.NotificationProxy.NotifyTwoSidesCardPickEnd();
                game.Shuffle(game.Decks[null, DeckType.Dealing]);

                Player current = game.CurrentPlayer = game.Players[1 - rulerId];

                Dictionary<Player, List<Card>> restDraw = new Dictionary<Player, List<Card>>();
                List<Player> players = new List<Player>(game.Players);
                foreach (Player p in players)
                {
                    restDraw.Add(p, new List<Card>(game.Decks[p, SelectedHero]));
                }

                var heroSelection = new Dictionary<Player, List<Card>>();
                int numberOfHeroes = Game.CurrentGame.Settings.DualHeroMode ? 2 : 1;
                game.GlobalProxy.AskForHeroChoice(restDraw, heroSelection, numberOfHeroes, new RequireCardsChoiceVerifier(numberOfHeroes, false, true));

                bool notUsed = true;
                game.SyncConfirmationStatus(ref notUsed);

                foreach (var pxy in game.UiProxies)
                {
                    pxy.Value.Freeze();
                }

                for (int repeat = 0; repeat < numberOfHeroes; repeat++)
                {
                    foreach (Player p in players)
                    {
                        Card c;
                        int idx;
                        //only server has the result
                        if (!game.IsClient)
                        {
                            idx = repeat;
                            if (heroSelection.ContainsKey(p))
                            {
                                c = heroSelection[p][repeat];
                                idx = restDraw[p].IndexOf(c);
                            }
                            else
                            {
                                c = restDraw[p][idx];
                            }
                            if (game.GameServer != null)
                            {
                                foreach (Player player in game.Players)
                                {
                                    game.GameServer.SendPacket(player.Id, new StatusSync() { Status = idx });
                                }
                                game.GameServer.SendPacket(game.Players.Count, new StatusSync() { Status = idx });
                            }
                        }
                        // you are client
                        else
                        {
                            idx = (int)game.GameClient.Receive();
                            c = restDraw[p][idx];
                        }
                        game.Decks[p, SelectedHero].Remove(c);
                        var h = (HeroCardHandler)c.Type;
                        Trace.TraceInformation("Assign {0} to player {1}", h.Hero.Name, p.Id);
                        var hero = h.Hero.Clone() as Hero;
                        foreach (var skill in new List<ISkill>(hero.Skills))
                        {
                            if (skill.IsRulerOnly)
                            {
                                hero.Skills.Remove(skill);
                            }
                        }

                        if (repeat == 0)
                        {
                            p.Hero = hero;
                            p.Allegiance = hero.Allegiance;
                            p.IsMale = hero.IsMale;
                            p.IsFemale = !hero.IsMale;
                            if (numberOfHeroes == 1)
                            {
                                p.MaxHealth = hero.MaxHealth;
                                p.Health = hero.MaxHealth;
                            }
                        }
                        else if (repeat == 1)
                        {
                            p.Hero2 = hero;
                            int aveHp = (p.Hero2.MaxHealth + p.Hero.MaxHealth) / 2;
                            p.MaxHealth = aveHp;
                            p.Health = aveHp;
                        }
                    }
                }

                foreach (var rm in heroPool)
                {
                    game.Decks[DeckType.Heroes].Remove(rm);
                }
                foreach (var st in game.Decks[game.Players[0], SelectedHero])
                {
                    st.Place = new DeckPlace(game.Players[0], SelectedHero);
                }
                foreach (var st in game.Decks[game.Players[1], SelectedHero])
                {
                    st.Place = new DeckPlace(game.Players[1], SelectedHero);
                }
                game.Shuffle(game.Decks[DeckType.Heroes]);
                if (game.IsClient)
                {
                    foreach (var card in game.Decks[DeckType.Heroes])
                    {
                        card.Type = new UnknownHeroCardHandler();
                        card.Id = Card.UnknownHeroId;
                    }
                }

                GameDelays.Delay(GameDelays.GameBeforeStart);

                Game.CurrentGame.NotificationProxy.NotifyGameStart();
                GameDelays.Delay(GameDelays.GameStart);
                GameDelays.Delay(GameDelays.GameStart);

                foreach (var pl in game.Players)
                {
                    StartGameDeal(game, pl);
                }
                foreach (var pl in game.Players)
                {
                    try
                    {
                        game.Emit(GameEvent.HeroDebut, new GameEventArgs() { Source = pl });
                    }
                    catch (EndOfTurnException)
                    {
                        game.CurrentPlayer = game.Players[1 - game.CurrentPlayer.Id];
                    }
                }

                foreach (var act in game.AlivePlayers)
                {
                    game.Emit(GameEvent.PlayerGameStartAction, new GameEventArgs() { Source = act });
                }

                //redo this: current player might change
                current = game.CurrentPlayer;
                while (true)
                {
                    GameEventArgs args = new GameEventArgs();
                    args.Source = current;
                    game.CurrentPhaseEventIndex = 0;
                    game.CurrentPhase = TurnPhase.BeforeStart;
                    game.CurrentPlayer = current;
                    game.Emit(GameEvent.DoPlayer, args);
                    current = game.NextAlivePlayer(current);
                }
            }
Esempio n. 17
0
 public void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options)
 {
     for (int i = 0; i < server.MaxClients; i++)
     {
         server.SendObject(i, 1);
         server.SendObject(i, answer.Count);
         foreach (var cards in answer)
         {
             server.SendObject(i, cards.Count);
             foreach (Card c in cards)
             {
                 if (verifier.Helper != null && verifier.Helper.RevealCards)
                 {
                     c.RevealOnce = true;
                 }
                 server.SendObject(i, c);
             }
         }
         if (options != null && options.Options != null) server.SendObject(i, options.OptionResult);
         server.Flush(i);
     }
 }
Esempio n. 18
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);
 }
Esempio n. 19
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);
            }
        }
 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;
 }
Esempio n. 21
0
            public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
            {
                Game game = Game.CurrentGame;

                foreach (Player pp in game.Players)
                {
                    game.HandCardVisibility.Add(pp, new List<Player>() { pp });
                }

                int numberOfDefectors = 1;

                // Put the whole deck in the dealing deck
                game.Decks[DeckType.Dealing] = game.CardSet.GetRange(0, game.CardSet.Count);
                var dealdeck = new List<Card>(game.Decks[DeckType.Dealing]);
                foreach (Card card in dealdeck)
                {
                    // We don't want hero cards
                    if (card.Type is HeroCardHandler)
                    {
                        game.Decks[DeckType.Dealing].Remove(card);
                        bool isSPHero = false;
                        if (!game.IsClient) isSPHero = (card.Type as HeroCardHandler).Hero.IsSpecialHero;
                        else isSPHero = card.Id == Card.UnknownSPHeroId;
                        if (isSPHero)
                        {
                            game.Decks[DeckType.SpecialHeroes].Add(card);
                            card.Place = new DeckPlace(null, DeckType.SpecialHeroes);
                        }
                        else
                        {
                            game.Decks[DeckType.Heroes].Add(card);
                            card.Place = new DeckPlace(null, DeckType.Heroes);
                        }

                    }
                    else if (card.Type is RoleCardHandler)
                    {
                        game.Decks[DeckType.Dealing].Remove(card);
                        card.Place = new DeckPlace(null, RoleDeckType);
                    }
                    else
                    {
                        card.Place = new DeckPlace(null, DeckType.Dealing);
                    }
                }
                if (game.Players.Count == 0)
                {
                    return;
                }
                // Await role decision
                int seed = DateTime.Now.Millisecond;
                Trace.TraceError("Seed is {0}", seed);
                Random random = new Random(seed);
                int rulerId = 0;

                game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Ruler));
                Trace.Assert(game.Players.Count > 1);
                Trace.Assert(numberOfDefectors + 1 <= game.Players.Count);
                int t = numberOfDefectors;
                while (t-- > 0)
                {
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Defector));
                }
                int remaining = game.Players.Count - numberOfDefectors;
                int rebel;
                int loyalist;
                if (remaining <= 1)
                {
                    rebel = 0;
                    loyalist = 0;
                }
                else
                {
                    rebel = (int)Math.Ceiling(((double)remaining) / 2);
                    loyalist = remaining - rebel - 1;
                }

                Trace.Assert(rebel + loyalist + numberOfDefectors + 1 == game.Players.Count);
                (game as RoleGame).NumberOfDefectors = numberOfDefectors;
                (game as RoleGame).NumberOfRebels = rebel;

                while (rebel-- > 0)
                {
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Rebel));
                }
                while (loyalist-- > 0)
                {
                    game.Decks[null, RoleDeckType].Add(_FindARoleCard(Role.Loyalist));
                }

                Shuffle(game.Decks[null, RoleDeckType]);

                if (game.IsClient)
                {
                    int count = game.Decks[null, RoleDeckType].Count;
                    game.Decks[null, RoleDeckType].Clear();
                    while (count-- > 0)
                    {
                        Card c = new Card(SuitType.None, 0, new UnknownRoleCardHandler());
                        c.Id = Card.UnknownRoleId;
                        c.Place = new DeckPlace(null, RoleDeckType);
                        game.Decks[null, RoleDeckType].Add(c);
                    }
                    game.SyncImmutableCardAll(game.Decks[null, RoleDeckType][0]);
                }
                else
                {
                    foreach (Card c in game.Decks[null, RoleDeckType])
                    {
                        c.Place = new DeckPlace(null, RoleDeckType);
                        if ((c.Type as RoleCardHandler).Role == Role.Ruler)
                        {
                            game.SyncImmutableCardAll(c);
                        }
                    }
                }

                int i = 0;
                for (i = 0; i < game.Players.Count; i++)
                {
                    game.SyncImmutableCard(game.Players[i], game.Decks[null, RoleDeckType][i]);
                }

                List<CardsMovement> moves = new List<CardsMovement>();
                i = 0;
                foreach (Player p in game.Players)
                {
                    CardsMovement move = new CardsMovement();
                    move.Cards = new List<Card>() { game.Decks[null, RoleDeckType][i] };
                    move.To = new DeckPlace(p, RoleDeckType);
                    moves.Add(move);
                    i++;
                }
                game.MoveCards(moves, null, GameDelayTypes.GameStart);

                i = 0;
                foreach (Player player in game.Players)
                {
                    Card card = game.Decks[player, RoleDeckType][0];
                    var role = card.Type as RoleCardHandler;
                    if (role != null)
                    {
                        if (role.Role == Role.Ruler)
                        {
                            rulerId = i;
                        }
                        player.Role = role.Role;
                    }
                    i++;
                }

                GameDelays.Delay(GameDelayTypes.RoleDistribute);

                game.NotificationProxy.NotifyLogEvent(new LogEvent("HerosInitialization"), new List<Player>());
                if (!game.IsClient) GameDelays.Delay(GameDelayTypes.ServerSideCompensation);

                //hero allocation
                Shuffle(game.Decks[DeckType.Heroes]);
                if (!game.IsClient)
                {
                    foreach (var hero in new List<Card>(game.Decks[DeckType.Heroes]))
                    {
                        foreach (var s in (hero.Type as HeroCardHandler).Hero.Skills)
                        {
                            if (s.IsRulerOnly)
                            {
                                game.Decks[DeckType.Heroes].Remove(hero);
                                game.Decks[DeckType.Heroes].Insert(0, hero);
                            }
                        }
                    }
                }
                int numHeroes = Game.CurrentGame.Settings.DualHeroMode ? 2 : 1;
                List<Card> rulerDraw = new List<Card>();
                int toDraw = 12 + (Game.CurrentGame.Settings.DualHeroMode ? 3 : 0);
                for (int rc = 0; rc < toDraw; rc++)
                {
                    game.SyncImmutableCardAll(game.Decks[DeckType.Heroes][rc]);
                    rulerDraw.Add(game.Decks[DeckType.Heroes][rc]);
                }
                game.SyncImmutableCards(game.Players[rulerId], rulerDraw);
                DeckType tempHero = new DeckType("TempHero");
                game.Decks[null, tempHero].AddRange(rulerDraw);
                Trace.TraceInformation("Ruler is {0}", rulerId);
                game.Players[rulerId].Role = Role.Ruler;
                List<DeckPlace> sourceDecks = new List<DeckPlace>();
                sourceDecks.Add(new DeckPlace(null, tempHero));
                List<string> resultDeckNames = new List<string>();
                resultDeckNames.Add("HeroChoice");
                List<int> resultDeckMaximums = new List<int>();
                resultDeckMaximums.Add(numHeroes);
                List<List<Card>> answer;
                if (!game.UiProxies[game.Players[rulerId]].AskForCardChoice(new CardChoicePrompt("RulerHeroChoice"), sourceDecks, resultDeckNames, resultDeckMaximums, new RequireCardsChoiceVerifier(numHeroes, false, true), out answer))
                {
                    answer = new List<List<Card>>();
                    answer.Add(new List<Card>());
                    answer[0].Add(game.Decks[DeckType.Heroes][0]);
                    if (Game.CurrentGame.Settings.DualHeroMode)
                    {
                        answer[0].Add(game.Decks[DeckType.Heroes][1]);
                    }
                }
                game.SyncImmutableCardAll(answer[0][0]);
                if (Game.CurrentGame.Settings.DualHeroMode)
                {
                    game.SyncImmutableCardAll(answer[0][1]);
                }
                game.Decks[DeckType.Heroes].Remove(answer[0][0]);
                if (Game.CurrentGame.Settings.DualHeroMode)
                {
                    game.Decks[DeckType.Heroes].Remove(answer[0][1]);
                }

                HeroCardHandler h = (HeroCardHandler)answer[0][0].Type;
                Trace.TraceInformation("Assign {0} to player {1}", h.Hero.Name, rulerId);
                Game.CurrentGame.Players[rulerId].Hero = h.Hero;
                Game.CurrentGame.Players[rulerId].Allegiance = h.Hero.Allegiance;
                Game.CurrentGame.Players[rulerId].IsMale = h.Hero.IsMale ? true : false;
                Game.CurrentGame.Players[rulerId].IsFemale = h.Hero.IsMale ? false : true;
                if (Game.CurrentGame.Settings.DualHeroMode)
                {
                    h = (HeroCardHandler)answer[0][1].Type;
                    var hero2 = h.Hero.Clone() as Hero;
                    Trace.TraceInformation("Assign {0} to player {1}", hero2.Name, rulerId);
                    Game.CurrentGame.Players[rulerId].Hero2 = hero2;
                }
                Game.CurrentGame.Players[rulerId].MaxHealth = Game.CurrentGame.Players[rulerId].Health = (game as RoleGame).GetMaxHealth(Game.CurrentGame.Players[rulerId]);

                int optionalHeros = game.Settings.NumHeroPicks;
                toDraw = optionalHeros + (Game.CurrentGame.Settings.DualHeroMode ? Math.Max(6 - optionalHeros, 0) : 0);
                Shuffle(game.Decks[DeckType.Heroes]);
                Dictionary<Player, List<Card>> restDraw = new Dictionary<Player, List<Card>>();
                List<Player> players = new List<Player>(game.Players);
                players.Remove(game.Players[rulerId]);
                int idx = 0;
                foreach (Player p in players)
                {
                    restDraw.Add(p, new List<Card>());
                    for (int n = 0; n < toDraw; n++)
                    {
                        game.SyncImmutableCard(p, game.Decks[DeckType.Heroes][idx]);
                        restDraw[p].Add(game.Decks[DeckType.Heroes][idx]);
                        idx++;
                    }
                }

                var heroSelection = new Dictionary<Player, List<Card>>();
                game.GlobalProxy.AskForHeroChoice(restDraw, heroSelection, numHeroes, new RequireCardsChoiceVerifier(numHeroes));

                bool notUsed = true;
                game.SyncConfirmationStatus(ref notUsed);

                List<Card> toRemove = new List<Card>();
                for (int repeat = 0; repeat < 2; repeat++)
                {
                    if (repeat == 1 && !Game.CurrentGame.Settings.DualHeroMode) break;
                    foreach (Player p in players)
                    {
                        Card c;
                        //only server has the result
                        if (!game.IsClient)
                        {
                            idx = repeat;
                            if (heroSelection.ContainsKey(p))
                            {
                                c = heroSelection[p][repeat];
                                idx = restDraw[p].IndexOf(c);
                            }
                            else
                            {
                                c = restDraw[p][idx];
                            }
                            foreach (Player player in game.Players)
                            {
                                game.GameServer.SendObject(player.Id, idx);
                            }
                            game.GameServer.SendObject(game.Players.Count, idx);
                        }
                        // you are client
                        else
                        {
                            idx = (int)game.GameClient.Receive();
                            c = restDraw[p][idx];
                        }
                        game.SyncImmutableCardAll(c);
                        toRemove.Add(c);
                        h = (HeroCardHandler)c.Type;
                        Trace.TraceInformation("Assign {0} to player {1}", h.Hero.Name, p.Id);
                        var hero = h.Hero.Clone() as Hero;
                        foreach (var skill in new List<ISkill>(hero.Skills))
                        {
                            if (skill.IsRulerOnly)
                            {
                                hero.Skills.Remove(skill);
                            }
                        }
                        if (repeat == 1) p.Hero2 = hero;
                        else p.Hero = hero;
                        if (repeat == 0) p.Allegiance = hero.Allegiance;
                        if (repeat == 0)
                        {
                            p.MaxHealth = p.Health = hero.MaxHealth;
                            p.IsMale = hero.IsMale ? true : false;
                            p.IsFemale = hero.IsMale ? false : true;
                        }
                        if (repeat == 1)
                        {
                            int aveHp = (p.Hero2.MaxHealth + p.Hero.MaxHealth) / 2;
                            p.MaxHealth = p.Health = aveHp;
                        }

                    }
                }
                foreach (var card in toRemove)
                {
                    game.Decks[DeckType.Heroes].Remove(card);
                }

                if (game.IsClient)
                {
                    foreach (var card in game.Decks[DeckType.Heroes])
                    {
                        card.Type = new UnknownHeroCardHandler();
                        card.Id = Card.UnknownHeroId;
                    }
                }
                Shuffle(game.Decks[DeckType.Heroes]);

                foreach (var pxy in game.UiProxies)
                {
                    pxy.Value.Freeze();
                }

                //Heroes Convert and handle god hero
                var toCheck = new List<Player>(game.Players);
                game.SortByOrderOfComputation(game.Players[rulerId], toCheck);
                Dictionary<string, List<Card>> convertibleHeroes = new Dictionary<string, List<Card>>();
                game.SyncImmutableCardsAll(game.Decks[DeckType.SpecialHeroes]);
                foreach (Card card in game.Decks[DeckType.SpecialHeroes])
                {
                    var hero = (card.Type as HeroCardHandler).Hero.HeroConvertFrom;
                    if (!convertibleHeroes.Keys.Contains(hero)) convertibleHeroes[hero] = new List<Card>();
                    convertibleHeroes[hero].Add(card);
                }
                foreach (var p in toCheck)
                {
                    bool changeHero = false;
                    for (int heroIndex = 0; heroIndex < 2; heroIndex++)
                    {
                        if (heroIndex == 1 && !Game.CurrentGame.Settings.DualHeroMode) break;
                        Hero playerHero = heroIndex == 0 ? p.Hero : p.Hero2;
                        if (convertibleHeroes.Keys.Contains(playerHero.Name))
                        {
                            DeckType tempSpHeroes = new DeckType("tempSpHeroes");
                            DeckPlace heroesConvert = new DeckPlace(p, tempSpHeroes);
                            game.Decks[heroesConvert].AddRange(convertibleHeroes[playerHero.Name]);
                            List<List<Card>> choice;
                            AdditionalCardChoiceOptions options = new AdditionalCardChoiceOptions();
                            options.IsCancellable = true;
                            if (p.AskForCardChoice(new CardChoicePrompt("HeroesConvert", p),
                                new List<DeckPlace>() { heroesConvert },
                                new List<string>() { "convert" },
                                new List<int>() { 1 },
                                new RequireOneCardChoiceVerifier(false, true),
                                out choice,
                                options))
                            {
                                foreach (var sk in playerHero.Skills)
                                {
                                    sk.Owner = null;
                                }
                                Hero hero = ((choice[0][0].Type as HeroCardHandler).Hero.Clone()) as Hero;
                                foreach (var skill in new List<ISkill>(hero.Skills))
                                {
                                    if (skill.IsRulerOnly && (p.Role != Role.Ruler || heroIndex == 1))
                                    {
                                        hero.Skills.Remove(skill);
                                    }
                                }
                                if (heroIndex == 0)
                                {
                                    p.Hero = hero;
                                    p.Allegiance = hero.Allegiance;
                                    p.IsMale = hero.IsMale ? true : false;
                                    p.IsFemale = hero.IsMale ? false : true;
                                }
                                else p.Hero2 = hero;
                                changeHero = true;
                                game.Emit(GameEvent.PlayerChangedHero, new GameEventArgs() { Source = p });
                            }
                            game.Decks[heroesConvert].Clear();
                        }
                    }
                    if (changeHero) p.MaxHealth = p.Health = (game as RoleGame).GetMaxHealth(p);
                    Game.CurrentGame.HandleGodHero(p);
                }

                Shuffle(game.Decks[null, DeckType.Dealing]);

                Player current = game.CurrentPlayer = game.Players[rulerId];

                GameDelays.Delay(GameDelayTypes.GameBeforeStart);
                StartGameDeal(game);

                Game.CurrentGame.NotificationProxy.NotifyGameStart();
                GameDelays.Delay(GameDelayTypes.GameStart);
                GameDelays.Delay(GameDelayTypes.GameStart);

                foreach (var act in game.AlivePlayers)
                {
                    game.Emit(GameEvent.PlayerGameStartAction, new GameEventArgs() { Source = act });
                }

                while (true)
                {
                    GameEventArgs args = new GameEventArgs();
                    args.Source = current;
                    game.CurrentPhaseEventIndex = 0;
                    game.CurrentPhase = TurnPhase.BeforeStart;
                    game.CurrentPlayer = current;
                    game.Emit(GameEvent.DoPlayer, args);
                    current = game.NextAlivePlayer(current);
                }
            }
Esempio n. 22
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 void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options)
 {
     for (int i = 0; i < server.MaxClients; i++)
     {
         int j = 0;
         if (answer != null)
         {
             foreach (var cards in answer)
             {
                 foreach (Card c in cards)
                 {
                     if (verifier.Helper != null && (verifier.Helper.RevealCards || (verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy != null && verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy[j])))
                     {
                         if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools)
                         {
                             c.RevealOnce = true;
                         }
                     }
                 }
                 j++;
             }
         }
         server.SendPacket(i, AskForCardChoiceResponse.Parse(proxy.QuestionId, answer, options == null? 0 : options.OptionResult, i));
     }
 }
Esempio n. 24
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 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;
        }
Esempio n. 26
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;
                    }
                }
            });
        }
Esempio n. 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;
 }
Esempio n. 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;
        }
Esempio n. 29
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();
 }
Esempio n. 30
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);
 }