public string Convert(IProfile profile, int indentSize = 0) { if (profile == null) { return(""); } var sb = new StringBuilder(); var indent = new string(' ', indentSize); sb.AppendLine(indent + "new IProfile()"); sb.AppendLine(indent + "{"); sb.AppendLine(indent + " Name = \"" + profile.Name + "\","); sb.AppendLine(indent + " Accesory = " + GetClothingItemInfo(profile.Accessory) + ","); sb.AppendLine(indent + " ChestOver = " + GetClothingItemInfo(profile.ChestOver) + ","); sb.AppendLine(indent + " ChestUnder = " + GetClothingItemInfo(profile.ChestUnder) + ","); sb.AppendLine(indent + " Feet = " + GetClothingItemInfo(profile.Feet) + ","); sb.AppendLine(indent + " Gender = Gender." + SharpHelper.EnumToString(profile.Gender) + ","); sb.AppendLine(indent + " Hands = " + GetClothingItemInfo(profile.Hands) + ","); sb.AppendLine(indent + " Head = " + GetClothingItemInfo(profile.Head) + ","); sb.AppendLine(indent + " Legs = " + GetClothingItemInfo(profile.Legs) + ","); sb.AppendLine(indent + " Skin = " + GetClothingItemInfo(profile.Skin) + ","); sb.AppendLine(indent + " Waist = " + GetClothingItemInfo(profile.Waist) + ","); sb.AppendLine(indent + "};"); return(sb.ToString()); }
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 ListBotType() { ScriptHelper.PrintMessage("--BotExtended list bot type--", ScriptHelper.ERROR_COLOR); foreach (var botType in SharpHelper.EnumToList <BotType>()) { ScriptHelper.PrintMessage((int)botType + ": " + SharpHelper.EnumToString(botType), ScriptHelper.WARNING_COLOR); } }
private static IEnumerable <string> GetFactionNames() { var factions = BotHelper.GetAvailableBotFactions(); foreach (var faction in factions) { yield return(((int)faction).ToString() + ": " + SharpHelper.EnumToString(faction)); } }
public static void CreateNewBot(IEnumerable <string> arguments) { if (arguments.Count() < 1) { return; } var botTypeStr = arguments.First(); var botType = BotType.None; if (SharpHelper.TryParseEnum(botTypeStr, out botType)) { arguments = arguments.Skip(1); } else { ScriptHelper.PrintMessage("--BotExtended spawn bot--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid query: " + botTypeStr, ScriptHelper.WARNING_COLOR); return; } var team = PlayerTeam.Independent; if (arguments.Any()) { if (TryParseTeam(arguments.First(), out team)) { arguments = arguments.Skip(1); } } var count = 1; if (arguments.Any()) { if (int.TryParse(arguments.First(), out count)) { count = (int)MathHelper.Clamp(count, Constants.BOT_SPAWN_COUNT_MIN, Constants.BOT_SPAWN_COUNT_MAX); } else { count = 1; } } for (var i = 0; i < count; i++) { BotManager.SpawnBot(botType, player: null, team: team, ignoreFullSpawner: true); } // Dont use the string name in case it just an index var bot = count > 1 ? " bots" : " bot"; ScriptHelper.PrintMessage("Spawned " + count + " " + SharpHelper.EnumToString(botType) + bot + " to " + team); }
public static void SetPlayer(IEnumerable <string> arguments) { if (arguments.Count() < 2) { ScriptHelper.PrintMessage("--BotExtended setplayer--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid arguments: " + string.Join(" ", arguments), ScriptHelper.WARNING_COLOR); return; } var playerArg = string.Join(" ", arguments.Take(arguments.Count() - 1)); IPlayer player; if (!TryParsePlayer(playerArg, out player)) { ScriptHelper.PrintMessage("--BotExtended setplayer--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("There is no player " + playerArg, ScriptHelper.WARNING_COLOR); return; } else { arguments = arguments.Skip(arguments.Count() - 1); } var botTypeArg = arguments.First(); BotType botType; if (!SharpHelper.TryParseEnum(botTypeArg, out botType)) { ScriptHelper.PrintMessage("--BotExtended setplayer--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid BotType: " + botTypeArg, ScriptHelper.WARNING_COLOR); return; } UpdatePlayerSettings(player, (old) => old.Update(botType.ToString())); if (botType == BotType.None) { ScriptHelper.PrintMessage("Player " + player.Name + " will be reset next round"); } else { BotHelper.SetPlayer(player, botType); } }
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; } } }
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]); } } } }
public static void SetWeapon(IEnumerable <string> arguments) { if (arguments.Count() == 2) { arguments = arguments.Concat(new string[] { "None" }); } if (arguments.Count() < 3) { ScriptHelper.PrintMessage("--BotExtended setweapon--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid arguments: " + string.Join(" ", arguments), ScriptHelper.WARNING_COLOR); return; } var playerArg = string.Join(" ", arguments.Take(arguments.Count() - 2)); IPlayer player; if (!TryParsePlayer(playerArg, out player)) { ScriptHelper.PrintMessage("--BotExtended setweapon--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("There is no player " + playerArg, ScriptHelper.WARNING_COLOR); return; } else { arguments = arguments.Skip(arguments.Count() - 2); } var weaponItemArg = arguments.First(); WeaponItem weaponItem; if (!SharpHelper.TryParseEnum(weaponItemArg, out weaponItem)) { ScriptHelper.PrintMessage("--BotExtended setweapon--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid WeaponItem: " + weaponItemArg, ScriptHelper.WARNING_COLOR); return; } else { weaponItemArg = weaponItem.ToString(); arguments = arguments.Skip(1); } var powerupArg = arguments.First(); var type = Mapper.GetWeaponItemType(weaponItem); if (type == WeaponItemType.Rifle || type == WeaponItemType.Handgun || type == WeaponItemType.Thrown) { RangedWeaponPowerup powerup; if (!SharpHelper.TryParseEnum(powerupArg, out powerup)) { ScriptHelper.PrintMessage("--BotExtended setweapon--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid range powerup: " + powerupArg, ScriptHelper.WARNING_COLOR); return; } else { powerupArg = powerup.ToString(); } } if (type == WeaponItemType.Melee) { MeleeWeaponPowerup powerup; if (!SharpHelper.TryParseEnum(powerupArg, out powerup)) { ScriptHelper.PrintMessage("--BotExtended setweapon--", ScriptHelper.ERROR_COLOR); ScriptHelper.PrintMessage("Invalid melee powerup: " + powerupArg, ScriptHelper.WARNING_COLOR); return; } else { powerupArg = powerup.ToString(); } } if (weaponItemArg == "NONE") { ScriptHelper.PrintMessage("Player " + player.Name + "'s weapon will be reset next round"); } UpdatePlayerSettings(player, (old) => old.Update(type, weaponItemArg, powerupArg)); BotHelper.SetWeapon(player, weaponItemArg, powerupArg); }
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"); }
private static void ShowCurrentSettings() { ScriptHelper.PrintMessage("--BotExtended settings--", ScriptHelper.ERROR_COLOR); var settings = Settings.Get(); ScriptHelper.PrintMessage("-Player settings", ScriptHelper.WARNING_COLOR); var activeUsers = ScriptHelper.GetActiveUsersByAccountID(); if (settings.PlayerSettings.Count() == 0) { ScriptHelper.PrintMessage("<Empty>"); } else { foreach (var ps in settings.PlayerSettings) { var playerSettings = PlayerSettings.Parse(ps); var accountID = playerSettings.AccountID; var name = activeUsers.ContainsKey(accountID) ? activeUsers[accountID].Name : accountID; ScriptHelper.PrintMessage(name + ": " + playerSettings.BotType); foreach (var w in playerSettings.Weapons) { ScriptHelper.PrintMessage(" - " + w[0] + " " + w[1]); } } } ScriptHelper.PrintMessage("-Factions", ScriptHelper.WARNING_COLOR); // TODO: show except for all faction minus a small amount of others foreach (var team in new PlayerTeam[] { PlayerTeam.Team1, PlayerTeam.Team2, PlayerTeam.Team3, PlayerTeam.Team4, }) { var factions = settings.BotFactions[team]; var currentFaction = settings.CurrentFaction[team]; ScriptHelper.PrintMessage(" -" + team, ScriptHelper.WARNING_COLOR); ScriptHelper.PrintMessage(" -Factions: ", ScriptHelper.WARNING_COLOR); if (factions.Count == SharpHelper.EnumToArray <BotFaction>().Count() - 1 /* minus BotFaction.None */) { ScriptHelper.PrintMessage(" ALL"); } else { foreach (var botFaction in factions) { var index = (int)botFaction; ScriptHelper.PrintMessage(" " + index + ": " + botFaction); } } ScriptHelper.PrintMessage(" -Current faction: " + currentFaction, ScriptHelper.WARNING_COLOR); } var rotationInterval = settings.FactionRotationEnabled ? settings.FactionRotationInterval.ToString() : "Disabled"; var roundsUntilRotation = settings.FactionRotationEnabled ? settings.RoundsUntilFactionRotation.ToString() : "N/a"; ScriptHelper.PrintMessage("-Faction rotation interval: " + rotationInterval, ScriptHelper.WARNING_COLOR); ScriptHelper.PrintMessage("-Rounds until rotation: " + roundsUntilRotation, ScriptHelper.WARNING_COLOR); ScriptHelper.PrintMessage("-Max bot count: " + settings.BotCount, ScriptHelper.WARNING_COLOR); }
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 )); } }
public static IEnumerable <BotFaction> GetAvailableBotFactions() { return(SharpHelper.EnumToList <BotFaction>().Where((f) => f != BotFaction.None)); }
public static string StorageKey(BotFaction botFaction, int factionIndex) { return(Constants.STORAGE_KEY_PREFIX + SharpHelper.EnumToString(botFaction).ToUpperInvariant() + "_" + factionIndex); }