Пример #1
0
        public static GeneralSelctor GeInstance()
        {
            if (selctor == null)
            {
                selctor = new GeneralSelctor();
            }

            return(selctor);
        }
Пример #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 (!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);
            }
        }
Пример #3
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");
            }
        }