全面去掉hero的redis依赖
This commit is contained in:
parent
2bbfb55704
commit
327f9c9b5a
@ -120,7 +120,13 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
|
||||
}
|
||||
|
||||
} 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,
|
||||
|
@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
|
||||
}
|
||||
} 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);
|
||||
|
@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/hero/PtlGetList";
|
||||
|
||||
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
||||
let list: ResGetList['list'] = {};
|
||||
let kvList: k_v<RedisCollections2['hero']> = {};
|
||||
//let kvList: k_v<RedisCollections2['hero']> = {};
|
||||
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<ReqGetList, ResGetList>) {
|
||||
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<ReqGetList, ResGetList>) {
|
||||
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 || {});
|
||||
|
@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqJinJie, ResJinJie, ServiceType>)
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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] = '';
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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, {
|
||||
|
@ -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];
|
||||
|
@ -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'),
|
||||
|
Loading…
Reference in New Issue
Block a user