Beispiel #1
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");
            }
        }
Beispiel #2
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 (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);
            //主公神将选国籍
            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 <Interactivity> receivers = new List <Interactivity>();
            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()
                };
                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()
            });

            //给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(options[player], player.GetRoleEnum());
                        }
                        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);
            }

            //非主公神将选国籍
            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;
                List <string> clientReply = room.GetInteractivity(player).ClientReply;
                if (clientReply != null && clientReply.Count > 0)
                {
                    answer = clientReply[0];
                }

                TrustedAI ai = room.GetAI(player);
                if (ai != null && ai is StupidAI)
                {
                    foreach (Player p in room.GetAllPlayers())
                    {
                        if (p.GetRoleEnum() == Player.PlayerRole.Lord)
                        {
                            answer = p.Kingdom;
                            break;
                        }
                    }
                }

                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");
            }
        }