private static void PrintStatistics() { ScriptHelper.PrintMessage("--BotExtended statistics--", ScriptHelper.ERROR_COLOR); var botFactions = BotHelper.GetAvailableBotFactions(); ScriptHelper.PrintMessage("[WinCount] [TotalMatch] [SurvivalRate]", ScriptHelper.WARNING_COLOR); foreach (var botFaction in botFactions) { var factionSet = GetFactionSet(botFaction); for (var i = 0; i < factionSet.Factions.Count; i++) { var factionKey = BotHelper.StorageKey(botFaction, i) + "_WIN_STATS"; int[] winStats; if (BotHelper.Storage.TryGetItemIntArr(factionKey, out winStats)) { var winCount = winStats[0]; var totalMatch = winStats[1]; var survivalRate = (float)winCount / totalMatch; var survivalRateStr = survivalRate.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture); ScriptHelper.PrintMessage(SharpHelper.EnumToString(botFaction) + " " + i + ": " + " " + winCount + " " + totalMatch + " " + survivalRateStr); } } } }
private static void SetBotCount(IEnumerable <string> arguments) { if (arguments.Count() != 1) { return; } var countStr = arguments.First(); var count = 1; if (arguments.Any()) { if (int.TryParse(countStr, out count)) { count = (int)MathHelper.Clamp(count, Constants.BOT_COUNT_MIN, Constants.BOT_COUNT_MAX); } else { ScriptHelper.PrintMessage("[Botextended] Invalid query: " + countStr, ScriptHelper.WARNING_COLOR); return; } } BotHelper.Storage.SetItem(BotHelper.StorageKey("BOT_COUNT"), count); ScriptHelper.PrintMessage("[Botextended] Update successfully"); }
private static void ClearStatistics() { var botFactions = BotHelper.GetAvailableBotFactions(); foreach (var botFaction in botFactions) { var factionSet = GetFactionSet(botFaction); for (var i = 0; i < factionSet.Factions.Count; i++) { var factionKey = BotHelper.StorageKey(botFaction, i) + "_WIN_STATS"; BotHelper.Storage.RemoveItem(factionKey); } } ScriptHelper.PrintMessage("[Botextended] Clear successfully"); }
private static void StoreStatistics() { if (!Game.IsGameOver) { return; // User exits in the middle of the round } var factionDead = true; foreach (var player in Game.GetPlayers()) { if (!player.IsDead && player.GetTeam() == BotTeam) { factionDead = false; break; } } var bosses = string.Join(".", CurrentFaction.Bosses); var factionWinStatsKey = BotHelper.StorageKey(CurrentBotFaction[BotTeam], CurrentFactionSetIndex) + "_" + bosses.ToUpper() + "_WIN_STATS"; int[] factionOldWinStats; int winCount, totalMatch; if (BotHelper.Storage.TryGetItemIntArr(factionWinStatsKey, out factionOldWinStats)) { if (factionDead) { winCount = factionOldWinStats[0]; } else { winCount = factionOldWinStats[0] + 1; } totalMatch = factionOldWinStats[1] + 1; } else { winCount = factionDead ? 0 : 1; totalMatch = 1; } BotHelper.Storage.SetItem(factionWinStatsKey, new int[] { winCount, totalMatch }); }
private static void SetFactionRotationInterval(IEnumerable <string> arguments) { var firstArg = arguments.FirstOrDefault(); if (firstArg == null) { return; } int value = -1; if (int.TryParse(firstArg, out value)) { value = (int)MathHelper.Clamp(value, 0, 10); BotHelper.Storage.SetItem(BotHelper.StorageKey("FACTION_ROTATION_INTERVAL"), value); BotHelper.Storage.SetItem(BotHelper.StorageKey("ROUNDS_UNTIL_FACTION_ROTATION"), value); ScriptHelper.PrintMessage("[Botextended] Update successfully"); } else { ScriptHelper.PrintMessage("[Botextended] Invalid query: " + firstArg, ScriptHelper.WARNING_COLOR); } }
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]); } } } }
private static void ClearPlayerSettings() { BotHelper.Storage.RemoveItem(BotHelper.StorageKey("PLAYER_SETTINGS")); ScriptHelper.PrintMessage("[Botextended] Update successfully"); }
private static void UpdatePlayerSettings(IPlayer player, Func <PlayerSettings, PlayerSettings> update) { if (!player.IsUser) { return; } var accountID = player.GetUser().AccountID; if (string.IsNullOrEmpty(accountID)) { return; } var key = BotHelper.StorageKey("PLAYER_SETTINGS"); string[] allPlayerSettings; if (BotHelper.Storage.TryGetItemStringArr(key, out allPlayerSettings)) { var isUpdate = false; for (var i = 0; i < allPlayerSettings.Length; i++) { if (allPlayerSettings[i].StartsWith(accountID)) { var oldPlayerSettings = PlayerSettings.Parse(allPlayerSettings[i]); var newPlayerSettings = update(oldPlayerSettings); isUpdate = true; if (newPlayerSettings.IsEmpty()) { var r = allPlayerSettings.ToList(); r.RemoveAt(i); allPlayerSettings = r.ToArray(); } else { allPlayerSettings[i] = newPlayerSettings.ToString(); } break; } } if (!isUpdate) { var a = allPlayerSettings.ToList(); var newPlayerSettings = update(PlayerSettings.Empty(accountID)); if (!newPlayerSettings.IsEmpty()) { a.Add(newPlayerSettings.ToString()); allPlayerSettings = a.ToArray(); } } } else { var newPlayerSettings = update(PlayerSettings.Empty(accountID)); if (!newPlayerSettings.IsEmpty()) { allPlayerSettings = new string[] { newPlayerSettings.ToString() }; } } BotHelper.Storage.SetItem(key, allPlayerSettings); }
private static void SkipCurrentFaction() { BotHelper.Storage.SetItem(BotHelper.StorageKey("ROUNDS_UNTIL_FACTION_ROTATION"), 1); ScriptHelper.PrintMessage("[Botextended] Update successfully"); }
private static void SetFactions(IEnumerable <string> arguments) { var allBotFactions = SharpHelper.EnumToList <BotFaction>() .Select((f) => SharpHelper.EnumToString(f)) .ToList(); var botFactions = new List <string>(); var excludeFlag = false; BotFaction botFaction; if (arguments.Count() == 0) { ScriptHelper.PrintMessage("--BotExtended setfaction--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid command: Argument is empty", ScriptHelper.WARNING_COLOR); return; } var team = PlayerTeam.Team4; if (TryParseTeam(arguments.First(), out team, PlayerTeam.Team4)) { arguments = arguments.Skip(1); } if (arguments.Count() == 1 && (arguments.Single() == "all" || arguments.Single() == "none")) { if (arguments.Single() == "all") { botFactions = new List <string> { "All" } } ; if (arguments.Single() == "none") { botFactions = new List <string> { "None" } } ; } else { if (arguments.First() == "-e") { excludeFlag = true; arguments = arguments.Skip(1); } foreach (var arg in arguments) { if (arg == "none") { ScriptHelper.PrintMessage("--BotExtended setfaction--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid argument: Cannot mix None with other options", ScriptHelper.WARNING_COLOR); return; } if (SharpHelper.TryParseEnum(arg, out botFaction)) { botFactions.Add(SharpHelper.EnumToString(botFaction)); } else { ScriptHelper.PrintMessage("--BotExtended setfaction--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid argument: " + arg, ScriptHelper.WARNING_COLOR); return; } } } if (excludeFlag) { botFactions = allBotFactions.Where((f) => !botFactions.Contains(f)).ToList(); } BotHelper.Storage.SetItem(BotHelper.StorageKey("BOT_FACTIONS_" + team), botFactions.Distinct().ToArray()); ScriptHelper.PrintMessage("[Botextended] Update successfully"); }
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 )); } }