From a26aa7dab33ecdcf50d6fe0e4237531b2df43f37 Mon Sep 17 00:00:00 2001 From: yushunrui <364203175@qq.com> Date: Wed, 10 Jan 2024 16:44:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=84=E7=90=86=E5=BC=BA=E5=8C=96?= =?UTF-8?q?=E4=BC=99=E4=BC=B4=E6=B4=BB=E5=8A=A8=E5=88=9D=E5=A7=8B=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E4=BB=BB=E5=8A=A1=E8=BF=9B=E5=BA=A6=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/chuanshuozhilu/ApiOpen.ts | 30 +++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts b/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts index 27dd5d5..a1d648d 100644 --- a/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts +++ b/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts @@ -12,11 +12,37 @@ export default async function (call: ApiCall) { // 无此活动 return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 }) } - let db = await G.mongodb.cEvent(`chuanshuozhilu${call.req.hdid}`).findOne({ uid: call.uid, type: `chuanshuozhilu${call.req.hdid}` }); + let _info = db?.info || {} + // 如果初始没有数据,就判断玩家是否有活动对应的影响,生成一下初始化数据 + if (!db) { + + let _dbType: `chuanshuozhilu${number}` = `chuanshuozhilu${call.req.hdid}` + const hid = _hdinfo.data.hid + let heros = await G.mongodb.collection("hero").find({uid: call.uid, heroId: hid}) + .sort({ "zhanli": -1 }).limit(1).toArray(); + + if (heros) { + let hero = heros[0] + const lv = hero.lv || 0 + const jieji = hero.jieji || 0 + let setInfo = {"lv": lv, "jieji": jieji} + await G.mongodb.cEvent(_dbType).updateOne( + { uid: call.uid, type: _dbType }, + { $set: G.mongodb.createTreeObj({ key: `info.${hid}`, val: setInfo})}, + { upsert: true} + ) + if (!cache[call.uid]) cache[call.uid] = {hid:{}}; + if (!cache[call.uid][hid]) cache[call.uid][hid] = setInfo; + _info[hid] = setInfo + G.server.sendMsgByUid(call.uid, 'msg_s2c/HongDianChange', ['huodonghd']); + } + + } + call.succ({ - info: db?.info || {}, + info: _info, hdinfo: _hdinfo }); }