koishi-plugin-tmp-bot 1.4.0 → 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.
@@ -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,6 +41,13 @@ 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
+
42
51
  // promods服ID集合
43
52
  let promodsServerIdList = [50, 51]
44
53
 
@@ -50,8 +59,10 @@ module.exports = async (ctx, cfg, session, tmpId) => {
50
59
  serverName: playerMapInfo.data.serverDetails.name,
51
60
  country: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
52
61
  realName: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName),
53
- x: playerMapInfo.data.x,
54
- y: playerMapInfo.data.y
62
+ currentPlayerId: tmpId,
63
+ centerX: playerMapInfo.data.x,
64
+ centerY: playerMapInfo.data.y,
65
+ playerList: areaPlayersData.data
55
66
  }
56
67
 
57
68
  let page
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'],
@@ -204,16 +204,18 @@
204
204
  document.getElementsByClassName('country')[0].innerText = data.country
205
205
  document.getElementsByClassName('real-name')[0].innerText = data.realName
206
206
 
207
- L.circleMarker(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.x, data.y), 8), {
208
- color: '#2f2f2f', // 标记点边框颜色
209
- weight: 2, // 标记点边框大小
210
- fillColor: '#158cfb', // 标记点填充颜色
211
- fillOpacity: 1, // 标记点填充不透明度(0到1之间的值)
212
- radius: 6 // 标记点半径(以像素为单位)
213
- }).addTo(map);
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
+ }
214
216
 
215
217
  // 移动地图到坐标,视角稍微向上移动
216
- map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.x, data.y + 80), 8), 7);
218
+ map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.centerX, data.centerY + 80), 8), 7);
217
219
  }
218
220
  </script>
219
221
  </body>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-tmp-bot",
3
3
  "description": "欧洲卡车模拟2 TMP查询机器人",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [