コード例 #1
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            map = string.IsNullOrEmpty(arguments)
                ? MapPicker.GetRecommendedMap(battle.GetContext())
                : MapPicker.FindResources(ResourceType.Map, arguments, battle.MinimalMapSupportLevel).FirstOrDefault();


            if (map == null)
            {
                battle.Respond(e, "Cannot find such map.");
                return(null);
            }
            else if (map.InternalName == battle.MapName)
            {
                battle.Respond(e, "Already on this map.");
                return(null);
            }
            else if (!string.IsNullOrEmpty(arguments) && map.MapSupportLevel < MapSupportLevel.Supported)
            {
                alternativeMap = MapPicker.FindResources(ResourceType.Map, arguments, MapSupportLevel.Supported).FirstOrDefault();
            }


            if (map.MapSupportLevel >= MapSupportLevel.Supported)
            {
                return($"Change map to {map.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID} ?");
            }
            else
            {
                return($"Change to UNSUPPORTED map {map.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID} ?");
            }
        }
コード例 #2
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            map = string.IsNullOrEmpty(arguments)
                ? MapPicker.GetRecommendedMap(battle.GetContext())
                : MapPicker.FindResources(ResourceType.Map, arguments).FirstOrDefault();

            if (map == null)
            {
                battle.Respond(e, "Cannot find such map.");
                return(null);
            }

            return($"Change map to {map.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID} ?");
        }
コード例 #3
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            Map = string.IsNullOrEmpty(arguments)
                ? MapPicker.GetRecommendedMap(battle.GetContext(), (battle.MinimalMapSupportLevel > MapSupportLevel.Featured) ? battle.MinimalMapSupportLevel : MapSupportLevel.Featured)
                : MapPicker.FindResources(ResourceType.Map, arguments, battle.MinimalMapSupportLevel, true).FirstOrDefault();


            if (Map == null)
            {
                var unsupportedMap = MapPicker.FindResources(ResourceType.Map, arguments, MapSupportLevel.None).FirstOrDefault();
                if (unsupportedMap != null)
                {
                    if (battle.IsAutohost)
                    {
                        battle.Respond(e, $"The map {unsupportedMap.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{unsupportedMap.ResourceID} is not available on this autohost. Play it in a player hosted battle.");
                    }
                    else
                    {
                        battle.Respond(e, $"The map {unsupportedMap.InternalName} {GlobalConst.BaseSiteUrl}/Maps/Detail/{unsupportedMap.ResourceID} is not supported. Unsupported maps can only be played on passworded hosts.");
                    }
                }
                else
                {
                    battle.Respond(e, "Cannot find such a map.");
                }
                return(null);
            }
            else if (Map.InternalName == battle.MapName)
            {
                battle.Respond(e, "Already on this map.");
                return(null);
            }
            else if (!string.IsNullOrEmpty(arguments) && Map.MapSupportLevel < MapSupportLevel.Supported)
            {
                alternativeMap = MapPicker.FindResources(ResourceType.Map, arguments, MapSupportLevel.Supported, true).FirstOrDefault();
            }


            if (Map.MapSupportLevel >= MapSupportLevel.Supported)
            {
                return($"Change map to {Map.InternalName}?");
            }
            else
            {
                return($"Change to UNSUPPORTED map {Map.InternalName}?");
            }
        }
コード例 #4
0
        private async Task <bool> CreateMultiMapPoll()
        {
            var poll = new CommandPoll(this, false, false, true);

            poll.PollEnded += MapVoteEnded;
            var        options    = new List <PollOption>();
            List <int> pickedMaps = new List <int>();

            pickedMaps.Add(HostedMap?.ResourceID ?? 0);
            using (var db = new ZkDataContext())
            {
                for (int i = 0; i < NumberOfMapChoices; i++)
                {
                    Resource map = null;
                    if (i < NumberOfMapChoices / 2)
                    {
                        map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Supported) ? MapSupportLevel.Supported : MinimalMapSupportLevel, MapRatings.GetMapRanking(Mode).TakeWhile(x => x.Percentile < 0.2).Select(x => x.Map).Where(x => !pickedMaps.Contains(x.ResourceID)).AsQueryable()); //choose at least 50% popular maps
                    }
                    if (map == null)
                    {
                        map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Featured) ? MapSupportLevel.Supported : MinimalMapSupportLevel, db.Resources.Where(x => !pickedMaps.Contains(x.ResourceID)));
                    }
                    pickedMaps.Add(map.ResourceID);
                    options.Add(new PollOption()
                    {
                        Name       = map.InternalName,
                        URL        = $"{GlobalConst.BaseSiteUrl}/Maps/Detail/{map.ResourceID}",
                        ResourceID = map.ResourceID,
                        Action     = async() =>
                        {
                            var cmd = new CmdMap().Create();
                            cmd.Arm(this, null, map.ResourceID.ToString());
                            if (cmd.Access == BattleCommand.AccessType.NotIngame && spring.IsRunning)
                            {
                                return;
                            }
                            if (cmd.Access == BattleCommand.AccessType.Ingame && !spring.IsRunning)
                            {
                                return;
                            }
                            await cmd.ExecuteArmed(this, null);
                        }
                    });
                }
            }
            return(await StartVote(new CmdMap().GetIneligibilityReasonFunc(this), options, null, "Choose the next map", poll, MapVoteTime));
        }
コード例 #5
0
 public RecommendedMapResult GetRecommendedMap(BattleContext context, bool pickNew)
 {
     return(MapPicker.GetRecommendedMap(context, pickNew));
 }
コード例 #6
0
        public void ValidateAndFillDetails()
        {
            if (IsNullOrEmpty(Title))
            {
                Title = $"{FounderName}'s game";
            }
            if (IsNullOrEmpty(EngineVersion) || (Mode != AutohostMode.None))
            {
                EngineVersion = server.Engine;
            }
            server.Downloader.GetResource(DownloadType.ENGINE, server.Engine);

            switch (Mode)
            {
            case AutohostMode.Game1v1:
                MaxPlayers = 2;
                break;

            case AutohostMode.Planetwars:
                if (MaxPlayers < 2)
                {
                    MaxPlayers = 16;
                }
                break;

            case AutohostMode.GameChickens:
                if (MaxPlayers < 2)
                {
                    MaxPlayers = 10;
                }
                break;

            case AutohostMode.GameFFA:
                if (MaxPlayers < 3)
                {
                    MaxPlayers = 16;
                }
                break;

            case AutohostMode.Teams:
                if (MaxPlayers < 4)
                {
                    MaxPlayers = 16;
                }
                break;

            case AutohostMode.None:
                if (MaxPlayers == 0)
                {
                    MaxPlayers = 16;
                }
                break;
            }
            if (MaxPlayers > 32)
            {
                MaxPlayers = 32;
            }

            HostedMod = MapPicker.FindResources(ResourceType.Mod, ModName ?? server.Game ?? GlobalConst.DefaultZkTag).FirstOrDefault();
            HostedMap = MapName != null
                ? MapPicker.FindResources(ResourceType.Map, MapName).FirstOrDefault()
                : MapPicker.GetRecommendedMap(GetContext());

            ModName = HostedMod?.InternalName ?? ModName ?? server.Game ?? GlobalConst.DefaultZkTag;
            MapName = HostedMap?.InternalName ?? MapName ?? "Small_Divide-Remake-v04";

            if (HostedMod != null)
            {
                try
                {
                    HostedModInfo = MetaDataCache.ServerGetMod(HostedMod.InternalName);
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Error loading mod metadata for {0} : {1}", HostedMod.InternalName, ex);
                }
            }
        }