Skip to content

Commit

Permalink
add support for fairy dust automation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Feb 2, 2024
1 parent 26de4e3 commit 16013be
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Automate/Framework/AutomationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public AutomationFactory(Func<ModConfig> config, IMonitor monitor, IReflectionHe

// machine in Data/Machines
if (obj.GetMachineData() != null)
return new DataBasedMachine(obj, location, tile);
return new DataBasedMachine(obj, location, tile, () => this.Config().MinMinutesForFairyDust);

// connector
if (this.IsConnector(obj))
Expand Down
43 changes: 39 additions & 4 deletions Automate/Framework/Machines/DataBasedMachine.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewValley;
Expand All @@ -8,29 +9,63 @@ namespace Pathoschild.Stardew.Automate.Framework.Machines
/// <summary>An object that accepts input and provides output based on the rules in <see cref="DataLoader.Machines"/>.</summary>
internal class DataBasedMachine : GenericObjectMachine<SObject>
{
/*********
** Fields
*********/
/// <summary>The minimum machine processing time in minutes for which to apply fairy dust.</summary>
private readonly Func<int> MinMinutesForFairyDust;


/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="machine">The underlying machine.</param>
/// <param name="location">The location containing the machine.</param>
/// <param name="tile">The tile covered by the machine.</param>
public DataBasedMachine(SObject machine, GameLocation location, Vector2 tile)
: base(machine, location, tile, DataBasedMachine.GetMachineId(machine.Name)) { }
/// <param name="minMinutesForFairyDust">The minimum machine processing time in minutes for which to apply fairy dust.</param>
public DataBasedMachine(SObject machine, GameLocation location, Vector2 tile, Func<int> minMinutesForFairyDust)
: base(machine, location, tile, DataBasedMachine.GetMachineId(machine.Name))
{
this.MinMinutesForFairyDust = minMinutesForFairyDust;
}

/// <inheritdoc />
public override bool SetInput(IStorage input)
{
if (!this.Machine.HasContextTag("machine_input"))
return false;

// add machine input
bool addedInput = false;
foreach (IContainer container in input.InputContainers)
{
if (this.Machine.AttemptAutoLoad(container.Inventory, Game1.player))
return true;
{
addedInput = true;
break;
}
}

return false;
// apply fairy dust
if (addedInput && this.Machine.heldObject.Value != null)
{
int minutesUntilReady = this.Machine.MinutesUntilReady;
if (minutesUntilReady > 10 && minutesUntilReady >= this.MinMinutesForFairyDust())
{
foreach (IContainer container in input.InputContainers)
{
if (container.Inventory.ContainsId("(O)872") && this.Machine.TryApplyFairyDust())
{
container.Inventory.ReduceId("(O)872", 1);
break;
}
}
}
}


return addedInput;
}


Expand Down
3 changes: 3 additions & 0 deletions Automate/Framework/Models/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ internal class ModConfig
/// <summary>The configuration for specific machines by ID.</summary>
public Dictionary<string, ModConfigMachine> MachineOverrides { get; set; } = new();

/// <summary>The minimum machine processing time in minutes for which to apply fairy dust.</summary>
public int MinMinutesForFairyDust { get; set; } = 20;


/*********
** Public methods
Expand Down
3 changes: 2 additions & 1 deletion Automate/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* Updated for Stardew Valley 1.6.
* Added support for custom machines in the new `Data/Machines` asset.
* Added support for custom floors/paths as connectors.
* Added support for fairy dust. You can configure the minimum processing time for which to apply it in `config.json`.
* Added options in Generic Mod Config Menu to toggle or set the priority for all machines in `Data/Machines`.
* `automate summary` now shows each chest's automation options if edited.
* Removed the 'prevent empty stack' chest option. This is no longer feasible due to how machines work in Stardew Valley 1.6.

**Known issues:**
* Fairy dust in chests isn't applied to connected machines yet.
* Fairy dust will only be applied once to casks, even if they can still be aged further.

## 1.28.7
Released 01 December 2023 for SMAPI 3.14.0 or later.
Expand Down
10 changes: 10 additions & 0 deletions LookupAnything/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ multi-key bindings with plus signs (like `LeftShift + F1`).
</td>
</tr>

<tr>
<td><code>MinMinutesForFairyDust</code></td>
<td>

Default `20`. The minimum machine processing time in minutes for which to apply any [fairy
dust](https://stardewvalleywiki.com/Fairy_Dust) in the chest.

</td>
</tr>

<tr>
<td><code>ProgressionMode</code></td>
<td>
Expand Down

0 comments on commit 16013be

Please sign in to comment.