예제 #1
0
 public virtual void CheckBigKingdoms(Room room)
 {
     room.DoBroadcastNotify(CommandType.S_COMMAND_LOG_EVENT, new List <string> {
         GameEventType.S_GAME_EVENT_BIG_KINGDOM.ToString(),
         JsonUntity.Object2Json(RoomLogic.GetBigKingdoms(room))
     });
 }
예제 #2
0
        public override void OnChooseGeneralReply(Room room, Interactivity client)
        {
            //该模式下玩家完成选将会立即先所有人公布
            Player        player      = room.GetPlayers(client.ClientId)[0];
            List <string> options     = JsonUntity.Json2List <string>((string)player.GetTag("generals"));
            List <string> reply       = client.ClientReply;
            bool          success     = true;
            string        generalName = string.Empty;

            if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
            {
                success = false;
            }
            else
            {
                generalName = reply[0];
            }

            if (!success || (!options.Contains(generalName) && room.GetClient(player).UserRight < 3) ||
                (player.Camp == Game3v3Camp.S_CAMP_COOL && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0] != General.KingdomENUM.Wei) ||
                (player.Camp == Game3v3Camp.S_CAMP_WARM && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0] != General.KingdomENUM.Qun))
            {
                generalName = options[0];
            }

            player.General1       = generalName;
            player.ActualGeneral1 = generalName;
            player.Kingdom        = General.GetKingdom(Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0]);
            player.General1Showed = true;
            room.BroadcastProperty(player, "General1");
            room.BroadcastProperty(player, "Kingdom");
        }
예제 #3
0
        public void InterHall(Client client, bool reconnect)
        {
            try
            {
                //update user profile
                //bring to hall
                bool proceed = client.GetProfile(!reconnect);
                if (!proceed)
                {
                    return;
                }

                clientList.TryAdd(client.UserID, client.Profile.NickName);
                //更新到form1
                Dictionary <int, string> client_list = clientList.ToDictionary(entry => entry.Key, entry => entry.Value);
                UpdateUsers(client_list);

                UId2ClientTable.TryGetValue(client.UserID, out Client temp);

                MyData data = new MyData();
                if (!reconnect)
                {
                    //发送当前已登录的其他玩家信息和游戏房间信息
                    Dictionary <int, RoomInfoStruct> ds = RoomList.Instance().GetRoomList();
                    data = new MyData
                    {
                        Description = PacketDescription.Hall2Cient,
                        Protocol    = Protocol.GetProfile,
                        Body        = new List <string> {
                            JsonUntity.Dictionary2Json(client_list), JsonUntity.Object2Json(ds)
                        }
                    };
                    client.SendProfileReply(data);
                }

                //通知其他客户端更新
                data = new MyData()
                {
                    Description = PacketDescription.Hall2Cient,
                    Protocol    = Protocol.UpdateHallJoin,
                    Body        = new List <string> {
                        client.UserID.ToString(), client.Profile.NickName, "0"
                    }
                };

                List <Client> clients = new List <Client>(UId2ClientTable.Values);
                foreach (Client other in clients)
                {
                    if (other != client)
                    {
                        other.SendProfileReply(data);
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(null, e);
                Debug(string.Format("error on inter hall {0} {1}", e.Message, e.TargetSite));
            }
        }
예제 #4
0
        public override void OnChooseGeneralReply(Room room, Client client)
        {
            Player        player      = room.GetPlayers(client)[0];
            List <string> options     = JsonUntity.Json2List <string>((string)player.GetTag("generals"));
            List <string> reply       = client.ClientReply;
            bool          success     = true;
            string        generalName = string.Empty;

            if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
            {
                success = false;
            }
            else
            {
                generalName = reply[0];
            }

            if (!success || (!options.Contains(Engine.GetMainGeneral(generalName)) && client.UserRight < 3))
            {
                generalName = options[0];
            }

            player.General1       = generalName;
            player.ActualGeneral1 = generalName;
            player.Kingdom        = Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom;
            player.General1Showed = true;
            room.NotifyProperty(room.GetClient(player), player, "General1");
            room.NotifyProperty(room.GetClient(player), player, "Kingdom");
        }
        public static MyData Unpack(byte[] bytes)
        {
            using (MemoryStream raw = new MemoryStream(bytes))
            {
                GZipInputStream zipFile = new GZipInputStream(raw);
                using (MemoryStream re = new MemoryStream(1000))
                {
                    int    count;
                    byte[] data = new byte[1000];
                    while ((count = zipFile.Read(data, 0, data.Length)) != 0)
                    {
                        re.Write(data, 0, count);
                    }
                    byte[] overarr = re.ToArray();
                    re.Close();
                    zipFile.Close();
                    raw.Close();

                    //将byte数组转为string
                    string result = Encoding.UTF8.GetString(overarr);
                    return(JsonUntity.Json2Object <MyData>(result));
                }
            }

            /*
             * string str = Encoding.UTF8.GetString(bytes);
             * return JsonUntity.Json2Object<MyData>(str);
             */
        }
예제 #6
0
        public override void OnChooseGeneralReply(Room room, Interactivity client)
        {
            Player        player      = room.GetPlayers(client.ClientId)[0];
            List <string> options     = JsonUntity.Json2List <string>((string)player.GetTag("generals"));
            List <string> reply       = client.ClientReply;
            bool          success     = true;
            string        generalName = string.Empty;

            if (!client.IsClientResponseReady || reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
            {
                success = false;
            }
            else
            {
                generalName = reply[0];
                string[] generals = generalName.Split('+');
                if (generals.Length != 2)
                {
                    success = false;
                }
                else
                {
                    General general1 = Engine.GetGeneral(generals[0], "Hegemony");
                    General general2 = Engine.GetGeneral(generals[1], "Hegemony");
                    if (general1 == null || general1.Hidden || general2 == null || general2.Hidden ||
                        !room.Setting.GeneralPackage.Contains(general1.Package) ||
                        !room.Setting.GeneralPackage.Contains(general2.Package) ||
                        (!options.Contains(generals[0]) && room.GetClient(player).UserRight < 3) ||
                        (!options.Contains(generals[1]) && room.GetClient(player).UserRight < 3) ||
                        !SetPlayerGeneral(room, player, generals[0], true) ||
                        !SetPlayerGeneral(room, player, generals[1], false))
                    {
                        success = false;
                    }
                }
            }

            if (!success)
            {
                List <string> default_generals = GeneralSelctor.GeInstance().SelectGenerals(room, options);
                SetPlayerGeneral(room, player, default_generals[0], true);
                SetPlayerGeneral(room, player, default_generals[1], false);
            }

            if (!string.IsNullOrEmpty(player.General1))
            {
                string name    = player.General1;
                string kingdom = General.GetKingdom(Engine.GetGeneral(name, room.Setting.GameMode).Kingdom[0]);
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1", name);
                room.NotifyProperty(room.GetClient(player), player, "Kingdom", kingdom);
            }
            if (!string.IsNullOrEmpty(player.General2))
            {
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral2", player.General2);
            }
        }
예제 #7
0
        public void InterHall(Client client, bool reconnect)
        {
            //update user profile
            //bring to hall
            bool proceed = client.GetProfile(!reconnect);

            if (!proceed)
            {
                return;
            }

            ClientList.Instance().AddClient(client.UserID, client.Profile.NickName);
            //更新到form1
            UpdateUsers(ClientList.Instance().GetUserList(0));

            MyData data = new MyData();

            if (!reconnect)
            {
                //发送当前已登录的其他玩家信息和游戏房间信息
                DataSet ds = new DataSet();
                ds.Tables.Add(ClientList.Instance().GetUserList(0).Copy());
                ds.Tables.Add(RoomList.Instance().GetRoomList().Copy());

                data = new MyData
                {
                    Description = PacketDescription.Hall2Cient,
                    Protocol    = protocol.GetProfile,
                    Body        = new List <string> {
                        JsonUntity.DataSet2Json(ds)
                    }
                };
                client.SendProfileReply(data);
            }

            //通知其他客户端更新
            data = new MyData()
            {
                Description = PacketDescription.Hall2Cient,
                Protocol    = protocol.UpdateHallJoin,
                Body        = new List <string> {
                    client.UserID.ToString(), client.Profile.NickName, "0"
                }
            };
            foreach (Client other in UId2ClientTable.Values)
            {
                if (other != client)
                {
                    other.SendProfileReply(data);
                }
            }
        }
        public static byte[] Data2byte(MyData data)
        {
            byte[] rawData = Encoding.UTF8.GetBytes(JsonUntity.Object2Json(data));
            using (MemoryStream ms = new MemoryStream())
            {
                GZipOutputStream compressedzipStream = new GZipOutputStream(ms);

                compressedzipStream.Write(rawData, 0, rawData.Length);
                compressedzipStream.Close();
                byte[] dataBody = ms.ToArray();
                ms.Close();
                return(dataBody);
            }
        }
예제 #9
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);
             }
         }
     }
 }
예제 #10
0
        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;
                    }
                }
            }
        }
예제 #11
0
        public override void OnChooseGeneralReply(Room room, Interactivity client)
        {
            Player        player      = room.GetPlayers(client.ClientId)[0];
            List <string> options     = JsonUntity.Json2List <string>((string)player.GetTag("generals"));
            List <string> reply       = client.ClientReply;
            bool          success     = true;
            string        generalName = string.Empty;

            if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
            {
                success = false;
            }
            else
            {
                generalName = reply[0];
            }

            General general = Engine.GetGeneral(generalName, "Doudizhu");

            if (!success || general == null || general.Hidden || !room.Setting.GeneralPackage.Contains(general.Package))
            {
                generalName = options[0];
            }

            player.General1       = generalName;
            player.ActualGeneral1 = generalName;
            player.Kingdom        = Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom;
            player.General1Showed = true;
            room.NotifyProperty(room.GetClient(player), player, "General1");
            room.NotifyProperty(room.GetClient(player), player, "Kingdom");

            if (player.GetRoleEnum() == PlayerRole.Rebel)
            {
                foreach (Player p in room.Players)
                {
                    if (p != player && p.GetRoleEnum() == player.GetRoleEnum())
                    {
                        room.NotifyProperty(room.GetClient(p), player, "General1");
                        room.NotifyProperty(room.GetClient(p), player, "Kingdom");
                    }
                }
            }
        }
        public static byte[] data2byte(MyData data, string Key)
        {
            //var commandData = new byte[4];//协议命令只占4位
            var commandData = Encoding.UTF8.GetBytes(Key);//协议命令只占4位,如果占的位数长过协议,那么协议解析肯定会出错的

            byte[] dataBody = System.Text.Encoding.UTF8.GetBytes(JsonUntity.Object2Json <MyData>(data));
            var    dataLen  = BitConverter.GetBytes(dataBody.Length);//int类型占4位,根据协议这里也只能4位,否则会出错


            var sendData = new byte[8 + dataBody.Length];//命令加内容长度为8

            // +-------+---+-------------------------------+
            // |request| l |                               |
            // | name  | e |    request body               |
            // |  (4)  | n |                               |
            // |       |(4)|                               |
            // +-------+---+-------------------------------+

            Array.ConstrainedCopy(commandData, 0, sendData, 0, 4);
            Array.ConstrainedCopy(dataLen, 0, sendData, 4, 4);
            Array.ConstrainedCopy(dataBody, 0, sendData, 8, dataBody.Length);

            return(sendData);
        }
예제 #13
0
        public override void Assign(Room room)
        {
            Thread.Sleep(1000);

            //分配武将
            AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options);
            //武将预览
            foreach (Player p in room.Players)
            {
                List <string> gongxinArgs = new List <string> {
                    string.Empty, JsonUntity.Object2Json(options[p]), string.Empty, string.Empty, "false"
                };
                room.DoNotify(room.GetClient(p), CommandType.S_COMMAND_VIEW_GENERALS, gongxinArgs);
            }

            List <Interactivity> receivers = new List <Interactivity>();
            List <Player>        lords     = new List <Player>();

            foreach (Client client in room.Clients)
            {
                List <string> args = new List <string> {
                    string.Empty, "userdefine:getlandlord", null
                };
                Interactivity inter = room.GetInteractivity(client.UserID);
                if (inter != null)
                {
                    inter.CommandArgs = args;
                    receivers.Add(inter);
                }
            }
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_INVOKE_SKILL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in room.Players)
            {
                Interactivity client = room.GetInteractivity(player);
                if (client != null && client.IsClientResponseReady && receivers.Contains(client))
                {
                    List <string> invoke = client.ClientReply;
                    if (invoke != null && invoke.Count > 0 && bool.TryParse(invoke[0], out bool success) && success)
                    {
                        lords.Add(player);
                    }
                }
            }

            bool get = true;

            if (lords.Count == 0)
            {
                get   = false;
                lords = new List <Player>(room.Players);
            }
            Player lord = null;

            Shuffle.shuffle(ref lords);
            lord = lords[0];

            if (get)
            {
                LogMessage log = new LogMessage
                {
                    Type = "#get_landlord",
                    From = lord.Name
                };
                room.SendLog(log);
            }
            else
            {
                LogMessage log = new LogMessage
                {
                    Type = "#distribute_landlord",
                    From = lord.Name
                };
                room.SendLog(log);
            }

            foreach (Player p in room.Players)
            {
                if (p == lord)
                {
                    p.Camp = Game3v3Camp.S_CAMP_COOL;
                    p.Role = "lord";
                    room.BroadcastProperty(p, "Camp");
                }
                else
                {
                    p.Role = "rebel";
                }
                room.BroadcastProperty(p, "Role");
            }

            //地主增加2框
            List <string> generals = (List <string>)room.GetTag(Name);

            for (int i = 0; i < 2; i++)
            {
                Shuffle.shuffle(ref generals);
                options[lord].Add(generals[0]);
                generals.RemoveAt(0);
            }

            //选将
            receivers.Clear();
            List <Player> players = new List <Player>();

            foreach (Player player in options.Keys)
            {
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,
                    string.Empty,
                    JsonUntity.Object2Json(options[player]),
                    true.ToString(),
                    true.ToString(),
                    false.ToString()
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null)
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            Countdown countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            //给AI和超时的玩家自动选择武将
            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (string.IsNullOrEmpty(player.General1))
                {
                    string        generalName = string.Empty;
                    Interactivity client      = room.GetInteractivity(player);
                    List <string> reply       = client?.ClientReply;
                    bool          success     = true;
                    if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                    {
                        success = false;
                    }
                    else
                    {
                        generalName = reply[0];
                    }

                    if (!success || (!options[player].Contains(generalName) && room.GetClient(player).UserRight < 3))
                    {
                        TrustedAI ai = room.GetAI(player);
                        if (ai != null && ai is StupidAI)
                        {
                            generalName = GeneralSelector.GetGeneral(room, options[player], player.GetRoleEnum(), player);
                        }
                        else
                        {
                            generalName = options[player][0];
                        }
                    }

                    player.General1       = generalName;
                    player.ActualGeneral1 = generalName;
                    player.Kingdom        = Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom;
                    player.General1Showed = true;
                }

                room.BroadcastProperty(player, "General1");
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                room.BroadcastProperty(player, "Kingdom");
                room.BroadcastProperty(player, "General1Showed");
                player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender;
                room.BroadcastProperty(player, "PlayerGender");

                player.SetSkillsPreshowed("hd");
                room.NotifyPlayerPreshow(player);
                List <string> names = new List <string> {
                    player.General1
                };
                room.SetTag(player.Name, names);
                room.HandleUsedGeneral(player.General1);
            }

            //神将选国籍
            string        choice  = "wei+qun+shu+wu";
            List <string> prompts = new List <string> {
                "@choose-kingdom"
            };

            receivers.Clear();
            players.Clear();
            foreach (Player player in room.Players)
            {
                if (player.Kingdom != "god")
                {
                    continue;
                }
                List <string> args = new List <string>
                {
                    player.Name,
                    "Kingdom",
                    choice,
                    JsonUntity.Object2Json(prompts)
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_MULTIPLE_CHOICE, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };
            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_MULTIPLE_CHOICE);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in players)
            {
                string        answer        = string.Empty;
                Interactivity interactivity = room.GetInteractivity(player);
                if (interactivity != null)
                {
                    List <string> clientReply = interactivity.ClientReply;
                    if (clientReply != null && clientReply.Count > 0)
                    {
                        answer = clientReply[0];
                    }
                }

                List <string> choices = new List <string>(choice.Split('+'));
                if (string.IsNullOrEmpty(answer) || !choices.Contains(answer))
                {
                    Shuffle.shuffle(ref choices);
                    answer = choices[0];
                }
                player.Kingdom = answer;
                room.BroadcastProperty(player, "Kingdom");
            }
        }
        public static MyData Unpack(byte[] bytes)
        {
            string str = System.Text.Encoding.UTF8.GetString(bytes);

            return(JsonUntity.Json2Object <MyData>(str));
        }
