public override void Use(TrustedAI ai, Player player, ref CardUseStruct use, WrappedCard card)
        {
            Room   room   = ai.Room;
            Player target = null;

            foreach (Player p in room.GetOtherPlayers(player))
            {
                if (ai.HasSkill("wendao", p))
                {
                    target = p;
                    break;
                }
            }

            bool will_use = true;

            if (target != null && !ai.IsFriend(target, player))
            {
                will_use = false;
                if (ai.GetOverflow(player) > 0 && room.GetCardPlace(card.GetEffectiveId()) == Player.Place.PlaceHand && room.GetCardOwner(card.GetEffectiveId()) == player)
                {
                    will_use = true;
                }
            }

            if (will_use)
            {
                ai.UseEquipCard(ref use, card);
            }
        }
Example #2
0
        public override double CardValue(TrustedAI ai, Player player, WrappedCard card, bool isUse, Player.Place place)
        {
            if (ai.HasSkill(Name) && ai.IsSituationClear())
            {
                FunctionCard fcard = Engine.GetFunctionCard(card.Name);
                if (fcard is DefensiveHorse || fcard is SpecialEquip)
                {
                    return(-2);
                }
            }

            if (!isUse && card.GetEffectiveId() >= 0 && ai.IsCard(card.GetEffectiveId(), Slash.ClassName, player))
            {
                Player jiangwei = ai.FindPlayerBySkill(Name);
                if (jiangwei != null && !ai.IsFriend(jiangwei, player) && RoomLogic.CanSlash(ai.Room, player, jiangwei))
                {
                    return(2);
                }
            }

            return(0);
        }
Example #3
0
        public virtual void OnCardAnnounce(Room room, CardUseStruct use, bool ignore_rule)
        {
            if (use.EffectCount == null)
            {
                use.EffectCount = new List <EffctCount>();
            }
            use.Card = RoomLogic.ParseUseCard(room, use.Card);
            room.ShowSkill(use.From, use.Card.ShowSkill, use.Card.SkillPosition);

            if (!ignore_rule)
            {
                CheckTargetModSkillShow(room, use);
            }

            WrappedCard use_card = use.Card;

            //将卡牌转化为延时锦囊就相当于改写了该牌的牌名,必须对其重写以保证此延时锦囊将来可以正确生效
            if (Engine.GetFunctionCard(use_card.Name) is DelayedTrick && RoomLogic.IsVirtualCard(room, use_card) && use_card.SubCards.Count == 1)
            {
                WrappedCard wrapped = room.GetCard(use_card.GetEffectiveId());
                wrapped.TakeOver(use_card);
                use.Card = wrapped;
            }

            //record big or small for fighttogether
            if (Engine.GetFunctionCard(use_card.Name) is FightTogether && use.To.Count > 0)
            {
                List <string> big_kingdoms = RoomLogic.GetBigKingdoms(room);
                if (big_kingdoms.Count > 0)
                {
                    string target_kingdom = (use.To[0].HasShownOneGeneral() ?
                                             (use.To[0].Role == "careerist" ? use.To[0].Name : use.To[0].Kingdom) : string.Empty);
                    bool big = big_kingdoms.Contains(target_kingdom);
                    if (big)
                    {
                        use.Pattern = "big";
                    }
                    else
                    {
                        use.Pattern = "small";
                    }
                }
                else
                {
                    use.Pattern = "unknown";
                }
            }

            OnUse(room, use);
        }
        public override double CardValue(TrustedAI ai, Player player, bool use, WrappedCard card, Player.Place place)
        {
            Room   room  = ai.Room;
            double value = 0;

            if (!use && ai.HasSkill("zhangwu", player))
            {
                value -= 2;
            }
            else
            {
                Player target = null;
                foreach (Player p in room.GetOtherPlayers(player))
                {
                    if (ai.HasSkill("zhangwu", p))
                    {
                        target = p;
                        break;
                    }
                }

                if (target != null)
                {
                    if (ai.IsFriend(target, player))
                    {
                        if (use && room.GetCardOwner(card.GetEffectiveId()) == player && !player.GetWeapon())
                        {
                            value += 2;
                        }
                        else
                        {
                            value -= 7;
                        }
                    }
                    else
                    {
                        if (!ai.HasSkill(TrustedAI.LoseEquipSkill, player) || !use)
                        {
                            value -= 6;
                        }
                    }
                }
            }

            return(value);
        }
Example #5
0
        public override double UseValueAdjust(TrustedAI ai, Player player, List <Player> targets, WrappedCard card)
        {
            Room room = ai.Room;

            if (ai.HasSkill("nuzhan", player) && targets.Count > 0)
            {
                WrappedCard  wrapped = room.GetCard(card.GetEffectiveId());
                FunctionCard fcard   = Engine.GetFunctionCard(wrapped.Name);
                if (fcard is TrickCard)
                {
                    return(2);
                }
                if (fcard is EquipCard)
                {
                    return(1.5);
                }
            }
            else if (targets.Count > 0)
            {
                return(0);
            }

            return(-1);
        }
Example #6
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);
        }
