Exemplo n.º 1
0
        static bool CheckPlayersMinimumConditions(BattleContext battleContext,
                                                  ZkDataContext dataContext,
                                                  AutohostConfig config,
                                                  ref string actionsDescription)
        {
            var ok = true;

            foreach (
                var p in
                battleContext.Players.Where(x => !x.IsSpectator)
                .Select(x => new { player = x, account = dataContext.Accounts.First(y => y.AccountID == x.LobbyID) }))
            {
                if ((config.MinLevel != null && p.account.Level < config.MinLevel) || (config.MaxLevel != null && p.account.Level > config.MaxLevel) ||
                    (config.MinElo != null && p.account.EffectiveElo < config.MinElo) ||
                    (config.MaxElo != null && p.account.EffectiveElo > config.MaxElo))
                {
                    SpecPlayerOnCondition(p.player,
                                          p.account,
                                          string.Format(
                                              "Sorry, you cannot play here because of skill limits. You can spectate/observe this game however."));
                    actionsDescription += string.Format("{0} cannot play here because of skill limits\n", p.account.Name);
                    ok = false;
                }
            }
            return(ok);
        }
Exemplo n.º 2
0
 public AhConfig(AutohostConfig db)
 {
     Login                  = db.Login;
     Password               = db.Password;
     JoinChannels           = (db.JoinChannels + "").Split('\n').Where(x => !string.IsNullOrEmpty(x)).ToArray();
     Title                  = db.Title;
     Welcome                = db.Welcome;
     Map                    = db.Map;
     Mod                    = db.Mod;
     MaxPlayers             = db.MaxPlayers;
     AutoSpawnClones        = db.AutoSpawn;
     AutoUpdateRapidTag     = db.AutoUpdateRapidTag;
     SpringVersion          = db.SpringVersion;
     SplitBiggerThan        = db.SplitBiggerThan;
     AutoUpdateSpringBranch = db.AutoUpdateSpringBranch;
     Mode                   = db.AutohostMode;
     BattlePassword         = db.BattlePassword;
     CommandLevels          = (db.CommandLevels + "").Split('\n').Where(x => !string.IsNullOrEmpty(x)).Select(x =>
     {
         var parts = x.Split('=');
         return(new CommandLevel()
         {
             Command = parts[0], Level = int.Parse(parts[1])
         });
     }).ToArray();
 }
