public static void Show()
        {
            Random     random = ModEntry.Random;
            string     type   = null;
            AnimalSkin skin   = null;

            if (ModEntry.Config.BalancedPetTypes)
            {
                double totalType = ModEntry.Pets.Count;
                Dictionary <string, double> types = ModEntry.Pets.Where(a => a.Value.Count > 0).ToDictionary(k => k.Key, v => totalType);
                foreach (Pet pet in ModEntry.GetAllPets().Where(p => ModEntry.PetTypesRev.ContainsKey(p.GetType()) && ModEntry.Pets[ModEntry.PetTypesRev[p.GetType()]].Count > 0))
                {
                    types[ModEntry.PetTypesRev[pet.GetType()]] *= 0.5;
                }
                types = types.ToDictionary(k => k.Key, v => v.Value / totalType);
                double   typeMax    = types.Values.OrderByDescending(a => a).First();
                double   typeChance = random.NextDouble() * typeMax;
                string[] validTypes = types.Where(a => a.Value >= typeChance).Select(a => a.Key).ToArray();
                if (validTypes.Length > 0)
                {
                    type = validTypes[random.Next(validTypes.Length)];
                }
            }
            if (string.IsNullOrEmpty(type))
            {
                string[] arr = ModEntry.Pets.Where(a => a.Value.Count > 0).Select(a => a.Key).ToArray();
                type = arr[random.Next(arr.Length)];
            }
            if (ModEntry.Config.BalancedPetSkins)
            {
                double totalSkin = ModEntry.Pets[type].Count;
                Dictionary <int, double> skins = ModEntry.Pets[type].ToDictionary(k => k.ID, v => totalSkin);
                foreach (Pet pet in ModEntry.GetAllPets().Where(pet => ModEntry.PetTypesRev.ContainsKey(pet.GetType()) && ModEntry.PetTypesRev[pet.GetType()].Equals(type) && skins.ContainsKey(pet.Manners)))
                {
                    skins[pet.Manners] *= 0.5;
                }
                skins = skins.ToDictionary(k => k.Key, v => v.Value / totalSkin);
                double skinMax    = skins.Values.OrderByDescending(a => a).First();
                double skinChance = random.NextDouble();
                int[]  validSkins = skins.Where(a => a.Value >= skinChance).Select(a => a.Key).ToArray();
                int    id         = 0;
                if (validSkins.Length > 0)
                {
                    id = validSkins[random.Next(validSkins.Length)];
                }
                skin = ModEntry.Pets[type].FirstOrDefault(a => a.ID == id);
            }
            if (skin == null)
            {
                skin = ModEntry.Pets[type][random.Next(ModEntry.Pets[type].Count)];
            }
            AdoptQuestion q = new AdoptQuestion(skin);

            ModEntry.SHelper.Events.Display.RenderedHud += q.Display;
            Game1.currentLocation.lastQuestionKey        = "AdoptPetQuestion";
            Game1.currentLocation.createQuestionDialogue(
                ModEntry.SHelper.Translation.Get("AdoptMessage", new { petType = type, adoptionPrice = ModEntry.Config.AdoptionPrice }),
                Game1.player.Money < ModEntry.Config.AdoptionPrice
                    ? new[]
            {
                new Response("n", ModEntry.SHelper.Translation.Get("AdoptNoGold", new { adoptionPrice = ModEntry.Config.AdoptionPrice }))
            }
                    : new[]
            {
                new Response("y", ModEntry.SHelper.Translation.Get("AdoptYes")),
                new Response("n", ModEntry.SHelper.Translation.Get("AdoptNo"))
            },
                q.Resolver);
        }
Exemple #2
0
        public static void Show()
        {
            Random random = ModEntry.Random;
            string type   = "";
            int    id     = 0;

            if (ModEntry.Config.BalancedPetTypes)
            {
                Dictionary <string, double> types = ModEntry.Pets.Keys.ToDictionary(k => k, v => 1.0);
                foreach (Pet pet in ModEntry.GetAllPets())
                {
                    string petType = ModEntry.Sanitize(pet.GetType().Name);
                    types[petType] *= 0.5;
                }
                double typeChance = random.NextDouble();
                foreach (KeyValuePair <string, double> pair in types.OrderBy(a => a.Value))
                {
                    if (pair.Value >= typeChance)
                    {
                        type = pair.Key;
                        break;
                    }
                }
            }
            else
            {
                type = ModEntry.Pets.Keys.ToArray()[random.Next(ModEntry.Pets.Count)];
            }
            if (ModEntry.Config.BalancedPetSkins)
            {
                Dictionary <int, double> skins = ModEntry.Pets[type].ToDictionary(k => k.ID, v => 1.0);
                foreach (Pet pet in ModEntry.GetAllPets().Where(pet => ModEntry.Sanitize(pet.GetType().Name) == type))
                {
                    skins[pet.Manners] *= 0.5;
                }
                double skinChance = random.NextDouble();
                foreach (KeyValuePair <int, double> pair in skins.OrderBy(a => a.Value))
                {
                    if (pair.Value >= skinChance)
                    {
                        id = pair.Key;
                        break;
                    }
                }
            }
            else
            {
                id = ModEntry.Pets[type][random.Next(ModEntry.Pets[type].Count)].ID;
            }
            AdoptQuestion q = new AdoptQuestion(type, id);

            ModEntry.SHelper.Events.Display.RenderedHud += q.Display;
            Game1.currentLocation.lastQuestionKey        = "AdoptPetQuestion";
            Game1.currentLocation.createQuestionDialogue(
                ModEntry.SHelper.Translation.Get("AdoptMessage", new { petType = type, adoptionPrice = ModEntry.Config.AdoptionPrice }),
                Game1.player.money < ModEntry.Config.AdoptionPrice
                    ? new[]
            {
                new Response("n", ModEntry.SHelper.Translation.Get("AdoptNoGold", new { adoptionPrice = ModEntry.Config.AdoptionPrice }))
            }
                    : new[]
            {
                new Response("y", ModEntry.SHelper.Translation.Get("AdoptYes")),
                new Response("n", ModEntry.SHelper.Translation.Get("AdoptNo"))
            },
                q.Resolver);
        }