Ejemplo n.º 1
0
        private static bool HandleStockSelection(
            ref Decorators.PurchaseAnimalsMenu moddedMenu,
            int x,
            int y,
            Farmer moddedPlayer)
        {
            var textureComponent = moddedMenu.GetAnimalsToPurchase().Where(o => (o.item as StardewValley.Object).Type == null)
                                   .FirstOrDefault(o => o.containsPoint(x, y));

            if (textureComponent == null)
            {
                return(true);
            }
            var amount = textureComponent.item.salePrice();

            if (!moddedPlayer.CanAfford(amount))
            {
                return(true);
            }
            var randomAnimalShopType =
                new Api.BetterFarmAnimalVariety(Mod.ReadConfig <ModConfig>()).GetRandomAnimalShopType(textureComponent.hoverText,
                                                                                                      moddedPlayer.GetOriginal());
            var farmAnimal1 = moddedPlayer.CreateFarmAnimal(randomAnimalShopType);

            SelectedStockBellsAndWhistles(ref moddedMenu);
            moddedMenu.SetOnFarm(true);
            moddedMenu.SetAnimalBeingPurchased(farmAnimal1);
            var farmAnimal2 = new Decorators.FarmAnimal(farmAnimal1);

            moddedMenu.SetPriceOfAnimal(farmAnimal2.GetPrice());
            return(false);
        }
        private static void HandleHatchling(
            ref Decorators.AnimalHouse moddedAnimalHouse,
            string name,
            Farmer moddedPlayer)
        {
            if (moddedAnimalHouse.IsFull())
            {
                return;
            }
            var withEggReadyToHatch = moddedAnimalHouse.GetIncubatorWithEggReadyToHatch();

            if (withEggReadyToHatch == null)
            {
                return;
            }
            string type;

            type = new Incubator(withEggReadyToHatch)
                   .GetRandomType(FarmAnimals.GroupTypesByCategory()
                                  .ToDictionary
                                      (kvp => kvp.Key,
                                      kvp => moddedPlayer.SanitizeBlueChickens(kvp.Value)));

            var building   = moddedAnimalHouse.GetBuilding();
            var farmAnimal = new Decorators.FarmAnimal(moddedPlayer.CreateFarmAnimal(type, name, building));

            farmAnimal.AddToBuilding(building);
            moddedAnimalHouse.ResetIncubator(withEggReadyToHatch);
            farmAnimal.SetCurrentProduce(-1);
        }
        private static void HandleNewborn(
            ref Decorators.AnimalHouse moddedAnimalHouse,
            string name,
            ref QuestionEvent questionEvent,
            Farmer moddedPlayer)
        {
            var withEggReadyToHatch = moddedAnimalHouse.GetIncubatorWithEggReadyToHatch();
            var moddedParent        = new Decorators.FarmAnimal(questionEvent.animal);
            var dictionary          = FarmAnimals.GroupTypesByCategory().Where(kvp => kvp.Value.Contains(moddedParent.GetTypeString()))
                                      .ToDictionary(kvp => kvp.Key, kvp => moddedPlayer.SanitizeBlueChickens(kvp.Value));
            var randomTypeFromProduce = moddedParent.GetRandomTypeFromProduce(dictionary);
            var building   = moddedAnimalHouse.GetBuilding();
            var farmAnimal = new Decorators.FarmAnimal(moddedPlayer.CreateFarmAnimal(randomTypeFromProduce, name, building));

            farmAnimal.AssociateParent(questionEvent.animal);
            farmAnimal.AddToBuilding(building);
            farmAnimal.SetCurrentProduce(-1);
            Event.ForceQuestionEventToProceed(questionEvent);
        }