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

Add Smart Mulch feature #366

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,23 @@ As of 1.1 this also includes 2 more additional features into the Treasures tab o

<a name="simple-auto-farmer"></a>
## Simple Auto Farmer (<a href="https://github.com/Ephenia/Pokeclicker-Scripts/blob/main/simpleautofarmer.user.js">simpleautofarmer.user.js</a>) (<a href="https://github.com/Ephenia/Pokeclicker-Scripts/raw/master/simpleautofarmer.user.js">One-Click Install</a>)
This script is a simple Auto Farmer which adds 4 new buttons below the Plant and Harvest all buttons as shown:<br>
This script is a simple Auto Farmer which adds 5 new buttons below the Plant and Harvest all buttons as shown:<br>

![](https://i.imgur.com/ei7lR95.png)

• Auto Farm will plant the berry that you have selected.<br/>
• Auto Harvest will harvest all ripe berries.<br/>
• Auto Replant will wait for ripe berries to be close to withering before harvesting, then replant the same kind of berry in that plot. This can be especially useful for mutating berries.<br/>
• Auto Mulch will wait for mulch to be close to running out, then use the same kind of mulch on that plot.
• Auto Mulch will wait for mulch to be close to running out, then use the same kind of mulch on that plot.<br/>
• Auto Smart Mulch will wait until the plot is ready to harvest, then apply rich mulch to increase the yield.

The Auto Farmer runs even while the farm window is closed. It also now saves your berry selection when the game restarts, to avoid farming interruptions.

```diff
- Note: the Auto Farmer runs once every 1 second.
- Note: Auto Replant cannot be used alongside Auto Plant or Auto Harvest.
- Note: Auto Smart Mulch cannot be used alongside Auto Mulch.
- Note: Auto Smart Mulch requires Auto Harvest or Auto Replant to be active in order to function.
```

<hr>
Expand Down
54 changes: 52 additions & 2 deletions simpleautofarmer.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @description Adds options to automatically plant, harvest, replant, and remulch. Unlike harvesting, replanting only harvests berries right before they wither, to maximize any auras. Make sure the correct berry is selected before auto planting; the script will save your selection across restarts. Auto replant and mulch maintain the berry/mulch already in each plot.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.7
// @version 1.8

// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
Expand All @@ -16,7 +16,7 @@
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==//
// ==/UserScript==

var scriptName = 'simpleautofarmer';

Expand All @@ -27,11 +27,13 @@ function initAutoFarm() {
var harvestState;
var replantState;
var mulchState;
var smartMulchState;

plantState = JSON.parse(localStorage.getItem('autoPlantState'));
harvestState = JSON.parse(localStorage.getItem('autoHarvestState'));
replantState = JSON.parse(localStorage.getItem('autoReplantState'));
mulchState = JSON.parse(localStorage.getItem('autoMulchState'));
smartMulchState = JSON.parse(localStorage.getItem('autoSmartMulchState'));

let plantSelected = JSON.parse(localStorage.getItem('autoPlantSelected'));
FarmController.selectedBerry(plantSelected);
Expand Down Expand Up @@ -79,6 +81,7 @@ function initAutoFarm() {
createButton('harvest', harvestState, autoHarvestToggle, 'l', true);
createButton('replant', replantState, autoReplantToggle, 'r', false);
createButton('mulch', mulchState, autoMulchToggle, 'l', false);
createButton('smart-mulch', smartMulchState, autoSmartMulchToggle, 'r', false);
}

function toggleFarmLoop() {
Expand Down Expand Up @@ -150,6 +153,10 @@ function initAutoFarm() {
}

function doHarvest() {
if (smartMulchState){
//Applies rich mulch to all ripe plots
doSmartMulch()
}
App.game.farming.harvestAll();
}

Expand Down Expand Up @@ -185,6 +192,10 @@ function initAutoFarm() {
var timeLeft = berryData[berry].growthTime[4] - plot.age;
timeLeft /= (App.game.farming.getGrowthMultiplier() * plot.getGrowthMultiplier());
if (timeLeft < 10) {
if (smartMulchState){
// Applies rich mulch to the current plot
doRipeMulch(plot)
}
App.game.farming.harvest(i, false);
App.game.farming.plant(i, berry, false);
}
Expand All @@ -196,6 +207,9 @@ function initAutoFarm() {
mulchState = !mulchState;
localStorage.setItem("autoMulchState", mulchState);
toggleFarmLoop();
if (smartMulchState) {
autoSmartMulchToggle();
}
let elt = document.getElementById('auto-mulch-toggle');
if (mulchState) {
elt.innerText = "Auto Mulch\n[ON]";
Expand All @@ -217,6 +231,41 @@ function initAutoFarm() {
}
}
}

function autoSmartMulchToggle() {
smartMulchState = !smartMulchState;
localStorage.setItem("autoHarvestState", smartMulchState);
toggleFarmLoop();
if (mulchState) {
autoMulchToggle();
}
let elt = document.getElementById('auto-smart-mulch-toggle');
if (smartMulchState) {
// No \n because it causes clipping issues with the shovel button. "Auto Smart Mulch" takes up two lines
elt.innerText = "Auto Smart Mulch [ON]";
elt.classList.remove('btn-danger');
elt.classList.add('btn-success');
} else {
elt.innerText = "Auto Smart Mulch [OFF]";
elt.classList.remove('btn-success');
elt.classList.add('btn-danger');
}
}
// Checks each plot to see if it's ripe, then calls the function to apply rich mulch to that plot if it is ripe
function doSmartMulch(){
for (let i = 0; i < 25; i++) {
let plot = App.game.farming.plotList[i];
if (plot.berry >= 0 && plot.stage() == 4) {
doRipeMulch(plot)
}
}
}
// Checks if the given plot has no mulch, and if it doesn't, applies rich mulch
function doRipeMulch(plot){
if (plot.mulch == MulchType.None) {
App.game.farming.addMulch(plot.index, 1);
}
}
}

function initSelectedBerryTracking() {
Expand Down Expand Up @@ -271,6 +320,7 @@ initLocalStorage("autoPlantState", false);
initLocalStorage("autoHarvestState", false);
initLocalStorage("autoReplantState", false);
initLocalStorage("autoMulchState", false);
initLocalStorage("autoSmartMulchState", false);
initLocalStorage("autoPlantSelected", 0);


Expand Down