Skip to content

Commit

Permalink
Fix issues with error items if no tree fruit were possible (ie season…
Browse files Browse the repository at this point in the history
…al only, but in winter)
  • Loading branch information
atravita-mods committed Feb 27, 2022
1 parent d7d2e08 commit 877d527
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
9 changes: 8 additions & 1 deletion FarmCaveSpawn/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
namespace FarmCaveSpawn;

public enum SeasonalBehavior
{
AllSeasons,
SeasonalOnly,
SeasonalExceptWinter,
}

#pragma warning disable SA1623 // Property summary documentation should match accessors
#pragma warning disable SA1201 // Elements should appear in the correct order - fields are kept next to their accessors for this class.
/// <summary>
Expand Down Expand Up @@ -70,7 +77,7 @@ public float TreeFruitChance
/// <summary>
/// Should I limit myself to just fruits in season?.
/// </summary>
public bool SeasonalOnly { get; set; } = false;
public SeasonalBehavior SeasonalOnly { get; set; } = SeasonalBehavior.AllSeasons;

/// <summary>
/// Should I allow any fruit tree product, even if it's not categorized as fruit.
Expand Down
31 changes: 15 additions & 16 deletions FarmCaveSpawn/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ private void SetUpConfig(object? sender, GameLaunchedEventArgs e)
min: 0f,
max: 100f);
}
else if (property.PropertyType.Equals(typeof(SeasonalBehavior)))
{
helper.AddEnumOption<ModConfig, SeasonalBehavior>(
property: property,
getConfig: () => this.config);
}
else
{
this.Monitor.DebugLog($"{property.Name} unaccounted for.", LogLevel.Warn);
Expand Down Expand Up @@ -310,7 +316,7 @@ private void SpawnFruit(object? sender, DayStartedEventArgs e)
/// <param name="tile">Tile to place fruit on.</param>
private void PlaceFruit(GameLocation location, Vector2 tile)
{
int fruitToPlace = Utility.GetRandom(this.Random.NextDouble() < (this.config.TreeFruitChance / 100f) ? this.TreeFruit : this.BASE_FRUIT, this.Random);
int fruitToPlace = Utility.GetRandom(this.Random.NextDouble() < (this.config.TreeFruitChance / 100f) && this.TreeFruit.Count > 0 ? this.TreeFruit : this.BASE_FRUIT, this.Random);
location.setObject(tile, new SObject(fruitToPlace, 1)
{
IsSpawnedObject = true,
Expand Down Expand Up @@ -348,6 +354,7 @@ private IEnumerable<Vector2> IterateTiles(GameLocation location, int xstart = 1,
/// </summary>
/// <param name="command">Name of command.</param>
/// <param name="args">Arguments for command.</param>
[SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Console command format.")]
private void ListFruits(string command, string[] args)
{
if (!Context.IsWorldReady)
Expand Down Expand Up @@ -406,13 +413,13 @@ private List<int> GetTreeFruits()
foreach (string tree in fruittrees.Values)
{
string[] treedata = tree.Split('/', StringSplitOptions.TrimEntries);
if (this.config.SeasonalOnly && Context.IsWorldReady)

if ((this.config.SeasonalOnly == SeasonalBehavior.SeasonalOnly
|| (this.config.SeasonalOnly == SeasonalBehavior.SeasonalExceptWinter && !currentseason.Contains("winter")))
&& !treedata[1].Contains(currentseason)
&& (!currentseason.Contains("summer") || !treedata[1].Contains("island")))
{
if (!treedata[1].Contains(currentseason)
&& (!currentseason.Contains("summer") || !treedata[1].Contains("island")))
{
continue;
}
continue;
}

if (int.TryParse(treedata[2], out int objectIndex))
Expand Down Expand Up @@ -442,15 +449,7 @@ private List<int> GetTreeFruits()
}
}
}
if (treeFruits.Count > 0)
{
return treeFruits;
}
else
{
this.Monitor.Log($"All fruits were eliminated, defaulting to vanilla fruit list.", LogLevel.Info);
return this.VANILLA_FRUIT;
}
return treeFruits;
}

private void BellsAndWhistles(object? sender, OneSecondUpdateTickingEventArgs e)
Expand Down
6 changes: 6 additions & 0 deletions FarmCaveSpawn/docs/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
* Figure out DGA fruit trees.
<!-- bat eyes for custom locations? -->

#### Version 1.0.9

* Fixes error items spawning in whenever no tree fruits are possible.
* Adds in a setting to exclude winter from Seasonal Only.
* Renames console command.

#### Version 1.0.8

* Corrects `UseModCave` option (would previously always use the additional locations list.) Adds new option to only use the six usual vanilla tree fruit.
Expand Down
7 changes: 5 additions & 2 deletions FarmCaveSpawn/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"UseMineCave.description": "Allows fruits to spawn in the mine entrance as well (after spawning in the Farm Cave, if Max Daily Spawns is not yet hit.",
"UseVanillaFruitOnly.title": "Use Vanilla Fruit Only",
"UseVanillaFruitOnly.description": "If true, will cause mod to only spawn the six vanilla tree fruit usually spawned in the fruit cave (and the four vanilla forage fruit).",
"SeasonalOnly.title": "Seasonal Fruit Only",
"SeasonalOnly.description": "Restrict to this season's fruit only",
"SeasonalOnly.title": "Seasonal Fruit",
"SeasonalOnly.description": "Allows restricting to the current season only. ",
"AllowAnyTreeProduct.title": "Allow Any Tree Product",
"AllowAnyTreeProduct.description": "If enabled, all products from fruit trees are allowed. If disabled, restricted to just fruit.",
"EdiblesOnly.title": "Restrict to Edible",
Expand All @@ -29,6 +29,9 @@
"PriceCap.title": "Price Cap",
"PriceCap.description": "Removes fruit if their base price is above this.",

"config.SeasonalBehavior.AllSeasons": "Spawn from all seasons.",
"config.SeasonalBehavior.SeasonalOnly": "Current season only.",
"config.SeasonalBehavior.SeasonalExceptWinter" : "Current season, except in winter.",

//Errors
"ExcessRegexMatches": "Do not recognize pattern {{loc}}; skipping for now.",
Expand Down
2 changes: 1 addition & 1 deletion FarmCaveSpawn/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://smapi.io/schemas/manifest.json",
"Name": "FarmCaveSpawn",
"Author": "atravita",
"Version": "1.0.8",
"Version": "1.0.9",
"Description": "Spawn more tree fruit in the fruit cave",
"UniqueID": "atravita.FarmCaveSpawn",
"EntryDll": "FarmCaveSpawn.dll",
Expand Down

0 comments on commit 877d527

Please sign in to comment.