Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }