コード例 #1
0
 public override void OnEvent(TrustedAI ai, TriggerEvent triggerEvent, Player player, object data)
 {
     if (triggerEvent == TriggerEvent.ChoiceMade && data is string str)
     {
         Room     room   = ai.Room;
         string[] strs   = str.Split(':');
         Player   target = room.FindPlayer(strs[3]);
         ai.UpdatePlayerRelation(player, target, true);
         if (player == ai.Self)
         {
             List <string> cards = new List <string>(strs[4].Split('+'));
             List <int>    ids   = JsonUntity.StringList2IntList(cards);
             foreach (int id in ids)
             {
                 ai.SetPrivateKnownCards(target, id);
             }
         }
     }
 }
コード例 #2
0
ファイル: MythAI.cs プロジェクト: LastSwing/Sanguosha-Unity
        public override void OnEvent(TrustedAI ai, TriggerEvent triggerEvent, Player player, object data)
        {
            if (triggerEvent == TriggerEvent.ChoiceMade && data is string choice && player != ai.Self)
            {
                string[]      choices = choice.Split(':');
                List <string> strs    = new List <string>(choices[3].Split('+'));
                List <int>    ids     = JsonUntity.StringList2IntList(strs);

                foreach (int id in ids)
                {
                    Player own = ai.Room.GetCardOwner(id);
                    if (own != player)
                    {
                        ai.UpdatePlayerRelation(player, own, false);
                        break;
                    }
                }
            }
        }
コード例 #3
0
        public override void Event(TriggerEvent triggerEvent, Player player, object data)
        {
            if (!self.Alive)
            {
                return;
            }

            base.Event(triggerEvent, player, data);

            if (triggerEvent == TriggerEvent.EventPhaseStart || triggerEvent == TriggerEvent.BuryVictim)
            {
                UpdatePlayers();
            }

            if (triggerEvent == TriggerEvent.CardsMoveOneTime && data is CardsMoveOneTimeStruct move)
            {
                bool   open      = false;
                bool   pile_open = false;
                Player from      = move.From;
                Player to        = move.To;

                foreach (Player p in room.GetAlivePlayers())
                {
                    if (p.HasFlag("Global_GongxinOperator") && (p == self || self.IsSameCamp(p)))
                    {
                        open = true;
                        break;
                    }
                }

                if ((from != null && (from == self || self.IsSameCamp(from))) || (to != null && (to == self || self.IsSameCamp(to)) && move.To_place != Player.Place.PlaceSpecial))
                {
                    open = true;
                }

                if (!open && to != null && !string.IsNullOrEmpty(move.To_pile_name) && !move.To_pile_name.StartsWith("#") && move.To != null)
                {
                    if (move.To.GetPileOpener(move.To_pile_name).Count == room.GetAllPlayers(true).Count)
                    {
                        pile_open = true;
                    }
                    else
                    {
                        foreach (string name in move.To.GetPileOpener(move.To_pile_name))
                        {
                            Player who = room.FindPlayer(name, true);
                            if (who != null && (who == self || self.IsSameCamp(who)))
                            {
                                open = true;
                                break;
                            }
                        }
                    }
                }

                if (to != null && move.To_place == Player.Place.PlaceHand)
                {
                    foreach (int id in move.Card_ids)
                    {
                        int         index = move.Card_ids.IndexOf(id);
                        WrappedCard card  = room.GetCard(id);
                        if (card.HasFlag("visible") || pile_open ||
                            move.From_places[index] == Player.Place.PlaceEquip || move.From_places[index] == Player.Place.PlaceDelayedTrick ||
                            move.From_places[index] == Player.Place.DiscardPile || move.From_places[index] == Player.Place.PlaceTable)
                        {
                            public_handcards[to].Add(id);
                            private_handcards[to].Add(id);
                            ClearCardLack(to, id);
                        }
                        else if (open)
                        {
                            private_handcards[to].Add(id);
                            ClearCardLack(to, id);
                        }
                        else
                        {
                            ClearCardLack(to);
                        }
                    }
                }

                if (to != null && move.To_place == Player.Place.PlaceSpecial && move.To_pile_name == "wooden_ox")
                {
                    foreach (int id in move.Card_ids)
                    {
                        if (open)
                        {
                            wooden_cards[to].Add(id);
                        }
                    }
                }

                if (from != null && move.From_places.Contains(Player.Place.PlaceHand))
                {
                    foreach (int id in move.Card_ids)
                    {
                        if (room.GetCard(id).HasFlag("visible") || pile_open || move.To_place == Player.Place.PlaceEquip ||
                            move.To_place == Player.Place.PlaceDelayedTrick || move.To_place == Player.Place.DiscardPile ||
                            move.To_place == Player.Place.PlaceTable)
                        {
                            public_handcards[from].RemoveAll(t => t == id);
                            private_handcards[from].RemoveAll(t => t == id);
                        }
                        else
                        {
                            public_handcards[from].Clear();
                            if (open)
                            {
                                private_handcards[from].RemoveAll(t => t == id);
                            }
                            else
                            {
                                private_handcards[from].Clear();
                            }
                        }
                    }
                }

                if (from != null && move.From_places.Contains(Player.Place.PlaceSpecial) && move.From_pile_names.Contains("wooden_ox"))
                {
                    foreach (int id in move.Card_ids)
                    {
                        int index = move.Card_ids.IndexOf(id);
                        if (open && move.From_pile_names[index] == "wooden_ox" && move.From_places[index] == Player.Place.PlaceSpecial)
                        {
                            wooden_cards[move.From].RemoveAll(t => t == id);
                        }
                    }
                }

                foreach (int id in move.Card_ids)
                {
                    int         index = move.Card_ids.IndexOf(id);
                    WrappedCard card  = room.GetCard(id);
                    if (move.From_places[index] == Player.Place.DrawPile)
                    {
                        if (move.To != null && move.To_place == Player.Place.PlaceHand && card.HasFlag("visible2" + self.Name))
                        {
                            private_handcards[move.To].Add(id);
                        }

                        if (guanxing.Key != null && guanxing.Value.Contains(id))
                        {
                            if (guanxing.Value[0] != id)
                            {
                                List <int> top_cards = new List <int>(guanxing.Value);
                                for (int y = top_cards.IndexOf(id); y < top_cards.Count; y++)
                                {
                                    guanxing.Value.RemoveAt(y);
                                }
                            }
                            else
                            {
                                guanxing.Value.RemoveAll(t => t == id);
                            }
                            if (guanxing.Value.Count == 0)
                            {
                                guanxing = new KeyValuePair <Player, List <int> >();
                            }
                        }
                    }
                }
            }

            if (triggerEvent == TriggerEvent.CardTargetAnnounced && data is CardUseStruct use)
            {
                FunctionCard fcard      = Engine.GetFunctionCard(use.Card.Name);
                string       class_name = fcard.Name;
                if (fcard is Slash)
                {
                    class_name = Slash.ClassName;
                }
                UseCard e = Engine.GetCardUsage(class_name);
                if (e != null)
                {
                    e.OnEvent(this, triggerEvent, player, data);
                }
            }

            if (triggerEvent == TriggerEvent.ChoiceMade && data is string str)
            {
                List <string> choices = new List <string>(str.Split(':'));
                foreach (SkillEvent e in skill_events.Values)
                {
                    if (e.Key.Contains(choices[0]))
                    {
                        e.OnEvent(this, triggerEvent, player, data);
                    }
                }

                foreach (UseCard e in Engine.GetCardUsages())
                {
                    if (e.Key.Contains(choices[0]))
                    {
                        e.OnEvent(this, triggerEvent, player, data);
                    }
                }

                if (choices[0] == "viewCards")
                {
                    List <int> ids = player.GetCards("h");
                    if (choices[choices.Count - 1] == "all")
                    {
                        public_handcards[player]  = ids;
                        private_handcards[player] = ids;
                    }
                    else if (choices[choices.Count - 1] == self.Name)
                    {
                        private_handcards[player] = ids;
                    }
                }
                else if (choices[0] == "showCards")
                {
                    List <int> ids = JsonUntity.StringList2IntList(new List <string>(choices[2].Split('+')));
                    if (choices[choices.Count - 1] == "all")
                    {
                        foreach (int id in ids)
                        {
                            if (!public_handcards[player].Contains(id))
                            {
                                public_handcards[player].Add(id);
                            }
                            if (!private_handcards[player].Contains(id))
                            {
                                private_handcards[player].Add(id);
                            }
                        }
                    }
                    else if (choices[choices.Count - 1] == self.Name)
                    {
                        foreach (int id in ids)
                        {
                            if (!private_handcards[player].Contains(id))
                            {
                                private_handcards[player].Add(id);
                            }
                        }
                    }
                }
                else if (choices[0] == "cardShow")
                {
                    int id = int.Parse(choices[choices.Count - 1].Substring(1, choices[choices.Count - 1].Length - 2));
                    if (!public_handcards[player].Contains(id))
                    {
                        public_handcards[player].Add(id);
                    }
                    if (!private_handcards[player].Contains(id))
                    {
                        private_handcards[player].Add(id);
                    }
                }
                else if (choices[0] == "ViewTopCards" || choices[0] == "ViewBottomCards")
                {
                    bool       open     = choices[choices.Count - 1] == "open";
                    List <int> drawpile = new List <int>(room.DrawPile);
                    List <int> moves    = JsonUntity.StringList2IntList(new List <string>(choices[2].Split('+')));
                    if (choices[0] == "ViewTopCards")
                    {
                        guanxing = new KeyValuePair <Player, List <int> >();
                        if (open)
                        {
                            for (int index = 0; index < moves.Count; index++)
                            {
                                int id = moves[index];
                                room.SetCardFlag(id, "visible");
                            }
                        }
                        else
                        {
                            foreach (int id in moves)
                            {
                                if (player == self || player.IsSameCamp(self))
                                {
                                    room.SetCardFlag(id, "visible2" + self.Name);
                                }
                            }

                            guanxing = new KeyValuePair <Player, List <int> >(player, moves);
                        }
                    }
                    else
                    {
                        if (open)
                        {
                            for (int index = 0; index < moves.Count; index++)
                            {
                                int id = moves[index];
                                room.SetCardFlag(id, "visible");
                            }
                        }
                        else
                        {
                            foreach (int id in moves)
                            {
                                room.SetCardFlag(id, "visible2" + choices[1]);
                            }
                        }
                    }
                }
            }
        }