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 bool HandleOnFarm( ref Decorators.PurchaseAnimalsMenu moddedMenu, int x, int y, Farmer moddedPlayer) { if (moddedMenu.IsNamingAnimal()) { return(true); } var viewport = Game.GetViewport(); var buildingAt = Game.GetFarm().getBuildingAt(new Vector2((x + viewport.X) / 64, (y + viewport.Y) / 64)); if (buildingAt == null) { return(true); } var animalBeingPurchased = moddedMenu.GetAnimalBeingPurchased(); var moddedAnimal = new Decorators.FarmAnimal(animalBeingPurchased); if (!moddedAnimal.CanLiveIn(buildingAt) || new Building(buildingAt).IsFull() || !moddedAnimal.CanBeNamed()) { return(true); } var priceOfAnimal = moddedMenu.GetPriceOfAnimal(); if (!moddedPlayer.CanAfford(priceOfAnimal)) { return(true); } moddedAnimal.AddToBuilding(buildingAt); moddedMenu.SetAnimalBeingPurchased(animalBeingPurchased); moddedMenu.SetNewAnimalHome(null); moddedMenu.SetNamingAnimal(false); moddedPlayer.SpendMoney(priceOfAnimal); PurchasedAnimalBellsAndWhistles(moddedAnimal); return(false); }