예제 #1
0
        public override void Use(Room room, CardUseStruct card_use)
        {
            Player player = card_use.From;
            Player target = card_use.To[0];

            if (target.Alive && !target.IsKongcheng() && RoomLogic.CanGetCard(room, player, target, "h"))
            {
                target.SetFlags("daoshu_target");
                string suit = room.AskForChoice(player, "daoshu", string.Join("+", suits));
                target.SetFlags("-daoshu_target");

                int id = room.AskForCardChosen(player, target, "h", "daoshu", false, HandlingMethod.MethodGet);
                room.ObtainCard(player, id);

                if (WrappedCard.GetSuitString(room.GetCard(id).Suit) == suit)
                {
                    room.Damage(new DamageStruct("daoshu", player, target));
                }
                else
                {
                    suit = WrappedCard.GetSuitString(room.GetCard(id).Suit);
                    player.SetFlags("daoshu");
                    List <int>     ids    = new List <int>();
                    CardMoveReason reason = new CardMoveReason(CardMoveReason.MoveReason.S_REASON_GIVE, player.Name, target.Name, "daoshu", string.Empty);
                    foreach (int card_id in player.GetCards("h"))
                    {
                        if (WrappedCard.GetSuitString(room.GetCard(card_id).Suit) != suit)
                        {
                            ids.Add(card_id);
                        }
                    }

                    if (ids.Count == 0)
                    {
                        room.ShowAllCards(player, null, "daoshu");
                    }
                    else if (ids.Count == 1)
                    {
                        room.ObtainCard(target, ref ids, reason, true);
                    }
                    else
                    {
                        List <int> to_give = room.AskForExchange(player, "daoshu", 1, 1, "@daoshu-give:" + target.Name, string.Empty, string.Format(".|^{0}|.|hand", suit), card_use.Card.SkillPosition);
                        if (to_give.Count == 1)
                        {
                            room.ObtainCard(target, ref to_give, reason, true);
                        }
                        else
                        {
                            List <int> give = new List <int> {
                                ids[0]
                            };
                            room.ObtainCard(target, ref give, reason, true);
                        }
                    }
                }
            }
        }
        public override string OnChoice(TrustedAI ai, Player player, string choice, object data)
        {
            Player target = null;
            Room   room   = ai.Room;

            foreach (Player p in room.GetOtherPlayers(player))
            {
                if (p.HasFlag("daoshu_target"))
                {
                    target = p;
                    break;
                }
            }

            List <int>    ids   = ai.GetKnownCards(target);
            List <string> suits = new List <string>(this.suits);

            if (ids.Count > 0)
            {
                Dictionary <string, int> pairs = new Dictionary <string, int>();
                foreach (string suit in suits)
                {
                    pairs[suit] = 0;
                }
                foreach (int id in ids)
                {
                    string suit = WrappedCard.GetSuitString(Engine.GetRealCard(id).Suit);
                    pairs[suit]++;
                }

                suits.Sort((x, y) => { return(pairs[x] > pairs[y] ? -1: 1); });
                return(suits[0]);
            }
            else
            {
                Shuffle.shuffle(ref suits);
                return(suits[0]);
            }
        }
