Merge pull request #76 from Limint/main

js 脚本:精确调整游戏时间到分钟 以及 调整大地图缩放
This commit is contained in:
辉鸭蛋
2024-11-08 15:41:36 +08:00
committed by GitHub
6 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
(async function () {
setGameMetrics(1920, 1080, 2);
const stepDuration = 50;
const commonX = 49;
const ZoomInButton = 428;
const ZoomOutButton = 654;
const start = 453;
const end = 628;
async function mouseClickNTimes(x, y,n) {
moveMouseTo(x, y);
await sleep(100);
for (let i =0; i < n; i++) {
leftButtonDown();
await sleep(50);
leftButtonUp();
await sleep(50);
}
await sleep(stepDuration);
}
async function mouseClickAndMove(x1, y1, x2, y2) {
moveMouseTo(x1, y1);
await sleep(50);
leftButtonDown();
await sleep(50);
moveMouseTo(x2, y2);
await sleep(50);
leftButtonUp();
await sleep(stepDuration);
}
async function setMapZoom(n) {
await mouseClickNTimes(commonX, ZoomOutButton, 5);
if (Number.isInteger(n)) {
mouseClickNTimes(commonX, ZoomInButton, 5 - n);
} else {
const targetY = Math.ceil(start + n * 35 - 0.5);
await mouseClickAndMove(commonX, end, commonX, targetY);
}
}
const zoom = Number(settings.zoom);
const n = Math.min(Math.max(zoom, 1),6)- 1;
log.info(`设置大地图缩放为 ${n+1}`);
await keyPress("M");
await sleep(1000);
await setMapZoom(n);
await sleep(1000);
await keyPress("Escape");
await sleep(1000);
})();

View File

@@ -0,0 +1,14 @@
{
"manifest_version": 1,
"name": "设置大地图缩放",
"version": "1.0",
"bgi_version": "0.36.0",
"description": "通过左侧缩放条调整大地图缩放1为最大放大6为最小3.5为中间",
"authors": [
{
"name": "Tim"
}
],
"settings_ui": "settings.json",
"main": "main.js"
}

View File

@@ -0,0 +1,7 @@
[
{
"name": "zoom",
"type": "input-text",
"label": "缩放范围是1~61表示最大放大3.5表示中间"
}
]

View File

@@ -0,0 +1,64 @@
(async function () {
// 设置游戏分辨率和DPI缩放
setGameMetrics(1920, 1080, 1);
// 圆心坐标
const centerX = 1441;
const centerY = 501.6;
// 半径
const r1 = 30;
const r2 = 150;
const r3 = 300;
const stepDuration = 50;
function getPosition(r, index) {
let angle = index * Math.PI / 720;
return [Math.round(centerX + r * Math.cos(angle)), Math.round(centerY + r * Math.sin(angle))];
}
async function mouseClick(x, y) {
moveMouseTo(x, y);
await sleep(50);
leftButtonDown();
await sleep(50);
leftButtonUp();
await sleep(stepDuration);
}
async function mouseClickAndMove(x1, y1, x2, y2) {
moveMouseTo(x1, y1);
await sleep(50);
leftButtonDown();
await sleep(50);
moveMouseTo(x2, y2);
await sleep(50);
leftButtonUp();
await sleep(stepDuration);
}
async function setTime(hour, minute) {
const end = (hour + 6) * 60 + minute-20;
const n = 3;
for (let i = - n + 1; i < 1; i++) {
let [x,y] = getPosition(r1, end + i * 1440 / n);
await mouseClick(x, y);
}
let [x1,y1] = getPosition(r2, end + 5);
let [x2, y2] = getPosition(r3, end + 20 + 0.5);
await mouseClickAndMove(x1, y1, x2, y2);
}
const hour = Number(settings.hour);
const minute = Number(settings.minute);
let h = Math.floor(hour+minute/60);
const m = Math.floor(hour*60+minute)-h*60;
h = ((h % 24) + 24) % 24;
log.info(`设置时间到 ${h}${m}`);
await keyPress("Escape");
await sleep(1000);
await click(50,700);
await sleep(2000);
await setTime(h, m);
await sleep(1000);
await click(1500,1000);//确认
await sleep(18000);
await keyPress("Escape");
await sleep(2000);
await keyPress("Escape");
await sleep(2000);
})();

View File

@@ -0,0 +1,14 @@
{
"manifest_version": 1,
"name": "精确调整游戏时间到分钟",
"version": "1.0",
"bgi_version": "0.36.0",
"description": "用于调整游戏时间,精确到分钟,请在调度器中使用",
"authors": [
{
"name": "Tim"
}
],
"settings_ui": "settings.json",
"main": "main.js"
}

View File

@@ -0,0 +1,12 @@
[
{
"name": "hour",
"type": "input-text",
"label": "输入小时0-24"
},
{
"name": "minute",
"type": "input-text",
"label": "输入分钟0-60"
}
]