koishi-plugin-ets2-tools-tmp 3.4.0 → 3.4.2

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.
@@ -46,11 +46,13 @@ module.exports = {
46
46
  },
47
47
  /**
48
48
  * 查询在线玩家
49
+ * @param game 可选,2=美卡(接口不传默认欧卡)
49
50
  */
50
- async mapPlayerList(http, serverId, ax, ay, bx, by) {
51
+ async mapPlayerList(http, serverId, ax, ay, bx, by, game) {
51
52
  let result = null
52
53
  try {
53
- result = await requestWithFallback(http, `/map/playerList?aAxisX=${ax}&aAxisY=${ay}&bAxisX=${bx}&bAxisY=${by}&serverId=${serverId}`)
54
+ const gameParam = game ? `&game=${game}` : ''
55
+ result = await requestWithFallback(http, `/map/playerList?aAxisX=${ax}&aAxisY=${ay}&bAxisX=${bx}&bAxisY=${by}&serverId=${serverId}${gameParam}`)
54
56
  } catch {
55
57
  return {
56
58
  error: true
@@ -6,6 +6,7 @@ const truckyAppApi = require('../api/truckyAppApi')
6
6
  const truckersMpApi = require('../api/truckersMpApi')
7
7
  const evmOpenApi = require('../api/evmOpenApi')
8
8
  const baiduTranslate = require('../util/baiduTranslate')
9
+ const { AtsIds } = require('../util/constant')
9
10
  const common = require('../util/common')
10
11
 
11
12
  /**
@@ -69,12 +70,15 @@ module.exports = async (ctx, cfg, session, tmpId) => {
69
70
  return '玩家离线'
70
71
  }
71
72
 
72
- // 查询周边玩家,并处理数据
73
+ // 查询周边玩家,并处理数据(美卡需显式传 game=2,接口不传默认欧卡)
74
+ const atsServerIdList = AtsIds
75
+ const isAts = atsServerIdList.indexOf(playerMapInfo.data.server) !== -1
73
76
  let areaPlayersData = await evmOpenApi.mapPlayerList(ctx.http, playerMapInfo.data.server,
74
77
  playerMapInfo.data.x - 4000,
75
78
  playerMapInfo.data.y + 2500,
76
79
  playerMapInfo.data.x + 4000,
77
- playerMapInfo.data.y - 2500)
80
+ playerMapInfo.data.y - 2500,
81
+ isAts ? 2 : undefined)
78
82
  let areaPlayerList = []
79
83
  if (!areaPlayersData.error) {
80
84
  areaPlayerList = areaPlayersData.data
@@ -94,9 +98,9 @@ module.exports = async (ctx, cfg, session, tmpId) => {
94
98
  // promods服ID集合
95
99
  let promodsServerIdList = [50, 51]
96
100
 
97
- // 构建地图数据
101
+ // 构建地图数据(在线的美卡服务器 → 用美卡地图)
98
102
  let data = {
99
- mapType: promodsServerIdList.indexOf(playerMapInfo.data.server) !== -1 ? 'promods' : 'ets',
103
+ mapType: isAts ? 'ats' : (promodsServerIdList.indexOf(playerMapInfo.data.server) !== -1 ? 'promods' : 'ets'),
100
104
  avatar: playerInfo.data.smallAvatar,
101
105
  username: playerInfo.data.name,
102
106
  serverName: playerMapInfo.data.serverDetails.name,
@@ -3,6 +3,7 @@ const dayjsRelativeTime = require('dayjs/plugin/relativeTime');
3
3
  const dayjsLocaleZhCn = require('dayjs/locale/zh-cn');
4
4
  const guildBind = require('../../database/guildBind');
5
5
  const tmpIdPicker = require('../../util/tmpIdPicker');
6
+ const { AtsIds } = require('../../util/constant');
6
7
  const truckyAppApi = require('../../api/truckyAppApi');
7
8
  const evmOpenApi = require('../../api/evmOpenApi');
8
9
  const baiduTranslate = require('../../util/baiduTranslate');
@@ -211,7 +212,10 @@ module.exports = async (ctx, cfg, session, tmpId) => {
211
212
  data.onlineCity = onlineCity;
212
213
  data.onlineX = playerMapInfo.data.x;
213
214
  data.onlineY = playerMapInfo.data.y;
214
- data.onlineMapType = playerMapInfo.data.serverDetails.id === 50 ? 'promods' : 'ets';
215
+ // 美卡服务器(8/10/45)用美卡地图,Promods 用 Promods 地图,其余用欧卡地图
216
+ data.onlineMapType = playerMapInfo.data.serverDetails.id === 50
217
+ ? 'promods'
218
+ : (AtsIds.indexOf(playerMapInfo.data.serverDetails.id) !== -1 ? 'ats' : 'ets');
215
219
  } else if (playerInfo.data.lastOnlineTime) {
216
220
  data.lastOnlineTime = dayjs(playerInfo.data.lastOnlineTime).fromNow(false);
217
221
  }
@@ -1,9 +1,31 @@
1
+ const evmOpenApi = require('../api/evmOpenApi');
1
2
  /**
2
3
  * TMP ID 绑定(支持一人绑定多个)
3
4
  * 表 tmp_guild_bind:一个绑定一行,同一 (platform, user_id) 可有多行;
4
5
  * get() 返回第一行(默认绑定),保持与旧版行为兼容。
5
6
  */
6
7
  module.exports = {
8
+ /**
9
+ * 补全缺失的玩家名(旧版本绑定的数据没有 tmp_name):查接口并写回数据库。
10
+ * 并发补查,单个失败保持未知(下次遇到再补)。
11
+ * @returns 原数组(行对象已被就地更新)
12
+ */
13
+ async ensureNames(ctx, rows) {
14
+ const missing = (rows || []).filter(r => !r.tmp_name);
15
+ if (missing.length === 0) {
16
+ return rows;
17
+ }
18
+ await Promise.all(missing.map(async (row) => {
19
+ try {
20
+ const info = await evmOpenApi.playerInfo(ctx.http, row.tmp_id);
21
+ if (!info.error && info.data && info.data.name) {
22
+ row.tmp_name = info.data.name;
23
+ await ctx.database.set('tmp_guild_bind', row.id, { tmp_name: info.data.name });
24
+ }
25
+ } catch { } // 查询失败保持未知,下次遇到再补
26
+ }));
27
+ return rows;
28
+ },
7
29
  /**
8
30
  * 获取默认绑定(第一行,兼容旧逻辑)
9
31
  * @param db 数据源
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ exports.apply = apply;
5
5
 
6
6
  const koishi_1 = require("koishi");
7
7
  const model = require('./database/model');
8
+ const guildBind = require('./database/guildBind');
8
9
  const { ServerType } = require('./util/constant');
9
10
  const { MileageRankingType } = require('./util/constant');
10
11
  const { LeadRoleCallMessage, LeadRoleCallTime } = require('./util/constant');
@@ -269,6 +270,8 @@ function registerBaseCommands(ctx, cfg) {
269
270
  if (bindings.length === 0) {
270
271
  return '还没有绑定编号,使用「绑定 tmpId」添加';
271
272
  }
273
+ // 旧绑定缺名字的先补查并写回
274
+ await guildBind.ensureNames(ctx, bindings);
272
275
  const lines = bindings.map((b, i) => `${i + 1}. ${b.tmp_name || '未知'} (${b.tmp_id})`);
273
276
  return `已绑定 ${bindings.length} 个编号:\n${lines.join('\n')}${bindings.length > 1 ? '\n查询时会列出序号供选择;使用「解绑 序号」可删除' : ''}`;
274
277
  });
@@ -282,6 +285,7 @@ function registerBaseCommands(ctx, cfg) {
282
285
  if (bindings.length === 0) {
283
286
  return '还没有绑定编号';
284
287
  }
288
+ await guildBind.ensureNames(ctx, bindings);
285
289
  if (!index) {
286
290
  return '请输入要解绑的序号或 all(序号见「我的绑定」)';
287
291
  }
@@ -51,13 +51,13 @@ let mapConfig = {
51
51
  ]
52
52
  }
53
53
  },
54
- // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json
55
- // (游戏坐标 x∈[-120098.891, 41144.094] y∈[-79127.37, 82115.62] 线性铺满 131072 网格)
54
+ // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json(tmp-ats-promods)
55
+ // (游戏坐标 x∈[-120835.742, 41880.945] y∈[-87127.17, 75589.516] 线性铺满 131072 网格)
56
56
  ats: {
57
- tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-yellow/Tiles/{z}/{x}/{y}.png',
57
+ tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-promods-yellow/Tiles/{z}/{x}/{y}.png',
58
58
  multipliers: {
59
- x: 97626.58,
60
- y: 64321.45
59
+ x: 97335.94,
60
+ y: 70182.92
61
61
  },
62
62
  breakpoints: {},
63
63
  bounds: {
@@ -69,8 +69,8 @@ let mapConfig = {
69
69
  // 游戏地转地图坐标
70
70
  calculateMapCoordinate (x, y) {
71
71
  return [
72
- x / 1.230185 + mapConfig.ats.multipliers.x,
73
- y / 1.230185 + mapConfig.ats.multipliers.y
72
+ x / 1.2414298 + mapConfig.ats.multipliers.x,
73
+ y / 1.2414298 + mapConfig.ats.multipliers.y
74
74
  ];
75
75
  }
76
76
  }
@@ -171,6 +171,28 @@
171
171
  y / 2.598541 + mapConfig.promods.multipliers.y
172
172
  ]
173
173
  }
174
+ },
175
+ // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json(tmp-ats-promods)
176
+ ats: {
177
+ tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-promods-yellow/Tiles/{z}/{x}/{y}.png',
178
+ multipliers: {
179
+ x: 97335.94,
180
+ y: 70182.92
181
+ },
182
+ breakpoints: {},
183
+ bounds: {
184
+ y: 131072,
185
+ x: 131072
186
+ },
187
+ maxZoom: 8,
188
+ minZoom: 0,
189
+ // 游戏地转地图坐标
190
+ calculateMapCoordinate (x, y) {
191
+ return [
192
+ x / 1.2414298 + mapConfig.ats.multipliers.x,
193
+ y / 1.2414298 + mapConfig.ats.multipliers.y
194
+ ];
195
+ }
174
196
  }
175
197
  }
176
198
 
@@ -1046,6 +1046,18 @@
1046
1046
  calculateMapCoordinate (x, y) {
1047
1047
  return [x / 2.598541 + mapConfig.promods.multipliers.x, y / 2.598541 + mapConfig.promods.multipliers.y];
1048
1048
  }
1049
+ },
1050
+ // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json(tmp-ats-promods)
1051
+ ats: {
1052
+ tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-promods-yellow/Tiles/{z}/{x}/{y}.png',
1053
+ multipliers: { x: 97335.94, y: 70182.92 },
1054
+ breakpoints: {},
1055
+ bounds: { y: 131072, x: 131072 },
1056
+ maxZoom: 8,
1057
+ minZoom: 0,
1058
+ calculateMapCoordinate (x, y) {
1059
+ return [x / 1.2414298 + mapConfig.ats.multipliers.x, y / 1.2414298 + mapConfig.ats.multipliers.y];
1060
+ }
1049
1061
  }
1050
1062
  }
1051
1063
 
@@ -265,15 +265,15 @@
265
265
  return [x / 2.598541 + mapConfig.promods.multipliers.x, y / 2.598541 + mapConfig.promods.multipliers.y];
266
266
  }
267
267
  },
268
- // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json
268
+ // 美卡(ATS):换算参数来自瓦片导出配置 TileMapInfo.json(tmp-ats-promods)
269
269
  ats: {
270
- tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-yellow/Tiles/{z}/{x}/{y}.png',
271
- multipliers: { x: 97626.58, y: 64321.45 },
270
+ tileUrl: 'https://ets_tiles.cnly.top/20260903/tmp-ats-promods-yellow/Tiles/{z}/{x}/{y}.png',
271
+ multipliers: { x: 97335.94, y: 70182.92 },
272
272
  breakpoints: {},
273
273
  bounds: { y: 131072, x: 131072 },
274
274
  maxZoom: 8, minZoom: 0,
275
275
  calculateMapCoordinate(x, y) {
276
- return [x / 1.230185 + mapConfig.ats.multipliers.x, y / 1.230185 + mapConfig.ats.multipliers.y];
276
+ return [x / 1.2414298 + mapConfig.ats.multipliers.x, y / 1.2414298 + mapConfig.ats.multipliers.y];
277
277
  }
278
278
  }
279
279
  };
@@ -5,6 +5,7 @@
5
5
  */
6
6
  const MAX_PICK = 5; // 单次多选上限
7
7
  const PICK_TIMEOUT = 60_000; // 等待回复时长(毫秒)
8
+ const guildBind = require('../database/guildBind');
8
9
 
9
10
  /**
10
11
  * key: `${platform}:${channelId}:${userId}` → { bindings, allowMulti, max, finish }
@@ -59,6 +60,8 @@ function register(ctx) {
59
60
  */
60
61
  async function pick(ctx, session, bindings, opts = {}) {
61
62
  if (!bindings || bindings.length === 0) return [];
63
+ // 旧绑定的行没有名字:先查接口补全并写回,避免列表显示"未知"
64
+ await guildBind.ensureNames(ctx, bindings);
62
65
  if (bindings.length === 1) return [String(bindings[0].tmp_id)];
63
66
  const allowMulti = opts.allowMulti !== false;
64
67
  const max = allowMulti ? MAX_PICK : 1;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ets2-tools-tmp",
3
3
  "description": "欧卡2 TruckersMP信息查询、车队平台查询及活动提醒",
4
- "version": "3.4.0",
4
+ "version": "3.4.2",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>"
7
7
  ],