配件修正
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']) {
|
async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
|
||||||
try {
|
try {
|
||||||
// 修复配件数据
|
// 修复配件数据
|
||||||
let peijianids = [];
|
//hero数据里,所有英雄穿戴中的配件的 _id(objectId)
|
||||||
Object.values(list).map(hero => {
|
// let peijianids = [];
|
||||||
hero.peijian && Object.values(hero.peijian).map(
|
// Object.values(list).map(hero => {
|
||||||
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
|
// 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(
|
//通过上述的_id,去配件表查询所有配件
|
||||||
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
|
// let wearedPeiJian = (await G.mongodb.collection("peijian").find(
|
||||||
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
|
// {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))))
|
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}}
|
{uid: call.uid, _id: {$in: shiwuIds}}, {projection: {_id: 1}}
|
||||||
).toArray()).map(i => G.mongodb.conversionId(i._id));
|
).toArray()).map(i => G.mongodb.conversionId(i._id));
|
||||||
|
|
||||||
let peijianChanges = {};
|
//let peijianChanges = {};
|
||||||
let shiwuChanges = {};
|
let shiwuChanges = {};
|
||||||
Object.values(list).map(hero => {
|
Object.values(list).map(hero => {
|
||||||
for (let pos in hero.peijian) {
|
// for (let pos in hero.peijian) {
|
||||||
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
|
// //hero该位置记录的穿戴中的配件_id
|
||||||
hero.peijian[pos] = "";
|
// let _pid = PeijianShared.fmt(hero.peijian[pos])._id;
|
||||||
peijianChanges[hero._id] = hero.peijian;
|
|
||||||
}
|
// if (!peijians.includes(_pid) || peijianWearTo?.[_pid] != hero._id ) {
|
||||||
}
|
// //这个配件,实际在peijian表里不存在 或 配件表里该配件并不是在这个英雄身上
|
||||||
|
// hero.peijian[pos] = "";
|
||||||
|
// peijianChanges[hero._id] = hero.peijian;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
for (let pos in hero.shiwu) {
|
for (let pos in hero.shiwu) {
|
||||||
if (!shiwus.includes(hero.shiwu[pos]._id)) {
|
if (!shiwus.includes(hero.shiwu[pos]._id)) {
|
||||||
hero.shiwu = R.omit([pos], hero.shiwu)
|
hero.shiwu = R.omit([pos], hero.shiwu)
|
||||||
@ -85,12 +97,12 @@ async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let oid in peijianChanges) {
|
// for (let oid in peijianChanges) {
|
||||||
// 修复数据
|
// // 修复数据
|
||||||
G.mongodb.collection("hero").updateOne(
|
// G.mongodb.collection("hero").updateOne(
|
||||||
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
|
// G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (let oid in shiwuChanges) {
|
for (let oid in shiwuChanges) {
|
||||||
// 修复数据
|
// 修复数据
|
||||||
|
@ -1,12 +1,38 @@
|
|||||||
import {ApiCall} from "tsrpc";
|
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>) {
|
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
||||||
let _maxLv = 0
|
let _maxLv = 0
|
||||||
let color = {}
|
let color = {}
|
||||||
let peijianCon = G.gc.peijian
|
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 => {
|
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 np = G.mongodb.conversionIdObj(p);
|
||||||
let {uid, ...ops} = np;
|
let {uid, ...ops} = np;
|
||||||
|
|
||||||
@ -16,17 +42,25 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
|
|||||||
return ops;
|
return ops;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 修复配件穿戴在不存在的英雄身上
|
//对hero的peijian字段进行修正
|
||||||
let heroIds = R.values(call.conn.gud.heroPos)
|
if(Object.keys(heroPeiJian).length > 0){
|
||||||
let fixIds = dbList.filter(i => i.wearId && !heroIds.includes(i.wearId)).map(i => G.mongodb.conversionId(i._id))
|
for(let heroid in heroPeiJian){
|
||||||
if (fixIds.length) {
|
await G.mongodb.collection("hero").updateOne({
|
||||||
await G.mongodb.collection('peijian').updateMany({_id: {$in: fixIds}}, {$set: {wearId: ''}})
|
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'},
|
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'},
|
||||||
{$set: {maxpeijianlv: _maxLv, peijiancolor: color}}, {upsert: true})
|
{$set: {maxpeijianlv: _maxLv, peijiancolor: color}}, {upsert: true})
|
||||||
|
|
||||||
|
|
||||||
let list = Object.fromEntries(dbList.map(p => [G.formatRedisKey(p._id), p]));
|
let list = Object.fromEntries(dbList.map(p => [G.formatRedisKey(p._id), p]));
|
||||||
G.redis.set('peijian', call.uid, list);
|
G.redis.set('peijian', call.uid, list);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user