public async Task InjectVillagerAsync(int index, string internalName) { if (!Globals.Bot.Config.DodoModeConfig.LimitedDodoRestoreOnlyMode) { await ReplyAsync($"{Context.User.Mention} - Villagers cannot be injected in order mode."); return; } if (!Globals.Bot.Config.AllowVillagerInjection) { await ReplyAsync($"{Context.User.Mention} - Villager injection is currently disabled."); return; } var bot = Globals.Bot; var nameSearched = internalName; if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; } if (internalName == default) { await ReplyAsync($"{Context.User.Mention} - {nameSearched} is not a valid internal villager name."); return; } if (index > byte.MaxValue || index < 0) { await ReplyAsync($"{Context.User.Mention} - {index} is not a valid index"); return; } int slot = index; var replace = VillagerResources.GetVillager(internalName); var user = Context.User; var mention = Context.User.Mention; var request = new VillagerRequest(Context.User.Username, replace, (byte)index, GameInfo.Strings.GetVillager(internalName)) { OnFinish = success => { var reply = success ? $"Villager has been injected by the bot at Index {slot}. Please go talk to them!" : "Failed to inject villager. Please tell the bot owner to look at the logs!"; Task.Run(async() => await ReplyAsync($"{mention}: {reply}").ConfigureAwait(false)); } }; bot.VillagerInjections.Enqueue(request); var msg = $"{mention}: Villager inject request has been added to the queue and will be injected momentarily. I will reply to you once this has completed."; await ReplyAsync(msg).ConfigureAwait(false); }
private static string SanityCheckVillagerName(string internalName) { if (VillagerResources.IsVillagerDataKnown(internalName)) { return(internalName); } return(GameInfo.Strings.VillagerMap.First(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key); }
public static bool AddToWaitingListPreset(string presetName, string display, string username, ulong id, bool sub, out string msg) { if (!IsQueueable(presetName, id, out var msge)) { msg = $"@{username} - {msge}"; return(false); } try { var cfg = Globals.Bot.Config; VillagerRequest?vr = null; // try get villager var result = VillagerOrderParser.ExtractVillagerName(presetName, out var res, out var san); if (result == VillagerOrderParser.VillagerRequestResult.InvalidVillagerRequested) { msg = $"@{username} - {res} Order has not been accepted."; return(false); } if (result == VillagerOrderParser.VillagerRequestResult.Success) { if (!cfg.AllowVillagerInjection) { msg = $"@{username} - Villager injection is currently disabled."; return(false); } presetName = san; var replace = VillagerResources.GetVillager(res); vr = new VillagerRequest(username, replace, 0, GameInfo.Strings.GetVillager(res)); } presetName = presetName.Trim(); var preset = PresetLoader.GetPreset(cfg.OrderConfig, presetName); if (preset == null) { msg = $"{username} - {presetName} is not a valid preset."; return(false); } return(InsertToQueue(preset, vr, display, username, id, sub, true, out msg)); } catch (Exception e) { LogUtil.LogError($"{username}@Preset:{presetName}: {e.Message}", nameof(TwitchHelper)); msg = $"@{username} {e.Message}"; return(false); } }
// Helper functions for commands public static bool AddToWaitingList(string orderString, string display, string username, ulong id, bool sub, bool cat, out string msg) { if (!IsQueueable(orderString, id, out var msge)) { msg = $"@{username} - {msge}"; return(false); } try { var cfg = Globals.Bot.Config; VillagerRequest?vr = null; // try get villager var result = VillagerOrderParser.ExtractVillagerName(orderString, out var res, out var san); if (result == VillagerOrderParser.VillagerRequestResult.InvalidVillagerRequested) { msg = $"@{username} - {res} Order has not been accepted."; return(false); } if (result == VillagerOrderParser.VillagerRequestResult.Success) { if (!cfg.AllowVillagerInjection) { msg = $"@{username} - Villager injection is currently disabled."; return(false); } orderString = san; var replace = VillagerResources.GetVillager(res); vr = new VillagerRequest(username, replace, 0, GameInfo.Strings.GetVillager(res)); } var items = string.IsNullOrWhiteSpace(orderString) ? new Item[1] { new Item(Item.NONE) } : ItemParser.GetItemsFromUserInput(orderString, cfg.DropConfig, ItemDestination.FieldItemDropped); return(InsertToQueue(items, vr, display, username, id, sub, cat, out msg)); } catch (Exception e) { LogUtil.LogError($"{username}@{orderString}: {e.Message}", nameof(TwitchHelper)); msg = $"@{username} {e.Message}"; return(false); } }
private void B_ReplaceVillager_Click(object sender, EventArgs e) { if (!Clipboard.ContainsText()) { WinFormsUtil.Error(MessageStrings.MsgVillagerReplaceNoText); return; } var internalName = Clipboard.GetText(); if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; if (internalName == default) { WinFormsUtil.Error(string.Format(MessageStrings.MsgVillagerReplaceUnknownName, internalName)); return; } } var index = VillagerIndex; var villager = Villagers[index]; if (villager is not Villager2 v2) { WinFormsUtil.Error(MessageStrings.MsgVillagerReplaceOutdatedSaveFormat); return; } var houses = SAV.GetVillagerHouses(); var houseIndex = Array.FindIndex(houses, z => z.NPC1 == index); var exist = new VillagerInfo(v2, houses[houseIndex]); var replace = VillagerSwap.GetReplacementVillager(exist, internalName); var nh = new VillagerHouse(replace.House); SAV.SetVillagerHouse(nh, houseIndex); var nv = new Villager2(replace.Villager); LoadVillager(Villagers[index] = nv); System.Media.SystemSounds.Asterisk.Play(); }
public static VillagerRequestResult ExtractVillagerName(string order, out string result, out string sanitizedOrder, string villagerFormat = "Villager:") { result = string.Empty; sanitizedOrder = string.Empty; var index = order.IndexOf(villagerFormat, StringComparison.InvariantCultureIgnoreCase); if (index < 0) { return(VillagerRequestResult.NoVillagerRequested); } var internalName = order.Substring(index + villagerFormat.Length); var nameSearched = internalName; internalName = internalName.Trim(); if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; } if (IsUnadoptable(nameSearched) || IsUnadoptable(internalName)) { result = $"{nameSearched} is not adoptable. Order setup required for this villager is unnecessary."; return(VillagerRequestResult.InvalidVillagerRequested); } if (internalName == default) { result = $"{nameSearched} is not a valid internal villager name."; return(VillagerRequestResult.InvalidVillagerRequested); } sanitizedOrder = order.Substring(0, index); result = internalName; return(VillagerRequestResult.Success); }
private async Task InjectVillagers(int startIndex, string[] villagerNames) { if (!Globals.Bot.Config.DodoModeConfig.LimitedDodoRestoreOnlyMode) { await ReplyAsync($"{Context.User.Mention} - Villagers cannot be injected in order mode.").ConfigureAwait(false); return; } if (!Globals.Bot.Config.AllowVillagerInjection) { await ReplyAsync($"{Context.User.Mention} - Villager injection is currently disabled.").ConfigureAwait(false); return; } var bot = Globals.Bot; int index = startIndex; int count = villagerNames.Length; if (count < 1) { await ReplyAsync($"{Context.User.Mention} - No villager names in command").ConfigureAwait(false); return; } foreach (var nameLookup in villagerNames) { var internalName = nameLookup; var nameSearched = internalName; if (!VillagerResources.IsVillagerDataKnown(internalName)) { internalName = GameInfo.Strings.VillagerMap.FirstOrDefault(z => string.Equals(z.Value, internalName, StringComparison.InvariantCultureIgnoreCase)).Key; } if (internalName == default) { await ReplyAsync($"{Context.User.Mention} - {nameSearched} is not a valid internal villager name."); return; } if (index > byte.MaxValue || index < 0) { await ReplyAsync($"{Context.User.Mention} - {index} is not a valid index"); return; } int slot = index; var replace = VillagerResources.GetVillager(internalName); var user = Context.User; var mention = Context.User.Mention; var extraMsg = string.Empty; if (VillagerOrderParser.IsUnadoptable(internalName)) { extraMsg += " Please note that you will not be able to adopt this villager."; } var request = new VillagerRequest(Context.User.Username, replace, (byte)index, GameInfo.Strings.GetVillager(internalName)) { OnFinish = success => { var reply = success ? $"{nameSearched} has been injected by the bot at Index {slot}. Please go talk to them!{extraMsg}" : "Failed to inject villager. Please tell the bot owner to look at the logs!"; Task.Run(async() => await ReplyAsync($"{mention}: {reply}").ConfigureAwait(false)); } }; bot.VillagerInjections.Enqueue(request); index = (index + 1) % 10; } var addMsg = count > 1 ? $"Villager inject request for {count} villagers have" : "Villager inject request has"; var msg = $"{Context.User.Mention}: {addMsg} been added to the queue and will be injected momentarily. I will reply to you once this has completed."; await ReplyAsync(msg).ConfigureAwait(false); }