예제 #3
0
        // '|' means 'and', '#' means 'or'.
        // the expression splited by '|' has 3 parts,
        // 1st part means the card name, and ',' means more than one options.
        // 2nd patt means the card suit, and ',' means more than one options.
        // 3rd part means the card number, and ',' means more than one options,
        // the number uses '~' to make a scale for valid expressions
        #endregion

        private bool MatchOne(Player player, Room room, WrappedCard card, string exp)
        {
            if (card == null && exp != ".")
            {
                return(false);
            }
            string[] factors = exp.Split('|');

            bool checkpoint = false;

            string[] card_types = factors[0].Split(',');
            foreach (string or_name in card_types)
            {
                checkpoint = false;
                foreach (string _name in or_name.Split('+'))
                {
                    string name = _name;
                    if (name == ".")
                    {
                        checkpoint = true;
                    }
                    else
                    {
                        bool positive = true;
                        if (name.StartsWith("^"))
                        {
                            positive = false;
                            name     = name.Substring(1);
                        }
                        //国战鏖战模式对桃特殊判断

                        bool name_match = false;
                        if (room.BloodBattle && card.Name == Peach.ClassName && !card.IsVirtualCard())
                        {
                            if (positive && (name == Slash.ClassName || name == "%Slash" || name == Jink.ClassName || name == "%Jink"))
                            {
                                name_match = true;
                            }
                            else if (positive && (name == Peach.ClassName || name == "%Peach"))
                            {
                                name_match = false;
                            }
                            else
                            {
                                name_match = Engine.GetFunctionCard(card.Name)?.IsKindOf(name) == true || ("%" + card.Name == name);
                            }
                        }
                        else
                        {
                            name_match = Engine.GetFunctionCard(card.Name)?.IsKindOf(name) == true || ("%" + card.Name == name);
                        }

                        if (name_match || (int.TryParse(name, out int id) && card.GetEffectiveId() == id))
                        {
                            checkpoint = positive;
                        }
                        else
                        {
                            checkpoint = !positive;
                        }
                    }
                    if (!checkpoint)
                    {
                        break;
                    }
                }
                if (checkpoint)
                {
                    break;
                }
            }
            if (!checkpoint)
            {
                return(false);
            }
            if (factors.Length < 2)
            {
                return(true);
            }

            checkpoint = false;
            string[] card_suits = factors[1].Split(',');
            foreach (string _suit in card_suits)
            {
                string suit = _suit;
                if (suit == ".")
                {
                    checkpoint = true;
                    break;
                }
                bool positive = true;
                if (suit.StartsWith("^"))
                {
                    positive = false;
                    suit     = suit.Substring(1);
                }
                checkpoint = WrappedCard.GetSuitString(RoomLogic.GetCardSuit(room, card)) == suit ||
                             (WrappedCard.IsBlack(RoomLogic.GetCardSuit(room, card)) && suit == "black") ||
                             (WrappedCard.IsRed(RoomLogic.GetCardSuit(room, card)) && suit == "red")
                    ? positive
                    : !positive;
                if (checkpoint)
                {
                    break;
                }
            }
            if (!checkpoint)
            {
                return(false);
            }
            if (factors.Length < 3)
            {
                return(true);
            }

            checkpoint = false;
            string[] card_numbers = factors[2].Split(',');
            int      cdn          = RoomLogic.GetCardNumber(room, card);

            foreach (string number in card_numbers)
            {
                if (number == ".")
                {
                    checkpoint = true;
                    break;
                }

                if (number.Contains('~'))
                {
                    string[] num_params = number.Split('~');
                    int      from, to;
                    if (num_params[0].Length == 0)
                    {
                        from = 1;
                    }
                    else
                    {
                        from = int.Parse(num_params[0]);
                    }
                    if (num_params.Length == 1 && num_params[1].Length == 0)
                    {
                        to = 13;
                    }
                    else
                    {
                        to = int.Parse(num_params[1]);
                    }

                    if (from <= cdn && cdn <= to)
                    {
                        checkpoint = true;
                    }
                }
                else if (int.TryParse(number, out int id) && id == cdn)
                {
                    checkpoint = true;
                }
                else if ((number == "A" && cdn == 1) ||
                         (number == "J" && cdn == 11) ||
                         (number == "Q" && cdn == 12) ||
                         (number == "K" && cdn == 13))
                {
                    checkpoint = true;
                }
                if (checkpoint)
                {
                    break;
                }
            }
            if (!checkpoint)
            {
                return(false);
            }
            if (factors.Length < 4)
            {
                return(true);
            }

            checkpoint = false;
            string place = factors[3];

            if (player == null || place == ".")
            {
                checkpoint = true;
            }
            if (!checkpoint)
            {
                List <int> ids = new List <int>(card.SubCards);
                if (ids.Count > 0)
                {
                    foreach (int id in ids)
                    {
                        checkpoint = false;
                        WrappedCard sub_card = room.GetCard(id);
                        foreach (string _p in place.Split(','))
                        {
                            string p = _p;
                            if (p == "equipped" && player.HasEquip(sub_card.Name))
                            {
                                checkpoint = true;
                            }
                            else if (p == "hand" && sub_card.Id >= 0)
                            {
                                foreach (int h_id in player.GetCards("h"))
                                {
                                    if (h_id == id)
                                    {
                                        checkpoint = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                if (p.Contains('$'))
                                {
                                    p = p.Replace('$', '#');
                                }
                                if (p.StartsWith("%"))
                                {
                                    p = p.Substring(1);
                                    foreach (Player pl in room.GetAlivePlayers())
                                    {
                                        if (pl.GetPile(p).Count > 0 && pl.GetPile(p).Contains(id))
                                        {
                                            checkpoint = true;
                                            break;
                                        }
                                    }
                                }
                                else if (player.GetPile(p).Count > 0 && player.GetPile(p).Contains(id))
                                {
                                    checkpoint = true;
                                }
                            }
                            if (checkpoint)
                            {
                                break;
                            }
                        }
                        if (!checkpoint)
                        {
                            break;
                        }
                    }
                }
            }
            return(checkpoint);
        }