腳本已歸檔
該腳本已經被作者歸檔,腳本可能失效並且作者不再維護,你無法再進行問題反饋。
// ==UserScript==
// @name 宝可梦点击(Poke Clicker)辅助脚本 自动农场模块
// @namespace PokeClickerHelper
// @version 0.1.4
// @description 自动农场功能:自动种植、收获、施肥、购买农药!
// @author 苍猫
// @match https://www.pokeclicker.com
// @match https://g8hh.github.io/pokeclicker/
// @match https://pokeclicker.g8hh.com
// @match https://yx.g8hh.com/pokeclicker/
// @match https://dreamnya.github.io/pokeclicker/
// @icon data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/319hf99fYX/fX2F/319hf8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////////////////////////99fYX/fX2F/319hf8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////wAAAP8AAAD/fX2F/319hf99fYX/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////8AAAD/AAAA/wAAAP99fYX/fX2F/wAAAP8AAAD/AAAA/319hf8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/HBT//xwU//8AAAD//////319hf8AAAD/Dgim/w4Ipv8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/HBT//xwU//8cFP//HBT//wAAAP8AAAD/Dgim/w4Ipv8OCKb/Dgim/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAA/xwU//8cFP//HBT//xwU/44cFP//HBT//xwU//8cFP//Dgim/w4Ipv8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/HBT//xwU/47/////HBT/jhwU//8cFP//HBT//w4Ipv8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/xwU//8cFP//HBT/jhwU//8OCKb/Dgim/w4Ipv8OCKb/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/xwU//8OCKb/Dgim/w4Ipv8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAPw/AADwDwAA4AcAAOAHAADAAwAAwAMAAMADAADAAwAA4AcAAOAHAADwDwAA/D8AAP//AAD//wAA//8AAA==
// @grant none
// @license MIT
// @run-at document-end
// ==/UserScript==
/* global App, $, PokeClickerHelper, GameConstants, FarmController */
////////////////////
// 自动农场模块 //
////////////////////
// 调用方法
// 开关自动种植 PCH.AutoFarmHelper.AutoPlantStatus = false/true
// 开关自动收获 PCH.AutoFarmHelper.AutoHarvestStatus = false/true
// 种植树果变量 PCH.AutoFarmHelper.BerryType => 赋值 -1 关闭自动锁定
// 农药类型变量 PCH.AutoFarmHelper.MulchType => 赋值 -1 关闭自动施肥
// 施肥时机变量 PCH.AutoFarmHelper.MulchTime
// 农药购买阈值 PCH.AutoFarmHelper.BuyMulchMoney
if (typeof PokeClickerHelper == typeof void 0) {
alert('宝可梦点击(Poke Clicker)辅助脚本 自动农场模块加载失败\n\n未找到核心模块,需要先安装核心模块才可正常使用\n\n论坛主页:https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=3842')
window.open("https://bbs.tampermonkey.net.cn/forum.php?mod=viewthread&tid=3842")
return
}
// UI相关
PokeClickerHelper.UIDOM.push(`
<div id='PokeClickerHelperAutoFarm' class="custom-row">
<div style="margin:auto;">
<label>
自动农场:
</label>
</div>
<div class="contentContainer ml-2">
<div class="form-row">
<select id="PokeClickerHelperSelectBerryType" class="col-12 col-md-5 custom-select" title="锁定选择的树果!(None取消锁定,可游戏内手动选择)"></select>
<select id="PokeClickerHelperSelectMulchType" class="col-12 col-md-6 custom-select" title="自动使用农药,在可收获前1分钟!(None则不适用)"></select>
</div>
<div class="form-row mt-1 mb-2">
<button id="PokeClickerHelperToggleFarmPlant" class="col-12 col-md-4 btn btn-sm btn-primary" value="false">种植 [OFF]</button>
<button id="PokeClickerHelperToggleFarmHarvest" class="col-12 col-md-4 btn btn-sm btn-primary" value="false">收获 [OFF]</button>
</div>
</div>
</div>
`)
let fuc = () => {
AutoFarmHelper.initialize();// 初始化读取 树果数据/农药数据/记忆选择数据
PokeClickerHelper.hookGameTickList.add(AutoFarmHelper.AutoPlant);// 委托GameTick 自动种植
PokeClickerHelper.hookGameTickList.add(AutoFarmHelper.AutoHarvest);// 委托GameTick 自动收获
}
const listener = () => {
$('#PokeClickerHelperToggleFarmPlant').on('click', function () {
AutoFarmHelper.LoadOver.Plant ? AutoFarmHelper.AutoPlantStatus = !AutoFarmHelper.AutoPlantStatus : AutoFarmHelper.LoadOver.Plant = true;
AutoFarmHelper.AutoPlantStatus ? $('#PokeClickerHelperToggleFarmPlant').text('种植 [ON]') : $('#PokeClickerHelperToggleFarmPlant').text('种植 [OFF]')
})
$('#PokeClickerHelperToggleFarmHarvest').on('click', function () {
AutoFarmHelper.LoadOver.Harvest ? AutoFarmHelper.AutoHarvestStatus = !AutoFarmHelper.AutoHarvestStatus : AutoFarmHelper.LoadOver.Harvest = true;
AutoFarmHelper.AutoHarvestStatus ? $('#PokeClickerHelperToggleFarmHarvest').text('收获 [ON]') : $('#PokeClickerHelperToggleFarmHarvest').text('收获 [OFF]')
})
$('#PokeClickerHelperSelectBerryType').on('change', function () {
AutoFarmHelper.BerryType = +this.value;
PokeClickerHelper.set('SelectBerryType', AutoFarmHelper.BerryType.toString());
})
$('#PokeClickerHelperSelectMulchType').on('change', function () {
AutoFarmHelper.MulchType = +this.value;
PokeClickerHelper.set('SelectMulchType', AutoFarmHelper.MulchType.toString())
})
}
PokeClickerHelper.UICustomFuc.push(fuc);
PokeClickerHelper.UIlistener.push(listener);
// 暴露对象方法到全局
const AutoFarmHelper = {};
PokeClickerHelper.AutoFarmHelper = AutoFarmHelper;
AutoFarmHelper.LoadOver = { Plant: false, Harvest: false } //判断是否加载完成
// 自动种植 变量初始化
PokeClickerHelper.get('ToggleFarmPlant', '') === '' ? PokeClickerHelper.set('ToggleFarmPlant', AutoFarmHelper.AutoPlantStatus = false) : AutoFarmHelper.AutoPlantStatus = JSON.parse(PokeClickerHelper.get('ToggleFarmPlant', 'false'));
// 自动收获 变量初始化
PokeClickerHelper.get('ToggleFarmHarvest', '') === '' ? PokeClickerHelper.set('ToggleFarmHarvest', AutoFarmHelper.AutoHarvestStatus = false) : AutoFarmHelper.AutoHarvestStatus = JSON.parse(PokeClickerHelper.get('ToggleFarmHarvest', 'false'));
// 树果类型 变量初始化
PokeClickerHelper.get('SelectBerryType', '') === '' ? PokeClickerHelper.set('SelectBerryType', AutoFarmHelper.BerryType = 0) : AutoFarmHelper.BerryType = JSON.parse(PokeClickerHelper.get('SelectBerryType', '0'));
// 农药类型 变量初始化
PokeClickerHelper.get('SelectedMulchType', '') === '' ? PokeClickerHelper.set('SelectedMulchType', AutoFarmHelper.MulchType = -1) : AutoFarmHelper.MulchType = JSON.parse(PokeClickerHelper.get('SelectedMulchType', '-1'));
// 施肥时机 变量初始化
PokeClickerHelper.get('MulchTime', '') === '' ? PokeClickerHelper.set('MulchTime', AutoFarmHelper.MulchTime = 3) : AutoFarmHelper.MulchTime = JSON.parse(PokeClickerHelper.get('MulchTime', '3'));
// 农药购买阈值 变量初始化
PokeClickerHelper.get('BuyMulchMoney', '') === '' ? PokeClickerHelper.set('BuyMulchMoney', AutoFarmHelper.BuyMulchMoney = 0) : AutoFarmHelper.BuyMulchMoney = JSON.parse(PokeClickerHelper.get('BuyMulchMoney', '0'));
// 自动种植方法
AutoFarmHelper.AutoPlant = () => {
// 未开启自动种植 return 修改 AutoFarmHelper.AutoPlantStatus 开启
if (!AutoFarmHelper.AutoPlantStatus) return
// 锁定种植的树果 如果别的模块需要修改种植 可修改全局变量 PCH.AutoFarmHelper.BerryType
if (AutoFarmHelper.BerryType != -1) FarmController.selectedBerry(AutoFarmHelper.BerryType)
// 树果数据 > 0 进行全部种植
AutoFarmHelper.BerryType != -1 ? App.game.farming.plantAll(AutoFarmHelper.BerryType) : App.game.farming.plantAll(FarmController.selectedBerry())
}
// 自动收获方法
AutoFarmHelper.AutoHarvest = () => {
// 未开启自动收获 return 修改 AutoFarmHelper.AutoHarvestStatus 开启
if (!AutoFarmHelper.AutoHarvestStatus) return
// 无需施肥 return 自动收获 不执行后面代码
if (AutoFarmHelper.MulchType == -1) return App.game.farming.harvestAll()
// 自动农药 购买并进行施肥
if (AutoFarmHelper.MulchType != -1) {
try {
App.game.farming.plotList.forEach(plot => {
if (plot.isUnlocked && plot.stage() == 3 && AutoFarmHelper.getStageTimeLeft(plot, AutoFarmHelper.MulchTime)) {
// 无需购买 施肥 throw Error
if (App.game.farming.mulchList[AutoFarmHelper.MulchType]() > 0) {
App.game.farming.addMulch(plot.index, AutoFarmHelper.MulchType, 1)
throw Error()
}
// 购买农药判断相关
// 读取Buyprice 购买单价
let Buyprice = Math.round(ItemList[MulchType[AutoFarmHelper.MulchType]].basePrice * (player.itemMultipliers[MulchType[AutoFarmHelper.MulchType]] || 1));
// 目前农场币
let PlayerFarmPoint = App.game.wallet.currencies[GameConstants.Currency.farmPoint]();
if (AutoFarmHelper.BuyMulchMoney == 0 && PlayerFarmPoint > Buyprice) { //阈值0 且 目前货币>购买单价
ItemList[MulchType[AutoFarmHelper.MulchType]].buy(1);//购买对应的农药
} else if (PlayerFarmPoint - Buyprice > AutoFarmHelper.BuyMulchMoney) { //阈值不为0 购买后剩余货币>阈值
ItemList[MulchType[AutoFarmHelper.MulchType]].buy(1);//购买对应的农药
}
// 施肥
App.game.farming.addMulch(plot.index, AutoFarmHelper.MulchType, 1)
}
})
} catch (error) { }
}
// 自动收获
App.game.farming.harvestAll()
}
// 初始化树果选择下拉框 读取选择树果和农药
AutoFarmHelper.initialize = () => {
// 遍历树果类型数据插入
$('#PokeClickerHelperSelectBerryType').append(`<option value="-1">None</option>`);
Object.keys(BerryType).filter(type => !isNaN(type) && type !== 'None' && type !== -1).forEach(berry => { $('#PokeClickerHelperSelectBerryType').append(`<option value="${berry}">${BerryType[berry]}</option>`); })
// 遍历农药类型数据插入
let MulchTypeSelect = document.getElementById('PokeClickerHelperSelectMulchType');
Object.keys(MulchType).forEach(value => {
if (isNaN(value)) MulchTypeSelect.innerHTML += `<option value="${MulchType[value]}">${value}</option>`;
})
let text = `
<ul id="AutoMulch" class="list-group p-0">
<li class="list-group-item list-group-item-action seed-list-item p-2">
<img src="assets/images/items/farm/Boost_Mulch.png" height="21px">
<span>施肥时机:</span>
<span><input id="PokeClickerHelperMulchTime" class="col-md-6" title="施肥时机 单位:分(成熟前多少分钟进行自动施肥)." type="text" style="text-align: center;" value="3"></span>
</li>
<li class="list-group-item list-group-item-action seed-list-item p-2">
<img src="assets/images/currency/farmPoint.svg" height="21px">
<span>购买阈值:</span>
<span><input id="PokeClickerHelperBuyMulchMoney" class="col-md-6" title="农药购买阈值(农场币低于阈值停止购买!0则不限制购买)." type="text" style="text-align: center;" value="0"></span>
</li>
</ul>
`
$('#shovelMulch').after(text)
$('#PokeClickerHelperMulchTime').on('change', event => {
AutoFarmHelper.MulchTime = +event.target.value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
if (isNaN(AutoFarmHelper.MulchTime) || AutoFarmHelper.MulchTime <= 0) AutoFarmHelper.MulchTime = 3;
PokeClickerHelper.set('MulchTime', AutoFarmHelper.MulchTime)
event.target.value = AutoFarmHelper.MulchTime.toLocaleString('en-US');
});
$('#PokeClickerHelperBuyMulchMoney').on('change', event => {
AutoFarmHelper.BuyMulchMoney = +event.target.value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
if (isNaN(AutoFarmHelper.BuyMulchMoney) || AutoFarmHelper.BuyMulchMoney <= 0) AutoFarmHelper.BuyMulchMoney = 0;
PokeClickerHelper.set('BuyMulchMoney', AutoFarmHelper.BuyMulchMoney)
event.target.value = AutoFarmHelper.BuyMulchMoney.toLocaleString('en-US');
});
// 首次加载读取上次选择的树果
$('#PokeClickerHelperSelectBerryType').prop('value', AutoFarmHelper.BerryType.toString())
$('#PokeClickerHelperSelectBerryType').change()
// 首次加载读取上次选择的农药
$('#PokeClickerHelperSelectMulchType').prop('value', PokeClickerHelper.get('SelectedMulchType', '-1'))
$('#PokeClickerHelperSelectMulchType').change()
// 首次加载购买阈值
$('#PokeClickerHelperMulchTime').prop('value', AutoFarmHelper.MulchTime.toString())
$('#PokeClickerHelperMulchTime').change()
// 首次加载施肥时机
$('#PokeClickerHelperBuyMulchMoney').prop('value', AutoFarmHelper.BuyMulchMoney.toString())
$('#PokeClickerHelperBuyMulchMoney').change()
}
// 获取土地是否达到施肥的条件 {土地,时间} return true or false
AutoFarmHelper.getStageTimeLeft = (Plot, time) => {
if (Plot.mulch > -1) return false; // Version0.1.2 加入判断 该土地已有肥料的情况直接return false 不进行施肥
time *= 60;
const growthTime = Plot.berryData.growthTime.find(t => Plot.age < t);
const timeLeft = Math.ceil(growthTime - Plot.age);
const growthMultiplier = App.game.farming.getGrowthMultiplier() * Plot.getGrowthMultiplier();
let StageTimeLeft = timeLeft / growthMultiplier
if (Plot._mulchTimeLeft() < time && StageTimeLeft < time) return true;
return false;
}