From dd34a1c3a4be92f20622a5a80073cbc6e1632aaf Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Mon, 18 Dec 2023 15:27:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?equip=E5=8E=BBredis=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/equip/ApiGetList.ts | 6 ++-- src/api_s2c/equip/ApiOneKeyWear.ts | 2 +- src/api_s2c/equip/ApiStarUp.ts | 4 +-- src/api_s2c/equip/ApiTakeOff.ts | 2 +- src/api_s2c/equip/ApiWear.ts | 2 +- src/public/equip.ts | 45 +++++++++++++++++++----------- src/public/player.ts | 8 +++--- src/setRedis.ts | 3 +- 8 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/api_s2c/equip/ApiGetList.ts b/src/api_s2c/equip/ApiGetList.ts index 6a258c8..06208e1 100644 --- a/src/api_s2c/equip/ApiGetList.ts +++ b/src/api_s2c/equip/ApiGetList.ts @@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/equip/PtlGetList" export default async function (call: ApiCall) { let list: ResGetList['list'] = {}; - let kvList: k_v = {}; + //let kvList: k_v = {}; let arrList = await G.mongodb.collection('equip').find({ uid: call.uid }).toArray(); let equipCon = G.gc.equip @@ -12,7 +12,7 @@ export default async function (call: ApiCall) { let maxequiplv = 0 arrList.forEach(v => { let d = G.mongodb.conversionIdObj(v); - kvList[G.formatRedisKey(d._id)] = d; + //kvList[G.formatRedisKey(d._id)] = d; list[d._id] = d; if (v.lv > maxequiplv) maxequiplv = v.lv @@ -24,7 +24,7 @@ export default async function (call: ApiCall) { await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' }, { $set: { maxequiplv: maxequiplv, equipcolor: color } }, { upsert: true }) - G.redis.set('equip', call.uid, kvList); + //G.redis.set('equip', call.uid, kvList); let recLshd = await G.mongodb.collection('playerInfo', 'lshd_equip').findOne({ uid: call.conn.uid, type: 'lshd_equip' }); let { uid, _id, type, ...equips } = (recLshd || {}); diff --git a/src/api_s2c/equip/ApiOneKeyWear.ts b/src/api_s2c/equip/ApiOneKeyWear.ts index 0041b08..1b6e93e 100644 --- a/src/api_s2c/equip/ApiOneKeyWear.ts +++ b/src/api_s2c/equip/ApiOneKeyWear.ts @@ -14,7 +14,7 @@ export default async function (call: ApiCall !!i) diff --git a/src/api_s2c/equip/ApiStarUp.ts b/src/api_s2c/equip/ApiStarUp.ts index 360a245..e689c64 100644 --- a/src/api_s2c/equip/ApiStarUp.ts +++ b/src/api_s2c/equip/ApiStarUp.ts @@ -11,7 +11,7 @@ import { PublicShared } from "../../shared/public/public"; export default async function (call: ApiCall) { - let equip = await G.redis.get('equip', call.uid, call.req.equipId); + let equip = await EquipFun.getEquip(call, call.req.equipId); if (!equip) return call.error(globalThis.lng.equip_1); if (!G.gc.equipstar[equip.equipId]) return call.error(globalThis.lng.equip_4); @@ -28,7 +28,7 @@ export default async function (call: ApiCall) for (let _id of call.req.equipArr) { //遍历客户端传过来的所有装备,如果不存在或处于穿戴中,则报错 - let equip = await G.redis.get('equip', call.conn.uid, _id); + let equip = await EquipFun.getEquip(call, _id); if (!equip) return call.error(globalThis.lng.equip_6); if (equip.wearaId) return call.error(globalThis.lng.equip_7); equipArr.push(equip); diff --git a/src/api_s2c/equip/ApiTakeOff.ts b/src/api_s2c/equip/ApiTakeOff.ts index 85d07ee..568e288 100644 --- a/src/api_s2c/equip/ApiTakeOff.ts +++ b/src/api_s2c/equip/ApiTakeOff.ts @@ -5,7 +5,7 @@ import { ServiceType } from '../../shared/protocols/serviceProto'; import kfjsFun from "../../public/kaifujingsai"; export default async function (call: ApiCall) { - let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId); + let equip = await EquipFun.getEquip(call, call.req.equipId); if (!equip) return call.error(globalThis.lng.equip_1); if (!equip.wearaId) return call.error(globalThis.lng.equip_9); diff --git a/src/api_s2c/equip/ApiWear.ts b/src/api_s2c/equip/ApiWear.ts index edea5c0..471d385 100644 --- a/src/api_s2c/equip/ApiWear.ts +++ b/src/api_s2c/equip/ApiWear.ts @@ -12,7 +12,7 @@ export default async function (call: ApiCall) { if (!hero) return call.error(globalThis.lng.equip_10); if (hero.lv < G.gc.herocom.equipOpenLv) return call.error(`英雄${G.gc.herocom.equipOpenLv}级开启`); - let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId); + let equip = await EquipFun.getEquip(call, call.req.equipId); if (!equip) return call.error(globalThis.lng.equip_1); if (equip.wearaId == hero._id) return call.error(globalThis.lng.equip_11); diff --git a/src/public/equip.ts b/src/public/equip.ts index 2238215..0cfba4e 100644 --- a/src/public/equip.ts +++ b/src/public/equip.ts @@ -27,9 +27,9 @@ export class EquipFun { Object.assign(equip, change); - for (let k in change) { - G.redis.set('equip', call.uid, equip._id, k as keyof CollectionEquip, change[k]); - } + // for (let k in change) { + // G.redis.set('equip', call.uid, equip._id, k as keyof CollectionEquip, change[k]); + // } G.mongodb.collection('equip').updateOne({uid: call.uid, _id: new ObjectId(equip._id)}, {$set: {...change}}); call.addEventMsg('msg_s2c/EquipChange', equip._id, change); } @@ -37,24 +37,37 @@ export class EquipFun { /** * 获取装备 */ - static async getEquip(call: ApiCall, oid: string): Promise; - static async getEquip(call: ApiCall, oid: string[]): Promise; - static async getEquip(call: ApiCall, oid: string | string[]) { + static async getEquip(call: ApiCall, oid?: string): Promise; + static async getEquip(call: ApiCall, oid?: string[]): Promise; + static async getEquip(call: ApiCall, oid?: string | string[]) { if (typeof oid == 'string') { - let data = await G.redis.get('equip', call.uid, oid); - if (!data) { - let {_id, ...info} = await G.mongodb.collection('equip').findOne({ - _id: G.mongodb.conversionId(oid) - }) - data = Object.assign({_id: _id.toHexString()}, info) - } + let {_id, ...info} = await G.mongodb.collection('equip').findOne({ + _id: G.mongodb.conversionId(oid) + }) + let data = Object.assign({_id: _id.toHexString()}, info) return data } else { - let equips = await G.mongodb.collection('equip').find({ + let filter = { uid: call.uid, - _id: {$in: oid.map(v => G.mongodb.conversionId(v))} - }).toArray(); + } + if(oid && oid.length > 0){ + filter['_id'] = {$in: oid.map(v => G.mongodb.conversionId(v))} + } + let equips = await G.mongodb.collection('equip').find(filter).toArray(); return equips.map(v => G.mongodb.conversionIdObj(v)); } } + + /** + * 获取所有的装备 + * 并对返回结果进行格式化,兼容原来的redis返回的格式 + */ + static async getAllEquips(call: ApiCall):Promise>{ + let res = {}; + let equips:CollectionEquip[] = await this.getEquip(call,[]); + equips.map(v => { + res['_'+v._id] = v; + }); + return res; + } } \ No newline at end of file diff --git a/src/public/player.ts b/src/public/player.ts index 09ded2c..d8322dd 100644 --- a/src/public/player.ts +++ b/src/public/player.ts @@ -350,10 +350,10 @@ export class PlayerFun { let id = result.insertedIds[key].toHexString(); let {_id, ...ops} = v; - G.redis.set('equip', call.uid, id, { - _id: id, - ...ops - }); + // G.redis.set('equip', call.uid, id, { + // _id: id, + // ...ops + // }); Wjjl.setVal(call.uid, `has_equip_color_${G.gc.equip[ops.equipId].colour}`, 1, false); diff --git a/src/setRedis.ts b/src/setRedis.ts index 484d2a4..0ea3cdd 100644 --- a/src/setRedis.ts +++ b/src/setRedis.ts @@ -76,8 +76,7 @@ async function clearRedis() { G.redis.fromatKey('user'), G.redis.fromatKey('item'), G.redis.fromatKey('hero'), - - //G.redis.fromatKey('equip'), + G.redis.fromatKey('equip'), //G.redis.fromatKey('shiwu'), //G.redis.fromatKey('gbtx'), //G.redis.fromatKey('dxlt'), From ea179c2a3cb4f3639f9b6027f514527d0f960625 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Mon, 18 Dec 2023 15:50:28 +0800 Subject: [PATCH 2/5] =?UTF-8?q?redis=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/email.ts | 2 +- src/public/gud.ts | 8 +++++--- src/setRedis.ts | 5 ++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/public/email.ts b/src/public/email.ts index e4b6f41..1f70f02 100644 --- a/src/public/email.ts +++ b/src/public/email.ts @@ -172,7 +172,7 @@ export class EmailFun { sendEmail.sid = uid.split('_')[0] } - if (prize.length > 0) { + if (prize?.length > 0) { sendEmail.prizeData = { prize: email.prize, isGet: false diff --git a/src/public/gud.ts b/src/public/gud.ts index 47fb68a..8ba809b 100644 --- a/src/public/gud.ts +++ b/src/public/gud.ts @@ -18,9 +18,11 @@ export async function clearGud(uid) { G.ioredis.del(`gudVersion:${uid}_pid`); G.ioredis.del(`gudVersion:${uid}_ver`); } - G.redis.del("equip",uid); - G.redis.del("hero",uid); - G.redis.del("shiwu",uid); + + if(await G.redis.type('tanxian', uid)){ + console.log('清空tanxian Redis',uid); + G.redis.del("tanxian",uid); + } }; /** diff --git a/src/setRedis.ts b/src/setRedis.ts index 0ea3cdd..b27ee0c 100644 --- a/src/setRedis.ts +++ b/src/setRedis.ts @@ -60,10 +60,9 @@ export async function initRedis() { //启动前清理redis残余数据 clusterRunOnce(async () => { await clearRedis(); + await setRedis(); }) - if (G.config.cleanRedis) await redisClient.flushDb(); - await setRedis(); console.log('connect redis succ'); } @@ -77,7 +76,7 @@ async function clearRedis() { G.redis.fromatKey('item'), G.redis.fromatKey('hero'), G.redis.fromatKey('equip'), - //G.redis.fromatKey('shiwu'), + G.redis.fromatKey('shiwu'), //G.redis.fromatKey('gbtx'), //G.redis.fromatKey('dxlt'), ]) From 7ae81dc6f504bd02642cb7cb28f92a2f477054f2 Mon Sep 17 00:00:00 2001 From: dy Date: Mon, 18 Dec 2023 15:50:40 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=88=98=E5=8A=9B=E6=95=B0=E5=80=BC?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=8A=A0=E4=B8=8A=E9=80=9F=E5=BA=A6=E5=80=8D?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/public/hero.ts | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/shared/public/hero.ts b/src/shared/public/hero.ts index 3f97fac..03a3c99 100644 --- a/src/shared/public/hero.ts +++ b/src/shared/public/hero.ts @@ -1,10 +1,10 @@ -import { ResGetList } from '../protocols/hero/PtlGetList'; -import { player } from '../protocols/user/type'; -import { EquipShared } from './equip'; -import { PeijianShared } from './peijian'; -import { PlayerShared } from './player'; -import { PublicShared } from './public'; -import { ShiwuShared } from './shiwu'; +import {ResGetList} from '../protocols/hero/PtlGetList'; +import {player} from '../protocols/user/type'; +import {EquipShared} from './equip'; +import {PeijianShared} from './peijian'; +import {PlayerShared} from './player'; +import {PublicShared} from './public'; +import {ShiwuShared} from './shiwu'; export type otherBuff = Partial; @@ -23,6 +23,7 @@ export class HeroShared { return allBuff; } + /** * 获取英雄基本属性 * @param hero 英雄数据 @@ -30,7 +31,7 @@ export class HeroShared { */ static getHeroBasicAttr(hero: heroDataType, otherBuff: otherBuff = G.otherBuff, pos = 0) { let jiban = 0; - let buff: k_v = { skillArr: [] }; + let buff: k_v = {skillArr: []}; let heroConf = G.gc.hero[hero.heroId]; let heroLv = G.gc.herolv[heroConf.lvup]; let heroGrow = G.gc.herogrow[heroConf.jjup]?.[hero.jieji]; @@ -39,7 +40,7 @@ export class HeroShared { for (let k in heroLv.buff) { let val = heroLv.buff[k]; if (typeof val == 'number') buff[k] = val; - else buff[k] = PublicShared.eval(val, { lv: hero.lv }); + else buff[k] = PublicShared.eval(val, {lv: hero.lv}); // else buff[k] = Math.floor(new Function(`let lv=${hero.lv}; return ${val}`)()); } @@ -126,7 +127,7 @@ export class HeroShared { PublicShared.mergeProperty(buff, PeijianShared.getAttr(p)); let conf = G.gc.peijian[p.peijianId]; if (conf.suit) { - if (!suitObj[conf.suit]) suitObj[conf.suit] = { num: 0, minLv: 0 }; + if (!suitObj[conf.suit]) suitObj[conf.suit] = {num: 0, minLv: 0}; suitObj[conf.suit].num++; if (!suitObj[conf.suit].minLv || p.lv < suitObj[conf.suit].minLv) suitObj[conf.suit].minLv = p.lv; } @@ -172,7 +173,7 @@ export class HeroShared { if (hero.qiannneg) { for (let type in hero.qiannneg) { // console.log(PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[hero.qiannneg[type]].buff)) - for(let i = 1; i <= hero.qiannneg[type]; i++) { + for (let i = 1; i <= hero.qiannneg[type]; i++) { G.gc.hero_qianneng[type]?.[i] && PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[i].buff); } } @@ -260,7 +261,7 @@ export class HeroShared { if (otherBuff?.skills) { for (let [id, lv] of Object.entries(otherBuff.skills)) { if (lv && G.gc.xunlianjihua[id].use == 0) { - PublicShared.mergeProperty(buff, Object.fromEntries([G.gc.xunlianjihua[id].skill].map(k => [k, PublicShared.eval(G.gc.xunlianjihua[id].v[0], { slv: lv })]))); + PublicShared.mergeProperty(buff, Object.fromEntries([G.gc.xunlianjihua[id].skill].map(k => [k, PublicShared.eval(G.gc.xunlianjihua[id].v[0], {slv: lv})]))); } } } @@ -286,6 +287,7 @@ export class HeroShared { return buff; }; + /**修正属性 数值取整*/ static amendAttr(buff: k_v) { for (let k in buff) { @@ -294,6 +296,7 @@ export class HeroShared { buff[k] = Math.floor(buff[k]); } } + /** * 获取英雄战力 * @param hero 英雄数据 @@ -303,6 +306,7 @@ export class HeroShared { let buff = this.getHeroBasicAttr(hero, otherBuff, pos); return this.computeHeroZhanLi(buff); } + /** * 计算英雄战力 */ @@ -313,6 +317,7 @@ export class HeroShared { let def = buff.def || 0; let hp = buff.hp || 0; let speed = buff.speed || 0; + let speedpro = buff.speedpro || 0; let hppro = buff.hppro || 0; let dpspro = buff.dpspro || 0; let undpspro = buff.undpspro || 0; @@ -329,11 +334,11 @@ export class HeroShared { (maxdps * .75) + (def * 1.03) + (hp * 1) + - (speed * 21.28) + (hp * hppro * .5) + + (speed * (speedpro + 1) * 21.28) + ((mindps + maxdps) / 2 * dpspro * .75) + (hp * undpspro * .6) + - ((mindps + maxdps) / 2 * xixuepro * 1) + + ((mindps + maxdps) / 2 * xixuepro) + ((mindps + maxdps) / 2 * baoshangpro * .75) + ((mindps + maxdps) / 2 * shanbipro * .5) + ((mindps + maxdps) / 2 * mingzhongpro * .5) + @@ -341,6 +346,7 @@ export class HeroShared { (hp * pvpdpsdrop * .5) ); } + /** * 获取英雄升级消耗 * @param id 英雄id @@ -349,10 +355,11 @@ export class HeroShared { static getHeroLvUpNeed(id: string | number, lv = 1): atn[] { return [ - { a: 'item', t: '1', n: G.gc.herolvup[lv].expneed }, - { a: 'attr', t: 'jinbi', n: G.gc.herolvup[lv].jinbineed } + {a: 'item', t: '1', n: G.gc.herolvup[lv].expneed}, + {a: 'attr', t: 'jinbi', n: G.gc.herolvup[lv].jinbineed} ]; } + /** * 获取英雄进阶消耗 * @param id 英雄id From 3f275e4af40526f78e5b341abc2bb1160fa90203 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Mon, 18 Dec 2023 18:01:55 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8F=91=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=97=B6=E7=9A=84=E4=B8=8A=E9=99=90=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/email.ts | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/public/email.ts b/src/public/email.ts index 1f70f02..b068322 100644 --- a/src/public/email.ts +++ b/src/public/email.ts @@ -186,27 +186,29 @@ export class EmailFun { sendEmail.lngContent = email.lngContent } - if (!isCross) { - let emailList = await this.getAllEmail(uid); - if (emailList.length >= 50) { - emailList.sort((a, b) => { - let noPrizeA = a.prizeData == undefined ? 0 : 1; - let noPrizeB = b.prizeData == undefined ? 0 : 1; - let getA = a.prizeData?.isGet == true ? 0 : 1; - let getB = b.prizeData?.isGet == true ? 0 : 1; + //太亏了!换其他清理机制,getAllEmail是性能消耗大户 + //todo.. 换其他清理机制 + // if (!isCross) { + // let emailList = await this.getAllEmail(uid); + // if (emailList.length >= 50) { + // emailList.sort((a, b) => { + // let noPrizeA = a.prizeData == undefined ? 0 : 1; + // let noPrizeB = b.prizeData == undefined ? 0 : 1; + // let getA = a.prizeData?.isGet == true ? 0 : 1; + // let getB = b.prizeData?.isGet == true ? 0 : 1; - if (noPrizeA != noPrizeB) { - return noPrizeA - noPrizeB; - } else if (getA != getB) { - return getA - getB; - } - return a.createTime - b.createTime; - }); + // if (noPrizeA != noPrizeB) { + // return noPrizeA - noPrizeB; + // } else if (getA != getB) { + // return getA - getB; + // } + // return a.createTime - b.createTime; + // }); - this.removeEmail(uid, emailList[0]._id); - G.server.sendMsgByUid(uid, 'msg_s2c/EmailDel', emailList[0]._id); - } - } + // this.removeEmail(uid, emailList[0]._id); + // G.server.sendMsgByUid(uid, 'msg_s2c/EmailDel', emailList[0]._id); + // } + // } let _id = (await G.mongodb.collection('email').insertOne({ ttl: new Date(), ...G.mongodb.conversionIdObj(sendEmail) From c8d6f7d4333c71dd82d0a21b69ffc0deff09b900 Mon Sep 17 00:00:00 2001 From: dy Date: Mon, 18 Dec 2023 19:12:51 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=85=E5=80=BC?= =?UTF-8?q?=E7=BB=8F=E9=AA=8C=E4=BB=BB=E5=8A=A1=E8=AE=A1=E7=AE=97=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E6=9C=8D=E7=8B=82=E6=AC=A2=E8=BF=9B=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96dayPay=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/kaifukuanghuan/ApiOpen.ts | 4 ++-- src/public/pay.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api_s2c/event/kaifukuanghuan/ApiOpen.ts b/src/api_s2c/event/kaifukuanghuan/ApiOpen.ts index 3f2dc96..94cb0c2 100644 --- a/src/api_s2c/event/kaifukuanghuan/ApiOpen.ts +++ b/src/api_s2c/event/kaifukuanghuan/ApiOpen.ts @@ -31,7 +31,7 @@ export default async function (call: ApiCall) { call.succ({ ...ops, - day: PublicShared.getOpenServerDay(call.conn.gud.cTime), + day: PublicShared.getOpenServerDay(), taskFinished: taskFinished }); } @@ -79,7 +79,7 @@ export async function getTaskVal(gud: player, taskTyps: string[]) { else if (t.indexOf('toDayPay') != -1) { let daystr = t.split('_')[1] || '1'; let day = Number(daystr); - let zeroTime = PublicShared.getToDayZeroTime(gud.cTime); + let zeroTime = PublicShared.getToDayZeroTime(G.openTime); val[t] = await PayFun.getPayDaysAllPayNum( gud.uid, zeroTime + (day - 1) * 24 * 3600, zeroTime + day * 24 * 3600 diff --git a/src/public/pay.ts b/src/public/pay.ts index 9a72587..cd9014e 100644 --- a/src/public/pay.ts +++ b/src/public/pay.ts @@ -478,9 +478,10 @@ export class PayFun { * 获取某个时间段内 玩家的充值总金额 */ static async getPayDaysAllPayNum(uid: string, sTime: number, eTime: number) { - let logs = await G.mongodb.collection('dayPay').find({uid: uid}).toArray() || []; - - logs = logs.filter(log => log.time >= sTime && log.time < eTime); + let logs = await G.mongodb.collection('dayPay').find({ + uid: uid, + time: {$gte: sTime, $lt: eTime} + }).toArray() || []; if (logs.length <= 0) return 0; return logs.map(log => log.payNum).reduce((a, b) => a + b);