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 }); }
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); } }
private bool TurnIntoZombie() { if (Body.IsRemoved || Body.IsBurnedCorpse) { return(false); } var player = Game.CreatePlayer(Body.GetWorldPosition()); var zombieType = BotHelper.GetZombieType(Type); var oldProfile = Body.GetProfile(); var oldWeapons = BotHelper.GetWeaponSet(Body); // TODO: test gun with lazer once gurt fixed https://www.mythologicinteractiveforums.com/viewtopic.php?f=31&t=4000 ScriptHelper.LogDebug(Type, "->", zombieType); player.SetBotName(Body.Name); // NOTE: set right now so SpawnLine dialogue will show the bot name correctly var zombie = BotManager.SpawnBot(zombieType, Faction, player, BotManager.GetBot(Body).InfectTeam); var zombieBody = zombie.Player; var modifiers = Body.GetModifiers(); // Survivor has fake MaxHealth to have blood effect on the face if (Enum.GetName(typeof(BotType), BotManager.GetBot(Body).Type).StartsWith("Survivor")) { modifiers.CurrentHealth = modifiers.MaxHealth = 50; } else { modifiers.CurrentHealth = modifiers.MaxHealth * 0.75f; } zombieBody.SetModifiers(modifiers); zombieBody.SetProfile(BotHelper.ToZombieProfile(oldProfile)); BotHelper.Equip(zombieBody, oldWeapons); Body.Remove(); Body = zombieBody; Body.SetBotBehaivorActive(false); Body.AddCommand(new PlayerCommand(PlayerCommandType.StartCrouch)); IsTurningIntoZombie = true; return(true); }
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"); }
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 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 )); } }