Example #1
0
        public static void SetWeapon(IPlayer player, string weaponItemStr, string powerupStr)
        {
            var weaponItem = SharpHelper.StringToEnum <WeaponItem>(weaponItemStr);
            var type       = Mapper.GetWeaponItemType(weaponItem);

            switch (type)
            {
            // TODO: Melee powerup
            case WeaponItemType.Melee:
                break;

            case WeaponItemType.Rifle:
            case WeaponItemType.Handgun:
            {
                var powerup = SharpHelper.StringToEnum <RangedWeaponPowerup>(powerupStr);
                ProjectileManager.SetPowerup(player, weaponItem, powerup);
                break;
            }
            }
        }
Example #2
0
        public static void Initialize()
        {
            ProjectileManager.Initialize();
            WeaponManager.Initialize();

            m_playerSpawners = BotHelper.GetEmptyPlayerSpawners();

            Events.PlayerWeaponAddedActionCallback.Start(OnPlayerPickedupWeapon);
            Events.PlayerWeaponRemovedActionCallback.Start(OnPlayerDroppedWeapon);
            Events.PlayerMeleeActionCallback.Start(OnPlayerMeleeAction);
            Events.PlayerDamageCallback.Start(OnPlayerDamage);
            Events.PlayerDeathCallback.Start(OnPlayerDeath);
            Events.ProjectileHitCallback.Start(OnProjectileHit);
            Events.UpdateCallback.Start(OnUpdate);
            Events.PlayerKeyInputCallback.Start(OnPlayerKeyInput);
            Events.UserMessageCallback.Start(Command.OnUserMessage);

            var settings = Settings.Get();

            if (settings.RoundsUntilFactionRotation == 1 || settings.CurrentFaction[BotTeam] == BotFaction.None)
            {
                foreach (var team in SharpHelper.EnumToList <PlayerTeam>())
                {
                    if (team == PlayerTeam.Independent)
                    {
                        continue;
                    }

                    List <BotFaction> botFactions;

                    if (settings.BotFactions[team].Count > 1)
                    {
                        botFactions = settings.BotFactions[team]
                                      .Where((f) => f != settings.CurrentFaction[team])
                                      .ToList();
                    }
                    else
                    {
                        botFactions = settings.BotFactions[team];
                    }

                    // TODO: disregard spawning only boss or not when count < 3 if team != BotTeam
                    var faction = BotHelper.RandomFaction(botFactions, settings.BotCount);

                    if (team == BotTeam)
                    {
                        ScriptHelper.PrintMessage("Change faction to " + faction);
                    }
                    CurrentBotFaction[team] = faction;
                }
            }
            else
            {
                CurrentBotFaction = settings.CurrentFaction;
            }
            BotHelper.Storage.SetItem(BotHelper.StorageKey("CURRENT_FACTION"), CurrentBotFaction.Values.Select(f => f.ToString()).ToArray());

            if (settings.FactionRotationEnabled)
            {
                var roundTillNextFactionRotation = settings.RoundsUntilFactionRotation == 1 ?
                                                   settings.FactionRotationInterval
                    :
                                                   settings.RoundsUntilFactionRotation - 1;
                BotHelper.Storage.SetItem(BotHelper.StorageKey("ROUNDS_UNTIL_FACTION_ROTATION"), roundTillNextFactionRotation);
            }

            var botSpawnCount = Math.Min(settings.BotCount, m_playerSpawners.Count);

            foreach (var item in CurrentBotFaction)
            {
                var team    = item.Key;
                var faction = item.Value;

                if (faction == BotFaction.None)
                {
                    continue;
                }

                if (team == BotTeam)
                {
                    SpawnRandomFaction(faction, botSpawnCount, team);
                }
                else
                {
                    SpawnRandomFaction(faction, 0, team);
                }
            }

            var activeUsers = ScriptHelper.GetActiveUsersByAccountID();

            foreach (var ps in settings.PlayerSettings)
            {
                var pst = PlayerSettings.Parse(ps);

                if (activeUsers.ContainsKey(pst.AccountID))
                {
                    var userID = activeUsers[pst.AccountID].UserIdentifier;
                    var player = Game.GetActiveUser(userID).GetPlayer();

                    if (pst.BotType != "None")
                    {
                        var botType = SharpHelper.StringToEnum <BotType>(pst.BotType);
                        BotHelper.SetPlayer(player, botType);
                    }

                    foreach (var w in pst.Weapons)
                    {
                        BotHelper.SetWeapon(player, w[0], w[1]);
                    }
                }
            }
        }
