原食脚本-抢劫NPC商店食材 (#1369)

基于图像识别购物脚本,可选择所需商品。相较于之前写的购物脚本,节省大量摩拉,节省很多时间。
This commit is contained in:
听雨♪
2025-07-20 10:05:04 +08:00
committed by GitHub
parent d73e03d6fc
commit 2cb362fe4c
38 changed files with 1526 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@@ -0,0 +1,30 @@
{
"info": {
"name": "ds",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 267.9560546875,
"y": -665.14794921875,
"action_params": ""
},
{
"id": 2,
"x": 257.146484375,
"y": -682.4951171875,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,39 @@
{
"info": {
"name": "卯师父",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 267.9580078125,
"y": -665.1201171875,
"action_params": ""
},
{
"id": 2,
"x": 226.04296875,
"y": -660.0048828125,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 227.4072265625,
"y": -668.20751953125,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,75 @@
{
"info": {
"name": "哈马维",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 2786.9755859375,
"y": -503.09130859375,
"action_params": ""
},
{
"id": 2,
"x": 2788.0830078125,
"y": -488.28173828125,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 2771.4755859375,
"y": -476.07421875,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 4,
"x": 2763.0478515625,
"y": -453.83349609375,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 5,
"x": 2760.521484375,
"y": -439.513671875,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 6,
"x": 2778.63671875,
"y": -435.7626953125,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 7,
"x": 2778.24609375,
"y": -430.80810546875,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,121 @@
{
"info": {
"name": "小畑",
"type": "collect",
"author": "听雨♪",
"version": "",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"x": -3812.7041015625,
"y": -2546.6064453125,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "teleport"
},
{
"id": 2,
"x": -3811.9248046875,
"y": -2567.5771484375,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 3,
"x": -3727.125996598583,
"y": -2570.25,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 4,
"x": -3720.250047457075,
"y": -2569.625
},
{
"id": 5,
"x": -3713.6250949141504,
"y": -2568.5
},
{
"id": 6,
"x": -3706.7501423712256,
"y": -2567.875
},
{
"id": 7,
"x": -3700.625284742451,
"y": -2566.875
},
{
"id": 8,
"x": -3693.2480542599114,
"y": -2564.875
},
{
"id": 9,
"x": -3684.874810171699,
"y": -2562.375
},
{
"id": 10,
"x": -3680.4998576287744,
"y": -2561.25
},
{
"id": 11,
"x": -3677.6251423712256,
"y": -2558.125
},
{
"id": 12,
"x": -3675.5,
"y": -2558.25,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 13,
"x": -3674.124952542925,
"y": -2560.125
},
{
"id": 14,
"x": -3672.624952542925,
"y": -2564,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 15,
"x": -3670.2495728863214,
"y": -2567.75
},
{
"id": 16,
"x": -3666.0014237122596,
"y": -2566
},
{
"id": 17,
"x": -3667.37571185613,
"y": -2561.125,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "target"
}
]
}

View File

@@ -0,0 +1,39 @@
{
"info": {
"name": "布兰琪",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": -867.720703125,
"y": 2281.377685546875,
"action_params": ""
},
{
"id": 2,
"x": -893.705078125,
"y": 2258.10791015625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": -895.7216796875,
"y": 2264.712890625,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,57 @@
{
"info": {
"name": "布希柯",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 4508.96875,
"y": 3630.584228515625,
"action_params": ""
},
{
"id": 2,
"x": 4514.79296875,
"y": 3605.441650390625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 4497.20556640625,
"y": 3586.030029296875,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 4,
"x": 4475.7421875,
"y": 3559.308837890625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 5,
"x": 4470.52685546875,
"y": 3560.251708984375,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,30 @@
{
"info": {
"name": "布特罗斯",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 2679.8427734375,
"y": -1935.005859375,
"action_params": ""
},
{
"id": 2,
"x": 2659.951171875,
"y": -1928.943359375,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,39 @@
{
"info": {
"name": "志村勘兵卫",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"x": -4402.5703125,
"y": -3053.0234375,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "teleport"
},
{
"id": 2,
"x": -4418.000213556839,
"y": -3083.5625,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 3,
"x": -4424.500332199528,
"y": -3080.375,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "target"
}
]
}

View File

@@ -0,0 +1,39 @@
{
"info": {
"name": "珀姆",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 2786.958984375,
"y": -503.0859375,
"action_params": ""
},
{
"id": 2,
"x": 2809.5712890625,
"y": -514.7138671875,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 2811.244140625,
"y": -509.603515625,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,102 @@
{
"info": {
"name": "买鱼-1",
"type": "buy",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"x": 263.5,
"y": -672.5,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "teleport"
},
{
"id": 2,
"x": 247.5,
"y": -664.5,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 3,
"x": 214.5,
"y": -661.5,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 4,
"x": 192.5,
"y": -682,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 5,
"x": 162.5,
"y": -681,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 6,
"x": 157.5000949141504,
"y": -630.375,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 7,
"x": 139.99022999999943,
"y": -608.2969000000003,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 8,
"x": 162.32030999999915,
"y": -592.3183600000002,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 9,
"x": 167.29102000000057,
"y": -599.75684,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 10,
"x": 163.2538999999997,
"y": -603.9433600000002,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,93 @@
{
"info": {
"name": "牢高",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"x": 263.5,
"y": -672.5,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "teleport"
},
{
"id": 2,
"x": 247.5,
"y": -664.5,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 3,
"x": 214.5,
"y": -661.5,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 4,
"x": 192.5,
"y": -682,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 5,
"x": 162.5,
"y": -681,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 6,
"x": 157.5000949141504,
"y": -630.375,
"action": "",
"move_mode": "run",
"action_params": "",
"type": "path"
},
{
"id": 7,
"x": 139.99022999999943,
"y": -608.2969000000003,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 8,
"x": 162.32030999999915,
"y": -592.3183600000002,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "path"
},
{
"id": 9,
"x": 158.751953125,
"y": -586.27294921875,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,39 @@
{
"info": {
"name": "莎拉",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": -867.7138671875,
"y": 2281.37646484375,
"action_params": ""
},
{
"id": 2,
"x": -891.755859375,
"y": 2255.769775390625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": -888.6591796875,
"y": 2240.89892578125,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,30 @@
{
"info": {
"name": "葵",
"type": "collect",
"author": "听雨♪",
"version": "1.1",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"x": -4402.5390625,
"y": -3053.0341796875,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "teleport"
},
{
"id": 2,
"x": -4402.687357628773,
"y": -3072.3125,
"action": "",
"move_mode": "walk",
"action_params": "",
"type": "target"
}
]
}

View File

@@ -0,0 +1,66 @@
{
"info": {
"name": "阿扎莱",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 4096.03125,
"y": -2025.9755859375,
"action_params": ""
},
{
"id": 2,
"x": 4085.078125,
"y": -2018.173828125,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 4076.845703125,
"y": -1995.6533203125,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 4,
"x": 4100.158203125,
"y": -1986.6904296875,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 5,
"x": 4100.736328125,
"y": -1979.58837890625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
},
{
"id": 6,
"x": 4091.5751953125,
"y": -1980.16015625,
"type": "path",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,57 @@
{
"info": {
"name": "ale",
"type": "collect",
"author": "听雨♪",
"version": "1.0",
"description": "",
"bgiVersion": "0.35.1"
},
"positions": [
{
"id": 1,
"action": "",
"move_mode": "walk",
"type": "teleport",
"x": 4645.490234375,
"y": 3467.8603515625,
"action_params": ""
},
{
"id": 2,
"x": 4635.865234375,
"y": 3475.1591796875,
"type": "path",
"move_mode": "fly",
"action": "",
"action_params": ""
},
{
"id": 3,
"x": 4639.42724609375,
"y": 3505.39697265625,
"type": "path",
"move_mode": "fly",
"action": "",
"action_params": ""
},
{
"id": 4,
"x": 4622.95654296875,
"y": 3509.7421875,
"type": "path",
"move_mode": "fly",
"action": "stop_flying",
"action_params": ""
},
{
"id": 5,
"x": 4602.0556640625,
"y": 3515.504150390625,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -0,0 +1,540 @@
const npcData = {
"Blanche": {
"name": "布兰琪",
"enable": true,
"page": 2,
"time": "night",
"path": "assets/path/布兰琪.json",
"goods": ["盐", "胡椒", "洋葱", "牛奶", "番茄", "卷心菜", "土豆", "小麦"]
},
"DongSheng": {
"name": "东升",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/东升.json",
"goods": ["洋葱", "牛奶", "卷心菜", "土豆", "小麦", "稻米", "虾仁", "豆腐", "杏仁", "盐", "胡椒", "番茄"]
},
"ChefMao": {
"name": "香菱爹",
"enable": true,
"page": 5,
"time": "any",
"path": "assets/path/卯师父.json",
"goods": ["鱼肉", "螃蟹"]
},
"UncleSun": {
"name": "奸商老孙",
"enable": true,
"page": 1,
"time": "day",
"path": "assets/path/老孙.json",
"goods": ["鱼肉", "螃蟹", "虾仁"]
},
"UncleGao": {
"name": "奸商老高",
"enable": true,
"page": 1,
"time": "day",
"path": "assets/path/老高.json",
"goods": ["鱼肉"]
},
"Aoi": {
"name": "葵",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/葵.json",
"goods": ["洋葱", "牛奶", "卷心菜", "土豆", "稻米", "虾仁", "豆腐", "盐", "胡椒", "番茄"]
},
"ShimuraKanbei": {
"name": "志村勘兵卫",
"enable": true,
"page": 4,
"time": "any",
"path": "assets/path/志村勘兵卫.json",
"goods": ["鱼肉", "螃蟹"]
},
"Butrus": {
"name": "布特罗斯",
"enable": true,
"page": 1,
"time": "any",
"path": "assets/path/布特罗斯.json",
"goods": ["鱼肉", "螃蟹", "虾仁"]
},
"Pam": {
"name": "珀姆",
"enable": true,
"page": 1,
"time": "any",
"path": "assets/path/珀姆.json",
"goods": ["鱼肉", "螃蟹", "虾仁"]
},
"Hamawi": {
"name": "哈马维",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/哈马维.json",
"goods": ["洋葱", "牛奶", "卷心菜", "土豆", "小麦", "稻米", "虾仁", "豆腐", "盐", "胡椒", "番茄"]
},
"Azalai": {
"name": "阿扎莱",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/阿扎莱.json",
"goods": ["鱼肉", "兽肉", "秃秃豆"]
},
"Boucicaut": {
"name": "布希柯",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/布希柯.json",
"goods": ["枫达", "洋葱", "牛奶", "卷心菜", "土豆", "小麦", "秃秃豆", "杏仁", "发酵果实汁", "盐", "胡椒", "番茄"]
},
"Arouet": {
"name": "阿鲁埃",
"enable": true,
"page": 2,
"time": "any",
"path": "assets/path/阿鲁埃.json",
"goods": ["咖啡豆", "枫达"]
}
}
const goodsData = {
"salt": {
"id": "salt",
"name": "盐",
"file": "assets/images/salt.png"
},
"pepper": {
"id": "pepper",
"name": "胡椒",
"file": "assets/images/pepper.png"
},
"onion": {
"id": "onion",
"name": "洋葱",
"file": "assets/images/onion.png"
},
"milk": {
"id": "milk",
"name": "牛奶",
"file": "assets/images/milk.png"
},
"tomato": {
"id": "tomato",
"name": "番茄",
"file": "assets/images/tomato.png"
},
"potato": {
"id": "potato",
"name": "土豆",
"file": "assets/images/potato.png"
},
"wheat": {
"id": "wheat",
"name": "小麦",
"file": "assets/images/wheat.png"
},
"rice": {
"id": "rice",
"name": "稻米",
"file": "assets/images/rice.png"
},
"shrimp": {
"id": "shrimp",
"name": "虾仁",
"file": "assets/images/shrimp.png"
},
"almond": {
"id": "almond",
"name": "杏仁",
"file": "assets/images/almond.png"
},
"cabbage": {
"id": "cabbage",
"name": "卷心菜",
"file": "assets/images/cabbage.png"
},
"tofu": {
"id": "tofu",
"name": "豆腐",
"file": "assets/images/tofu.png"
},
"fish": {
"id": "fish",
"name": "鱼肉",
"file": "assets/images/fish.png"
},
"crab": {
"id": "crab",
"name": "螃蟹",
"file": "assets/images/crab.png"
},
"coffeeBeans": {
"id": "coffeeBeans",
"name": "咖啡豆",
"file": "assets/images/coffeeBeans.png"
},
"glabrousBeans": {
"id": "glabrousBeans",
"name": "秃秃豆",
"file": "assets/images/glabrousBeans.png"
},
"rawMeat": {
"id": "rawMeat",
"name": "兽肉",
"file": "assets/images/rawMeat.png"
},
"fermentedJuice": {
"id": "fermentedJuice",
"name": "发酵果实汁",
"file": "assets/images/fermentedJuice.png"
},
"fonta": {
"id": "fonta",
"name": "枫达",
"file": "assets/images/fonta.png"
}
};
const translationList = {};
const enableGoods = new Set([]);
const othrtRo = {
"buy": {
"name": "购买按钮",
"file": "assets/images/buyBtn.png"
}
}
// 设置游戏时间
async function setTime(hour, minute) {
// 关于setTime
// 原作者: Tim
// 脚本名称: SetTimeMinute - 精确调整游戏时间到分钟
// 脚本版本: 1.0
// Hash: f5c2547dfc286fc643c733d630f775e8fbf12971
// 设置游戏分辨率和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);
}
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);
}
// 地图追踪
async function autoPath(locationPath) {
try {
let filePath = locationPath;
await pathingScript.runFile(filePath);
sleep(2000);
return true;
} catch (error) {
log.error(`执行 ${locationName} 路径时发生错误`);
log.error(error.message);
}
return false;
}
// 平滑过渡函数(缓动效果)
function smoothStep(t) {
return t * t * (3 - 2 * t);
}
// 模拟鼠标移动到指定位置(带曲线路径)
async function naturalMove(initX, initY, targetX, targetY, duration, wiggle = 30) {
// 生成控制点(使路径形成曲线)
const controlX = (initX + targetX) / 2 + (Math.random() * wiggle * 2 - wiggle);
const controlY = (initY + targetY) / 2 + (Math.random() * wiggle * 2 - wiggle);
const steps = Math.max(duration / 20, 10); // 计算步数
for (let i = 0; i <= steps; i++) {
const progress = i / steps;
const t = smoothStep(progress); // 使用平滑过渡
// 二次贝塞尔曲线计算
const x = (1 - t) * (1 - t) * initX + 2 * (1 - t) * t * controlX + t * t * targetX;
const y = (1 - t) * (1 - t) * initY + 2 * (1 - t) * t * controlY + t * t * targetY;
moveMouseTo(Math.trunc(x), Math.trunc(y));
// 随机延迟使移动更自然
await sleep(Math.trunc(duration / steps * (0.8 + Math.random() * 0.4)));
}
// 确保最终位置准确
moveMouseTo(targetX, targetY);
}
// 切换下一页商品
async function nextGoodsPage() {
//设置脚本环境的游戏分辨率和DPI缩放
setGameMetrics(3840, 2160, 1.5);
let [initX, initY] = [1500, 1850];
let [targetX, targetY] = [1800, 260];
moveMouseTo(initX, initY);
leftButtonDown();
await naturalMove(initX, initY, targetX, targetY, 300);
// 按住了, 防止弹太远
await sleep(520);
leftButtonUp();
}
// 快速购买
async function qucikBuy() {
//设置脚本环境的游戏分辨率和DPI缩放
setGameMetrics(3840, 2160, 1.5);
let [buyBtnX, buyBtnY] = [3200, 2045];
let [confirmBtnX, confirmBtnY] = [2025, 1570];
let [addNumX, addNumY] = [2060, 1208];
// 等待界面切换
await sleep(200);
// 查找购买按钮
let captureRegion = captureGameRegion();
let buyBtn = captureRegion.Find(othrtRo.buy.ro);
if (buyBtn.isEmpty()) {
return false;
}
// 点击购买按钮
click(buyBtn.x * 2 + buyBtn.width, buyBtn.y * 2 + buyBtn.height);
// 等待购买窗口弹出
await sleep(300);
// 增加数量至最大
leftButtonDown();
await naturalMove(addNumX, addNumY, addNumX + 666, addNumY - 233, 100);
leftButtonUp();
// 点击确认按钮
click(confirmBtnX, confirmBtnY);
// 等待购买完成
await sleep(200);
// 点击空白关闭
click(buyBtnX, buyBtnY);
await sleep(200);
return true;
}
// 跳过对话
async function spikChat(count = 5) {
await sleep(100);
for (let i = 0; i < count; i++) {
keyPress("VK_F");
await sleep(1300);
}
await sleep(1000);
}
// 购买逻辑
async function buyGoods(npcName) {
// 设置脚本环境的游戏分辨率和DPI缩放
setGameMetrics(3840, 2160, 1.5);
let tempGoods = [...npcData[npcName].enableGoods];
// 多页购买
for (let i = 0; i < npcData[npcName].page; i++) {
log.info("购买列表: {goods}", [...tempGoods].join(", "));
// 获取一张截图
let captureRegion = captureGameRegion();
// 记录已经购买的物品
let boughtGoods = new Set([]);
// 匹配商品
for (let item of tempGoods) {
let resList = captureRegion.FindMulti(goodsData[item].ro);
for (let res of resList) {
log.info("找到物品: {i} 位置({x},{y},{h},{w})", goodsData[item].name, res.x, res.y, res.width, res.height);
// 移除已购买的物品
boughtGoods.add(item);
// 点击商品
click(res.x * 2 + res.width, res.y * 2 + res.height);
if (await qucikBuy()) {
log.info("购买成功: {item}", goodsData[item].name);
await sleep(500);
// 重新截图
captureRegion = captureGameRegion();
}
else {
log.info("购买失败: {item}, 背包已经满或商品已售罄", goodsData[item].name);
}
}
}
// 从已购买物品中移除
tempGoods = tempGoods.filter(item => !boughtGoods.has(item));
// 若不是最后一页且还有未购买的物品
if (tempGoods.length > 0 && i !== npcData[npcName].page - 1) {
log.info("切换到下一页商品");
await nextGoodsPage();
// 最后一次切换界面, 等待UI回弹
if (i === npcData[npcName].page - 2) {
log.info("等待界面回弹");
await sleep(500);
}
}
}
}
// 初始化NPC商品
async function initNpcData() {
for (let [key, npc] of Object.entries(npcData)) {
// 翻译物品名称
let npcGoods = new Set([]);
Object.entries(npc.goods).forEach(([count, item]) => {
npcGoods.add(translationList[item]);
});
// 筛选已启用的商品
npc.enableGoods = [...enableGoods].filter(item => npcGoods.has(item));
// 如果没有启用的商品, 则不启用该NPC
if (npc.enableGoods.length === 0) {
npc.enable = false;
}
}
}
// 加载识别对象
async function initRo() {
try {
// 加载识别对象
for (let [key, item] of Object.entries(goodsData)) {
// 填充中英文对照表
translationList[item.name] = item.id;
// 判断启动商品、加载识别对象
if (settings[item.id]) {
enableGoods.add(item.id);
item.ro = RecognitionObject.TemplateMatch(file.ReadImageMatSync(item.file));
item.ro.Threshold = 0.75;
item.ro.Use3Channels = true;
}
}
// 加载其他识别对象
for (let [key, item] of Object.entries(othrtRo)) {
item.ro = RecognitionObject.TemplateMatch(file.ReadImageMatSync(item.file));
item.ro.Threshold = 0.85;
}
return true;
}
catch (error) {
log.error("加载识别对象时发生错误: {error}", error.message);
throw error;
}
}
(async function () {
// ==================== 初始化识别对象 ====================
await initRo();
log.info("识别对象初始化完成");
// ==================== 初始化NPC数据 ====================
await initNpcData();
log.info("NPC数据初始化完成");
// ==================== 自动购买 ====================
for (let [key, npc] of Object.entries(npcData)) {
if (npc.enable) {
log.info("开始购买NPC: {npcName}", npc.name);
// 设置游戏时间
if (npc.time === "night") {
await setTime(20, 0); // 设置为晚上8点
}
else if (npc.time === "day") {
await setTime(8, 0); // 设置为早上8点
}
await autoPath(npc.path);
await spikChat();
await buyGoods(key);
// 返回主界面
await genshin.returnMainUi();
log.info("完成购买NPC: {npcName}", npc.name);
}
else {
log.info("跳过未启用的NPC: {npcName}", npc.name);
}
}
})();

View File

@@ -0,0 +1,14 @@
{
"manifest_version": 1,
"name": "抢劫(购买)NPC商品-图像识别",
"version": "2.0.0",
"description": "原食脚本: 基于图像识别的抢劫NPC商品, 可选择性购买商品, 节省大量摩拉与时间.",
"authors": [
{
"name": "听雨♪",
"link": "https://github.com/TingYu-lulumi"
}
],
"settings_ui": "settings.json",
"main": "main.js"
}

View File

@@ -0,0 +1,116 @@
[
{
"name": "salt",
"type": "checkbox",
"label": "盐",
"default": true
},
{
"name": "pepper",
"type": "checkbox",
"label": "胡椒",
"default": true
},
{
"name": "onion",
"type": "checkbox",
"label": "洋葱",
"default": true
},
{
"name": "milk",
"type": "checkbox",
"label": "牛奶",
"default": true
},
{
"name": "tomato",
"type": "checkbox",
"label": "番茄",
"default": true
},
{
"name": "potato",
"type": "checkbox",
"label": "土豆",
"default": true
},
{
"name": "wheat",
"type": "checkbox",
"label": "小麦",
"default": true
},
{
"name": "rice",
"type": "checkbox",
"label": "稻米",
"default": true
},
{
"name": "shrimp",
"type": "checkbox",
"label": "虾仁",
"default": true
},
{
"name": "almond",
"type": "checkbox",
"label": "杏仁",
"default": true
},
{
"name": "cabbage",
"type": "checkbox",
"label": "卷心菜",
"default": true
},
{
"name": "tofu",
"type": "checkbox",
"label": "豆腐",
"default": true
},
{
"name": "fish",
"type": "checkbox",
"label": "鱼肉",
"default": true
},
{
"name": "crab",
"type": "checkbox",
"label": "螃蟹",
"default": true
},
{
"name": "coffeeBeans",
"type": "checkbox",
"label": "咖啡豆",
"default": true
},
{
"name": "glabrousBeans",
"type": "checkbox",
"label": "秃秃豆",
"default": true
},
{
"name": "rawMeat",
"type": "checkbox",
"label": "兽肉",
"default": true
},
{
"name": "fermentedJuice",
"type": "checkbox",
"label": "发酵果实汁",
"default": true
},
{
"name": "fonta",
"type": "checkbox",
"label": "苏乐达(枫达)",
"default": true
}
]