feat(将魂出售): 修复将魂回收的问题

4cfbce94e - 2fa8c7a91 by zhangxk
This commit is contained in:
luying
2023-07-19 15:51:04 +08:00
parent 523eaad05e
commit f09ebd56b1
5 changed files with 79 additions and 59 deletions

View File

@@ -45,7 +45,7 @@ export class HeroSkin {
talent: Talent[]; // 天赋树
@prop({ required: true })
usedTalentPoint: number; // 已使用的天赋点数
constructor(skin: SkinUpdate, enable = true) {
this.id = skin.id;
this.skinId = skin.skinId;
@@ -83,9 +83,9 @@ export class EPlace {
@prop({ required: true })
jewel: number = 0;
getInitialStone? () {
getInitialStone?() {
let result: Stone[] = [];
for(let id = 1; id <= 3; id++) {
for (let id = 1; id <= 3; id++) {
result.push({ id, stone: 0 });
}
return result;
@@ -95,7 +95,7 @@ export class EPlace {
this.id = id;
this.equipId = equipId;
this.stones = this.getInitialStone();
}
}
}
@index({ seqId: 1 })
@@ -166,7 +166,7 @@ export default class Hero extends BaseModel {
consumes: Reward[]; // 消耗
@prop({ required: true, default: 0 })
artifact: number|string; // 宝物
artifact: number | string; // 宝物
@prop({ required: true, default: 0 })
subHid: number; // 副将
@@ -221,6 +221,11 @@ export default class Hero extends BaseModel {
return hero;
}
public static async findByHidsAndRole(roleId: string, hids: Array<number>, select?: string, getters = false) {
const heros: HeroType[] = await HeroModel.find({ roleId, hid: { $in: hids } }).select(select).lean({ getters });
return heros;
}
public static async findSubHero(roleId: string, subHid: number) {
const hero: HeroType = await HeroModel.findOne({ roleId, subHid }).lean();
return hero;
@@ -228,9 +233,9 @@ export default class Hero extends BaseModel {
// 设置副将
public static async setSubHero(roleId: string, hid: number, subSkinId: number, subActorId: number) {
const preHero = subActorId > 0? await HeroModel.findOneAndUpdate({ roleId, subActorId }, { $set: { subActorId: 0, subHid: 0 } }, { new: true }).lean(): null;
const preHero = subActorId > 0 ? await HeroModel.findOneAndUpdate({ roleId, subActorId }, { $set: { subActorId: 0, subHid: 0 } }, { new: true }).lean() : null;
const curHero: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: { subHid: subSkinId, subActorId } }, { new: true }).lean();
return { preHid: preHero?.hid||0, curHero };
return { preHid: preHero?.hid || 0, curHero };
}
public static async addEquip(roleId: string, hid: number, ePlaceId: number, equipId: string) {
@@ -253,7 +258,7 @@ export default class Hero extends BaseModel {
let dicHero = gameData.hero.get(hid)
let { quality, initialStar: star, initialColorStar: colorStar, jobid: job, name: hName } = dicHero;
const doc = new HeroModel();
const update = { ...doc.toJSON(), hid, skinId: hid, hName, star, colorStar, quality, job, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0, ...heroInfo};
const update = { ...doc.toJSON(), hid, skinId: hid, hName, star, colorStar, quality, job, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0, ...heroInfo };
delete update._id;
return update
}
@@ -329,18 +334,18 @@ export default class Hero extends BaseModel {
private static getSearchObj(form: SearchHeroParam) {
let searchObj = {};
if(form.roleId) searchObj['roleId'] = form.roleId;
if(form.roleName) searchObj['roleName'] = { $regex: new RegExp(form.roleName.toString(), 'i') };
if(form.hid) searchObj['hid'] = form.hid;
if (form.roleId) searchObj['roleId'] = form.roleId;
if (form.roleName) searchObj['roleName'] = { $regex: new RegExp(form.roleName.toString(), 'i') };
if (form.hid) searchObj['hid'] = form.hid;
return searchObj
}
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchHeroParam = {}) {
}
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchHeroParam = {}) {
let searchObj = this.getSearchObj(form);
let sort = {};
if(sortField && sortOrder) {
if(sortOrder == 'ascend') {
if (sortField && sortOrder) {
if (sortOrder == 'ascend') {
sort[sortField] = 1;
} else if (sortOrder == 'descend') {
sort[sortField] = -1;
@@ -348,15 +353,15 @@ export default class Hero extends BaseModel {
}
const result: HeroType[] = await HeroModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
return result;
}
public static async countByCondition(form: SearchHeroParam = {}) {
let searchObj = this.getSearchObj(form);
const result = await HeroModel.count(searchObj);
return result;
}
}
public static async countByCondition(form: SearchHeroParam = {}) {
let searchObj = this.getSearchObj(form);
const result = await HeroModel.count(searchObj);
return result;
}
}
export const HeroModel = getModelForClass(Hero);

View File

@@ -68,6 +68,5 @@ export interface guildInter {
export interface recycleSoulFastPara {
hid: number;
goodsId: number;
count: number;
}