Example #3
0
        public static Settings Get()
        {
            int botCount;
            var botCountKey = BotHelper.StorageKey("BOT_COUNT");

            if (!BotHelper.Storage.TryGetItemInt(botCountKey, out botCount))
            {
                botCount = Constants.DEFAULT_MAX_BOT_COUNT;
                BotHelper.Storage.SetItem(botCountKey, Constants.DEFAULT_MAX_BOT_COUNT);
            }

            botCount = (int)MathHelper.Clamp(botCount, Constants.BOT_COUNT_MIN, Constants.BOT_COUNT_MAX);

            int factionRotationInterval;
            var factionRotationIntervalKey = BotHelper.StorageKey("FACTION_ROTATION_INTERVAL");

            if (!BotHelper.Storage.TryGetItemInt(factionRotationIntervalKey, out factionRotationInterval))
            {
                factionRotationInterval = Constants.DEFAULT_FACTION_ROTATION_INTERVAL;
                BotHelper.Storage.SetItem(factionRotationIntervalKey, Constants.DEFAULT_FACTION_ROTATION_INTERVAL);
            }

            int roundsUntilRotation;
            var roundsUntilRotationKey = BotHelper.StorageKey("ROUNDS_UNTIL_FACTION_ROTATION");

            if (!BotHelper.Storage.TryGetItemInt(roundsUntilRotationKey, out roundsUntilRotation))
            {
                roundsUntilRotation = factionRotationInterval;
                BotHelper.Storage.SetItem(roundsUntilRotationKey, factionRotationInterval);
            }

            var teams          = SharpHelper.EnumToList <PlayerTeam>();
            var botFactions    = new Dictionary <PlayerTeam, List <BotFaction> >();
            var currentFaction = new Dictionary <PlayerTeam, BotFaction>();

            string[] currentFactionStr;
            var      currentFactionKey = BotHelper.StorageKey("CURRENT_FACTION");

            if (!BotHelper.Storage.TryGetItemStringArr(currentFactionKey, out currentFactionStr))
            {
                currentFactionStr = new string[] { "None", "None", "None", "None" };
            }

            for (var i = 0; i < 4; i++)
            {
                currentFaction.Add((PlayerTeam)i + 1, SharpHelper.StringToEnum <BotFaction>(currentFactionStr[i]));
            }

            foreach (var team in teams)
            {
                if (team == PlayerTeam.Independent)
                {
                    continue;
                }

                string[] factions    = null;
                var      factionsKey = BotHelper.StorageKey("BOT_FACTIONS_" + team);
                if (!BotHelper.Storage.TryGetItemStringArr(factionsKey, out factions))
                {
                    if (team == BotManager.BotTeam)
                    {
                        factions = Constants.DEFAULT_FACTIONS;
                    }
                    else
                    {
                        factions = new string[] { "None" }
                    };
                    BotHelper.Storage.SetItem(factionsKey, factions);
                }

                List <BotFaction> botFactionList;
                if (factions.Count() == 1 && factions.Single() == "All")
                {
                    botFactionList = BotHelper.GetAvailableBotFactions().ToList();
                }
                else
                {
                    botFactionList = new List <BotFaction>();
                    foreach (var faction in factions)
                    {
                        botFactionList.Add(SharpHelper.StringToEnum <BotFaction>(faction));
                    }
                }

                botFactions.Add(team, botFactionList);
            }

            string[] playerSettings;
            var      playerSettingsKey = BotHelper.StorageKey("PLAYER_SETTINGS");

            if (!BotHelper.Storage.TryGetItemStringArr(playerSettingsKey, out playerSettings))
            {
                playerSettings = new string[] { };
            }

            return(new Settings(
                       botCount,
                       factionRotationInterval,
                       roundsUntilRotation,
                       botFactions,
                       currentFaction,
                       playerSettings
                       ));
        }
    }