koishi-plugin-tmp-bot 1.3.3 → 1.4.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.
@@ -4,6 +4,7 @@ const guildBind = require('../database/guildBind')
4
4
  const truckyAppApi = require('../api/truckyAppApi')
5
5
  const truckersMpApi = require('../api/truckersMpApi')
6
6
  const baiduTranslate = require('../util/baiduTranslate')
7
+ const common = require('../util/common')
7
8
 
8
9
  /**
9
10
  * 定位
@@ -38,7 +39,12 @@ module.exports = async (ctx, cfg, session, tmpId) => {
38
39
  return '玩家离线'
39
40
  }
40
41
 
42
+ // promods服ID集合
43
+ let promodsServerIdList = [50, 51]
44
+
45
+ // 构建地图数据
41
46
  let data = {
47
+ mapType: promodsServerIdList.indexOf(playerMapInfo.data.server) !== -1 ? 'promods' : 'ets',
42
48
  avatar: playerInfo.data.smallAvatar,
43
49
  username: playerInfo.data.name,
44
50
  serverName: playerMapInfo.data.serverDetails.name,
@@ -54,6 +60,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
54
60
  await page.setViewport({ width: 1000, height: 1000 })
55
61
  await page.goto(`file:///${resolve(__dirname, '../resource/position.html')}`)
56
62
  await page.evaluate(`setData(${JSON.stringify(data)})`)
63
+ await common.sleep(100)
57
64
  await page.waitForNetworkIdle()
58
65
  const element = await page.$("#container");
59
66
  return (
@@ -11,7 +11,9 @@ const userGroup = {
11
11
  'Player': '玩家',
12
12
  'Retired Legend': '退役',
13
13
  'Game Developer': '游戏开发者',
14
- 'Retired Team Member': '退休团队成员'
14
+ 'Retired Team Member': '退休团队成员',
15
+ 'Add-On Team': 'Add-On Team',
16
+ 'Game Moderator': 'Game Moderator'
15
17
  }
16
18
 
17
19
  /**
@@ -113,25 +113,61 @@
113
113
  </div>
114
114
  </div>
115
115
  <script>
116
- let multipliers = {
117
- x: 71292,
118
- y: 60412
119
- }
120
- let breakpoints = {
121
- uk: {
122
- x: -31056.8,
123
- y: -5832.867
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,45 @@
139
175
  zoomControl: false
140
176
  });
141
177
 
142
- // 边界
143
- let bounds = L.latLngBounds(
144
- map.unproject([0, 131072], 2),
145
- map.unproject([131072, 0], 2)
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
- L.tileLayer("https://ets-map.oss-cn-beijing.aliyuncs.com/ets2/05102019/{z}/{x}/{y}.png", {
150
- minZoom: 2,
151
- maxZoom: 10,
152
- maxNativeZoom: 8,
153
- tileSize: 512,
154
- bounds: bounds,
155
- reuseTiles: true
156
- }).addTo(map);
157
- map.setMaxBounds(
158
- new L.LatLngBounds(
159
- map.unproject([0, 131072], 8),
160
- map.unproject([131072, 0], 8)
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
- let mapCoordinate = map.unproject(calculateMapCoordinate(data.x, data.y), 8)
172
- L.circleMarker(mapCoordinate, {
173
- color: '#3e9edc', // 标记点边框颜色
174
- fillColor: '#3e9edc', // 标记点填充颜色
175
- fillOpacity: 1, // 标记点填充不透明度(0到1之间的值)
176
- radius: 6 // 标记点半径(以像素为单位)
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 // 标记点半径(以像素为单位)
177
213
  }).addTo(map);
178
214
 
179
- // 移动地图到坐标
180
- map.setView(mapCoordinate, 7);
215
+ // 移动地图到坐标,视角稍微向上移动
216
+ map.setView(map.unproject(mapConfig[data.mapType].calculateMapCoordinate(data.x, data.y + 80), 8), 7);
181
217
  }
182
218
  </script>
183
219
  </body>
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ sleep (ms) {
3
+ return new Promise(resolve => setTimeout(resolve, ms));
4
+ }
5
+ }
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.3.3",
4
+ "version": "1.4.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [