Beispiel #1
0
        public void ForcePlayerDiscard(Player player, NumberOfCardsToForcePlayerDiscard numberOfCards, bool canDiscardEquipment, bool atOnce = true)
        {
            if (player.IsDead)
            {
                return;
            }
            Trace.TraceInformation("Player {0} discard.", player);
            int cannotBeDiscarded      = 0;
            int numberOfCardsDiscarded = 0;

            while (true)
            {
                int handCardCount  = Decks[player, DeckType.Hand].Count;      // 玩家手牌数
                int equipCardCount = Decks[player, DeckType.Equipment].Count; // 玩家装备牌数
                int toDiscard      = numberOfCards(player, numberOfCardsDiscarded);
                // Have we finished discarding everything?
                // We finish if
                //      玩家手牌数 小于等于 我们要强制弃掉的数目
                //  或者玩家手牌数 (小于)等于 不可弃的牌的数目(此时装备若可弃,必须弃光)
                if (toDiscard == 0 || (handCardCount <= cannotBeDiscarded && (!canDiscardEquipment || equipCardCount == 0)))
                {
                    break;
                }
                Trace.Assert(UiProxies.ContainsKey(player));
                IPlayerProxy  proxy = UiProxies[player];
                ISkill        skill;
                List <Card>   cards;
                List <Player> players;
                cannotBeDiscarded = 0;
                foreach (Card c in Decks[player, DeckType.Hand])
                {
                    if (!PlayerCanDiscardCard(player, c))
                    {
                        cannotBeDiscarded++;
                    }
                }
                //如果玩家无法达到弃牌要求 则 摊牌
                bool status = cannotBeDiscarded == 0 || ((canDiscardEquipment ? equipCardCount : 0) + handCardCount - toDiscard >= cannotBeDiscarded);
                SyncConfirmationStatus(ref status);
                if (!status)
                {
                    SyncImmutableCardsAll(Decks[player, DeckType.Hand]);
                    ShowHandCards(player, Decks[player, DeckType.Hand]);
                    if (Game.CurrentGame.IsClient)
                    {
                        //刷新所有客户端该玩家不可弃掉的牌的数目
                        cannotBeDiscarded = 0;
                        foreach (Card c in Decks[player, DeckType.Hand])
                        {
                            if (!PlayerCanDiscardCard(player, c))
                            {
                                cannotBeDiscarded++;
                            }
                        }
                    }
                }
                int minimum;
                if (!atOnce)
                {
                    minimum = 1;
                }
                else
                {
                    minimum = status ? toDiscard : (canDiscardEquipment ? equipCardCount : 0) + handCardCount - cannotBeDiscarded;
                }
                PlayerForceDiscardVerifier v = new PlayerForceDiscardVerifier(toDiscard, canDiscardEquipment, minimum);
                if (!proxy.AskForCardUsage(new Prompt(Prompt.DiscardPhasePrompt, toDiscard),
                                           v, out skill, out cards, out players))
                {
                    //玩家没有回应(default)
                    Trace.TraceInformation("Invalid answer, choosing for you");
                    cards = new List <Card>();
                    int cardsDiscarded = 0;
                    var chooseFrom     = new List <Card>(Decks[player, DeckType.Hand]);
                    if (canDiscardEquipment)
                    {
                        chooseFrom.AddRange(Decks[player, DeckType.Equipment]);
                    }
                    foreach (Card c in chooseFrom)
                    {
                        if (PlayerCanDiscardCard(player, c))
                        {
                            cards.Add(c);
                            cardsDiscarded++;
                        }
                        if (cardsDiscarded == toDiscard)
                        {
                            SyncCardsAll(cards);
                            break;
                        }
                    }
                }
                numberOfCardsDiscarded += cards.Count;
                if (cards.Count != 0)
                {
                    HandleCardDiscard(player, cards);
                }
            }
        }