Exemplo n.º 3
0
        public AutohostConfig GetConfig()
        {
            if (config != null)
            {
                return(config);
            }
            if (string.IsNullOrEmpty(AutohostName))
            {
                return(null);
            }
            var db    = new ZkDataContext();
            var name  = AutohostName.TrimNumbers();
            var entry = db.AutohostConfigs.SingleOrDefault(x => x.Login == name);

            if (entry != null)
            {
                config = entry;
            }
            return(config);
        }
        public static PlayerJoinResult AutohostPlayerJoined(BattleContext context, int accountID)
        {
            var          res  = new PlayerJoinResult();
            var          db   = new ZkDataContext();
            AutohostMode mode = context.GetMode();

            if (mode == AutohostMode.Planetwars)
            {
                Planet planet = db.Galaxies.Single(x => x.IsDefault).Planets.SingleOrDefault(x => x.Resource.InternalName == context.Map);
                if (planet == null)
                {
                    res.PublicMessage = "Invalid map";
                    return(res);
                }
                Account account = db.Accounts.Find(accountID); // accountID is in fact lobbyID

                if (account != null)
                {
                    var config = context.GetConfig();
                    if (account.Level < config.MinLevel)
                    {
                        res.PrivateMessage = string.Format("Sorry, PlanetWars is competive online campaign for experienced players. You need to be at least level {0} to play here. To increase your level, play more games on other hosts or open multiplayer game and play against computer AI bots.  You can still spectate this game, however.", config.MinLevel);
                        res.ForceSpec      = true;
                        return(res);
                    }


                    string owner = "";
                    if (planet.Account != null)
                    {
                        owner = planet.Account.Name;
                    }
                    string facRoles = string.Join(",",
                                                  account.AccountRolesByAccountID.Where(x => !x.RoleType.IsClanOnly).Select(x => x.RoleType.Name).ToList());
                    if (!string.IsNullOrEmpty(facRoles))
                    {
                        facRoles += " of " + account.Faction.Name + ", ";
                    }

                    string clanRoles = string.Join(",",
                                                   account.AccountRolesByAccountID.Where(x => x.RoleType.IsClanOnly).Select(x => x.RoleType.Name).ToList());
                    if (!string.IsNullOrEmpty(clanRoles))
                    {
                        clanRoles += " of " + account.Clan.ClanName;
                    }

                    res.PublicMessage = string.Format("Greetings {0} {1}{2}, welcome to {3} planet {4} {6}/PlanetWars/Planet/{5}",
                                                      account.Name,
                                                      facRoles,
                                                      clanRoles,
                                                      owner,
                                                      planet.Name,
                                                      planet.PlanetID,
                                                      GlobalConst.BaseSiteUrl);

                    return(res);
                }
            }
            Account acc = db.Accounts.Find(accountID); // accountID is in fact lobbyID

            if (acc != null)
            {
                AutohostConfig config = context.GetConfig();
                if (acc.Level < config.MinLevel)
                {
                    res.PrivateMessage = string.Format("Sorry, you need to be at least level {0} to play here. To increase your level, play more games on other hosts or open multiplayer game and play against computer AI bots. You can still spectate this game, however.",
                                                       config.MinLevel);
                    res.ForceSpec = true;
                    return(res);
                }
                else if (acc.Level > config.MaxLevel)
                {
                    res.PrivateMessage = string.Format("Sorry, your level must be {0} or lower to play here. Pick on someone your own size! You can still spectate this game, however.",
                                                       config.MaxLevel);
                    res.ForceSpec = true;
                    return(res);
                }

                // FIXME: use 1v1 Elo for 1v1
                if (acc.EffectiveElo < config.MinElo)
                {
                    res.PrivateMessage = string.Format("Sorry, you need to have an Elo rating of at least {0} to play here. Win games against human opponents to raise your Elo. You can still spectate this game, however.",
                                                       config.MinElo);
                    res.ForceSpec = true;
                    return(res);
                }
                else if (acc.EffectiveElo > config.MaxElo)
                {
                    res.PrivateMessage = string.Format("Sorry, your Elo rating must be {0} or lower to play here. Pick on someone your own size! You can still spectate this game, however.",
                                                       config.MaxElo);
                    res.ForceSpec = true;
                    return(res);
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        static BalanceTeamsResult PerformBalance(BattleContext context,
                                                 bool isGameStart,
                                                 int?allyCount,
                                                 bool?clanWise,
                                                 AutohostConfig config,
                                                 int playerCount)
        {
            var res  = new BalanceTeamsResult();
            var mode = context.GetMode();

            using (var db = new ZkDataContext()) {
                if (!CheckPlayersMinimumConditions(context, db, config, ref res.Message))
                {
                    res.CanStart = false;
                    return(res);
                }

                switch (mode)
                {
                case AutohostMode.None:
                {
                    if (!isGameStart)
                    {
                        res = new Balancer().LegacyBalance(allyCount ?? 2, clanWise == true ? BalanceMode.ClanWise : BalanceMode.Normal, context);
                    }
                }
                break;

                case AutohostMode.Generic:
                {
                    if (allyCount == null && res.Bots != null && res.Bots.Any())
                    {
                        res.Players = context.Players.ToList();
                        res.Bots    = context.Bots.Where(x => x.Owner != context.AutohostName).ToList();
                        foreach (var p in res.Players)
                        {
                            p.AllyID = 0;
                        }
                        foreach (var b in res.Bots)
                        {
                            b.AllyID = 1;
                        }
                    }
                    else
                    {
                        var map = db.Resources.Single(x => x.InternalName == context.Map);
                        res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 2,
                                                           clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                                           context);
                        res.DeleteBots = mode == AutohostMode.Teams;
                    }
                    return(res);
                }

                case AutohostMode.Teams:
                {
                    var map = db.Resources.Single(x => x.InternalName == context.Map);
                    res            = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 2, clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise, context);
                    res.DeleteBots = mode == AutohostMode.Teams;
                    return(res);
                }

                case AutohostMode.Game1v1:
                {
                    res            = new Balancer().LegacyBalance(allyCount ?? 2, clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise, context);
                    res.DeleteBots = true;
                }
                break;

                case AutohostMode.GameChickens:
                {
                    res.Players = context.Players.ToList();
                    res.Bots    = context.Bots.Where(x => x.Owner != context.AutohostName).ToList();
                    foreach (var p in res.Players)
                    {
                        p.AllyID = 0;
                    }
                    foreach (var b in res.Bots)
                    {
                        b.AllyID = 1;
                    }

                    if (!res.Bots.Any() && res.Players.Count > 0)
                    {
                        res.Message  = "Add some bot (computer player) as your enemy. Use button on bottom left. Chicken or CAI is recommended.";
                        res.CanStart = false;

                        /*else
                         *      {
                         *          res.Bots.Add(new BotTeam() { AllyID = 1, TeamID = 16, BotName = "default_Chicken", BotAI = "Chicken: Normal", });
                         *          res.Message = "Adding a normal chickens bot for you";
                         *      }*/
                    }
                }
                break;

                case AutohostMode.GameFFA:
                {
                    var map = db.Resources.Single(x => x.InternalName == context.Map);
                    if (map.MapFFAMaxTeams != null)
                    {
                        res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams.Value,
                                                           clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                                           context);
                    }
                    else
                    {
                        res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 8,
                                                           clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                                           context);
                    }
                    return(res);
                }

                case AutohostMode.Planetwars:

                    return(new Balancer().PlanetwarsBalance(context));
                }
                return(res);
            }
        }
