koishi-plugin-tmp-bot 1.3.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/truckersMpMapApi.js +26 -0
- package/lib/command/tmpPosition.js +18 -2
- package/lib/command/tmpQuery.js +3 -1
- package/lib/index.js +1 -0
- package/lib/resource/position.html +83 -45
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const BASE_API = 'https://tracker.ets2map.com'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
/**
|
|
5
|
+
* 区域查询玩家
|
|
6
|
+
*/
|
|
7
|
+
async area (http, serverId, x1, y1, x2, y2) {
|
|
8
|
+
let result = null
|
|
9
|
+
try {
|
|
10
|
+
result = await http.get(`${BASE_API}/v3/area?x1=${x1}&y1=${y1}&x2=${x2}&y2=${y2}&server=${serverId}`)
|
|
11
|
+
} catch {
|
|
12
|
+
return {
|
|
13
|
+
error: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 拼接返回数据
|
|
18
|
+
let data = {
|
|
19
|
+
error: !result || !result.Success
|
|
20
|
+
}
|
|
21
|
+
if (!data.error) {
|
|
22
|
+
data.data = result.Data
|
|
23
|
+
}
|
|
24
|
+
return data
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -3,6 +3,7 @@ const { resolve } = require('path')
|
|
|
3
3
|
const guildBind = require('../database/guildBind')
|
|
4
4
|
const truckyAppApi = require('../api/truckyAppApi')
|
|
5
5
|
const truckersMpApi = require('../api/truckersMpApi')
|
|
6
|
+
const truckersMpMapApi = require('../api/truckersMpMapApi')
|
|
6
7
|
const baiduTranslate = require('../util/baiduTranslate')
|
|
7
8
|
const common = require('../util/common')
|
|
8
9
|
|
|
@@ -10,6 +11,7 @@ const common = require('../util/common')
|
|
|
10
11
|
* 定位
|
|
11
12
|
*/
|
|
12
13
|
module.exports = async (ctx, cfg, session, tmpId) => {
|
|
14
|
+
// 5265655
|
|
13
15
|
if (ctx.puppeteer) {
|
|
14
16
|
if (tmpId && isNaN(tmpId)) {
|
|
15
17
|
return `请输入正确的玩家编号`
|
|
@@ -39,14 +41,28 @@ module.exports = async (ctx, cfg, session, tmpId) => {
|
|
|
39
41
|
return '玩家离线'
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
// 查询周边玩家
|
|
45
|
+
let areaPlayersData = await truckersMpMapApi.area(ctx.http, playerMapInfo.data.server,
|
|
46
|
+
playerMapInfo.data.x - 4000,
|
|
47
|
+
playerMapInfo.data.y + 2500,
|
|
48
|
+
playerMapInfo.data.x + 4000,
|
|
49
|
+
playerMapInfo.data.y - 2500)
|
|
50
|
+
|
|
51
|
+
// promods服ID集合
|
|
52
|
+
let promodsServerIdList = [50, 51]
|
|
53
|
+
|
|
54
|
+
// 构建地图数据
|
|
42
55
|
let data = {
|
|
56
|
+
mapType: promodsServerIdList.indexOf(playerMapInfo.data.server) !== -1 ? 'promods' : 'ets',
|
|
43
57
|
avatar: playerInfo.data.smallAvatar,
|
|
44
58
|
username: playerInfo.data.name,
|
|
45
59
|
serverName: playerMapInfo.data.serverDetails.name,
|
|
46
60
|
country: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
|
|
47
61
|
realName: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName),
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
currentPlayerId: tmpId,
|
|
63
|
+
centerX: playerMapInfo.data.x,
|
|
64
|
+
centerY: playerMapInfo.data.y,
|
|
65
|
+
playerList: areaPlayersData.data
|
|
50
66
|
}
|
|
51
67
|
|
|
52
68
|
let page
|
package/lib/command/tmpQuery.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const tmpServer = require('./command/tmpServer');
|
|
|
8
8
|
const tmpBind = require('./command/tmpBind');
|
|
9
9
|
const tmpTraffic = require('./command/tmpTraffic');
|
|
10
10
|
const tmpPosition = require('./command/tmpPosition');
|
|
11
|
+
const api = require('./api/truckersMpMapApi');
|
|
11
12
|
exports.name = 'tmp-bot';
|
|
12
13
|
exports.inject = {
|
|
13
14
|
required: ['database'],
|
|
@@ -113,25 +113,61 @@
|
|
|
113
113
|
</div>
|
|
114
114
|
</div>
|
|
115
115
|
<script>
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
let mapConfig = {
|
|
117
|
+
ets: {
|
|
118
|
+
tileUrl: 'https://ets-map.oss-cn-beijing.aliyuncs.com/ets2/05102019/{z}/{x}/{y}.png',
|
|
119
|
+
multipliers: {
|
|
120
|
+
x: 71292,
|
|
121
|
+
y: 60412
|
|
122
|
+
},
|
|
123
|
+
breakpoints: {
|
|
124
|
+
uk: {
|
|
125
|
+
x: -31056.8,
|
|
126
|
+
y: -5832.867
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
bounds: {
|
|
130
|
+
y: 131072,
|
|
131
|
+
x: 131072
|
|
132
|
+
},
|
|
133
|
+
maxZoom: 8,
|
|
134
|
+
minZoom: 2,
|
|
135
|
+
// 游戏地转地图坐标
|
|
136
|
+
calculateMapCoordinate (x, y) {
|
|
137
|
+
return [
|
|
138
|
+
x / 1.325928 + mapConfig.ets.multipliers.x,
|
|
139
|
+
y / 1.325928 + mapConfig.ets.multipliers.y
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
promods: {
|
|
144
|
+
tileUrl: 'https://tiles.truckyapp.com/promods/05102019/{z}/{x}/{y}.png',
|
|
145
|
+
multipliers: {
|
|
146
|
+
x: 41828,
|
|
147
|
+
y: 77369
|
|
148
|
+
},
|
|
149
|
+
breakpoints: {
|
|
150
|
+
uk: {
|
|
151
|
+
x: -31056.8,
|
|
152
|
+
y: -5832.867
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
bounds: {
|
|
156
|
+
y: 131072,
|
|
157
|
+
x: 131072
|
|
158
|
+
},
|
|
159
|
+
maxZoom: 8,
|
|
160
|
+
minZoom: 2,
|
|
161
|
+
// 游戏地转地图坐标
|
|
162
|
+
calculateMapCoordinate (x, y) {
|
|
163
|
+
return [
|
|
164
|
+
x / 2.303589 + mapConfig.promods.multipliers.x,
|
|
165
|
+
y / 2.303589 + mapConfig.promods.multipliers.y
|
|
166
|
+
]
|
|
167
|
+
}
|
|
124
168
|
}
|
|
125
169
|
}
|
|
126
170
|
|
|
127
|
-
// 游戏地转地图坐标
|
|
128
|
-
function calculateMapCoordinate(x, y) {
|
|
129
|
-
return [
|
|
130
|
-
x / 1.325928 + multipliers.x,
|
|
131
|
-
y / 1.325928 + multipliers.y
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
171
|
// 定义地图
|
|
136
172
|
let map = L.map('map', {
|
|
137
173
|
attributionControl: false,
|
|
@@ -139,45 +175,47 @@
|
|
|
139
175
|
zoomControl: false
|
|
140
176
|
});
|
|
141
177
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
178
|
+
function setData(data) {
|
|
179
|
+
// 边界
|
|
180
|
+
let bounds = L.latLngBounds(
|
|
181
|
+
map.unproject([0, mapConfig[data.mapType].bounds.y], mapConfig[data.mapType].maxZoom),
|
|
182
|
+
map.unproject([mapConfig[data.mapType].bounds.x, 0], mapConfig[data.mapType].maxZoom)
|
|
183
|
+
);
|
|
147
184
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
185
|
+
// 瓦片地图
|
|
186
|
+
L.tileLayer(mapConfig[data.mapType].tileUrl, {
|
|
187
|
+
minZoom: 2,
|
|
188
|
+
maxZoom: 10,
|
|
189
|
+
maxNativeZoom: 8,
|
|
190
|
+
tileSize: 512,
|
|
191
|
+
bounds: bounds,
|
|
192
|
+
reuseTiles: true
|
|
193
|
+
}).addTo(map);
|
|
194
|
+
map.setMaxBounds(
|
|
195
|
+
new L.LatLngBounds(
|
|
196
|
+
map.unproject([0, mapConfig[data.mapType].bounds.y], mapConfig[data.mapType].maxZoom),
|
|
197
|
+
map.unproject([mapConfig[data.mapType].bounds.x, 0], mapConfig[data.mapType].maxZoom)
|
|
198
|
+
)
|
|
199
|
+
);
|
|
163
200
|
|
|
164
|
-
function setData(data) {
|
|
165
201
|
document.getElementsByClassName('avatar')[0].src = data.avatar
|
|
166
202
|
document.getElementsByClassName('username')[0].innerText = data.username
|
|
167
203
|
document.getElementsByClassName('server-name')[0].innerText = data.serverName
|
|
168
204
|
document.getElementsByClassName('country')[0].innerText = data.country
|
|
169
205
|
document.getElementsByClassName('real-name')[0].innerText = data.realName
|
|
170
206
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
207
|
+
for (let player of data.playerList) {
|
|
208
|
+
L.circleMarker(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(player.X, player.Y), 8), {
|
|
209
|
+
color: '#2f2f2f', // 标记点边框颜色
|
|
210
|
+
weight: 2, // 标记点边框大小
|
|
211
|
+
fillColor: '#158cfb', // 标记点填充颜色
|
|
212
|
+
fillOpacity: data.currentPlayerId === player.MpId.toString() ? 1 : 0.6, // 标记点填充不透明度(0到1之间的值)
|
|
213
|
+
radius: data.currentPlayerId === player.MpId.toString() ? 6 : 4 // 标记点半径(以像素为单位)
|
|
214
|
+
}).addTo(map);
|
|
215
|
+
}
|
|
178
216
|
|
|
179
217
|
// 移动地图到坐标,视角稍微向上移动
|
|
180
|
-
map.setView(map.unproject(calculateMapCoordinate(data.
|
|
218
|
+
map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.centerX, data.centerY + 80), 8), 7);
|
|
181
219
|
}
|
|
182
220
|
</script>
|
|
183
221
|
</body>
|