Esempio n. 1
0
        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);
            }
        }
        public override List <int> OnExchange(TrustedAI ai, Player player, string pattern, int min, int max, string pile)
        {
            Room room = ai.Room;

            if (ai.WillSkipPlayPhase(player))
            {
                List <int> ids = new List <int>(), cards = player.GetCards("h");
                ai.SortByKeepValue(ref cards, false);

                while (cards.Count >= player.Hp)
                {
                    ids.Add(cards[0]);
                    cards.RemoveAt(0);
                }

                if (ids.Count == 0 && cards.Count > 0)
                {
                    return new List <int> {
                               cards[0]
                    }
                }
                ;
                else
                {
                    return(ids);
                }
            }
            if (ai is SmartAI)
            {
                if (ai.GetOverflow(player) > 0 && !ai.IsSituationClear())
                {
                    List <int> ids = new List <int>();
                    foreach (int id in player.GetCards("h"))
                    {
                        if (room.GetCard(id).Name.Contains("Slash"))
                        {
                            ids.Add(id);
                        }
                    }

                    return(ids);
                }
            }

            return(new List <int>());
        }
        public override List <WrappedCard> GetTurnUse(TrustedAI ai, Player player)
        {
            Room room = ai.Room;

            ai.Target[Name] = null;
            if (player.HasUsed(ClassicWoodenOxCard.ClassName) || player.IsKongcheng() || player.GetPile("wooden_ox").Count >= 5)
            {
                return(null);
            }
            List <int> cards = player.GetCards("h");

            int sub = -1;

            foreach (int id in cards)
            {
                WrappedCard card = room.GetCard(id);
                if (card.Name == DragonPhoenix.ClassName)
                {
                    Player target = null;
                    foreach (Player p in room.GetOtherPlayers(player))
                    {
                        if (ai.HasSkill("zhangwu", p))
                        {
                            target = p;
                            break;
                        }
                    }

                    if (target != null && !ai.IsFriend(target, player) || !ai.HasSkill(TrustedAI.LoseEquipSkill, player))
                    {
                        sub = id;
                        break;
                    }
                }
                else if (card.Name == PeaceSpell.ClassName)
                {
                    Player target = null;
                    foreach (Player p in room.GetOtherPlayers(player))
                    {
                        if (ai.HasSkill("wendao", p))
                        {
                            target = p;
                            break;
                        }
                    }

                    if (target != null && !ai.IsFriend(target, player))
                    {
                        sub = id;
                        break;
                    }
                }
                else if (card.Name == LuminouSpearl.ClassName)
                {
                    Player target = null;
                    foreach (Player p in room.GetOtherPlayers(player))
                    {
                        if (ai.HasSkill("jubao", p))
                        {
                            target = p;
                            break;
                        }
                    }

                    if (target != null && !ai.IsFriend(target, player))
                    {
                        sub = id;
                        break;
                    }
                }
            }

            ai.SortByUseValue(ref cards);
            bool keep = false;

            if (ai.HasSkill("jijiu"))
            {
                foreach (Player p in ai.GetFriends(player))
                {
                    if (ai.IsWeak(p))
                    {
                        keep = true;
                        break;
                    }
                }
            }

            if (!keep)
            {
                List <Player> targets = new List <Player>();
                foreach (Player p in ai.FriendNoSelf)
                {
                    if (RoomLogic.CanPutEquip(p, room.GetCard(player.Treasure.Key)) && ai.GetSameEquip(room.GetCard(player.Treasure.Key), p) == null)
                    {
                        targets.Add(p);
                    }
                }

                Player next = null;
                room.SortByActionOrder(ref targets);
                foreach (Player p in targets)
                {
                    if (!ai.WillSkipPlayPhase(p))
                    {
                        next = p;
                        break;
                    }
                }
                if (next != null)
                {
                    if (sub != -1)
                    {
                        ai.Target[Name] = next;
                        WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                        {
                            Skill = Name
                        };
                        card.AddSubCard(sub);
                        return(new List <WrappedCard> {
                            card
                        });
                    }
                    else
                    {
                        KeyValuePair <Player, int> result = ai.GetCardNeedPlayer(cards, new List <Player> {
                            next
                        });
                        if (result.Key != null)
                        {
                            ai.Target[Name] = next;
                            WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                            {
                                Skill = Name
                            };
                            card.AddSubCard(result.Value);
                            return(new List <WrappedCard> {
                                card
                            });
                        }
                    }
                }
                else if (ai.HasSkill(TrustedAI.LoseEquipSkill) && targets.Count > 0)
                {
                    if (sub != -1)
                    {
                        ai.Target[Name] = targets[0];
                        WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                        {
                            Skill = Name
                        };
                        card.AddSubCard(sub);
                        return(new List <WrappedCard> {
                            card
                        });
                    }
                    else
                    {
                        ai.Target[Name] = targets[0];
                        ai.SortByUseValue(ref cards, false);
                        WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                        {
                            Skill = Name
                        };
                        card.AddSubCard(cards[0]);
                        return(new List <WrappedCard> {
                            card
                        });
                    }
                }
                else if (targets.Count > 0)
                {
                    List <Player> weaks = new List <Player>();
                    foreach (Player p in targets)
                    {
                        if (ai.IsWeak(p))
                        {
                            weaks.Add(p);
                        }
                    }

                    if (sub != -1 && weaks.Count > 0)
                    {
                        ai.SortByDefense(ref weaks, false);
                        ai.Target[Name] = weaks[0]; WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                        {
                            Skill = Name
                        };
                        card.AddSubCard(sub);
                        return(new List <WrappedCard> {
                            card
                        });
                    }

                    KeyValuePair <Player, int> result = ai.GetCardNeedPlayer(cards, weaks);
                    if (result.Key != null)
                    {
                        ai.Target[Name] = result.Key;
                        WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                        {
                            Skill = Name
                        };
                        card.AddSubCard(result.Value);
                        return(new List <WrappedCard> {
                            card
                        });
                    }
                }
            }

            if (ai.GetOverflow(player) > 0)
            {
                WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                {
                    Skill = Name
                };
                if (sub != -1)
                {
                    card.AddSubCard(sub);
                }
                else
                {
                    ai.SortByKeepValue(ref cards, false);
                    card.AddSubCard(cards[ai.GetOverflow(player) - 1]);
                }
                return(new List <WrappedCard> {
                    card
                });
            }

            if (player.HandcardNum == 1 && ai.HasSkill("kongcheng|kongcheng_jx"))
            {
                WrappedCard card = new WrappedCard(ClassicWoodenOxCard.ClassName)
                {
                    Skill = Name
                };
                card.AddSubCards(player.GetCards("h"));
                return(new List <WrappedCard> {
                    card
                });
            }

            return(null);
        }
        public override CardUseStruct OnResponding(TrustedAI ai, Player player, string pattern, string prompt, object data)
        {
            Room room = ai.Room;

            string[] strs = prompt.Split(':');

            CardUseStruct use    = new CardUseStruct(null, player, new List <Player>());
            Player        target = room.FindPlayer(strs[1]);

            if (target != null)
            {
                use.To.Add(target);

                List <ScoreStruct> values = ai.CaculateSlashIncome(player, null, new List <Player> {
                    target
                });
                if (values.Count > 0 && values[0].Score > 0)
                {
                    bool will_slash = false;
                    if (values[0].Score >= 10)
                    {
                        will_slash = true;
                    }
                    else if (ai.GetEnemies(player).Count == 1 && ai.GetOverflow(player) > 0)
                    {
                        foreach (int id in values[0].Card.SubCards)
                        {
                            if (room.GetCardPlace(id) == Player.Place.PlaceHand)
                            {
                                will_slash = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (Player p in values[0].Players)
                        {
                            if (ai.GetPrioEnemies().Contains(p))
                            {
                                will_slash = true;
                                break;
                            }
                        }
                    }

                    //todo: adjust ai personality
                    if (!will_slash && ai.GetOverflow(player) > 0)
                    {
                        foreach (int id in values[0].Card.SubCards)
                        {
                            if (room.GetCardPlace(id) == Player.Place.PlaceHand)
                            {
                                will_slash = true;
                                break;
                            }
                        }
                    }

                    if (will_slash)
                    {
                        use.Card = values[0].Card;
                    }
                }
            }
            return(use);
        }
Esempio n. 5
0
        public override List <int> OnDiscard(TrustedAI ai, Player player, List <int> cards, int min, int max, bool option)
        {
            if (!ai.WillShowForAttack())
            {
                return(new List <int>());
            }

            Room       room   = ai.Room;
            Player     target = room.Current;
            List <int> ids    = new List <int>();

            foreach (int id in player.HandCards)
            {
                if (RoomLogic.CanDiscard(room, player, player, id))
                {
                    ids.Add(id);
                }
            }
            ai.SortByKeepValue(ref ids, false);
            double value = ai.GetKeepValue(ids[0], player);

            if (ai.GetOverflow(player) > 1)
            {
                value /= 3;
            }
            DamageStruct damage = new DamageStruct(Name, player, target);

            if (ai.IsFriend(target))
            {
                bool range = false;
                foreach (Player p in room.GetOtherPlayers(target))
                {
                    if (ai.GetPrioEnemies().Contains(p) && RoomLogic.InMyAttackRange(room, target, p))
                    {
                        range = true;
                        break;
                    }
                }

                if (range && target.HandcardNum + target.GetPile("wooden_ox").Count > 3)
                {
                    if (ai.GetDamageScore(damage).Score < -3 && ai.HasSkill("wushuang|jianchu", target) && value < 3)
                    {
                        return new List <int> {
                                   ids[0]
                        }
                    }
                    ;
                }
            }
            else
            {
                if (ai.GetDamageScore(damage).Score > 7 && value < 7)
                {
                    return new List <int> {
                               ids[0]
                    }
                }
                ;
                else if (ai.GetDamageScore(damage).Score > 4 && value < 3)
                {
                    if (ai.IsLackCard(target, Slash.ClassName) || target.HandcardNum + target.GetPile("wooden_ox").Count < 3)
                    {
                        return(new List <int> {
                            ids[0]
                        });
                    }
                    else
                    {
                        bool range = false;
                        foreach (Player p in room.GetOtherPlayers(target))
                        {
                            if (ai.IsFriend(p) && RoomLogic.InMyAttackRange(room, target, p))
                            {
                                range = true;
                                break;
                            }
                        }

                        if (!range)
                        {
                            return new List <int> {
                                       ids[0]
                            }
                        }
                        ;
                    }
                }
            }

            return(new List <int>());
        }
    }