Exemplo n.º 6
0
        static BalanceTeamsResult PerformBalance(BattleContext context,
                                                 bool isGameStart,
                                                 int? allyCount,
                                                 bool? clanWise,
                                                 AutohostConfig config,
                                                 int playerCount) {
            var res = new BalanceTeamsResult();
            var mode = context.GetMode();

            using (var db = new ZkDataContext()) {
                if (!CheckPlayersMinimumConditions(context, db, config, ref res.Message)) {
                    res.CanStart = false;
                    return res;
                }

                switch (mode) {
                    case AutohostMode.None:
                    {
                        if (!isGameStart) res = new Balancer().LegacyBalance(allyCount ?? 2, clanWise == true ? BalanceMode.ClanWise : BalanceMode.Normal, context);
                    }
                        break;
                    case AutohostMode.Generic:
                    {
                        if (allyCount == null && res.Bots != null && res.Bots.Any())
                        {
                            res.Players = context.Players.ToList();
                            res.Bots = context.Bots.Where(x => x.Owner != context.AutohostName).ToList();
                            foreach (var p in res.Players) p.AllyID = 0;
                            foreach (var b in res.Bots) b.AllyID = 1;
                        }
                        else
                        {
                            var map = db.Resources.Single(x => x.InternalName == context.Map);
                            res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 2,
                                clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                context);
                            res.DeleteBots = mode == AutohostMode.Teams;
                        }
                        return res;
                    }
                    
                    case AutohostMode.Teams:
                    {
                        var map = db.Resources.Single(x => x.InternalName == context.Map);
                        res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 2, clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise, context);
                        res.DeleteBots = mode == AutohostMode.Teams;
                        return res;
                    }
                    case AutohostMode.Game1v1:
                    {
                        res = new Balancer().LegacyBalance(allyCount ?? 2, clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise, context);
                        res.DeleteBots = true;
                    }
                        break;

                    case AutohostMode.GameChickens:
                    {
                        res.Players = context.Players.ToList();
                        res.Bots = context.Bots.Where(x => x.Owner != context.AutohostName).ToList();
                        foreach (var p in res.Players) p.AllyID = 0;
                        foreach (var b in res.Bots) b.AllyID = 1;

                        if (!res.Bots.Any() && res.Players.Count > 0) {
                            res.Message = "Add some bot (computer player) as your enemy. Use button on bottom left. Chicken or CAI is recommended.";
                            res.CanStart = false;
                            /*else
                                    {
                                        res.Bots.Add(new BotTeam() { AllyID = 1, TeamID = 16, BotName = "default_Chicken", BotAI = "Chicken: Normal", });
                                        res.Message = "Adding a normal chickens bot for you";
                                    }*/
                        }
                    }
                        break;
                    case AutohostMode.GameFFA:
                    {
                        var map = db.Resources.Single(x => x.InternalName == context.Map);
                        if (map.MapFFAMaxTeams != null)
                            res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams.Value,
                                                               clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                                               context);
                        else
                            res = new Balancer().LegacyBalance(allyCount ?? map.MapFFAMaxTeams ?? 8,
                                                               clanWise == false ? BalanceMode.Normal : BalanceMode.ClanWise,
                                                               context);
                        return res;
                    }
                    case AutohostMode.Planetwars:

                        return new Balancer().PlanetwarsBalance(context);
                }
                return res;
            }
        }
Exemplo n.º 7
0
 static bool CheckPlayersMinimumConditions(BattleContext battleContext,
                                           ZkDataContext dataContext,
                                           AutohostConfig config,
                                           ref string actionsDescription) {
     var ok = true;
     foreach (
         var p in
             battleContext.Players.Where(x => !x.IsSpectator)
                          .Select(x => new { player = x, account = dataContext.Accounts.First(y => y.AccountID == x.LobbyID) })) {
         if ((config.MinLevel != null && p.account.Level < config.MinLevel) || (config.MaxLevel != null && p.account.Level > config.MaxLevel) ||
             (config.MinElo != null && p.account.EffectiveElo < config.MinElo) ||
             (config.MaxElo != null && p.account.EffectiveElo > config.MaxElo)) {
             SpecPlayerOnCondition(p.player,
                                   p.account,
                                   string.Format(
                                       "Sorry, you cannot play here because of skill limits. You can spectate/observe this game however."));
             actionsDescription += string.Format("{0} cannot play here because of skill limits\n", p.account.Name);
             ok = false;
         }
     }
     return ok;
 }