Example #7
0
        public override void Use(Room room, CardUseStruct card_use)
        {
            WrappedCard card = card_use.Card;

            if (card_use.To.Count == 0)
            {
                CardMoveReason reason = new CardMoveReason(CardMoveReason.MoveReason.S_REASON_USE, card_use.From.Name, null, card.Skill, null)
                {
                    CardString = RoomLogic.CardToString(room, card_use.Card)
                };
                room.MoveCardTo(card, room.GetCardOwner(card.GetEffectiveId()), null, Place.DiscardPile, reason, true);
            }

            if (room.GetCardIdsOnTable(card).Count == 0)
            {
                return;
            }

            int    equipped_id = -1;
            Player target      = card_use.To[0];

            if (target.HasEquip((int)EquipLocation()))
            {
                equipped_id = target.GetEquip((int)EquipLocation());
            }

            List <CardsMoveStruct> exchangeMove = new List <CardsMoveStruct> {
            };
            CardsMoveStruct move1 = new CardsMoveStruct(card.GetEffectiveId(), target, Place.PlaceEquip,
                                                        new CardMoveReason(CardMoveReason.MoveReason.S_REASON_USE, target.Name));

            move1.Reason.CardString = RoomLogic.CardToString(room, card_use.Card);
            exchangeMove.Add(move1);
            if (equipped_id != -1)
            {
                CardsMoveStruct move2 = new CardsMoveStruct(equipped_id, target, Place.PlaceTable,
                                                            new CardMoveReason(CardMoveReason.MoveReason.S_REASON_CHANGE_EQUIP, target.Name));
                exchangeMove.Add(move2);
            }
            room.MoveCardsAtomic(exchangeMove, true);

            LogMessage log = new LogMessage
            {
                From     = target.Name,
                Type     = "$Install",
                Card_str = card.GetEffectiveId().ToString()
            };

            room.SendLog(log);

            if (equipped_id != -1)
            {
                if (room.GetCardPlace(equipped_id) == Place.PlaceTable)
                {
                    CardsMoveStruct move3 = new CardsMoveStruct(equipped_id, null, Place.DiscardPile,
                                                                new CardMoveReason(CardMoveReason.MoveReason.S_REASON_CHANGE_EQUIP, target.Name));
                    room.MoveCardsAtomic(new List <CardsMoveStruct> {
                        move3
                    }, true);
                }
            }
        }
Example #8
0
        public override void OnNullified(Room room, Player target, WrappedCard card)
        {
            RoomThread thread = room.RoomThread;

            string card_str = RoomLogic.CardToString(room, card);
            bool   move     = false;
            Player p        = null;

            if (movable)
            {
                List <Player> players       = new List <Player>();
                List <Player> count_players = new List <Player>(room.Players);
                Player        starter       = target;
                int           index         = count_players.IndexOf(starter);
                for (int i = index + 1; i < count_players.Count; i++)
                {
                    if (count_players[i].Alive)
                    {
                        players.Add(count_players[i]);
                    }
                }

                for (int i = 0; i <= index; i++)
                {
                    if (count_players[i].Alive)
                    {
                        players.Add(count_players[i]);
                    }
                }

                foreach (Player player in players)
                {
                    if (RoomLogic.PlayerContainsTrick(room, player, Name))
                    {
                        continue;
                    }

                    Skill skill = RoomLogic.IsProhibited(room, null, player, card);
                    if (skill != null)
                    {
                        skill = Engine.GetMainSkill(skill.Name);
                        LogMessage log = new LogMessage
                        {
                            Type = "#SkillAvoid",
                            From = player.Name,
                            Arg  = skill.Name,
                            Arg2 = Name
                        };
                        room.SendLog(log);

                        room.BroadcastSkillInvoke(skill.Name, player);
                        continue;
                    }
                    if (player.HasFlag(card_str + "_delay_trick_cancel"))
                    {
                        continue;
                    }

                    CardUseStruct use  = new CardUseStruct(room.GetCard(card.GetEffectiveId()), null, player);
                    object        data = use;
                    thread.Trigger(TriggerEvent.TargetConfirming, room, player, ref data);
                    CardUseStruct new_use = (CardUseStruct)data;
                    if (new_use.To.Count == 0)
                    {
                        p = player;
                        player.SetFlags(card_str + "_delay_trick_cancel");
                        break;
                    }

                    CardMoveReason reason = new CardMoveReason(CardMoveReason.MoveReason.S_REASON_TRANSFER, string.Empty)
                    {
                        CardString = RoomLogic.CardToString(room, card)
                    };
                    room.MoveCardTo(card, null, player, Place.PlaceDelayedTrick, reason, true);
                    move = true;

                    foreach (Player p2 in room.GetAllPlayers())
                    {
                        thread.Trigger(TriggerEvent.TargetChosen, room, p2, ref data);
                    }
                    foreach (Player p2 in room.GetAllPlayers())
                    {
                        thread.Trigger(TriggerEvent.TargetConfirmed, room, p2, ref data);
                    }
                    break;
                }
            }

            if (p != null)
            {
                OnNullified(room, p, card);
            }
            else if (!move)
            {
                foreach (Player player in room.GetAllPlayers())
                {
                    if (player.HasFlag(RoomLogic.CardToString(room, card) + "_delay_trick_cancel"))
                    {
                        player.SetFlags(string.Format("-{0}{1}", card_str, "_delay_trick_cancel"));
                    }
                }

                CardMoveReason reason = new CardMoveReason(CardMoveReason.MoveReason.S_REASON_NATURAL_ENTER, string.Empty);
                room.MoveCardTo(card, null, Place.DiscardPile, reason, true);
            }
        }