配件修正
This commit is contained in:
parent
72b215451b
commit
c09c9dec89
@ -51,16 +51,24 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
||||
async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
|
||||
try {
|
||||
// 修复配件数据
|
||||
let peijianids = [];
|
||||
Object.values(list).map(hero => {
|
||||
hero.peijian && Object.values(hero.peijian).map(
|
||||
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
|
||||
)
|
||||
});
|
||||
//hero数据里,所有英雄穿戴中的配件的 _id(objectId)
|
||||
// let peijianids = [];
|
||||
// Object.values(list).map(hero => {
|
||||
// hero.peijian && Object.values(hero.peijian).map(
|
||||
// i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
|
||||
// )
|
||||
// });
|
||||
|
||||
let peijians = (await G.mongodb.collection("peijian").find(
|
||||
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
|
||||
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
|
||||
//通过上述的_id,去配件表查询所有配件
|
||||
// let wearedPeiJian = (await G.mongodb.collection("peijian").find(
|
||||
// {uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1, wearId:1}}
|
||||
// ).toArray());
|
||||
|
||||
// //peijians = 所有从db里查到的peijian的 _id字符串数据集合
|
||||
// let peijians = wearedPeiJian.map(temp => {
|
||||
// let idstr = G.mongodb.conversionId(temp._id)
|
||||
// return idstr;
|
||||
// });
|
||||
|
||||
let shiwuIds = R.flatten(R.values(list).map(hero => R.values(hero.shiwu).map(i => G.mongodb.conversionId(i._id))))
|
||||
|
||||
@ -68,15 +76,19 @@ async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
|
||||
{uid: call.uid, _id: {$in: shiwuIds}}, {projection: {_id: 1}}
|
||||
).toArray()).map(i => G.mongodb.conversionId(i._id));
|
||||
|
||||
let peijianChanges = {};
|
||||
//let peijianChanges = {};
|
||||
let shiwuChanges = {};
|
||||
Object.values(list).map(hero => {
|
||||
for (let pos in hero.peijian) {
|
||||
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
|
||||
hero.peijian[pos] = "";
|
||||
peijianChanges[hero._id] = hero.peijian;
|
||||
}
|
||||
}
|
||||
// for (let pos in hero.peijian) {
|
||||
// //hero该位置记录的穿戴中的配件_id
|
||||
// let _pid = PeijianShared.fmt(hero.peijian[pos])._id;
|
||||
|
||||
// if (!peijians.includes(_pid) || peijianWearTo?.[_pid] != hero._id ) {
|
||||
// //这个配件,实际在peijian表里不存在 或 配件表里该配件并不是在这个英雄身上
|
||||
// hero.peijian[pos] = "";
|
||||
// peijianChanges[hero._id] = hero.peijian;
|
||||
// }
|
||||
// }
|
||||
for (let pos in hero.shiwu) {
|
||||
if (!shiwus.includes(hero.shiwu[pos]._id)) {
|
||||
hero.shiwu = R.omit([pos], hero.shiwu)
|
||||
@ -85,12 +97,12 @@ async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
|
||||
}
|
||||
})
|
||||
|
||||
for (let oid in peijianChanges) {
|
||||
// 修复数据
|
||||
G.mongodb.collection("hero").updateOne(
|
||||
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
|
||||
)
|
||||
}
|
||||
// for (let oid in peijianChanges) {
|
||||
// // 修复数据
|
||||
// G.mongodb.collection("hero").updateOne(
|
||||
// G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
|
||||
// )
|
||||
// }
|
||||
|
||||
for (let oid in shiwuChanges) {
|
||||
// 修复数据
|
||||
|
@ -1,12 +1,38 @@
|
||||
import {ApiCall} from "tsrpc";
|
||||
import {ReqGetList, ResGetList} from "../../shared/protocols/peijian/PtlGetList";
|
||||
import { connGameLogDB } from "../../gameLog";
|
||||
import {PeiJian, ReqGetList, ResGetList} from "../../shared/protocols/peijian/PtlGetList";
|
||||
import { PeijianShared } from "../../shared/public/peijian";
|
||||
|
||||
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
||||
let _maxLv = 0
|
||||
let color = {}
|
||||
let peijianCon = G.gc.peijian
|
||||
|
||||
//所有上阵的英雄_id
|
||||
let heroIds = R.values(call.conn.gud.heroPos)
|
||||
//将所有未上阵的英雄的配件卸下
|
||||
if(heroIds.length>0){
|
||||
let _ids = heroIds.map(_id => G.mongodb.conversionId(_id));
|
||||
await G.mongodb.collection("hero").updateMany({uid: call.conn.uid},{
|
||||
$set:{
|
||||
peijian:{}
|
||||
}
|
||||
});
|
||||
}
|
||||
//如果配件穿戴在了未上阵的hero身上,则执行卸下操作
|
||||
await G.mongodb.collection('peijian').updateMany({uid: call.conn.uid, wearId: {$nin: heroIds}}, {$set: {wearId: ''}})
|
||||
|
||||
|
||||
let heroPeiJian = {};
|
||||
let dbList = (await G.mongodb.collection('peijian').find({uid: call.uid}).toArray()).map(p => {
|
||||
|
||||
if(p.wearId){
|
||||
if(!heroPeiJian[ p.wearId ]){
|
||||
heroPeiJian[ p.wearId ] = {};
|
||||
}
|
||||
heroPeiJian[ p.wearId ][ Object.keys(heroPeiJian[ p.wearId ]).length + 1 ] = PeijianShared.fmt( p as any )
|
||||
}
|
||||
|
||||
let np = G.mongodb.conversionIdObj(p);
|
||||
let {uid, ...ops} = np;
|
||||
|
||||
@ -16,17 +42,25 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
||||
return ops;
|
||||
});
|
||||
|
||||
// 修复配件穿戴在不存在的英雄身上
|
||||
let heroIds = R.values(call.conn.gud.heroPos)
|
||||
let fixIds = dbList.filter(i => i.wearId && !heroIds.includes(i.wearId)).map(i => G.mongodb.conversionId(i._id))
|
||||
if (fixIds.length) {
|
||||
await G.mongodb.collection('peijian').updateMany({_id: {$in: fixIds}}, {$set: {wearId: ''}})
|
||||
//对hero的peijian字段进行修正
|
||||
if(Object.keys(heroPeiJian).length > 0){
|
||||
for(let heroid in heroPeiJian){
|
||||
await G.mongodb.collection("hero").updateOne({
|
||||
uid : call.conn.uid,
|
||||
_id : G.mongodb.conversionId(heroid)
|
||||
},{
|
||||
$set:{
|
||||
peijian : heroPeiJian[heroid]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 记录玩家最大等级,颜色相关数据 注册任务用
|
||||
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'},
|
||||
{$set: {maxpeijianlv: _maxLv, peijiancolor: color}}, {upsert: true})
|
||||
|
||||
|
||||
let list = Object.fromEntries(dbList.map(p => [G.formatRedisKey(p._id), p]));
|
||||
G.redis.set('peijian', call.uid, list);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user