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); }
public static bool Prefix(ref StardewValley.FarmAnimal __instance, ref Farmer who) { var moddedAnimal = new Decorators.FarmAnimal(__instance); AttemptToSpawnProduce(ref moddedAnimal, Game.GetMasterPlayer()); if (ShouldStopFindingProduce(ref moddedAnimal)) { moddedAnimal.SetCurrentProduce(-1); } return(false); }
private static void HandleCurrentProduce(ref Decorators.FarmAnimal moddedAnimal, byte originalFullness) { var daysToLay = moddedAnimal.GetDaysToLay(moddedAnimal.GetOwner()); var seed = (int)moddedAnimal.GetUniqueId() / 2 + Game.GetDaysPlayed(); var flag = RollRandomProduceChance(moddedAnimal, originalFullness, seed); if (!moddedAnimal.IsAProducer() || moddedAnimal.IsBaby()) { moddedAnimal.SetCurrentProduce(-1); } else { if (moddedAnimal.GetDaysSinceLastLay() < daysToLay) { return; } if (!flag) { moddedAnimal.SetCurrentProduce(-1); } else { HandleGameStats(moddedAnimal); var player = Game.GetPlayer(); var farmAnimals = FarmAnimals.ReadCache(); var typeStr = moddedAnimal.GetTypeString(); var farmAnimalType = farmAnimals.Categories.SelectMany(o => (IEnumerable <FarmAnimalType>)o.Types) .Where(o => o.Type == typeStr).FirstOrDefault(); var deluxeProduceLuck = farmAnimalType == null ? 0.0 : farmAnimalType.DeluxeProduceLuck; var produceIndex = moddedAnimal.RollProduce(seed, player, deluxeProduceLuck); moddedAnimal.SetCurrentProduce(produceIndex); if (!Paritee.StardewValley.Core.Characters.FarmAnimal.IsProduceAnItem(produceIndex)) { return; } moddedAnimal.SetDaysSinceLastLay(0); HandleProduceQuality(moddedAnimal, seed); HandleProduceSpawn(moddedAnimal); } } }
private static void HandleProduceSpawn(Decorators.FarmAnimal moddedAnimal) { if (!moddedAnimal.LaysProduce() || !moddedAnimal.HasHome()) { return; } var indoors = Paritee.StardewValley.Core.Locations.AnimalHouse.GetIndoors(moddedAnimal.GetHome()); var tileLocation = moddedAnimal.GetTileLocation(); var currentProduce = moddedAnimal.GetCurrentProduce(); var produceQuality = moddedAnimal.GetProduceQuality(); var flag = true; foreach (var @object in indoors.Objects.Values) { int num; if ((bool)@object.bigCraftable && (int)@object.parentSheetIndex == 165 && @object.heldObject.Value != null) { num = (@object.heldObject.Value as Chest).addItem( new StardewValley.Object(Vector2.Zero, currentProduce, null, false, true, false, false) { Quality = produceQuality }) == null ? 1 : 0; } else { num = 0; } if (num != 0) { @object.showNextIndex.Value = true; flag = false; break; } } if (flag && !indoors.Objects.ContainsKey(tileLocation)) { var @object = new StardewValley.Object(Vector2.Zero, currentProduce, null, false, true, false, true) { Quality = produceQuality }; Location.SpawnObject(indoors, tileLocation, @object); } moddedAnimal.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); }