Beispiel #2
0
        public void ForcePlayerDiscard(Player player, NumberOfCardsToForcePlayerDiscard numberOfCards, bool canDiscardEquipment)
        {
            Trace.TraceInformation("Player {0} discard.", player);
            int cannotBeDiscarded = 0;
            int numberOfCardsDiscarded = 0;
            while (true)
            {
                int handCardCount = Game.CurrentGame.Decks[player, DeckType.Hand].Count; // 玩家手牌数
                int equipCardCount = Game.CurrentGame.Decks[player, DeckType.Equipment].Count; // 玩家装备牌数
                int toDiscard = numberOfCards(player, numberOfCardsDiscarded);
                // Have we finished discarding everything?
                // We finish if
                //      玩家手牌数 小于等于 我们要强制弃掉的数目
                //  或者玩家手牌数 (小于)等于 不可弃的牌的数目(此时装备若可弃,必须弃光)
                if (toDiscard == 0 || (handCardCount <= cannotBeDiscarded && (!canDiscardEquipment || equipCardCount == 0)))
                {
                    break;
                }
                Trace.Assert(Game.CurrentGame.UiProxies.ContainsKey(player));
                IUiProxy proxy = Game.CurrentGame.UiProxies[player];
                ISkill skill;
                List<Card> cards;
                List<Player> players;
                PlayerForceDiscardVerifier v = new PlayerForceDiscardVerifier(toDiscard, canDiscardEquipment);
                cannotBeDiscarded = 0;
                foreach (Card c in Game.CurrentGame.Decks[player, DeckType.Hand])
                {
                    if (!Game.CurrentGame.PlayerCanDiscardCard(player, c))
                    {
                        cannotBeDiscarded++;
                    }
                }
                //如果玩家无法达到弃牌要求 则 摊牌
                bool status = (canDiscardEquipment ? equipCardCount : 0) + handCardCount - toDiscard >= cannotBeDiscarded;
                Game.CurrentGame.SyncConfirmationStatus(ref status);
                if (!status)
                {
                    Game.CurrentGame.SyncImmutableCardsAll(Game.CurrentGame.Decks[player, DeckType.Hand]);
                }

                if (!proxy.AskForCardUsage(new Prompt(Prompt.DiscardPhasePrompt, toDiscard),
                                           v, out skill, out cards, out players))
                {
                    //玩家没有回应(default)
                    //如果玩家有不可弃掉的牌(这个只有服务器知道) 则通知所有客户端该玩家手牌
                    status = (cannotBeDiscarded == 0);
                    Game.CurrentGame.SyncConfirmationStatus(ref status);
                    if (!status)
                    {
                        Game.CurrentGame.SyncImmutableCardsAll(Game.CurrentGame.Decks[player, DeckType.Hand]);
                    }
                    cannotBeDiscarded = 0;
                    foreach (Card c in Game.CurrentGame.Decks[player, DeckType.Hand])
                    {
                        if (!Game.CurrentGame.PlayerCanDiscardCard(player, c))
                        {
                            cannotBeDiscarded++;
                        }
                    }

                    Trace.TraceInformation("Invalid answer, choosing for you");
                    cards = new List<Card>();
                    int cardsDiscarded = 0;
                    var chooseFrom = new List<Card>(Game.CurrentGame.Decks[player, DeckType.Hand]);
                    if (canDiscardEquipment)
                    {
                        chooseFrom.AddRange(Game.CurrentGame.Decks[player, DeckType.Equipment]);
                    }
                    foreach (Card c in chooseFrom)
                    {
                        if (Game.CurrentGame.PlayerCanDiscardCard(player, c))
                        {
                            cards.Add(c);
                            cardsDiscarded++;
                        }
                        if (cardsDiscarded == toDiscard)
                        {
                            SyncCardsAll(cards);
                            break;
                        }
                    }
                }
                numberOfCardsDiscarded += cards.Count;
                Game.CurrentGame.HandleCardDiscard(player, cards);
            }
        }
Beispiel #3
0
 public void ForcePlayerDiscard(Player player, NumberOfCardsToForcePlayerDiscard numberOfCards, bool canDiscardEquipment, bool atOnce = true)
 {
     if (player.IsDead) return;
     Trace.TraceInformation("Player {0} discard.", player);
     int cannotBeDiscarded = 0;
     int numberOfCardsDiscarded = 0;
     while (true)
     {
         int handCardCount = Decks[player, DeckType.Hand].Count; // 玩家手牌数
         int equipCardCount = Decks[player, DeckType.Equipment].Count; // 玩家装备牌数
         int toDiscard = numberOfCards(player, numberOfCardsDiscarded);
         // Have we finished discarding everything?
         // We finish if
         //      玩家手牌数 小于等于 我们要强制弃掉的数目
         //  或者玩家手牌数 (小于)等于 不可弃的牌的数目(此时装备若可弃,必须弃光)
         if (toDiscard == 0 || (handCardCount <= cannotBeDiscarded && (!canDiscardEquipment || equipCardCount == 0)))
         {
             break;
         }
         Trace.Assert(UiProxies.ContainsKey(player));
         IPlayerProxy proxy = UiProxies[player];
         ISkill skill;
         List<Card> cards;
         List<Player> players;
         cannotBeDiscarded = 0;
         foreach (Card c in Decks[player, DeckType.Hand])
         {
             if (!PlayerCanDiscardCard(player, c))
             {
                 cannotBeDiscarded++;
             }
         }
         //如果玩家无法达到弃牌要求 则 摊牌
         bool status = cannotBeDiscarded == 0 || ((canDiscardEquipment ? equipCardCount : 0) + handCardCount - toDiscard >= cannotBeDiscarded);
         SyncConfirmationStatus(ref status);
         if (!status)
         {
             SyncImmutableCardsAll(Decks[player, DeckType.Hand]);
             ShowHandCards(player, Decks[player, DeckType.Hand]);
             if (Game.CurrentGame.IsClient)
             {
                 //刷新所有客户端该玩家不可弃掉的牌的数目
                 cannotBeDiscarded = 0;
                 foreach (Card c in Decks[player, DeckType.Hand])
                 {
                     if (!PlayerCanDiscardCard(player, c))
                     {
                         cannotBeDiscarded++;
                     }
                 }
             }
         }
         int minimum;
         if (!atOnce) minimum = 1;
         else minimum = status ? toDiscard : (canDiscardEquipment ? equipCardCount : 0) + handCardCount - cannotBeDiscarded;
         PlayerForceDiscardVerifier v = new PlayerForceDiscardVerifier(toDiscard, canDiscardEquipment, minimum);
         if (!proxy.AskForCardUsage(new Prompt(Prompt.DiscardPhasePrompt, toDiscard),
                                    v, out skill, out cards, out players))
         {
             //玩家没有回应(default)
             Trace.TraceInformation("Invalid answer, choosing for you");
             cards = new List<Card>();
             int cardsDiscarded = 0;
             var chooseFrom = new List<Card>(Decks[player, DeckType.Hand]);
             if (canDiscardEquipment)
             {
                 chooseFrom.AddRange(Decks[player, DeckType.Equipment]);
             }
             foreach (Card c in chooseFrom)
             {
                 if (PlayerCanDiscardCard(player, c))
                 {
                     cards.Add(c);
                     cardsDiscarded++;
                 }
                 if (cardsDiscarded == toDiscard)
                 {
                     SyncCardsAll(cards);
                     break;
                 }
             }
         }
         numberOfCardsDiscarded += cards.Count;
         if (cards.Count != 0)
         {
             HandleCardDiscard(player, cards);
         }
     }
 }