Skip to content

Commit

Permalink
Feat: Add PettingPet Config and Add WhoChecks Config (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
WuZhuoran authored Apr 21, 2024
1 parent e3a15c7 commit 49f4b22
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 8 deletions.
80 changes: 78 additions & 2 deletions AnimalSitter/AnimalSitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Object = StardewValley.Object;
using AnimalSitter.Integrations.GenericModConfigMenu;
using Microsoft.Xna.Framework.Input;
using System.Reflection;
using StardewValley.Characters;

namespace AnimalSitter
{
Expand All @@ -35,9 +35,12 @@ public class AnimalSitter : Mod
// Whether to harvest animal drops while visiting.
private bool HarvestEnabled = true;

// Whether to pet animals as they are visited.
// Whether to pet animals (Not Pets) as they are visited.
private bool PettingEnabled = true;

// Whether to pet all pets as they are visited.
private bool PettingPetEnabled = true;

// Whether to max the animal's friendship toward the farmer while visiting, even though the farmer is completely ignoring them.
private bool MaxFriendshipEnabled = true;

Expand Down Expand Up @@ -159,6 +162,14 @@ private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
setValue: value => this.Config.PettingEnabled = value
);

configMenu.AddBoolOption(
mod: this.ModManifest,
name: () => I18n.Config_PettingPetEnabled(),
tooltip: () => I18n.Config_PettingPetEnabled_Description(),
getValue: () => this.Config.PettingPetEnabled,
setValue: value => this.Config.PettingPetEnabled = value
);

configMenu.AddBoolOption(
mod: this.ModManifest,
name: () => I18n.Config_MaxFriendshipEnabled(),
Expand All @@ -175,6 +186,15 @@ private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
setValue: value => this.Config.CostPerAction = value
);

configMenu.AddTextOption(
mod: this.ModManifest,
name: () => I18n.Config_WhoChecks(),
tooltip: () => I18n.Config_WhoChecks_Description(),
getValue: () => this.Config.WhoChecks,
setValue: value => this.Config.WhoChecks = value,
allowedValues: new string[] { "spouse", "pet", "Shane", "Haley", "Alex", "Leah", "Marnie" }
);

configMenu.AddBoolOption(
mod: this.ModManifest,
name: () => I18n.Config_EnableMessages(),
Expand Down Expand Up @@ -219,6 +239,7 @@ private void ImportConfiguration()
}

this.PettingEnabled = this.Config.PettingEnabled;
this.PettingPetEnabled = this.Config.PettingPetEnabled;
this.GrowUpEnabled = this.Config.GrowUpEnabled;
this.MaxHappinessEnabled = this.Config.MaxHappinessEnabled;
this.MaxFriendshipEnabled = this.Config.MaxFriendshipEnabled;
Expand Down Expand Up @@ -268,12 +289,44 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
private void IterateOverAnimals()
{
Farmer farmer = Game1.player;
Farm farm = Game1.getFarm();
AnimalTasks stats = new AnimalTasks();

if (farmer.hasPet() && this.PettingPetEnabled)
{
// Pet each Pet
foreach (Pet pet in this.GetPets())
{
try
{
pet.checkAction(farmer, farm);
this.Monitor.Log(I18n.Log_PettingAnimal(animal_name: pet.Name), LogLevel.Trace);
}
catch (Exception ex)
{
this.Monitor.Log(I18n.Log_ExceptionOnkeyreleased(ex: ex), LogLevel.Error);
}
}

// Water all the bowl
this.WaterPetBowl();
}



foreach (FarmAnimal animal in this.GetAnimals())
{
try
{
if (animal.wasPet.Value && this.PettingPetEnabled)
{
this.Monitor.Log($"{animal.Name}");
animal.pet(Game1.player);
stats.AnimalsPet++;

this.Monitor.Log(I18n.Log_PettingAnimal(animal_name: animal.Name), LogLevel.Trace);
}

if (!animal.wasPet.Value && this.PettingEnabled)
{
animal.pet(Game1.player);
Expand Down Expand Up @@ -683,6 +736,29 @@ private List<FarmAnimal> GetAnimals()
return animals;
}

private List<Pet> GetPets()
{
List<Pet> pets = new List<Pet>();
foreach (GameLocation location in Game1.locations)
{
foreach (Pet pet in location.characters.OfType<Pet>())
{
pets.Add(pet);
}
}
return pets;
}
private void WaterPetBowl()
{
foreach (GameLocation location in Game1.locations)
{
foreach (PetBowl item in location.buildings.OfType<PetBowl>())
{
item.watered.Set(true);
this.Monitor.Log(I18n.Log_WateringBowl(X: item.tileX.Value, Y: item.tileY.Value), LogLevel.Trace);
}
}
}
private string GetRandomMessage(string messageStoreName, int low=1, int high=4)
{
var rand = RandomDialogue.Next(low, high + 1);
Expand Down
7 changes: 5 additions & 2 deletions AnimalSitter/AnimalSitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>AnimalSitter</AssemblyName>
<RootNamespace>AnimalSitter</RootNamespace>
<Version>2.2.3</Version>
<Version>2.3.0</Version>
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -12,12 +12,15 @@
<EnableHarmony>true</EnableHarmony>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
<PackageReference Include="Pathoschild.Stardew.ModTranslationClassBuilder" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="i18n\default.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions AnimalSitter/Framework/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class ModConfig : IConfig
public bool MaxFullnessEnabled { get; set; }
public bool HarvestEnabled { get; set; } = true;
public bool PettingEnabled { get; set; } = true;
public bool PettingPetEnabled { get; set; } = true;
public bool MaxFriendshipEnabled { get; set; }
public int CostPerAction { get; set; } = 25;
public string WhoChecks { get; set; } = "spouse";
Expand Down
1 change: 1 addition & 0 deletions AnimalSitter/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"MaxFullnessEnabled": false,
"HarvestEnabled": true,
"PettingEnabled": true,
"PettingPetEnabled": true,
"MaxFriendshipEnabled": false,
"CostPerAction": 25,
"WhoChecks": "spouse",
Expand Down
7 changes: 5 additions & 2 deletions AnimalSitter/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"config.PettingEnabled": "PettingEnabled",
"config.PettingEnabled.description": "This tells your animal worker that you want your animals petted. This is the whole reason I made this mod, so it defaults to true. So if you set this to false, please keep it to yourself. If you enjoy petting each of your animals (because you don't have a hundred of them) then set it to false.",

"config.PettingPetEnabled": "PettingPetEnabled",
"config.PettingPetEnabled.description": "This tells your animal worker that you want your pets petted. Default as true.",

"config.MaxFriendshipEnabled": "MaxFriendshipEnabled",
"config.MaxFriendshipEnabled.description": "This tells your animal worker whether they have to wear your YOU mask, so that the affection of the animals is directed toward you, and not the help. Defaults to false.",

Expand All @@ -26,7 +29,6 @@
"config.WhoChecks": "WhoChecks",
"config.WhoChecks.description": "This is the name of the person (or animal) who checks your animals. Defaults to 'spouse'. You can also set it to 'pet'-- they do a really good job, but they don't provide much feedback. You can also set this to any character in the game, which will enable dialogues with that character. If it's set to anything else, that name will be used in messages.",


"config.EnableMessages": "EnableMessages",
"config.EnableMessages.description": "This is whether to enable in-game messages and dialogues revolving around your animal checker. It defaults to true.",

Expand Down Expand Up @@ -108,5 +110,6 @@
"log.found_coop_object": "Found coop object: {{obj_name}} / {{obj_category}}/{{obj_isAnimalProduct}}",
"log.meow": "Meow..",
"log.woof": "Woof..",
"log.imaginary_pet_take_care": "Your imaginary pet has taken care of your animals."
"log.imaginary_pet_take_care": "Your imaginary pet has taken care of your animals.",
"log.watering_bowl": "Watering Bowl at X: {{X}}, Y: {{Y}}."
}
6 changes: 5 additions & 1 deletion AnimalSitter/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"config.PettingEnabled": "抚摸开关",
"config.PettingEnabled.description": "助手会抚摸动物。默认开启。如果想自己动手,则设置为关闭。",

"config.PettingPetEnabled": "PettingPetEnabled",
"config.PettingPetEnabled.description": "This tells your animal worker that you want your pets petted. Default as true.",

"config.MaxFriendshipEnabled": "好感度开关",
"config.MaxFriendshipEnabled.description": "助手照料动物后,动物好感度是否增长。默认为否。",

Expand Down Expand Up @@ -108,5 +111,6 @@
"log.found_coop_object": "Found coop object: {{obj_name}} / {{obj_category}}/{{obj_isAnimalProduct}}",
"log.meow": "喵……",
"log.woof": "汪……",
"log.imaginary_pet_take_care": "你幻想的宠物已经照料完了你的动物。"
"log.imaginary_pet_take_care": "你幻想的宠物已经照料完了你的动物。",
"log.watering_bowl": "Watering Bowl at X: {{X}}, Y: {{Y}}."
}
2 changes: 1 addition & 1 deletion AnimalSitter/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Animal Sitter LTS",
"Author": "oliver",
"Version": "2.2.3",
"Version": "2.3.0",
"Description": "Long Term Support Mod Version for Animal Sitter Mod. Let someone else pet all those pesky animals!",
"UniqueID": "oliver.AnimalSitterLTS",
"EntryDll": "AnimalSitter.dll",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Here's the default configuration:
"maxFullnessEnabled": false,
"harvestEnabled": true,
"pettingEnabled": true,
"PettingPetEnabled": true,
"maxFriendshipEnabled": false,
"verboseLogging": false,
"costPerAction": 0,
Expand All @@ -55,6 +56,8 @@ Here's the default configuration:

**pettingEnabled**: This tells your animal worker that you want your animals petted. This is the whole reason I made this mod, so it defaults to true. So if you set this to "false", please keep it to yourself. If you enjoy petting each of your animals (because you don't have a hundred of them) then set it to false.

**PettingPetEnabled**: This will give love to your pet and water all the PetBowls.

**maxFriendshipEnabled**: This tells your animal worker whether they have to wear your "you" mask, so that the affection of the animals is directed toward you, and not the help. Defaults to false.

**verboseLogging**: This enables or disabled debug logging. Useful for troubleshooting.
Expand Down

0 comments on commit 49f4b22

Please sign in to comment.