private async Task TryInjectVillagerAsync(string internalName, int slot) { var vd = State.Existing[slot + Config.MinVillagerIndex]; if (vd == null) { await ReplyAsync("Villager data not initialized. Tell the bot owner to enable the correct setting.").ConfigureAwait(false); return; } var replace = VillagerSwap.GetReplacementVillager(vd, internalName, true); var user = Context.User; var mention = Context.User.Mention; var request = new VillagerRequest(user.Username, user.Id, new[] { replace }) { Index = slot, 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)); } }; State.Injections.Enqueue(request); var msg = $"{mention}: Villager inject request{(request.Items.Count > 1 ? "s have" : " has")} been added to the queue and will be injected momentarily."; await ReplyAsync(msg).ConfigureAwait(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(); }