public static void MoveOldPregnancyData() { if (Context.IsMainPlayer) { if (FarmerData?.PregnancyData == null || FarmerData.PregnancyData.Count == 0) { return; } AnimalHusbandryModEntry.monitor.Log($"Migrating pregnancy data from old format to the new one.", LogLevel.Info); FarmerData?.PregnancyData?.RemoveAll(p => { try { FarmAnimal farmAnimal = Utility.getAnimal(p.Id); if (farmAnimal != null) { farmAnimal.allowReproduction.Value = p.AllowReproductionBeforeInsemination; PregnancyController.AddPregnancy(farmAnimal, p.DaysUntilBirth); farmAnimal.allowReproduction.Value = false; } else { AnimalHusbandryModEntry.monitor.Log($"The animal id '{p.Id}' was not found in the game and its pregnancy data is being discarded.", LogLevel.Warn); } return(true); } catch (Exception e) { AnimalHusbandryModEntry.monitor.Log($"Unexpected error while trying to migrate pregnancy data of animal id '{p.Id}'. The pregnancy data will be kept on the old format but will not be used.", LogLevel.Warn); AnimalHusbandryModEntry.monitor.Log($"Message from pregnancy error above: {e.Message}"); return(false); } }); } }
public static bool DoFunction(MilkPail __instance, GameLocation location, int x, int y, int power, StardewValley.Farmer who) { if (!IsInseminationSyringe(__instance)) { return(true); } string inseminationSyringeId = __instance.modData[InseminationSyringeKey]; BaseToolDoFunction(__instance, location, x, y, power, who); __instance.CurrentParentTileIndex = InitialParentTileIndex; __instance.indexOfMenuItemView.Value = IndexOfMenuItemView; Animals.TryGetValue(inseminationSyringeId, out FarmAnimal animal); if (animal != null) { who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f); int daysUtillBirth = ((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.Value; if (!DataLoader.ModConfig.DisableContestBonus && AnimalContestController.HasFertilityBonus(animal)) { daysUtillBirth -= (int)Math.Round(daysUtillBirth / 10.0, MidpointRounding.AwayFromZero); } PregnancyController.AddPregnancy(animal, daysUtillBirth); animal.allowReproduction.Value = false; --__instance.attachments[0].Stack; if (__instance.attachments[0].Stack <= 0) { Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.ItemConsumed", new { itemName = __instance.attachments[0].DisplayName })); __instance.attachments[0] = null; } Animals[inseminationSyringeId] = (FarmAnimal)null; } if (Game1.activeClickableMenu == null) { who.CanMove = true; who.completelyStopAnimatingOrDoingAction(); } else { who.Halt(); } who.UsingTool = false; who.canReleaseTool = true; DataLoader.Helper.Reflection.GetMethod(__instance, "finish").Invoke(); return(false); }
public override void DoFunction(GameLocation location, int x, int y, int power, StardewValley.Farmer who) { this.lastUser = who; Game1.recentMultiplayerRandom = new Random((int)(short)Game1.random.Next((int)short.MinValue, 32768)); this.CurrentParentTileIndex = InitialParentTileIndex; this.indexOfMenuItemView.Value = IndexOfMenuItemView; if (this._animal != null) { who.Stamina -= ((float)4f - (float)who.FarmingLevel * 0.2f); int daysUtillBirth = ((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(this._animal)).MinimumDaysUtillBirth.Value; if (!DataLoader.ModConfig.DisableContestBonus && AnimalContestController.HasFertilityBonus(_animal)) { daysUtillBirth -= (int)Math.Round(daysUtillBirth / 10.0, MidpointRounding.AwayFromZero); } PregnancyController.AddPregnancy(new PregnancyItem(this._animal.myID.Value, daysUtillBirth, this._animal.allowReproduction.Value)); this._animal.allowReproduction.Value = false; --this.attachments[0].Stack; if (this.attachments[0].Stack <= 0) { Game1.showGlobalMessage(DataLoader.i18n.Get("Tool.InseminationSyringe.ItemConsumed", new { itemName = this.attachments[0].DisplayName })); this.attachments[0] = (StardewValley.Object)null; } this._animal = (FarmAnimal)null; } if (Game1.activeClickableMenu == null) { who.CanMove = true; who.completelyStopAnimatingOrDoingAction(); } else { who.Halt(); } who.UsingTool = false; who.canReleaseTool = true; DataLoader.Helper.Reflection.GetMethod(this, "finish").Invoke(); }