예제 #15
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]);
                            }
                        }
                    }
                }
            }
        }
예제 #16
0
        public override void Assign(Room room)
        {
            AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options);

            List <Interactivity> receivers = new List <Interactivity>();

            foreach (Player player in options.Keys)
            {
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,                                    //操作的玩家名
                    string.Empty,                                   //原因
                    JsonUntity.Object2Json(options[player]),        //备选武将
                    false.ToString(),                               //是否单将
                    true.ToString(),                                //是否可以武将转换SP
                    false.ToString()                                //双将时是否匹配相同国籍
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
            }

            List <Player> players   = room.Players;
            Countdown     countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (!string.IsNullOrEmpty(player.General1))
                {
                    continue;
                }
                bool          success = true;
                Interactivity client  = room.GetInteractivity(player);
                List <string> reply   = client?.ClientReply;
                if (client == null || !client.IsClientResponseReady || reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                {
                    success = false;
                }
                else
                {
                    string   generalName = reply[0];
                    string[] generals    = generalName.Split('+');
                    if (generals.Length != 2 || (!options[player].Contains(generals[0]) && room.GetClient(player).UserRight < 3) ||
                        (!options[player].Contains(generals[1]) && room.GetClient(player).UserRight < 3) ||
                        !SetPlayerGeneral(room, player, generals[0], true) ||
                        !SetPlayerGeneral(room, player, generals[1], false))
                    {
                        success = false;
                    }
                }
                if (!success)
                {
                    SetPlayerGeneral(room, player, options[player][0], true);
                    SetPlayerGeneral(room, player, options[player][1], false);
                }
            }

            foreach (Player player in players)
            {
                List <string> names = new List <string>();
                if (!string.IsNullOrEmpty(player.General1))
                {
                    string name = player.General1;
                    names.Add(name);
                    player.General1 = "anjiang";
                    room.BroadcastProperty(player, "General1");
                    room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");

                    foreach (Client p in room.Clients)
                    {
                        if (p != room.GetClient(player))
                        {
                            room.NotifyProperty(p, player, "Kingdom", "god");
                        }
                    }
                }

                if (!string.IsNullOrEmpty(player.General2))
                {
                    string name = player.General2;
                    names.Add(name);
                    player.General2 = "anjiang";
                    room.BroadcastProperty(player, "General2");
                    room.NotifyProperty(room.GetClient(player), player, "ActualGeneral2");
                }
                room.SetTag(player.Name, names);

                room.HandleUsedGeneral(names[0]);
                room.HandleUsedGeneral(names[1]);

                if (reserved.TryGetValue(player, out List <string> p_reserved) && (p_reserved.Contains(names[0]) || p_reserved.Contains(names[1])))
                {
                    LogMessage reserved_log = new LogMessage();
                    reserved_log.Type = "#reserved_pick";
                    reserved_log.From = player.Name;
                    room.SendLog(reserved_log);
                }

                if (!options[player].Contains(names[0]) || !options[player].Contains(names[1]))
                {
                    LogMessage log = new LogMessage();
                    log.Type = "#cheat_pick";
                    log.From = player.Name;
                    room.SendLog(log);
                }
            }

            //选择国籍
            receivers.Clear();
            players.Clear();
            List <string> prompts = new List <string> {
                "@choose-kingdom"
            };
            Dictionary <Player, List <string> > kingdoms = new Dictionary <Player, List <string> >();

            foreach (Player player in room.Players)
            {
                List <string> choices = new List <string> {
                    "careerist"
                };
                General g1 = Engine.GetGeneral(player.ActualGeneral1, Name);
                General g2 = Engine.GetGeneral(player.ActualGeneral2, Name);
                foreach (General.KingdomENUM kingdom in g1.Kingdom)
                {
                    if (!choices.Contains(General.GetKingdom(kingdom)))
                    {
                        choices.Add(General.GetKingdom(kingdom));
                    }
                }
                foreach (General.KingdomENUM kingdom in g2.Kingdom)
                {
                    if (!choices.Contains(General.GetKingdom(kingdom)))
                    {
                        choices.Add(General.GetKingdom(kingdom));
                    }
                }
                kingdoms.Add(player, choices);
                List <string> args = new List <string>
                {
                    player.Name,
                    "Kingdom",
                    string.Join("+", choices),
                    JsonUntity.Object2Json(prompts)
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_MULTIPLE_CHOICE, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };
            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_MULTIPLE_CHOICE);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in players)
            {
                string        answer        = string.Empty;
                Interactivity interactivity = room.GetInteractivity(player);
                if (interactivity != null)
                {
                    List <string> clientReply = interactivity.ClientReply;
                    if (clientReply != null && clientReply.Count > 0)
                    {
                        answer = clientReply[0];
                    }
                }

                List <string> choices = kingdoms[player];
                if (string.IsNullOrEmpty(answer) || !choices.Contains(answer))
                {
                    Shuffle.shuffle(ref choices);
                    answer = choices[0];
                }

                if (answer != "careerist")
                {
                    player.Kingdom = player.Role = answer;
                    room.NotifyProperty(room.GetClient(player), player, "Kingdom");
                }
                else
                {
                    player.Kingdom = "god";
                    player.Role    = answer;
                    room.NotifyProperty(room.GetClient(player), player, "Role");
                }
            }

            //君主转换
            if (room.Setting.LordConvert)
            {
                room.AskForLordConvert();
            }

            foreach (Player player in players)
            {
                General general1 = Engine.GetGeneral(player.ActualGeneral1, room.Setting.GameMode);
                General general2 = Engine.GetGeneral(player.ActualGeneral2, room.Setting.GameMode);

                if (general1.CompanionWith(player.ActualGeneral2, Name))
                {
                    player.AddMark("CompanionEffect");
                }

                int max_hp = general1.GetMaxHpHead() + general2.GetMaxHpDeputy();
                player.SetMark("HalfMaxHpLeft", max_hp % 2);

                player.MaxHp = max_hp / 2;
                player.Hp    = player.MaxHp;

                room.BroadcastProperty(player, "MaxHp");
                room.BroadcastProperty(player, "Hp");
            }
        }
예제 #17
0
        private void RoomSwitch(Client client, MyData data)
        {
            switch (data.Protocol)
            {
            case protocol.CreateRoom:
                CreateRoom(client, JsonUntity.Json2Object <GameSetting>(data.Body[0]));
                break;

            case protocol.JoinRoom:
                int    room_id = -1;
                string pass    = string.Empty;
                if (data.Body.Count > 0)
                {
                    room_id = int.Parse(data.Body[0]);
                    pass    = data.Body[1].ToString();
                }
                else
                {
                    room_id = client.GameRoom;
                }

                Room room   = RId2Room.ContainsKey(room_id) ? RId2Room[room_id] : null;
                bool result = false;
                if (room != null)
                {
                    //if (JoinRoom != null)
                    //{
                    //    Delegate[] delArray = JoinRoom.GetInvocationList();
                    //    foreach (Delegate del in delArray)
                    //    {
                    //        Room target = (Room)del.Target;
                    //        if (target != null && target.RoomId == room_id)
                    //        {
                    //            JoinRoomDelegate method = (JoinRoomDelegate)del;
                    //            result = method(client, room_id, pass);
                    //        }
                    //    }
                    //}
                    //JoinRoom?.Invoke(client, room_id, pass);
                    result = room.OnClientRequestInter(client, room_id, pass);
                }
                if (!result)
                {
                    Debug(string.Format("{0} join request fail at hall", client.UserName));
                    data = new MyData
                    {
                        Description = PacketDescription.Hall2Cient,
                        Protocol    = protocol.JoinRoom,
                    };
                    client.SendSwitchReply(data);
                }
                else
                {
                    ClientList.Instance().AddClient(client.UserID, client.Profile.NickName, room_id);
                    UpdateUsers(ClientList.Instance().GetUserList(0));
                }
                break;

            case protocol.LeaveRoom:
                if (RId2Room.ContainsKey(client.GameRoom))
                {
                    client.RequestLeaveRoom();

                    //更新form
                    ClientList.Instance().AddClient(client.UserID, client.Profile.NickName);
                    UpdateUsers(ClientList.Instance().GetUserList(0));
                }
                break;

            case protocol.UpdateRoom:
                client.RequstReady(bool.Parse(data.Body[0]));
                break;

            case protocol.RoleReserved:
                if (client.UserRight >= 2 && RId2Room.ContainsKey(client.GameRoom))
                {
                    room = RId2Room[client.GameRoom];
                    if (!room.GameStarted && room.Setting.GameMode == "Classic")
                    {
                        client.RoleReserved = data.Body[0];
                    }
                }
                break;

            case protocol.KickOff:
                room = RId2Room.ContainsKey(client.GameRoom) ? RId2Room[client.GameRoom] : null;
                if (room != null && room.Host == client && !room.GameStarted)
                {
                    int    victim_id = int.Parse(data.Body[0]);
                    Client victim    = GetClient(victim_id);
                    if (victim != null || victim_id < 0)
                    {
                        victim.RequestLeaveRoom(true);

                        //更新form
                        ClientList.Instance().AddClient(client.UserID, client.Profile.NickName);
                        UpdateUsers(ClientList.Instance().GetUserList(0));
                    }
                }
                break;

            case protocol.ConfigChange:
                room = RId2Room.ContainsKey(client.GameRoom) ? RId2Room[client.GameRoom] : null;
                if (room != null && room.Host == client && !room.GameStarted)
                {
                    room.ChangeSetting(JsonUntity.Json2Object <GameSetting>(data.Body[0]));
                }
                break;

            default:
                break;
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int      ctrl = 0;

            foreach (string s in strs)
            {
                ctrl = int.Parse(s);
                switch (ctrl)
                {
                case 1:
                    _TestDelegateEvent();
                    break;

                case 2:
                    _TestSingleton();
                    break;

                case 3:
                    IA ia = new C();
                    Console.WriteLine("子类对接口实现");
                    ia.H();
                    //需要明白父类和子类之间是如何实现多态的

                    /*
                     * 在运行时,会根据实际创建的对象类型决定使用那个方法。
                     * 一般将这称为动态绑定。
                     */
                    Console.WriteLine("不同子类对同一个类的继承,是如何形成多态的");
                    D d;
                    d = new C();
                    d.H();
                    d = new E();
                    d.H();
                    break;

                case 4:
                    System sys = new System();
                    System.Console.WriteLine("hello world");
                    //global::Console.WriteLine("global");//在全局命名空间里面没有找到命名空间是Console的
                    global::System.Console.WriteLine("global");

                    /*
                     *  如果global是为了避免命名冲突,但是为什么又说要通知编译器从根目录开始寻找这个namespace或者class
                     *  global::System 来表示根命名空间,而非是自定义类System
                     *  It's often added to generated code to avoid name clashes with user code.
                     */
                    break;

                case 5:
                    QuestionMark.Instance.Example1();
                    QuestionMark.Instance?.Example2();
                    QuestionMark.Instance.Example3();
                    QuestionMark.Instance.Example4();
                    break;

                case 6:
                    newProj.UsingGlobal.Print("hello world 6");    //使用命名空间别名
                    break;

                case 7:
                    Dictionary <string, Dictionary <string, string> > dic = new Dictionary <string, Dictionary <string, string> >();
                    Dictionary <string, string> dataItem = new Dictionary <string, string>();
                    Dictionary <string, string> msgItem  = new Dictionary <string, string>();
                    dataItem.Add("weekTask", "完成消耗500金币");
                    dataItem.Add("seasonTask", "一共完成十场周任务");
                    dataItem.Add("battlePassportLv", "积分/战星是1000");
                    dataItem.Add("shopItem", "任务卡");
                    dic.Add("data", dataItem);    //数据主要是服务器记录的信息,包括玩家的通行证等级、购买数据、一般是比较持久存储,不断根据玩家游戏经历更新的数据
                    msgItem.Add("buyLv", "购买等级成功");
                    msgItem.Add("sharePassport", "分享成功");
                    dic.Add("msg", msgItem);    //消息主要是玩家和游戏交互,传递的信息,包括点击购买等级、分享后等从服务器及时返回的消息
                    //dic.Add("code", codeItem);
                    string jsonStr = JsonUntity.SerializeDictionaryToJsonString <string, Dictionary <string, string> >(dic);
                    dic.Clear();
                    dic = JsonUntity.DeserializeStringToDictionary <string, Dictionary <string, string> >(jsonStr);
                    foreach (var item in dic)
                    {
                        Console.WriteLine($"item.key={item.Key},item.Value={item.Value}");
                        foreach (var tmp in item.Value)
                        {
                            Console.WriteLine($"tmp.key={tmp.Key},tmp.Value={tmp.Value}");
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            Console.ReadKey();
        }
예제 #19
0
        private void RoomSwitch(Client client, MyData data)
        {
            try
            {
                Room room = null;
                switch (data.Protocol)
                {
                case Protocol.CreateRoom:
                    CreateRoom(client, JsonUntity.Json2Object <GameSetting>(data.Body[0]));
                    break;

                case Protocol.JoinRoom:
                    int    room_id = -1;
                    string pass    = string.Empty;
                    if (data.Body.Count > 0)
                    {
                        room_id = int.Parse(data.Body[0]);
                        pass    = data.Body[1].ToString();
                    }
                    else
                    {
                        room_id = client.GameRoom;
                    }

                    bool result = false;
                    if (RId2Room.TryGetValue(room_id, out room))
                    {
                        //if (JoinRoom != null)
                        //{
                        //    Delegate[] delArray = JoinRoom.GetInvocationList();
                        //    foreach (Delegate del in delArray)
                        //    {
                        //        Room target = (Room)del.Target;
                        //        if (target != null && target.RoomId == room_id)
                        //        {
                        //            JoinRoomDelegate method = (JoinRoomDelegate)del;
                        //            result = method(client, room_id, pass);
                        //        }
                        //    }
                        //}
                        //JoinRoom?.Invoke(client, room_id, pass);
                        result = room.OnClientRequestInter(client, room_id, pass);
                    }
                    if (!result)
                    {
                        Debug(string.Format("{0} join request fail at hall", client.UserName));
                        data = new MyData
                        {
                            Description = PacketDescription.Hall2Cient,
                            Protocol    = Protocol.JoinRoom,
                        };
                        client.SendSwitchReply(data);
                    }
                    break;

                case Protocol.LeaveRoom:
                    if (RId2Room.TryGetValue(client.GameRoom, out room))
                    {
                        client.RequestLeaveRoom();
                    }
                    break;

                case Protocol.UpdateRoom:
                    client.RequstReady(bool.Parse(data.Body[0]));
                    break;

                case Protocol.RoleReserved:
                    if (client.UserRight >= 2 && RId2Room.TryGetValue(client.GameRoom, out room))
                    {
                        if (!room.GameStarted && room.Setting.GameMode == "Classic")
                        {
                            client.RoleReserved = data.Body[0];
                        }
                    }
                    break;

                case Protocol.GeneralReserved:
                    if (client.UserRight >= 2 && RId2Room.TryGetValue(client.GameRoom, out room) && !room.GameStarted &&
                        (room.Setting.GameMode == "Classic" || room.Setting.GameMode == "Hegemony") && data.Body.Count <= 2)
                    {
                        client.GeneralReserved = data.Body;
                    }
                    break;

                case Protocol.KickOff:
                    if (RId2Room.TryGetValue(client.GameRoom, out room) && room != null && room.Host == client && !room.GameStarted)
                    {
                        int victim_id = int.Parse(data.Body[0]);
                        if (!UId2ClientTable.TryGetValue(victim_id, out Client victim) || victim != null || victim_id < 0)
                        {
                            victim.RequestLeaveRoom(true);
                        }
                    }
                    break;

                case Protocol.ConfigChange:
                    if (RId2Room.TryGetValue(client.GameRoom, out room) && room != null && room.Host == client && !room.GameStarted)
                    {
                        GameSetting setting = JsonUntity.Json2Object <GameSetting>(data.Body[0]);
                        GameMode    mode    = Engine.GetMode(room.Setting.GameMode);

                        if (room.Setting.GameMode == setting.GameMode && room.Setting.PlayerNum == setting.PlayerNum && setting.GeneralPackage.Count > 0 && setting.CardPackage.Count > 0)
                        {
                            foreach (string general in setting.GeneralPackage)
                            {
                                if (!mode.GeneralPackage.Contains(general))
                                {
                                    return;
                                }
                            }

                            foreach (string card in setting.CardPackage)
                            {
                                if (!mode.CardPackage.Contains(card))
                                {
                                    return;
                                }
                            }

                            room.ChangeSetting(setting);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(null, e);
                Debug(string.Format("error on switch room {0} {1}", e.Message, e.TargetSite));
            }
        }
예제 #20
0
        public override void Assign(Room room)
        {
            AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options);

            List <Interactivity> receivers = new List <Interactivity>();

            foreach (Player player in options.Keys)
            {
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,
                    string.Empty,
                    JsonUntity.Object2Json(options[player]),
                    false.ToString(),
                    true.ToString(),
                    true.ToString()
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
            }

            List <Player> players   = room.Players;
            Countdown     countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (!string.IsNullOrEmpty(player.General1))
                {
                    continue;
                }
                bool          success = true;
                Interactivity client  = room.GetInteractivity(player);
                List <string> reply   = client?.ClientReply;
                if (client == null || !client.IsClientResponseReady || reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                {
                    success = false;
                }
                else
                {
                    string   generalName = reply[0];
                    string[] generals    = generalName.Split('+');
                    if (generals.Length != 2 || (!options[player].Contains(generals[0]) && room.GetClient(player).UserRight < 3) ||
                        (!options[player].Contains(generals[1]) && room.GetClient(player).UserRight < 3) ||
                        !SetPlayerGeneral(room, player, generals[0], true) ||
                        !SetPlayerGeneral(room, player, generals[1], false))
                    {
                        success = false;
                    }
                }
                if (!success)
                {
                    List <string> default_generals = GeneralSelctor.GeInstance().SelectGenerals(room, options[player]);
                    SetPlayerGeneral(room, player, default_generals[0], true);
                    SetPlayerGeneral(room, player, default_generals[1], false);
                }
            }

            foreach (Player player in players)
            {
                List <string> names = new List <string>();
                if (!string.IsNullOrEmpty(player.General1))
                {
                    string name = player.General1;
                    player.Kingdom = General.GetKingdom(Engine.GetGeneral(player.General1, room.Setting.GameMode).Kingdom[0]);
                    string role = Engine.GetMappedRole(player.Kingdom);
                    if (string.IsNullOrEmpty(role))
                    {
                        role = General.GetKingdom(Engine.GetGeneral(player.General1, room.Setting.GameMode).Kingdom[0]);
                    }
                    names.Add(name);
                    player.Role     = role;
                    player.General1 = "anjiang";
                    foreach (Client p in room.Clients)
                    {
                        if (p != room.GetClient(player))
                        {
                            room.NotifyProperty(p, player, "Kingdom", "god");
                        }
                    }
                    room.BroadcastProperty(player, "General1");
                    room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                    room.NotifyProperty(room.GetClient(player), player, "Kingdom");
                }

                if (!string.IsNullOrEmpty(player.General2))
                {
                    string name = player.General2;
                    names.Add(name);
                    player.General2 = "anjiang";
                    room.BroadcastProperty(player, "General2");
                    room.NotifyProperty(room.GetClient(player), player, "ActualGeneral2");
                }
                room.SetTag(player.Name, names);

                room.HandleUsedGeneral(names[0]);
                room.HandleUsedGeneral(names[1]);

                if (reserved.TryGetValue(player, out List <string> p_reserved) && (p_reserved.Contains(names[0]) || p_reserved.Contains(names[1])))
                {
                    LogMessage reserved_log = new LogMessage();
                    reserved_log.Type = "#reserved_pick";
                    reserved_log.From = player.Name;
                    room.SendLog(reserved_log);
                }

                if (!options[player].Contains(names[0]) || !options[player].Contains(names[1]))
                {
                    LogMessage log = new LogMessage();
                    log.Type = "#cheat_pick";
                    log.From = player.Name;
                    room.SendLog(log);
                }
            }

            //君主转换
            if (room.Setting.LordConvert)
            {
                room.AskForLordConvert();
            }

            foreach (Player player in players)
            {
                General general1 = Engine.GetGeneral(player.ActualGeneral1, room.Setting.GameMode);
                General general2 = Engine.GetGeneral(player.ActualGeneral2, room.Setting.GameMode);

                if (general1.CompanionWith(player.ActualGeneral2, Name))
                {
                    player.AddMark("CompanionEffect");
                }

                int max_hp = general1.GetMaxHpHead() + general2.GetMaxHpDeputy();
                player.SetMark("HalfMaxHpLeft", max_hp % 2);

                player.MaxHp = max_hp / 2;
                player.Hp    = player.MaxHp;

                room.BroadcastProperty(player, "MaxHp");
                room.BroadcastProperty(player, "Hp");
            }
        }
예제 #21
0
        public override void Assign(Room room)
        {
            System.Threading.Thread.Sleep(1000);
            //先确定两边主公
            foreach (Player lord in room.Players)
            {
                if (lord.GetRoleEnum() == Player.PlayerRole.Lord)
                {
                    if (lord.Camp == Game3v3Camp.S_CAMP_COOL)
                    {
                        lord.General1 = lord.ActualGeneral1 = "caocao_jx";
                    }
                    else
                    {
                        lord.General1 = lord.ActualGeneral1 = "yuanshao";
                    }

                    General lord_gen = Engine.GetGeneral(lord.General1, room.Setting.GameMode);
                    lord.PlayerGender   = lord_gen.GeneralGender;
                    lord.Kingdom        = General.GetKingdom(lord_gen.Kingdom[0]);
                    lord.General1Showed = true;
                    room.BroadcastProperty(lord, "General1");
                    room.BroadcastProperty(lord, "PlayerGender");
                    room.NotifyProperty(room.GetClient(lord), lord, "ActualGeneral1");
                    room.BroadcastProperty(lord, "Kingdom");
                    room.BroadcastProperty(lord, "General1Showed");
                    foreach (string skill in Engine.GetGeneralSkills(lord.General1, Name, true))
                    {
                        room.AddPlayerSkill(lord, skill);
                        Skill s = Engine.GetSkill(skill);
                        if (s != null && s.SkillFrequency == Frequency.Limited && !string.IsNullOrEmpty(s.LimitMark))
                        {
                            room.SetPlayerMark(lord, s.LimitMark, 1);
                        }
                    }

                    room.SendPlayerSkillsToOthers(lord, true);

                    //技能预亮
                    lord.SetSkillsPreshowed("hd");
                    room.NotifyPlayerPreshow(lord);
                    room.HandleUsedGeneral(lord.General1);
                }
            }

            System.Threading.Thread.Sleep(1000);

            //为其余玩家分配武将
            List <string> generals = room.Generals, warms = new List <string>(), cools = new List <string>();

            generals.Remove("caocao_jx"); generals.Remove("yuanshao");
            foreach (string general in generals)
            {
                General gen = Engine.GetGeneral(general, room.Setting.GameMode);
                if (gen.Kingdom[0] == General.KingdomENUM.Wei)
                {
                    cools.Add(general);
                }
                else
                {
                    warms.Add(general);
                }
            }
            Shuffle.shuffle(ref warms);
            Shuffle.shuffle(ref cools);

            Dictionary <Player, List <string> > options = new Dictionary <Player, List <string> >();

            foreach (Player player in room.Players)
            {
                if (player.GetRoleEnum() == Player.PlayerRole.Lord)
                {
                    continue;
                }
                List <string> choices = new List <string>();

                if (player.Camp == Game3v3Camp.S_CAMP_COOL)
                {
                    choices.Add(cools[0]);
                    cools.RemoveAt(0);
                    choices.Add(cools[0]);
                    cools.RemoveAt(0);
                }
                else
                {
                    choices.Add(warms[0]);
                    warms.RemoveAt(0);
                    choices.Add(warms[0]);
                    warms.RemoveAt(0);
                }

                options.Add(player, choices);
            }

            //玩家选将
            List <Interactivity> receivers = new List <Interactivity>();
            List <Player>        players   = new List <Player>();

            foreach (Player player in options.Keys)
            {
                if (player.GetRoleEnum() == Player.PlayerRole.Lord)
                {
                    continue;
                }
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,
                    string.Empty,
                    JsonUntity.Object2Json(options[player]),
                    true.ToString(),
                    true.ToString(),
                    false.ToString()
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            Countdown countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            //按武将强度排序
            List <string> prefer_cools = new List <string> {
                "xunyou", "xunyu", "chengyu", "guojia", "liuye", "caoren", "guanyu_sp", "xuhuang_jx", "zhangliao_jx",
                "hanhaoshihuan", "yujin", "caohong", "manchong", "litong", "zangba"
            };
            List <string> prefer_warms = new List <string> {
                "chunyuqiong", "xunchen", "shenpei", "liubei_gd", "chenlin_gd", "jvshou", "xuyou", "zhanghe_gd", "gaolan",
                "guotupangji", "tianfeng", "yanliangwenchou", "eryuan", "xinpi_gd", "erlv"
            };

            //给AI和超时的玩家自动选择武将
            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (string.IsNullOrEmpty(player.General1))
                {
                    string        generalName = string.Empty;
                    List <string> reply       = room.GetInteractivity(player)?.ClientReply;
                    bool          success     = true;
                    if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                    {
                        success = false;
                    }
                    else
                    {
                        generalName = reply[0];
                    }

                    if (!success || (!options[player].Contains(generalName) && room.GetClient(player).UserRight < 3) ||
                        (player.Camp == Game3v3Camp.S_CAMP_COOL && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0] != General.KingdomENUM.Wei) ||
                        (player.Camp == Game3v3Camp.S_CAMP_WARM && Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0] != General.KingdomENUM.Qun))
                    {
                        if (player.Status == "bot")
                        {
                            List <string> prefers;
                            if (player.Camp == Game3v3Camp.S_CAMP_COOL)
                            {
                                prefers = prefer_cools;
                            }
                            else
                            {
                                prefers = prefer_warms;
                            }

                            options[player].Sort((x, y) => { return(prefers.IndexOf(x) < prefers.IndexOf(y) ? -1 : 1); });
                        }
                        generalName = options[player][0];
                    }
                    player.General1       = generalName;
                    player.ActualGeneral1 = generalName;
                    player.Kingdom        = General.GetKingdom(Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0]);
                    player.General1Showed = true;
                }

                room.BroadcastProperty(player, "General1");
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                room.BroadcastProperty(player, "Kingdom");
                room.BroadcastProperty(player, "General1Showed");
                player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender;
                room.BroadcastProperty(player, "PlayerGender");

                player.SetSkillsPreshowed("hd");
                room.NotifyPlayerPreshow(player);
                List <string> names = new List <string> {
                    player.General1
                };
                room.SetTag(player.Name, names);
                room.HandleUsedGeneral(player.General1);
            }
        }
예제 #22
0
        public override void Assign(Room room)
        {
            //确定身份
            Player lord = room.Players[0];

            lord.Role = "lord";
            room.BroadcastProperty(lord, "Role");

            List <string> roles = new List <string> {
                "loyalist", "rebel", "renegade"
            };

            if (room.Players.Count == 5)
            {
                roles.Add("rebel");
            }
            else if (room.Players.Count == 6)
            {
                roles.Add("rebel");
                roles.Add("rebel");
            }
            else if (room.Players.Count == 7)
            {
                roles.Add("loyalist");
                roles.Add("rebel");
                roles.Add("rebel");
            }
            else if (room.Players.Count == 8)
            {
                roles.Add("loyalist");
                roles.Add("rebel");
                roles.Add("rebel");
                roles.Add("rebel");
            }
            List <Player> all = new List <Player>(room.Players);

            all.Remove(lord);

            //点选内奸的玩家
            List <Player> to_choose = new List <Player>();

            foreach (Player p in room.Players)
            {
                if (p.GetRoleEnum() != PlayerRole.Lord && room.GetClient(p).RoleReserved == "renegade")
                {
                    to_choose.Add(p);
                }
            }

            if (to_choose.Count > 0)
            {
                List <string> renegades = roles.FindAll(t => t == "renegade");
                Shuffle.shuffle(ref to_choose);
                for (int i = 0; i < Math.Min(to_choose.Count, renegades.Count); i++)
                {
                    to_choose[i].Role = "renegade";
                    roles.Remove("renegade");
                    all.Remove(to_choose[i]);
                }
            }

            //点选忠臣的玩家
            to_choose.Clear();
            foreach (Player p in room.Players)
            {
                if (p.GetRoleEnum() != PlayerRole.Lord && room.GetClient(p).RoleReserved == "loyalist")
                {
                    to_choose.Add(p);
                }
            }

            if (to_choose.Count > 0)
            {
                List <string> loyalists = roles.FindAll(t => t == "loyalist");
                Shuffle.shuffle(ref to_choose);
                for (int i = 0; i < Math.Min(loyalists.Count, to_choose.Count); i++)
                {
                    to_choose[i].Role = "loyalist";
                    roles.Remove("loyalist");
                    all.Remove(to_choose[i]);
                }
            }
            //点选反贼的玩家
            to_choose.Clear();
            foreach (Player p in room.Players)
            {
                if (p.GetRoleEnum() != PlayerRole.Lord && room.GetClient(p).RoleReserved == "rebel")
                {
                    to_choose.Add(p);
                }
            }

            if (to_choose.Count > 0)
            {
                List <string> rebels = roles.FindAll(t => t == "rebel");
                Shuffle.shuffle(ref to_choose);
                for (int i = 0; i < Math.Min(rebels.Count, to_choose.Count); i++)
                {
                    to_choose[i].Role = "rebel";
                    roles.Remove("rebel");
                    all.Remove(to_choose[i]);
                }
            }

            //为剩余玩家随机身份
            if (roles.Count > 0)
            {
                Shuffle.shuffle(ref roles);
                for (int i = 0; i < all.Count; i++)
                {
                    all[i].Role = roles[i];
                }
            }

            //通知各玩家身份
            foreach (Player p in room.Players)
            {
                room.NotifyProperty(room.GetClient(p), p, "Role");
            }

            room.UpdateStateItem();

            Thread.Sleep(2500);

            AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options);
            //主公选将
            string lord_general = room.AskForGeneral(lord, new List <string>(options[lord]), string.Empty, true, "gamerule", null, true);

            lord.General1       = lord_general;
            lord.ActualGeneral1 = lord_general;
            General lord_gen = Engine.GetGeneral(lord_general, room.Setting.GameMode);

            lord.PlayerGender   = lord_gen.GeneralGender;
            lord.Kingdom        = lord_gen.Kingdom;
            lord.General1Showed = true;
            room.BroadcastProperty(lord, "General1");
            room.BroadcastProperty(lord, "PlayerGender");
            room.NotifyProperty(room.GetClient(lord), lord, "ActualGeneral1");
            room.BroadcastProperty(lord, "Kingdom");
            room.BroadcastProperty(lord, "General1Showed");

            foreach (string skill in Engine.GetGeneralSkills(lord_general, Name, true))
            {
                room.AddPlayerSkill(lord, skill);
                Skill s = Engine.GetSkill(skill);
                if (skill != null && s.SkillFrequency == Frequency.Limited && !string.IsNullOrEmpty(s.LimitMark))
                {
                    room.SetPlayerMark(lord, s.LimitMark, 1);
                }
            }
            room.SendPlayerSkillsToOthers(lord, true);

            //技能预亮
            lord.SetSkillsPreshowed("hd");
            room.NotifyPlayerPreshow(lord);
            //主公神将选国籍
            string        choice  = "wei+qun+shu+wu";
            List <string> prompts = new List <string> {
                "@choose-kingdom"
            };

            if (lord.Kingdom == "god")
            {
                lord.Kingdom = room.AskForChoice(lord, "Kingdom", choice, prompts);
                room.BroadcastProperty(lord, "Kingdom");
            }

            //其他玩家选将
            List <Client> receivers = new List <Client>();
            List <Player> players   = new List <Player>();

            foreach (Player player in options.Keys)
            {
                if (player.GetRoleEnum() == PlayerRole.Lord)
                {
                    continue;
                }
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,
                    string.Empty,
                    JsonUntity.Object2Json(options[player]),
                    true.ToString(),
                    true.ToString(),
                    false.ToString()
                };
                Client client = room.GetClient(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            Countdown countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_CHOOSE_GENERAL, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_CHOOSE_GENERAL);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            //给AI和超时的玩家自动选择武将
            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (string.IsNullOrEmpty(player.General1))
                {
                    string        generalName = string.Empty;
                    Client        client      = room.GetClient(player);
                    List <string> reply       = client?.ClientReply;
                    bool          success     = true;
                    if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                    {
                        success = false;
                    }
                    else
                    {
                        generalName = reply[0];
                    }

                    if (!success || (!options[player].Contains(Engine.GetMainGeneral(generalName)) && room.GetClient(player).UserRight < 3))
                    {
                        generalName = options[player][0];
                    }

                    player.General1       = generalName;
                    player.ActualGeneral1 = generalName;
                    player.Kingdom        = Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom;
                    player.General1Showed = true;
                }

                room.BroadcastProperty(player, "General1");
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                room.BroadcastProperty(player, "Kingdom");
                room.BroadcastProperty(player, "General1Showed");
                player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender;
                room.BroadcastProperty(player, "PlayerGender");

                player.SetSkillsPreshowed("hd");
                room.NotifyPlayerPreshow(player);
                List <string> names = new List <string> {
                    player.General1
                };
                room.SetTag(player.Name, names);
                room.HandleUsedGeneral(player.General1);
            }

            //非主公神将选国籍
            receivers.Clear();
            players.Clear();
            foreach (Player player in room.Players)
            {
                if (player.Kingdom != "god")
                {
                    continue;
                }
                List <string> args = new List <string>
                {
                    player.Name,
                    "Kingdom",
                    choice,
                    JsonUntity.Object2Json(prompts)
                };
                Client client = room.GetClient(player);
                if (client != null && !receivers.Contains(client))
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_MULTIPLE_CHOICE, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };
            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_MULTIPLE_CHOICE);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            foreach (Player player in players)
            {
                string        answer      = string.Empty;
                List <string> clientReply = room.GetClient(player).ClientReply;
                if (clientReply != null && clientReply.Count > 0)
                {
                    answer = clientReply[0];
                }
                List <string> choices = new List <string>(choice.Split('+'));

                if (string.IsNullOrEmpty(answer) || !choices.Contains(answer))
                {
                    Shuffle.shuffle(ref choices);
                    answer = choices[0];
                }
                player.Kingdom = answer;
                room.BroadcastProperty(player, "Kingdom");
            }
        }
예제 #23
0
        public override void Assign(Room room)
        {
            System.Threading.Thread.Sleep(1000);

            List <Player> players = new List <Player>();

            if (room.Players.Count == 8)
            {
                List <string> soldiers = new List <string> {
                    "longxiangjun", "hubenjun", "baoluejun", "fengyaojun", "feixiongjun", "tanlangjun"
                };
                Shuffle.shuffle(ref soldiers);

                room.Players[1].General1 = room.Players[1].ActualGeneral1 = soldiers[0];
                room.Players[2].General1 = room.Players[2].ActualGeneral1 = "huaxiong_al";
                room.Players[3].General1 = room.Players[3].ActualGeneral1 = soldiers[1];
                room.Players[5].General1 = room.Players[5].ActualGeneral1 = soldiers[2];
                room.Players[6].General1 = room.Players[6].ActualGeneral1 = "sunjian_jx";
                room.Players[7].General1 = room.Players[7].ActualGeneral1 = soldiers[3];

                players.Add(room.Players[0]);
                players.Add(room.Players[4]);
                foreach (Player lord in room.Players)
                {
                    if (lord.Camp == Game3v3Camp.S_CAMP_WARM || lord.General1 == "sunjian_jx")
                    {
                        General lord_gen = Engine.GetGeneral(lord.General1, room.Setting.GameMode);
                        lord.PlayerGender   = lord_gen.GeneralGender;
                        lord.Kingdom        = General.GetKingdom(lord_gen.Kingdom[0]);
                        lord.General1Showed = true;
                        room.BroadcastProperty(lord, "General1");
                        room.BroadcastProperty(lord, "PlayerGender");
                        room.BroadcastProperty(lord, "Kingdom");
                        room.BroadcastProperty(lord, "General1Showed");
                        foreach (string skill in Engine.GetGeneralSkills(lord.General1, Name, true))
                        {
                            room.AddPlayerSkill(lord, skill);
                            Skill s = Engine.GetSkill(skill);
                            if (s != null && s.SkillFrequency == Frequency.Limited && !string.IsNullOrEmpty(s.LimitMark))
                            {
                                room.SetPlayerMark(lord, s.LimitMark, 1);
                            }
                        }

                        room.SendPlayerSkillsToOthers(lord, true);

                        //技能预亮
                        lord.SetSkillsPreshowed("hd");
                        room.NotifyPlayerPreshow(lord);
                        room.HandleUsedGeneral(lord.General1);
                    }
                }
            }
            else
            {
                //随机关卡
                Random rand  = new Random();
                int    stage = rand.Next(0, 6);
                //AI将领
                switch (stage)
                {
                case 0:
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "zhangji_al";
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = room.Players[4].General1 = room.Players[4].ActualGeneral1 = "longxiangjun";
                    break;

                case 1:
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "fanchou_al";
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = room.Players[4].General1 = room.Players[4].ActualGeneral1 = "hubenjun";
                    break;

                case 2:
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "dongxie_al";
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = room.Players[4].General1 = room.Players[4].ActualGeneral1 = "fengyaojun";
                    break;

                case 3:
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "dongyue_al";
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = room.Players[4].General1 = room.Players[4].ActualGeneral1 = "baoluejun";
                    break;

                case 4:
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = "tanlangjun";
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "lijue_al";
                    room.Players[4].General1 = room.Players[4].ActualGeneral1 = "feixiongjun";
                    break;

                case 5:
                    room.Players[2].General1 = room.Players[2].ActualGeneral1 = "tanlangjun";
                    room.Players[3].General1 = room.Players[3].ActualGeneral1 = "guosi_al";
                    room.Players[4].General1 = room.Players[4].ActualGeneral1 = "feixiongjun";
                    break;
                }

                players.Add(room.Players[0]);
                players.Add(room.Players[1]);
                foreach (Player lord in room.Players)
                {
                    if (lord.Camp == Game3v3Camp.S_CAMP_WARM)
                    {
                        General lord_gen = Engine.GetGeneral(lord.General1, room.Setting.GameMode);
                        lord.PlayerGender   = lord_gen.GeneralGender;
                        lord.Kingdom        = General.GetKingdom(lord_gen.Kingdom[0]);
                        lord.General1Showed = true;
                        room.BroadcastProperty(lord, "General1");
                        room.BroadcastProperty(lord, "PlayerGender");
                        room.BroadcastProperty(lord, "Kingdom");
                        room.BroadcastProperty(lord, "General1Showed");
                        foreach (string skill in Engine.GetGeneralSkills(lord.General1, Name, true))
                        {
                            room.AddPlayerSkill(lord, skill);
                            Skill s = Engine.GetSkill(skill);
                            if (s != null && s.SkillFrequency == Frequency.Limited && !string.IsNullOrEmpty(s.LimitMark))
                            {
                                room.SetPlayerMark(lord, s.LimitMark, 1);
                            }
                        }

                        room.SendPlayerSkillsToOthers(lord, true);

                        //技能预亮
                        lord.SetSkillsPreshowed("hd");
                        room.NotifyPlayerPreshow(lord);
                        room.HandleUsedGeneral(lord.General1);
                    }
                }
            }
            System.Threading.Thread.Sleep(700);

            //为其余玩家分配武将
            AssignGeneralsForPlayers(room, out Dictionary <Player, List <string> > options);
            //选将
            List <Interactivity> receivers             = new List <Interactivity>();
            Dictionary <string, List <string> > choose = new Dictionary <string, List <string> >();

            foreach (Player player in options.Keys)
            {
                choose[player.Name] = options[player];
            }

            foreach (Player player in options.Keys)
            {
                player.SetTag("generals", JsonUntity.Object2Json(options[player]));
                List <string> args = new List <string>
                {
                    player.Name,
                    JsonUntity.Object2Json(choose),
                };
                Interactivity client = room.GetInteractivity(player);
                if (client != null)
                {
                    client.CommandArgs = args;
                    receivers.Add(client);
                }
                players.Add(player);
            }

            Countdown countdown = new Countdown
            {
                Max  = room.Setting.GetCommandTimeout(CommandType.S_COMMAND_GENERAL_PICK, ProcessInstanceType.S_CLIENT_INSTANCE),
                Type = Countdown.CountdownType.S_COUNTDOWN_USE_SPECIFIED
            };

            room.NotifyMoveFocus(players, countdown);
            room.DoBroadcastRequest(receivers, CommandType.S_COMMAND_GENERAL_PICK);
            room.DoBroadcastNotify(CommandType.S_COMMAND_UNKNOWN, new List <string> {
                false.ToString()
            });

            //给AI和超时的玩家自动选择武将
            foreach (Player player in options.Keys)
            {
                player.RemoveTag("generals");
                if (string.IsNullOrEmpty(player.General1))
                {
                    string        generalName = string.Empty;
                    Interactivity client      = room.GetInteractivity(player);
                    List <string> reply       = client?.ClientReply;
                    bool          success     = true;
                    if (reply == null || reply.Count == 0 || string.IsNullOrEmpty(reply[0]))
                    {
                        success = false;
                    }
                    else
                    {
                        generalName = reply[0];
                    }

                    if (!success)
                    {
                        if (client == null)
                        {
                            continue;
                        }
                        else
                        {
                            generalName = options[player][0];
                        }
                    }
                    else if (!string.IsNullOrEmpty(generalName) && !options[player].Contains(generalName) && room.GetClient(player).UserRight < 3)
                    {
                        generalName = options[player][0];
                    }

                    player.General1       = generalName;
                    player.ActualGeneral1 = generalName;
                    player.Kingdom        = General.GetKingdom(Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0]);
                    player.General1Showed = true;
                }

                room.BroadcastProperty(player, "General1");
                room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                room.BroadcastProperty(player, "Kingdom");
                room.BroadcastProperty(player, "General1Showed");
                player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender;
                room.BroadcastProperty(player, "PlayerGender");

                player.SetSkillsPreshowed("hd");
                room.NotifyPlayerPreshow(player);
                List <string> names = new List <string> {
                    player.General1
                };
                room.SetTag(player.Name, names);
                room.HandleUsedGeneral(player.General1);
            }

            foreach (Player player in options.Keys)
            {
                if (string.IsNullOrEmpty(player.General1))
                {
                    Player human = null;
                    foreach (Player p2 in options.Keys)
                    {
                        if (p2 != player)
                        {
                            human = p2;
                            break;
                        }
                    }
                    string generalName = room.AskForGeneral(human, options[player], null, true, Name, null, true);

                    player.General1       = generalName;
                    player.ActualGeneral1 = generalName;
                    player.Kingdom        = General.GetKingdom(Engine.GetGeneral(generalName, room.Setting.GameMode).Kingdom[0]);
                    player.General1Showed = true;

                    room.BroadcastProperty(player, "General1");
                    room.NotifyProperty(room.GetClient(player), player, "ActualGeneral1");
                    room.BroadcastProperty(player, "Kingdom");
                    room.BroadcastProperty(player, "General1Showed");
                    player.PlayerGender = Engine.GetGeneral(player.General1, room.Setting.GameMode).GeneralGender;
                    room.BroadcastProperty(player, "PlayerGender");

                    player.SetSkillsPreshowed("hd");
                    room.NotifyPlayerPreshow(player);
                    List <string> names = new List <string> {
                        player.General1
                    };
                    room.SetTag(player.Name, names);
                    room.HandleUsedGeneral(player.General1);
                }
            }
        }