diff --git a/game-server/app/servers/role/handler/equipHandler.ts b/game-server/app/servers/role/handler/equipHandler.ts index e5892416d..4927bcb47 100644 --- a/game-server/app/servers/role/handler/equipHandler.ts +++ b/game-server/app/servers/role/handler/equipHandler.ts @@ -615,12 +615,13 @@ export class EquipHandler { if (index < 0) return resResult(STATUS.WRONG_PARMS); let equipOffInfo = hero.ePlace[index].equip; + console.log('**********equipOffInfo', equipOffInfo&&equipOffInfo.seqId) let curEquip = await changeEquip(serverId, roleId, sid, equipOffInfo, equip.hid, id, equip, funcs); if (!!curEquip) - curEquips.push(curEquip); + curEquips.push(...curEquip); curEquip = await dressEquip(serverId, roleId, sid, hero, equip, funcs); if (!!curEquip) - curEquips.push(curEquip); + curEquips.push(...curEquip); //任务 //英雄满装备且都镶嵌相同阶数的宝石 @@ -632,7 +633,7 @@ export class EquipHandler { if (!equip.hid) return resResult(STATUS.EQUIP_NOT_EQUIPED); let curEquip = await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id, funcs); - curEquips.push(curEquip); + curEquips.push(...curEquip); } return resResult(STATUS.SUCCESS, { curEquips: curEquips }); @@ -681,7 +682,7 @@ export class EquipHandler { if (sortedAndSuitEquips.length > 0) { let { equip } = sortedAndSuitEquips.shift(); let curEquip = await dressEquip(serverId, roleId, sid, hero, equip, funcs); - if (!!curEquip) curEquips.push(curEquip); + if (!!curEquip) curEquips.push(...curEquip); } } diff --git a/game-server/app/services/equipService.ts b/game-server/app/services/equipService.ts index bf768e8cc..c8b987e3e 100644 --- a/game-server/app/services/equipService.ts +++ b/game-server/app/services/equipService.ts @@ -85,16 +85,13 @@ export async function changeEquip(serverId: number, roleId: string, sid: string, if (!!equipA) {//需要卸下的装备 if (!!heroB) { let goodInfo = getGoodById(equipA.id); - if (goodInfo.lvLimited > heroB.lv) { + if (goodInfo.lvLimited > heroB.lv || !checkEquipCanPut(hid, equipA.id)) { // 不能穿,就只卸载 let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力 return res; - } - if (checkEquipCanPut(hid, equipA.id)) { - let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力 + } else { + let res = await dressEquip(serverId, roleId, sid, heroB, equipA, funcs);//替换给武将,并计算战力 return res; } - let res = await dressEquip(serverId, roleId, sid, heroB, equipA, funcs);//替换给武将,并计算战力 - return res; } else { let res = await takeOffEquipAndCalPlayerCe(roleId, sid, null, equipA, id, funcs);//卸下装备并重算战力 return res; @@ -113,7 +110,7 @@ export async function changeEquip(serverId: number, roleId: string, sid: string, * @param id */ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero: HeroType, equip: EquipType, id: number, funcs: number[]) { - console.log(roleId, sid, hero, equip, id) + console.log('***takeOffEquipAndCalPlayerCe', roleId, sid, hero&&hero.hid, equip.seqId, id) if (hero) { let args = calEquipSeids(hero); hero = await HeroModel.removeEquip(roleId, hero.hid, id, equip._id); @@ -126,7 +123,7 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, he // 任务 await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, -1, true, {}); await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equip, [-1]); - return { seqId: equip.seqId, hid: 0, id: equip.id, ePlaceId: equip.ePlaceId }; + return [{ seqId: equip.seqId, hid: 0, id: equip.id, ePlaceId: equip.ePlaceId }]; } /** * 穿戴装备并重算战力 @@ -136,9 +133,12 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, he * @param equip */ export async function dressEquip(serverId: number, roleId: string, sid: string, hero: HeroType, equip: EquipType, funcs: number[]) { - let args = calEquipSeids(hero); + console.log('***dressEquip', roleId, sid, hero&&hero.hid, equip.seqId) - hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id); + let args = calEquipSeids(hero); + let index = hero.ePlace.findIndex(cur => cur.id == equip.ePlaceId); + let equipOffInfo = hero.ePlace[index].equip; + hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id, equipOffInfo?._id); await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args); // 任务 @@ -148,7 +148,13 @@ export async function dressEquip(serverId: number, roleId: string, sid: string, await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equip.quality }) await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_SUM, 1) - return { seqId: equip.seqId, hid: hero.hid, id: equip.id, ePlaceId: equip.ePlaceId }; + let res = [ + { seqId: equip.seqId, hid: hero.hid, id: equip.id, ePlaceId: equip.ePlaceId } + ]; + if(equipOffInfo) { + res.push({ seqId: equipOffInfo.seqId, hid: 0, id: equipOffInfo.id, ePlaceId: equipOffInfo.ePlaceId }) + } + return res } export function checkEquipCanPut(hid: number, id: number) { diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index 4ef763afb..11b6e4513 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -182,14 +182,13 @@ export default class Hero extends BaseModel { return hero; } - public static async addEquip(roleId: string, hid: number, ePlaceId: number, equipId: string, lean = true) { + public static async addEquip(roleId: string, hid: number, ePlaceId: number, equipId: string, equipOffId: string) { const hero: HeroType = await HeroModel.findOneAndUpdate( { roleId, hid, 'ePlace.id': ePlaceId }, { $set: { 'ePlace.$.equip': equipId } }, - { new: true }).populate('ePlace.equip').lean(lean); - if (hero) { - await Equip.putOnOrOff(equipId, hero.hid); - } + { new: true }).populate('ePlace.equip').lean(); + await Equip.putOnOrOff(equipId, hero.hid); + if(equipOffId) await Equip.putOnOrOff(equipOffId, 0); return hero; } @@ -198,6 +197,7 @@ export default class Hero extends BaseModel { { roleId, hid, 'ePlace.id': ePlaceId }, { $set: { 'ePlace.$.equip': null } }, { new: true }).populate('ePlace.equip').lean(lean); + if (hero) { await Equip.putOnOrOff(equipId, 0); }