koishi-plugin-tmp-bot 1.4.0 → 1.6.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
 
@@ -39,6 +40,28 @@ module.exports = async (ctx, cfg, session, tmpId) => {
39
40
  return '玩家离线'
40
41
  }
41
42
 
43
+ // 查询周边玩家,并处理数据
44
+ let areaPlayersData = await truckersMpMapApi.area(ctx.http, playerMapInfo.data.server,
45
+ playerMapInfo.data.x - 4000,
46
+ playerMapInfo.data.y + 2500,
47
+ playerMapInfo.data.x + 4000,
48
+ playerMapInfo.data.y - 2500)
49
+ let areaPlayerList = []
50
+ if (!areaPlayersData.error) {
51
+ areaPlayerList = areaPlayersData.data
52
+ let index = areaPlayerList.findIndex((player) => {
53
+ return player.MpId.toString() === tmpId
54
+ })
55
+ if (index !== -1) {
56
+ areaPlayerList.splice(index, 1)
57
+ }
58
+ }
59
+ areaPlayerList.push({
60
+ X: playerMapInfo.data.x,
61
+ Y: playerMapInfo.data.y,
62
+ MpId: tmpId
63
+ })
64
+
42
65
  // promods服ID集合
43
66
  let promodsServerIdList = [50, 51]
44
67
 
@@ -50,8 +73,10 @@ module.exports = async (ctx, cfg, session, tmpId) => {
50
73
  serverName: playerMapInfo.data.serverDetails.name,
51
74
  country: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
52
75
  realName: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName),
53
- x: playerMapInfo.data.x,
54
- y: playerMapInfo.data.y
76
+ currentPlayerId: tmpId,
77
+ centerX: playerMapInfo.data.x,
78
+ centerY: playerMapInfo.data.y,
79
+ playerList: areaPlayerList
55
80
  }
56
81
 
57
82
  let page
@@ -204,16 +204,19 @@
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: data.currentPlayerId === player.MpId.toString() ? '#1cb715' : '#158cfb', // 标记点填充颜色
212
+ fillOpacity: 1, // 标记点填充不透明度(0到1之间的值)
213
+ radius: 5, // 标记点半径(以像素为单位)
214
+ zIndex: data.currentPlayerId === player.MpId.toString() ? 1000 : undefined
215
+ }).addTo(map);
216
+ }
214
217
 
215
218
  // 移动地图到坐标,视角稍微向上移动
216
- map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.x, data.y + 80), 8), 7);
219
+ map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.centerX, data.centerY + 80), 8), 7);
217
220
  }
218
221
  </script>
219
222
  </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.6.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [