Skip to content

Commit

Permalink
Merge pull request #5 from hawkfalcon/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
EienWolf authored Jun 6, 2024
2 parents 6827250 + 04ea462 commit 72b97f6
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 33 deletions.
11 changes: 9 additions & 2 deletions BetterJunimos/Abilities/Base/PlantCropsAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public bool PerformAction(GameLocation location, Vector2 pos, JunimoHarvester ju
private Item PlantableSeed(GameLocation location, Chest chest, string cropType=null) {
var foundItems = chest.Items.ToList().FindAll(item =>
item != null
&& (new StardewValley.Object(item.ItemId, 1)).Type == "Seeds"
//&& new StardewValley.Object(item.ItemId, 1).Type == "Seeds"
&& !(BetterJunimos.Config.JunimoImprovements.AvoidPlantingCoffee && item.ParentSheetIndex == Util.CoffeeId)
);

foundItems = foundItems.FindAll(item => IsCrop(item, location));
switch (cropType)
{
case CropTypes.Trellis:
Expand Down Expand Up @@ -117,6 +117,7 @@ private Item PlantableSeed(GameLocation location, Chest chest, string cropType=n
}
} catch (KeyNotFoundException)
{

// Monitor.Log($"Cache miss: {key} {Game1.currentSeason}", LogLevel.Debug);
var crop = new Crop(key, 0, 0, location);
cropSeasons[Game1.currentSeason][key] = crop.IsInSeason(location);
Expand All @@ -135,6 +136,12 @@ private bool IsTrellisCrop(Item item, GameLocation location) {
return crop.raisedSeeds.Value;
}

//Verify if the item is a crop seed
private bool IsCrop(Item item, GameLocation location) {
var objCrop = new StardewValley.Object(item.ItemId, 1);
return objCrop.Category == -74 && item.ItemId != "770" && item.ItemId != "MixedFlowerSeeds";
}

public List<string> RequiredItems() {
return new List<string> { ItemCategory.ToString() };
}
Expand Down
5 changes: 4 additions & 1 deletion BetterJunimos/BetterJunimos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private void DoHarmonyRegistration() {
replacements.Add("areThereMatureCropsWithinRadius", junimoHutType, typeof(PatchSearchAroundHut));

// replacements for hardcoded max junimos
replacements.Add("dayUpdate", junimoHutType, typeof(ReplaceJunimoHutdayUpdate));
replacements.Add("Update", junimoHutType, typeof(ReplaceJunimoHutUpdate));
replacements.Add("updateWhenFarmNotCurrentLocation", junimoHutType, typeof(ReplaceJunimoHutupdateWhenFarmNotCurrentLocation));
replacements.Add("getUnusedJunimoNumber", junimoHutType, typeof(ReplaceJunimoHutNumber));
replacements.Add("performTenMinuteAction", junimoHutType, typeof(ReplaceJunimoTimerNumber));

Expand Down Expand Up @@ -254,7 +256,8 @@ void OnDayStarted(object sender, DayStartedEventArgs e) {
Util.Payments.JunimoPaymentsToday.Clear();
Util.Payments.WereJunimosPaidToday = false;
}

Monitor.Log($"On day starter",
LogLevel.Debug);
var huts = Util.GetAllHuts();

// tag each hut chest so later we can tell whether a GrabMenu close is for a Junimo chest or some other chest
Expand Down
5 changes: 4 additions & 1 deletion BetterJunimos/Patches/JunimoHarvesterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public static bool Prefix(JunimoHarvester __instance, ref PathNode currentNode,
public class PatchTryToHarvestHere {
public static bool Prefix(JunimoHarvester __instance, ref int ___harvestTimer, ref NetGuid ___netHome) {
if (!Context.IsMainPlayer) return true;

if (__instance.home is null) {
//BetterJunimos.SMonitor.Log($"No hut assigned");
return false;
}
var id = ___netHome.Value;
var pos = __instance.Tile;

Expand Down
86 changes: 77 additions & 9 deletions BetterJunimos/Patches/JunimoHutPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static bool Prefix(JunimoHut __instance, ref bool __result) {
private static bool SearchAroundHut(JunimoHut hut) {
var id = Util.GetHutIdFromHut(hut);
var radius = Util.CurrentWorkingRadius;
GameLocation farm = Game1.currentLocation;
GameLocation farm = hut.GetParentLocation();

// SearchHutGrid manages hut.lastKnownCropLocation and Util.Abilities.lastKnownCropLocations
var foundWork = SearchHutGrid(hut, radius, farm, id);
Expand Down Expand Up @@ -122,6 +122,74 @@ private static bool SearchHutGrid(JunimoHut hut, int radius, GameLocation farm,
}
}

/* Update
*
* To allow more junimos, allow working in rain
*/
[HarmonyPriority(Priority.Low)]
internal class ReplaceJunimoHutupdateWhenFarmNotCurrentLocation
{
// This is to prevent the update function from running, other than base.Update()
// Capture sendOutTimer and use to stop execution
public static bool Prefix(JunimoHut __instance, GameTime time, ref int ___junimoSendOutTimer, out int __state) {
__state = ___junimoSendOutTimer;
___junimoSendOutTimer = 0;
if (__state <= 0) return true;
if (!Context.IsMainPlayer) return true;
//BetterJunimos.SMonitor.Log($"ReplaceJunimoHutupdateWhenFarmNotCurrentLocation: postfix starts", LogLevel.Debug);

___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds;
//__instance.shouldSendOutJunimos.Value = true;
// Don't work on farmEvent days
// Base game work on event days
// if (Game1.farmEvent != null)
// return;
// Winter
if (__instance.GetParentLocation().IsWinterHere() && !Util.Progression.CanWorkInWinter) {
return true;
}
// Rain
if (__instance.GetParentLocation().IsRainingHere() && !Util.Progression.CanWorkInRain){
//BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain");
return true;
}
// Currently sending out a junimo
if (___junimoSendOutTimer > 0) {
//BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} - ReplaceJunimoHutUpdate: sending");
return true;
}
// Already enough junimos
if (__instance.myJunimos.Count >= Util.Progression.MaxJunimosUnlocked){
//BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} Already {__instance.myJunimos.Count} Junimos, limit is {Util.Progression.MaxJunimosUnlocked}");
return true;
}
// Nothing to do
if (!__instance.areThereMatureCropsWithinRadius()) {
//BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} No work for Junimos to do, not spawning another", LogLevel.Debug);
return true;
}
//BetterJunimos.SMonitor.Log($"{__instance.parentLocationName} ReplaceJunimoHutUpdate: spawning");
Util.SpawnJunimoAtHut(__instance);
// BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: postfix ends");
___junimoSendOutTimer = 1000;
return true;
}
}

/* Update
*
* To allow more junimos, allow working
*/
[HarmonyPriority(Priority.VeryHigh)]
internal class ReplaceJunimoHutdayUpdate
{
public static void Postfix(JunimoHut __instance, int dayOfMonth)
{
//BetterJunimos.SMonitor.Log($"ReplaceJunimoHutdayUpdate: postfix starts", LogLevel.Debug);
__instance.shouldSendOutJunimos.Value = true;
}
}

/* Update
*
* To allow more junimos, allow working in rain
Expand All @@ -142,17 +210,17 @@ public static void Postfix(JunimoHut __instance, GameTime time, ref int ___junim
// BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: postfix starts");

___junimoSendOutTimer = __state - time.ElapsedGameTime.Milliseconds;

// Don't work on farmEvent days
if (Game1.farmEvent != null)
return;
// if (Game1.farmEvent != null)
// return;
// Winter
if (Game1.IsWinter && !Util.Progression.CanWorkInWinter) {
if (__instance.GetParentLocation().IsWinterHere() && !Util.Progression.CanWorkInWinter) {
return;
}
// Rain
if (Game1.isRaining && !Util.Progression.CanWorkInRain){
BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain");
if (__instance.GetParentLocation().IsRainingHere() && !Util.Progression.CanWorkInRain){
//BetterJunimos.SMonitor.Log($"ReplaceJunimoHutUpdate: rain");
return;
}
// Currently sending out a junimo
Expand Down Expand Up @@ -227,13 +295,13 @@ public static bool Prefix(int timeElapsed, JunimoHut __instance, ref int ___juni
__instance.myJunimos[index].pokeToHarvest();
}

if (Game1.timeOfDay is >= 2000 and < 2400 && (!Game1.IsWinter && Game1.random.NextDouble() < 0.2))
if (Game1.timeOfDay is >= 2000 and < 2400 && !__instance.GetParentLocation().IsWinterHere() && Game1.random.NextDouble() < 0.2)
{
__instance.wasLit.Value = true;
}
else
{
if (Game1.timeOfDay != 2400 || Game1.IsWinter)
if (Game1.timeOfDay != 2400 || __instance.GetParentLocation().IsWinterHere())
return false;
__instance.wasLit.Value = false;
}
Expand Down
40 changes: 20 additions & 20 deletions BetterJunimos/[CP] Better Junimos Config Wizard/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
"hawkfalcon.BetterJunimos/JunimoHuts": "true"
},
"Entries": {
"22210001/H": "continue/64 15/farmer 64 15 2 Wizard 64 17 0/skippable/pause 1000/speak Wizard \"So it is true! I heard you convinced the Junimos to move in, but I had to see it for myself.$1#$b#Ahem. I am Rasmodius... I appear before you as the mighty Initial Configuration Wizard, tamer of the arcane.#$b#There are a few things you need to know about the Junimos.$0\"/speak Wizard \"$q -1 null#Shall I go on?$8#$r 22219010 0 2221_continue_y#Please, I appreciate your other-worldy wisdom.#$r 22219011 0 2221_continue_n#Another time perhaps. I have a lot of ducks to feed.#$r 22219012 0 2221_continue_fu#Cram it old man, I can figure this out myself.\"/fork 22219010 2221_continue_y/fork 22219011 2221_continue_n/fork 22219012 2221_continue_fu/end",
"22210001/H": "continue/64 15/farmer 64 15 2 Wizard 64 17 0/ignoreCollisions farmer/ignoreCollisions Wizard/skippable/pause 1000/speak Wizard \"{{i18n:22210001.01}}$1#$b#{{i18n:22210001.02}}#$b#{{i18n:22210001.03}}$0\"/speak Wizard \"$q -1 null#{{i18n:22210001.04}}$8#$r 22219010 0 2221_continue_y#{{i18n:22210001.05}}#$r 22219011 0 2221_continue_n#{{i18n:22210001.06}}#$r 22219012 0 2221_continue_fu#{{i18n:22210001.07}}\"/fork 22219010 2221_continue_y/fork 22219011 2221_continue_n/fork 22219012 2221_continue_fu/end",
"2221_continue_n": "skippable/emote Wizard 16/pause 500/playSound wand/end",
"2221_continue_fu": "skippable/playSound thunder/glow 255 0 0/emote Wizard 12/speak Wizard \"May your most vital orifices be clogged with dirt! To you I say, good day!$5\"/friendship Wizard -60/pause 500/playSound wand/end",
"2221_continue_y": "skippable/friendship Wizard 60/speak Wizard \"You only need to supply the items once, then the Junimos can perform that ability for ever.#$b#Or I suppose I could just summon all the items they'll ever need right now.\"/speak Wizard \"$q -1 null#What'll it be?$8#$r 22219020 0 2221_progression_y#I'm a mighty adventurer, I'll quest for anything the Junimos need.#$r 22219021 0 2221_progression_n#I'm just a humble farmer, please unlock all the abilities.\"/switchEvent 2221_wages",
"2221_wages": "skippable/speak Wizard \"Secondly, the Junimos need to be paid for their hard work. Each day you need to give them a fruit, flower, or forage item and they'll get to work.#$b#But there is another way. I could cast a spell to convince them to work for free...\"/speak Wizard \"$q -1 null#What wages will you pay?$8#$r 22219030 0 2221_fruit#Fruit#$r 22219031 0 2221_flowers#Flowers#$r 22219032 0 2221_forage#Forage#$r 22219033 0 2221_all#One of each#$r 22219034 0 2221_none#Do that spell thing so they work for free\"/switchEvent 2221_communicate",
"2221_communicate": "skippable/speak Wizard \"I should teach you how to communicate with the Junimos.#$b#There's a box outside the hut. Put in seeds, fertilizer, wages, and items they request. Take out the crops, and forage they harvest.#$b#There's also a note in the hut that tells you if they're working and what they need. Read it if you're confused about what they're doing.\"/switchEvent 2221_greenhouse",
"2221_greenhouse": "skippable/speak Wizard \"The Junimos can enter your greenhouse, if it's within walking distance of their hut. They will not travel farther than that.\"/switchEvent 2221_config",
"2221_config": "skippable/speak Wizard \"Finally, you can change the working arrangements at any time. It's very flexible.\"/speak Wizard \"$q -1 null#Shall I show you the things you can change?#$r 22219040 0 2221_config_y#Yes, show me all the options.#$r 22219041 0 2221_config_n#No, I can look at options later.\"/switchEvent 2221_end",
"2221_end": "skippable/speak Wizard \"I may return periodically to study the Junimos and learn more about their ways. Rest assured though, your feeble mortal eyes will be unable to see me.$0\"/pause 500/playSound wand/end"
"2221_continue_fu": "skippable/playSound thunder/glow 255 0 0/emote Wizard 12/speak Wizard \"{{i18n:2221_continue_fu}}$5\"/friendship Wizard -60/pause 500/playSound wand/end",
"2221_continue_y": "skippable/friendship Wizard 60/speak Wizard \"{{i18n:2221_continue_y.01}}#$b#{{i18n:2221_continue_y.02}}\"/speak Wizard \"$q -1 null#{{i18n:2221_continue_y.03}}$8#$r 22219020 0 2221_progression_y#{{i18n:2221_continue_y.04}}#$r 22219021 0 2221_progression_n#{{i18n:2221_continue_y.05}}\"/switchEvent 2221_wages",
"2221_wages": "skippable/speak Wizard \"{{i18n:2221_wages.01}}#$b#{{i18n:2221_wages.02}}\"/speak Wizard \"$q -1 null#{{i18n:2221_wages.03}}$8#$r 22219030 0 2221_fruit#Fruit#$r 22219031 0 2221_flowers#Flowers#$r 22219032 0 2221_forage#Forage#$r 22219033 0 2221_all#One of each#$r 22219034 0 2221_none#{{i18n:2221_wages.04}}\"/switchEvent 2221_communicate",
"2221_communicate": "skippable/speak Wizard \"{{i18n:2221_communicate.01}}#$b#{{i18n:2221_communicate.02}}#$b#{{i18n:2221_communicate.03}}\"/switchEvent 2221_greenhouse",
"2221_greenhouse": "skippable/speak Wizard \"{{i18n:2221_greenhouse}}\"/switchEvent 2221_config",
"2221_config": "skippable/speak Wizard \"{{i18n:2221_config.01}}\"/speak Wizard \"$q -1 null#{{i18n:2221_config.02}}#$r 22219040 0 2221_config_y#{{i18n:2221_config.03}}#$r 22219041 0 2221_config_n#{{i18n:2221_config.04}}\"/switchEvent 2221_end",
"2221_end": "skippable/speak Wizard \"{{i18n:2221_end}}$0\"/pause 500/playSound wand/end"
}
},
{
"Action": "EditData",
"Target": "Characters/Dialogue/Wizard",
"Entries": {
"2221_continue_y": "Very well. First, the Junimos have many abilities, animal vegetable and mineral. But they need items, which they will request from you, to perform each ability.",
"2221_continue_n": "Very well. Good day to you, @.",
"2221_continue_fu": "You're not so clever @, if you think it wise to make an enemy of me.$5",
"2221_progression_y": "An admirable choice! The Junimos' needs will take you on many adventures.",
"2221_progression_n": "I understand. You wield a hoe, not a sword.",
"2221_fruit": "A very suitable choice, @.",
"2221_flowers": "To brighten the Junimos' day. Very good.",
"2221_forage": "The bounty of the forest, how apt.",
"2221_all": "A fair and generous choice, @.",
"2221_none": "As you wish. It's not for me to decide what's fair.",
"2221_config_y": "Then I will leave you to look over it. Good day to you, @.",
"2221_config_n": "I have many other things to do anyway. Good day to you, @."
"2221_continue_y": "{{i18n:dialogue.2221_continue_y}}",
"2221_continue_n": "{{i18n:dialogue.2221_continue_n}}",
"2221_continue_fu": "{{i18n:dialogue.2221_continue_fu}}$5",
"2221_progression_y": "{{i18n:dialogue.2221_progression_y}}",
"2221_progression_n": "{{i18n:dialogue.2221_progression_n}}",
"2221_fruit": "{{i18n:dialogue.2221_fruit}}",
"2221_flowers": "{{i18n:dialogue.2221_flowers}}",
"2221_forage": "{{i18n:dialogue.2221_forage}}",
"2221_all": "{{i18n:dialogue.2221_all}}",
"2221_none": "{{i18n:dialogue.2221_none}}",
"2221_config_y": "{{i18n:dialogue.2221_config_y}}",
"2221_config_n": "{{i18n:dialogue.2221_config_n}}"
}
}
]
Expand Down
Loading

0 comments on commit 72b97f6

Please sign in to comment.