午安农场挂机版 1.0 (shell)
反正马上新版本了, 给你们又如何???
包含基本功能:收获,扩建,种植,种子也是种一次买一颗,反正能多请求一次就多请求一次,不给午安留面子。
没图亦可言屌,直接说步骤
1,首先需要jq库的支持
macos 命令:brew install jq
centos 命令:yum install jq
可以使用which jq 查看安装路径,如果不是默认的环境变量path如/usr/bin,则需要手动在crontab中设置path
2,创建.sh文件
注意权限问题
拿我为例(macos),在/usr/local/shell下创建farm.sh 和 farm.log(用于查看日志)
然后将代码填入farm.sh文件:(记得更改openid)
代码如下:
#!/bin/bash
# 配置
OPENID="填入你的openid"
BASE_URL="https://meta-backend.yuimeta.com/api/openFarm"
expansion_requirements='[
{"lv": 5, "gold": 10000},
{"lv": 7, "gold": 20000},
{"lv": 9, "gold": 30000},
{"lv": 11, "gold": 50000},
{"lv": 13, "gold": 70000},
{"lv": 15, "gold": 90000},
{"lv": 17, "gold": 120000},
{"lv": 19, "gold": 150000},
{"lv": 21, "gold": 180000},
{"lv": 23, "gold": 230000},
{"lv": 25, "gold": 300000},
{"lv": 27, "gold": 500000},
{"lv": 29, "gold": 85000},
{"lv": 31, "gold": 1100000},
{"lv": 33, "gold": 1300000},
{"lv": 35, "gold": 1500000},
{"lv": 37, "gold": 1700000},
{"lv": 39, "gold": 2000000}
]'
# 获取账户信息
get_farm_info() {
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/farms/view_farm", "openid": "'"$OPENID"'", "method": "GET", "params": {}}' "$BASE_URL"
}
# 获取商店信息
get_store_info() {
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/store", "openid": "'"$OPENID"'", "method": "GET"}' "$BASE_URL"
}
# 购买种子
buy_seed() {
local seed_name=$1
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/store", "openid": "'"$OPENID"'", "method": "POST", "data": {"name": "'"$seed_name"'", "num": 1}}' "$BASE_URL"
}
# 种植作物
plant_crop() {
local plot_id=$1
local crop_id=$2
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/farms/plant_crop", "openid": "'"$OPENID"'", "method": "POST", "data": {"plot_id": '"$plot_id"', "crop_id": "'"$crop_id"'"}}' "$BASE_URL"
}
# 收获作物
harvest_crop() {
local plot_id=$1
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/farms/harvest_crop", "openid": "'"$OPENID"'", "method": "POST", "data": {"plot_id": '"$plot_id"'}}' "$BASE_URL"
}
# 扩建土地
expand_plot() {
curl -s -X POST -H "Content-Type: application/json" -d '{"url": "/farms/expand_plot", "openid": "'"$OPENID"'", "method": "GET"}' "$BASE_URL"
}
# 获取账户信息
farm_info=$(get_farm_info)
# 检查获取账户信息是否成功
code=$(echo "$farm_info" | jq -r '.code')
if [ "$code" -ne 200 ]; then
echo "获取账户信息失败"
exit 1
fi
# 解析账户信息
plots=$(echo "$farm_info" | jq -c '.data.plots[]')
farm_level=$(echo "$farm_info" | jq -r '.data.farm_level')
farm_gold=$(echo "$farm_info" | jq -r '.data.farm_gold')
expandable_plots=$(echo "$farm_info" | jq -r '.data.expandable_plots') #扩建的土地数
seeds=$(echo "$farm_info" | jq -c '.data.warehouse.seeds[]')
# 先收获可收获的作物
for plot in $plots; do
plot_status=$(echo "$plot" | jq -r '.plot_status')
plot_number=$(echo "$plot" | jq -r '.plot_number')
if [ "$plot_status" = "可收获" ]; then
echo "收获作物,地块编号:$plot_number"
harvest_crop "$plot_number"
fi
done
# 扩建逻辑
for requirement in $(echo "$expansion_requirements" | jq -c '.[]'); do
lv=$(echo "$requirement" | jq -r '.lv')
required_gold=$(echo "$requirement" | jq -r '.gold')
# 判断是否需要更新扩建索引
if [ "$lv" -eq "$((expandable_plots * 2 + 5))" ]; then
# 检查是否满足扩建条件
if [ "$farm_level" -ge "$lv" ] && [ "$farm_gold" -ge "$required_gold" ]; then
echo "扩建土地到等级 $lv,当前金币: $farm_gold,需求金币: $required_gold"
expand_plot
# 扩建后重新获取账户信息
farm_info=$(get_farm_info)
expandable_plots=$(echo "$farm_info" | jq -r '.data.expandable_plots')
plots=$(echo "$farm_info" | jq -c '.data.plots[]')
break
fi
fi
done
# 获取商店信息
store_info=$(get_store_info)
# 检查获取商店信息是否成功
code=$(echo "$store_info" | jq -r '.code')
if [ "$code" -ne 200 ]; then
echo "获取商店信息失败"
exit 1
fi
# 解析商店信息,选择经验值最高且符合等级的种子
best_seed=$(echo "$store_info" | jq -c '[.data[] | select(.required_level <= '"$farm_level"')] | sort_by(-.exp) | .[0]')
best_seed_name=$(echo "$best_seed" | jq -r '.name')
# 种植种子
for plot in $plots; do
plot_status=$(echo "$plot" | /opt/homebrew/bin/jq -r '.plot_status')
plot_number=$(echo "$plot" | /opt/homebrew/bin/jq -r '.plot_number')
if [ "$plot_status" = "可收获" ] || [ "$plot_status" = "未种植" ]; then
echo "购买种子:$best_seed_name"
buy_seed "$best_seed_name"
echo "种植作物,地块编号:$plot_number"
plant_crop "$plot_number" "$best_seed_name"
fi
done
3,设置定时任务
crontab -e 设置定时任务,排除宵禁时间
设置为早上8点到下午7.30自动执行,每分钟一次
注意:如果jq安装位置不在环境变量path内,需要设置如:PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin
参考代码:
PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin
* 8-18 * * * /usr/local/shell/farm.sh >> /usr/local/shell/farm.log 2>&1
* 19 1-30 * * * /usr/local/shell/farm.sh >> /usr/local/shell/farm.log 2>&1
ok,完活了,脚本每天会按时自动运行。
本机的话,只要不关机,休眠也可以自动运行。
看不懂,牛逼就完事了
看不懂,牛逼就完事了
看不懂,牛逼就完事了
老甲鱼你还有这本事
NB
阅
牛逼
看不懂,牛逼就完事了
看不懂,牛逼就完事了
看不懂,牛逼就完事了
29级的扩建金币写错了
开挂党太强了,不玩了不玩了
大佬