diff --git a/src/api_s2c/ApiBingo.ts b/src/api_s2c/ApiBingo.ts index b4cd9d2..9ec8155 100644 --- a/src/api_s2c/ApiBingo.ts +++ b/src/api_s2c/ApiBingo.ts @@ -120,7 +120,13 @@ export default async function (call: ApiCall) { } } else if (shell[0] == 'heroMaxLv') { - let heros = await G.redis.get('hero', call.uid); + //let heros = await G.redis.get('hero', call.uid); + + let s = await G.mongodb.collection('hero').find({ + uid: call.uid + }).toArray(); + let heros = s.map(h => G.mongodb.conversionIdObj(h)); + for (let [_id, hero] of Object.entries(heros)) { await HeroFun.changeHeroAttr(call, hero, { lv: Object.keys(G.gc.playerLv).length * 3, diff --git a/src/api_s2c/hero/ApiChangePos.ts b/src/api_s2c/hero/ApiChangePos.ts index e1cf832..1ec5316 100644 --- a/src/api_s2c/hero/ApiChangePos.ts +++ b/src/api_s2c/hero/ApiChangePos.ts @@ -39,7 +39,7 @@ export default async function (call: ApiCall) { } } else if (call.req.state == 'change') { if (heroPos[call.req.pos]) { - let unLoadHero = await G.redis.get('hero', call.uid, heroPos[call.req.pos]); + let unLoadHero = await HeroFun.getHero(call, heroPos[call.req.pos]); unLoadHero && fightHeros.removeOne(id => id == unLoadHero.heroId); } if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2); diff --git a/src/api_s2c/hero/ApiGetList.ts b/src/api_s2c/hero/ApiGetList.ts index e9db5af..c0882cb 100644 --- a/src/api_s2c/hero/ApiGetList.ts +++ b/src/api_s2c/hero/ApiGetList.ts @@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/hero/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('hero').find({ uid: call.uid }).toArray(); let heroCon = G.gc.hero; @@ -12,7 +12,7 @@ export default async function (call: ApiCall) { let maxherolv = 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 > maxherolv) maxherolv = v.lv; @@ -23,7 +23,7 @@ export default async function (call: ApiCall) { await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' }, { $set: { maxherolv: maxherolv, herocolor: color } }, { upsert: true }); - G.redis.set('hero', call.uid, kvList); + //G.redis.set('hero', call.uid, kvList); let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({ uid: call.conn.uid, type: 'lshd_hero' }); let { uid, _id, type, ...heros } = (recLshd || {}); diff --git a/src/api_s2c/hero/ApiJinJie.ts b/src/api_s2c/hero/ApiJinJie.ts index 47b8cd3..90fda22 100644 --- a/src/api_s2c/hero/ApiJinJie.ts +++ b/src/api_s2c/hero/ApiJinJie.ts @@ -39,7 +39,7 @@ export default async function (call: ApiCall) let selectHeros: ResGetList['list'][''][] = []; for (let _id of call.req.idArr) { - let _hero = await G.redis.get('hero', call.uid, _id); + let _hero = await HeroFun.getHero(call, _id); if (!_hero) return call.error(globalThis.lng.hero_1); selectHeros.push(_hero); } diff --git a/src/public/equip.ts b/src/public/equip.ts index 126fec0..2238215 100644 --- a/src/public/equip.ts +++ b/src/public/equip.ts @@ -17,7 +17,7 @@ export class EquipFun { //穿戴装备时该装备穿戴在另一个英雄身上 if (change.wearaId != undefined && equip.wearaId && equip.wearaId != change.wearaId && changeHero) { - let takeHero = await G.redis.get('hero', call.uid, equip.wearaId); + let takeHero = await HeroFun.getHero(call, equip.wearaId); if (takeHero) { let _equip = Object.assign({}, takeHero.equip); _equip[G.gc.equip[equip.equipId].type] = ''; diff --git a/src/public/hero.ts b/src/public/hero.ts index 3e630bb..52e104a 100644 --- a/src/public/hero.ts +++ b/src/public/hero.ts @@ -24,9 +24,9 @@ export class HeroFun { hero.zhanli = HeroShared.getHeroZhanLi(hero, call.otherBuff, Object.values(call.conn.gud.heroPos).indexOf(hero._id)); change.zhanli = hero.zhanli; - for (let k in change) { - await G.redis.set('hero', call.uid, hero._id, k as any, change[k]); - } + // for (let k in change) { + // await G.redis.set('hero', call.uid, hero._id, k as any, change[k]); + // } await G.mongodb.collection('hero').updateOne({uid: call.uid, _id: new ObjectId(hero._id)}, { $set: { @@ -41,13 +41,13 @@ export class HeroFun { /**获取英雄 */ static async getHero(call: call, oid: string) { - let data = await G.redis.get('hero', call.uid, oid); - if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库 + //let data = await G.redis.get('hero', call.uid, oid); + //if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库 let {_id, ...info} = await G.mongodb.collection("hero").findOne({ _id: G.mongodb.conversionId(oid) }) - data = Object.assign({_id: _id.toHexString()}, info) - } + let data = Object.assign({_id: _id.toHexString()}, info) + //} return data } diff --git a/src/public/player.ts b/src/public/player.ts index 7c38a1c..09ded2c 100644 --- a/src/public/player.ts +++ b/src/public/player.ts @@ -432,12 +432,12 @@ export class PlayerFun { //hero/apiGetList里会G.redis.set('hero', call.uid, kvList); //在这之后再执行下面的代码则不会报错 - if (await G.redis.type('hero', call.uid) != null) { - G.redis.set('hero', call.uid, id, { - _id: id, - ...ops - }); - } + // if (await G.redis.type('hero', call.uid) != null) { + // G.redis.set('hero', call.uid, id, { + // _id: id, + // ...ops + // }); + // } call.addEventMsg('msg_s2c/HeroChange', id, { diff --git a/src/public/shiwu.ts b/src/public/shiwu.ts index 4d1e715..e05018e 100644 --- a/src/public/shiwu.ts +++ b/src/public/shiwu.ts @@ -38,7 +38,7 @@ export class ShiwuFun { //穿戴饰物时该装备穿戴在另一个英雄身上 if (change.wearId != undefined && shiwu.wearId && shiwu.wearId != change.wearId && changeHero) { - let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); + let takeHero = await HeroFun.getHero(call, shiwu.wearId); if (takeHero) { let _shiwu = Object.assign({}, takeHero.shiwu); let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; @@ -55,7 +55,7 @@ export class ShiwuFun { //属性发生变化并且穿戴在英雄身上时 if (change.wearId == undefined && shiwu.wearId) { - let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); + let takeHero = await HeroFun.getHero(call, shiwu.wearId); if (takeHero) { let _shiwu = Object.assign({}, takeHero.shiwu); let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; diff --git a/src/setRedis.ts b/src/setRedis.ts index 449987f..484d2a4 100644 --- a/src/setRedis.ts +++ b/src/setRedis.ts @@ -75,8 +75,9 @@ async function clearRedis() { G.redis.fromatKey('jjc'), G.redis.fromatKey('user'), G.redis.fromatKey('item'), + G.redis.fromatKey('hero'), + //G.redis.fromatKey('equip'), - //G.redis.fromatKey('hero'), //G.redis.fromatKey('shiwu'), //G.redis.fromatKey('gbtx'), //G.redis.fromatKey('dxlt'),