Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some attachments can have a larger radius than others #841

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
10 changes: 3 additions & 7 deletions TractorMod/Framework/Attachments/FertilizerAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Attachments
{
/// <summary>An attachment for fertilizer or speed-gro.</summary>
internal class FertilizerAttachment : BaseAttachment
internal class FertilizerAttachment : ExtendedDistanceAttachment<ExtendedDistanceConfig>
{
/*********
** Fields
*********/
/// <summary>The attachment settings.</summary>
private readonly GenericAttachmentConfig Config;

/// <summary>Simplifies access to private code.</summary>
private readonly IReflectionHelper Reflection;

Expand All @@ -27,10 +24,9 @@ internal class FertilizerAttachment : BaseAttachment
/// <param name="config">The attachment settings.</param>
/// <param name="modRegistry">Fetches metadata about loaded mods.</param>
/// <param name="reflection">Simplifies access to private code.</param>
public FertilizerAttachment(GenericAttachmentConfig config, IModRegistry modRegistry, IReflectionHelper reflection)
: base(modRegistry)
public FertilizerAttachment(ExtendedDistanceConfig config, IModRegistry modRegistry, IReflectionHelper reflection)
: base(config, modRegistry)
{
this.Config = config;
this.Reflection = reflection;
}

Expand Down
3 changes: 3 additions & 0 deletions TractorMod/Framework/Attachments/IAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ internal interface IAttachment
/// <param name="location">The current location.</param>
bool Apply(Vector2 tile, SObject? tileObj, TerrainFeature? tileFeature, Farmer player, Tool? tool, Item? item, GameLocation location);

/// <summary>Determines if the tool range should be applied in an extended pattern or just the core area.</summary>
bool IsDistanceExtended { get; }

/// <summary>Method called when the tractor attachments have been activated for a location.</summary>
/// <param name="location">The current tractor location.</param>
void OnActivated(GameLocation location);
Expand Down
9 changes: 2 additions & 7 deletions TractorMod/Framework/Attachments/ScytheAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Attachments
{
/// <summary>An attachment for the scythe.</summary>
internal class ScytheAttachment : BaseAttachment
internal class ScytheAttachment : ExtendedDistanceAttachment<ScytheConfig>
{
/*********
** Fields
*********/
/// <summary>The attachment settings.</summary>
private readonly ScytheConfig Config;

/// <summary>A cache of is-flower checks by item ID for <see cref="ShouldHarvest"/>.</summary>
private readonly Dictionary<string, bool> IsFlowerCache = new();
Expand All @@ -36,10 +34,7 @@ internal class ScytheAttachment : BaseAttachment
/// <param name="config">The mod configuration.</param>
/// <param name="modRegistry">Fetches metadata about loaded mods.</param>
public ScytheAttachment(ScytheConfig config, IModRegistry modRegistry)
: base(modRegistry)
{
this.Config = config;
}
: base(config, modRegistry) { }

/// <summary>Get whether the tool is currently enabled.</summary>
/// <param name="player">The current player.</param>
Expand Down
10 changes: 3 additions & 7 deletions TractorMod/Framework/Attachments/SeedAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Attachments
{
/// <summary>An attachment for seeds.</summary>
internal class SeedAttachment : BaseAttachment
internal class SeedAttachment : ExtendedDistanceAttachment<ExtendedDistanceConfig>
{
/*********
** Fields
*********/
/// <summary>The attachment settings.</summary>
private readonly GenericAttachmentConfig Config;

/// <summary>Simplifies access to private code.</summary>
private readonly IReflectionHelper Reflection;

Expand All @@ -30,10 +27,9 @@ internal class SeedAttachment : BaseAttachment
/// <param name="config">The attachment settings.</param>
/// <param name="modRegistry">Fetches metadata about loaded mods.</param>
/// <param name="reflection">Simplifies access to private code.</param>
public SeedAttachment(GenericAttachmentConfig config, IModRegistry modRegistry, IReflectionHelper reflection)
: base(modRegistry)
public SeedAttachment(ExtendedDistanceConfig config, IModRegistry modRegistry, IReflectionHelper reflection)
: base(config, modRegistry)
{
this.Config = config;
this.Reflection = reflection;
}

Expand Down
12 changes: 3 additions & 9 deletions TractorMod/Framework/Attachments/WateringCanAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Attachments
{
/// <summary>An attachment for the watering can.</summary>
internal class WateringCanAttachment : BaseAttachment
internal class WateringCanAttachment : ExtendedDistanceAttachment<ExtendedDistanceConfig>
{
/*********
** Fields
*********/
/// <summary>The attachment settings.</summary>
private readonly GenericAttachmentConfig Config;

/// <summary>An infinite watering can to apply.</summary>
private readonly WateringCan WateringCan = new()
{
Expand All @@ -33,11 +30,8 @@ internal class WateringCanAttachment : BaseAttachment
/// <summary>Construct an instance.</summary>
/// <param name="config">The attachment settings.</param>
/// <param name="modRegistry">Fetches metadata about loaded mods.</param>
public WateringCanAttachment(GenericAttachmentConfig config, IModRegistry modRegistry)
: base(modRegistry)
{
this.Config = config;
}
public WateringCanAttachment(ExtendedDistanceConfig config, IModRegistry modRegistry)
: base(config, modRegistry) { }

/// <summary>Get whether the tool is currently enabled.</summary>
/// <param name="player">The current player.</param>
Expand Down
4 changes: 4 additions & 0 deletions TractorMod/Framework/BaseAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ internal abstract class BaseAttachment : IAttachment
/// <param name="location">The current location.</param>
public abstract bool Apply(Vector2 tile, SObject? tileObj, TerrainFeature? tileFeature, Farmer player, Tool? tool, Item? item, GameLocation location);

/// <summary>Determines if the tool range should be applied in an extended pattern or just the core area.</summary>
public virtual bool IsDistanceExtended => false;


/// <summary>Method called when the tractor attachments have been activated for a location.</summary>
/// <param name="location">The current tractor location.</param>
public virtual void OnActivated(GameLocation location)
Expand Down
12 changes: 12 additions & 0 deletions TractorMod/Framework/Config/ExtendedDistanceConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Config
{
/// <summary>Configuration for an attachment which just has on/off and might be long-range.</summary>
internal class ExtendedDistanceConfig : IExtendedDistanceConfig
{
/// <summary>Whether to enable the attachment.</summary>
public bool Enable { get; set; } = true;

/// <summary>If true, causes the area of effect to be increased somewhat from <see cref="ModConfig.Distance"/></summary>
public bool IncreaseDistance { get; set; } = true;
}
}
11 changes: 11 additions & 0 deletions TractorMod/Framework/Config/IExtendedDistanceConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Config
{
/// <summary>
/// Attachments that can affect a wider radius implement this config
/// </summary>
internal interface IExtendedDistanceConfig
{
/// <summary>If true, causes the area of effect to be increased somewhat from <see cref="ModConfig.Distance"/></summary>
public bool IncreaseDistance { get; set; }
}
}
5 changes: 4 additions & 1 deletion TractorMod/Framework/Config/ScytheConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Pathoschild.Stardew.TractorMod.Framework.Config
{
/// <summary>Configuration for the scythe attachment.</summary>
internal class ScytheConfig
internal class ScytheConfig : IExtendedDistanceConfig
{
/// <summary>Whether to harvest crops.</summary>
public bool HarvestCrops { get; set; } = true;
Expand Down Expand Up @@ -29,5 +29,8 @@ internal class ScytheConfig

/// <summary>Whether to clear weeds.</summary>
public bool ClearWeeds { get; set; } = true;

/// <summary>If true, causes the area of effect to be increased somewhat from <see cref="ModConfig.Distance"/></summary>
public bool IncreaseDistance { get; set; } = true;
}
}
8 changes: 4 additions & 4 deletions TractorMod/Framework/Config/StandardAttachmentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class StandardAttachmentsConfig
public AxeConfig Axe { get; set; } = new();

/// <summary>Configuration for the fertilizer attachment.</summary>
public GenericAttachmentConfig Fertilizer { get; set; } = new();
public ExtendedDistanceConfig Fertilizer { get; set; } = new() { IncreaseDistance = false };
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For fertilizer and seeding, I felt like it fits the "non-destructive" idea, but as for playing this way all the time, I'm not so sure. It's a rarely done activity, so personally, I care more about precision than speed. So I made it something that folks could turn on if they felt differently about it, but left if off by default.


/// <summary>Configuration for the grass starter attachment.</summary>
public GenericAttachmentConfig GrassStarter { get; set; } = new();
Expand All @@ -34,7 +34,7 @@ internal class StandardAttachmentsConfig
public ScytheConfig Scythe { get; set; } = new();

/// <summary>Configuration for the seeds attachment.</summary>
public GenericAttachmentConfig Seeds { get; set; } = new();
public ExtendedDistanceConfig Seeds { get; set; } = new() { IncreaseDistance = false };

/// <summary>Configuration for the shears attachment.</summary>
public GenericAttachmentConfig Shears { get; set; } = new();
Expand All @@ -43,9 +43,9 @@ internal class StandardAttachmentsConfig
public GenericAttachmentConfig Slingshot { get; set; } = new() { Enable = false };

/// <summary>Configuration for the watering can attachment.</summary>
public GenericAttachmentConfig WateringCan { get; set; } = new();
public ExtendedDistanceConfig WateringCan { get; set; } = new();

/// <summary>Configuration for the Seed Bag mod attachment.</summary>
public GenericAttachmentConfig SeedBagMod { get; set; } = new();
public ExtendedDistanceConfig SeedBagMod { get; set; } = new();
}
}
27 changes: 27 additions & 0 deletions TractorMod/Framework/ExtendedDistanceAttachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Pathoschild.Stardew.TractorMod.Framework.Config;
using StardewModdingAPI;

namespace Pathoschild.Stardew.TractorMod.Framework
{
/// <summary>The base class for attachments that can operate over a larger area.
/// </summary>
/// <typeparam name="TConfig">The type of the config file.</typeparam>
internal abstract class ExtendedDistanceAttachment<TConfig> : BaseAttachment
NermNermNerm marked this conversation as resolved.
Show resolved Hide resolved
where TConfig : IExtendedDistanceConfig

{
/// <summary>Construct an instance.</summary>
/// <param name="config">The configuration for the attachment.</param>
protected ExtendedDistanceAttachment(TConfig config, IModRegistry modRegistry, int rateLimit = 0)
: base(modRegistry, rateLimit)
{
this.Config = config;
}

/// <summary>The configuration for the attachment.</summary>
protected TConfig Config { get; }

/// <summary>If true, the attachment's area of affect should be expanded by a tile.</summary>
public override bool IsDistanceExtended => this.Config.IncreaseDistance;
}
}
24 changes: 24 additions & 0 deletions TractorMod/Framework/GenericModConfigMenuIntegrationForTractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ public void Register()

// scythe
.AddSectionTitle(I18n.Config_Scythe)
.AddCheckbox(
name: I18n.Config_IncreaseScytheDistance,
tooltip: I18n.Config_IncreaseScytheDistance_Tooltip,
get: config => config.StandardAttachments.Scythe.IncreaseDistance,
set: (config, value) => config.StandardAttachments.Scythe.IncreaseDistance = value
)
.AddCheckbox(
name: I18n.Config_HarvestCrops_Name,
tooltip: I18n.Config_HarvestCrops_Tooltip,
Expand Down Expand Up @@ -412,12 +418,24 @@ public void Register()
get: config => config.StandardAttachments.WateringCan.Enable,
set: (config, value) => config.StandardAttachments.WateringCan.Enable = value
)
.AddCheckbox(
name: I18n.Config_IncreaseWateringCanDistance,
tooltip: I18n.Config_IncreaseWateringCanDistance_Tooltip,
get: config => config.StandardAttachments.WateringCan.IncreaseDistance,
set: (config, value) => config.StandardAttachments.WateringCan.IncreaseDistance = value
)
.AddCheckbox(
name: I18n.Config_Fertilizer_Name,
tooltip: I18n.Config_Fertilizer_Tooltip,
get: config => config.StandardAttachments.Fertilizer.Enable,
set: (config, value) => config.StandardAttachments.Fertilizer.Enable = value
)
.AddCheckbox(
name: I18n.Config_IncreaseFertilizerDistance,
tooltip: I18n.Config_IncreaseFertilizerDistance_Tooltip,
get: config => config.StandardAttachments.Fertilizer.IncreaseDistance,
set: (config, value) => config.StandardAttachments.Fertilizer.IncreaseDistance = value
)
.AddCheckbox(
name: I18n.Config_GrassStarters_Name,
tooltip: I18n.Config_GrassStarters_Tooltip,
Expand All @@ -430,6 +448,12 @@ public void Register()
get: config => config.StandardAttachments.Seeds.Enable,
set: (config, value) => config.StandardAttachments.Seeds.Enable = value
)
.AddCheckbox(
name: I18n.Config_IncreaseSeedingDistance,
tooltip: I18n.Config_IncreaseSeedingDistance_Tooltip,
get: config => config.StandardAttachments.Seeds.IncreaseDistance || config.StandardAttachments.SeedBagMod.IncreaseDistance,
set: (config, value) => { config.StandardAttachments.Seeds.IncreaseDistance = value; config.StandardAttachments.SeedBagMod.IncreaseDistance = value; }
)
.AddCheckbox(
name: I18n.Config_SeedBags_Name,
tooltip: I18n.Config_SeedBags_Tooltip,
Expand Down
14 changes: 3 additions & 11 deletions TractorMod/Framework/ModAttachments/SeedBagAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@
namespace Pathoschild.Stardew.TractorMod.Framework.ModAttachments
{
/// <summary>An attachment for the Seed Bag mod.</summary>
internal class SeedBagAttachment : BaseAttachment
internal class SeedBagAttachment : ExtendedDistanceAttachment<ExtendedDistanceConfig>
{
/*********
** Fields
*********/
/// <summary>The attachment settings.</summary>
private readonly GenericAttachmentConfig Config;


/*********
** Accessors
*********/
Expand All @@ -31,10 +24,9 @@ internal class SeedBagAttachment : BaseAttachment
/// <summary>Construct an instance.</summary>
/// <param name="config">The attachment settings.</param>
/// <param name="modRegistry">Fetches metadata about loaded mods.</param>
public SeedBagAttachment(GenericAttachmentConfig config, IModRegistry modRegistry)
: base(modRegistry)
public SeedBagAttachment(ExtendedDistanceConfig config, IModRegistry modRegistry)
: base(config, modRegistry)
{
this.Config = config;
}

/// <summary>Get whether the tool is currently enabled.</summary>
Expand Down
10 changes: 7 additions & 3 deletions TractorMod/Framework/TractorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,16 @@ private void UpdateAttachmentEffects()
// This must be done outside the temporary interaction block below, since that dismounts
// the player which changes their position from what the player may expect.
Vector2 origin = Game1.player.Tile;
Vector2[] grid = this.GetTileGrid(origin, this.Config.Distance).ToArray();
HashSet<Vector2> coreGrid = this.GetTileGrid(origin, this.Config.Distance).ToHashSet();
Vector2[] extendedGrid = this.GetTileGrid(origin, this.Config.Distance+1).ToArray();

// apply tools
this.TemporarilyFakeInteraction(() =>
{
foreach (Vector2 tile in grid)
foreach (Vector2 tile in extendedGrid)
{
bool isCoreTile = coreGrid.Contains(tile);

// face tile to avoid game skipping interaction
this.GetRadialAdjacentTile(origin, tile, out Vector2 adjacentTile, out int facingDirection);
player.Position = adjacentTile * Game1.tileSize;
Expand All @@ -348,7 +351,8 @@ private void UpdateAttachmentEffects()
location.terrainFeatures.TryGetValue(tile, out TerrainFeature? tileFeature);
foreach (IAttachment attachment in attachments)
{
if (attachment.Apply(tile, tileObj, tileFeature, Game1.player, tool, item, Game1.currentLocation))
if ((isCoreTile || attachment.IsDistanceExtended)
&& attachment.Apply(tile, tileObj, tileFeature, Game1.player, tool, item, Game1.currentLocation))
{
this.ResetCooldown(attachment);
break;
Expand Down
14 changes: 13 additions & 1 deletion TractorMod/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,17 @@
"config.slingshot.tooltip": "Whether to fire the slingshot towards the cursor. (This is massively overpowered and will consume ammo voraciously due to the tractor tool speed.)",

"config.custom-tool-names.name": "Custom Tool Names",
"config.custom-tool-names.tooltip": "The custom items/tools to enable while riding the tractor. Tools will be used on each surrounding tile, while items will be put down. If you specify something that's already supported (like the axe), this overrides all limitations on its use. You must specify the exact internal name (not the translated display name), like 'Axe' or 'Mega Bomb'. Separate multiple values with commas."
"config.custom-tool-names.tooltip": "The custom items/tools to enable while riding the tractor. Tools will be used on each surrounding tile, while items will be put down. If you specify something that's already supported (like the axe), this overrides all limitations on its use. You must specify the exact internal name (not the translated display name), like 'Axe' or 'Mega Bomb'. Separate multiple values with commas.",

"config.increase-scythe-distance": "Increase Scythe Distance",
"config.increase-scythe-distance.tooltip": "Whether to make the scythe tool affect an area around the tractor one tile wider than the base distance (e.g. with this checked, the scythe will affect a 5x5 area while the hoe only affects 3x3)",

"config.increase-watering-can-distance": "Increase Watering Can Distance",
"config.increase-watering-can-distance.tooltip": "Whether to make the watering can affect an area around the tractor one tile wider than the base distance (e.g. with this checked, water will spray over a 5x5 area while the hoe only affects 3x3)",

"config.increase-fertilizer-distance": "Increase Fertilizer Distance",
"config.increase-fertilizer-distance.tooltip": "Whether to make spreading fertilizer affect an area around the tractor one tile wide than the base distance (e.g. with this checked, fertilizer will spray over a 5x5 area while the hoe only affects 3x3)",

"config.increase-seeding-distance": "Increase Seeder Distance",
"config.increase-seeding-distance.tooltip": "Whether to make seed spreading affect an area around the tractor one tile wide than the base distance (e.g. with this checked, seeds will affect a 5x5 area while the hoe only affects 3x3)"
}