Пример #1
0
        private void SayNextMap()
        {
            if (CurrentPlaylist.Count == 0)
            {
                BuildPlaylist(GameInterface.GetDvar("mapname", ""));
            }

            if (CurrentPlaylist.Count > 0)
            {
                Utilities.SayAll("Next map: " + CurrentPlaylist[0].Map + " (" + CurrentPlaylist[0].GameType.Name + ")");
            }
        }
Пример #2
0
        public WebHome()
            : base()
        {
            Get["/"] = parameters =>
            {
                // fetch stat points
                var oneDayAgo  = DateTime.UtcNow - new TimeSpan(24, 0, 0);
                var statPoints = WebBaseScript.Database.Table <PlayerCountStatisticPoint>().Where(p => p.Time >= oneDayAgo);

                return(View["Index", new
                            {
                                StatPoints = statPoints,
                                MapName = GameInterface.GetDvar("mapname", ""),
                                GameType = GameInterface.GetDvar("g_gametype", "dm"),
                                PlayerLimit = GameInterface.GetDvar("sv_maxclients", "0"),
                                PlayerCount = WebBaseScript.NumPlayers
                            }]);
            };
        }
Пример #3
0
        public static void RotateMap()
        {
            try
            {
                if (CurrentPlaylist.Count == 0)
                {
                    BuildPlaylist(GameInterface.GetDvar("mapname", ""));

                    if (CurrentPlaylist.Count == 0)
                    {
                        Utilities.ExecuteCommand("map_restart");
                        return;
                    }
                }

                var nextEntry = CurrentPlaylist[0];
                CurrentPlaylist.RemoveAt(0);

                GameType = nextEntry.GameType;

                ApplyVariables(Rules);
                ApplyVariables(Values);
                ApplyVariables(nextEntry.GameType.Rules);
                ApplyVariables(nextEntry.GameType.Values);
                ApplyVariables(Playlist.Rules);
                ApplyVariables(Playlist.Values);

                Utilities.ExecuteCommand("ui_gametype {0}; g_gametype {1}; map {2}; ", nextEntry.GameType.Script, nextEntry.GameType.Script, nextEntry.Map);
            }
            catch (Exception ex)
            {
                Log.Error("Error during map rotation: " + ex.ToString());

                Utilities.ExecuteCommand("map_restart");
            }
        }
Пример #4
0
 static WebBaseScript()
 {
     Database = new SQLiteConnection("zone/" + GameInterface.GetDvar("sv_baseConfigName", "dummy") + ".iw4db", true);
     Database.CreateTable <PlayerCountStatisticPoint>();
 }
Пример #5
0
        private static void BuildPlaylist(string currentMap = "")
        {
            // generate a list containing unique maps, with entries the number of times as the weight indicates
            var list     = new List <PlaylistEntry>();
            var mapsDone = new HashSet <string>();

            var rnd = new Random();

            var curPlaylistId = int.Parse(GameInterface.GetDvar("playlist", "0"));

            if (curPlaylistId < 0 || curPlaylistId > PlaylistSet.Playlists.Length)
            {
                Log.Debug("curPlaylistId seems invalid.");
                return;
            }

            var curPlaylist = PlaylistSet.Playlists[curPlaylistId];

            if (curPlaylist == null)
            {
                Log.Debug("curPlaylistId seems null.");
                return;
            }

            Playlist = curPlaylist;

            var newEntries = from e in curPlaylist.Entries
                             orderby rnd.Next()
                             select e;

            foreach (var entry in newEntries)
            {
                if (!mapsDone.Contains(entry.Map))
                {
                    list.Add(entry);
                    mapsDone.Add(entry.Map);
                }
            }

            // duplicate the entries with a >1 weight
            var duplicateList = list.GetRange(0, list.Count);

            foreach (var entry in duplicateList)
            {
                if (entry.Weight > 1)
                {
                    for (int i = 1; i < entry.Weight; i++)
                    {
                        list.Add(entry);
                    }
                }
            }

            // shuffle the list, again
            list = (from e in list
                    orderby rnd.Next()
                    select e).ToList();

            // remove current map from start of list, so we won't rotate to the same map
            if (list.Count > 0 && list[0].Map == currentMap)
            {
                list.RemoveAt(0);
            }

            CurrentPlaylist = list;
        }