Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ButcherMod/animals/data/PregnancyData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SObject = StardewValley.Object;


namespace AnimalHusbandryMod.animals.data
{
public class PregnancyData
{
public Dictionary<string, string> PreganancyItems;

public PregnancyData()
{
PreganancyItems = new Dictionary<string, string>();
}

public bool MatchingPregnancyItem(FarmAnimal animal, SObject o)
{
if (animal == null || o == null)
{
return false;
}
else if (!PreganancyItems.ContainsKey(animal.displayType))
{
AnimalHusbandryModEntry.monitor.Log($"Dont know anything about {animal.displayType}");
return false;
}
return PreganancyItems.ContainsKey(animal.displayType) && PreganancyItems[animal.displayType].Equals(o.Name);
}

public string GetPregnancyItemName(FarmAnimal animal)
{
if (PreganancyItems.ContainsKey(animal.displayType))
{
return PreganancyItems[animal.displayType];
}
AnimalHusbandryModEntry.monitor.Log($"Dont know anything about {animal.displayType}");
return "";
}
}
}
5 changes: 5 additions & 0 deletions ButcherMod/common/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DataLoader : IAssetEditor, IAssetLoader
public static AnimalData AnimalData;
public static AnimalBuildingData AnimalBuildingData;
public static AnimalContestData AnimalContestData;
public static PregnancyData PregnancyData;

public static String LooseSpritesName;
public static Texture2D LooseSprites;
Expand Down Expand Up @@ -93,6 +94,10 @@ public DataLoader(IModHelper helper, IManifest manifest)
// load Livin' With The Animals channel
TvController.AddChannel(new LivingWithTheAnimalsChannel());

// load the pregnancy item config
PregnancyData = Helper.Data.ReadJsonFile<PregnancyData>("data\\pregnancydata.json") ?? new PregnancyData();
Helper.Data.WriteJsonFile("data\\pregnancydata.json", PregnancyData);

// add editors (must happen *after* data is initialised above, since SMAPI may reload affected assets immediately)
var editors = Helper.Content.AssetEditors;
var loaders = Helper.Content.AssetLoaders;
Expand Down
34 changes: 29 additions & 5 deletions ButcherMod/tools/InseminationSyringeOverrides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public static bool beginUsing(MilkPail __instance, GameLocation location, int x,
{
dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.EggAnimal", new { animalName = animal.displayName });
}
else if (animal.displayName.Contains("Male") || animal.displayType.Contains("Male"))
{
dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
}
else if (!((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).MinimumDaysUtillBirth.HasValue)
{
dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CantBeInseminated", new { animalName = animal.displayName });
Expand All @@ -134,7 +138,16 @@ public static bool beginUsing(MilkPail __instance, GameLocation location, int x,
else if (!CheckCorrectProduct(animal, __instance.attachments[0]))
{
var data = DataLoader.Helper.Content.Load<Dictionary<int, string>>(@"Data\ObjectInformation.xnb", ContentSource.GameContent);
string produceName = data[animal.defaultProduceIndex.Value].Split('/')[4];
string produceName = "the correct item";
if (animal.defaultProduceIndex.Value > 0)
{
produceName = data[animal.defaultProduceIndex.Value].Split('/')[4];
}
string customProduceName = DataLoader.PregnancyData.GetPregnancyItemName(animal);
if (customProduceName != "")
{
produceName = customProduceName;
}
dialogue = DataLoader.i18n.Get("Tool.InseminationSyringe.CorrectItem", new { itemName = produceName });
}
else if (PregnancyController.CheckBuildingLimit(animal))
Expand Down Expand Up @@ -235,7 +248,7 @@ public static bool canThisBeAttached(Tool __instance, SObject o, ref bool __resu
{
if (!IsInseminationSyringe(__instance)) return true;

__result = o == null || DataLoader.AnimalData.SyringeItemsIds.Contains(o.ParentSheetIndex);
__result = o == null || DataLoader.AnimalData.SyringeItemsIds.Contains(o.ParentSheetIndex) || DataLoader.PregnancyData.PreganancyItems.ContainsValue(o.Name);
return false;
}

Expand Down Expand Up @@ -299,9 +312,20 @@ private static bool IsInseminationSyringe(Item tool)

private static bool CheckCorrectProduct(FarmAnimal animal, SObject o)
{
return animal.defaultProduceIndex.Value == o.ParentSheetIndex
|| (((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).CanUseDeluxeItemForPregnancy
&& animal.deluxeProduceIndex.Value == o.ParentSheetIndex);
if (DataLoader.PregnancyData.PreganancyItems.ContainsKey(animal.displayType))
{
return DataLoader.PregnancyData.MatchingPregnancyItem(animal, o);
}
else if (animal.defaultProduceIndex.Value == o.ParentSheetIndex)
{
return true;
}
else if (((ImpregnatableAnimalItem)DataLoader.AnimalData.GetAnimalItem(animal)).CanUseDeluxeItemForPregnancy
&& animal.deluxeProduceIndex.Value == o.ParentSheetIndex)
{
return true;
}
return false;
}

public static bool IsEggAnimal(FarmAnimal animal)
Expand Down