装备:装备逻辑变化
This commit is contained in:
@@ -5,18 +5,19 @@ import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { resResult, parseGoodStr } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost, decreaseItems, combineItems } from "../../../services/rewardService";
|
||||
import { EquipModel, EquipType } from "../../../db/Equip";
|
||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||
import { HeroModel, EPlace, HeroType } from "../../../db/Hero";
|
||||
import Role from "../../../db/Role";
|
||||
import { calPlayerCeAndSave } from "../../../services/playerCeService";
|
||||
import { getGoodById, gameData } from "../../../pubUtils/data";
|
||||
import { BAG, EQUIP } from "../../../pubUtils/dicParam";
|
||||
import { ITID, QUALITY_TYPE, equipTypeToSortAttr, IT_TYPE, QUENCH_TYPE, REFINE_TYPE } from "../../../consts";
|
||||
import { changeEquip, dressEquip, checkMaterialEnough, takeOffEquipAndCalPlayerCe, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe } from "../../../services/equipService";
|
||||
import { checkMaterialEnough, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe } from "../../../services/equipService";
|
||||
|
||||
import { findIndex, pick } from 'underscore';
|
||||
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
|
||||
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, checkTaskConditionEquipSuitJewelStage, checkActivityTask } from "../../../services/taskService";
|
||||
import { QuenchLogParam } from "../../../domain/roleField/equip";
|
||||
import { calEquipSeids } from "../../../pubUtils/playerCe";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -593,47 +594,107 @@ export class EquipHandler {
|
||||
public async putOnOrOff(msg: { eid: number, hid: number, type: number }, session: BackendSession) {
|
||||
let { eid, hid, type } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let equip = await EquipModel.getEquip(eid);
|
||||
let serverId: number = session.get('serverId');
|
||||
let sid: string = session.get('sid');
|
||||
let funcs: number[] = session.get('funcs');
|
||||
|
||||
// 原武将:heroA,原武将穿戴着的装备a,将要穿戴的装备b,装备b被装备着的武将B
|
||||
let heroA = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!heroA) return resResult(STATUS.HERO_NOT_FIND);
|
||||
|
||||
let equip = await EquipModel.getEquip(eid); // 装备:1-equipB 2-equipA
|
||||
if(!equip) return resResult(STATUS.EQUIP_NOT_FIND);
|
||||
|
||||
let argsA = calEquipSeids(heroA);
|
||||
let heroB: HeroType, equipA: EquipType, equipB: EquipType, argsB: number[] = [];
|
||||
let heroAPutNum = 0, heroBPutTNum = 0; // 1:多一件 0:没变化 -1:少一件
|
||||
|
||||
let goodInfo = getGoodById(equip.id);
|
||||
let obj = ITID.get(goodInfo.itid);
|
||||
let id = obj.type;
|
||||
let curEquips: Array<{ seqId: number, hid: number }> = [];
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero)
|
||||
return resResult(STATUS.HERO_NOT_FIND);
|
||||
if (type == 1) {
|
||||
if (equip.hid == hid)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (goodInfo.lvLimited > hero.lv)
|
||||
return resResult(STATUS.EQUIP_LEVEL_LIMIT);
|
||||
if(!checkEquipCanPut(hid, equip.id))
|
||||
return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
|
||||
let index = findIndex(hero.ePlace, { id });
|
||||
if (index < 0)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let equipOffInfo = <EquipType>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);
|
||||
curEquip = await dressEquip(serverId, roleId, sid, hero, equip, funcs);
|
||||
if (!!curEquip)
|
||||
curEquips.push(...curEquip);
|
||||
let eplaceId = obj.type; // 位置
|
||||
|
||||
//任务
|
||||
//英雄满装备且都镶嵌相同阶数的宝石
|
||||
let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(hero)
|
||||
if (type == 1) {
|
||||
equipB = equip; // 要穿上的装备
|
||||
if (equipB.hid == hid) return resResult(STATUS.WRONG_PARMS);
|
||||
if(!checkEquipCanPut(heroA, equipB.id)) return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
|
||||
|
||||
let index = heroA.ePlace.findIndex(cur => cur.id == eplaceId);
|
||||
if (index == -1) return resResult(STATUS.WRONG_PARMS);
|
||||
equipA = <EquipType>heroA.ePlace[index].equip; // 要脱下的装备
|
||||
|
||||
if(equipB.hid > 0) {
|
||||
heroB = await HeroModel.findByHidAndRoleWithEquip(equipB.hid, roleId);
|
||||
argsB = calEquipSeids(heroB);
|
||||
}
|
||||
|
||||
if(equipA) {
|
||||
if(equipB.hid > 0) {
|
||||
if(checkEquipCanPut(heroB, equipA.id)) { // A=>b & B=>a
|
||||
equipA = await EquipModel.putOnOrOff(equipA._id, equipB.hid);
|
||||
heroB = await HeroModel.addEquip(roleId, heroB.hid, eplaceId, equipA._id);
|
||||
} else { // A=>b & B=>0 & 0=>a
|
||||
equipA = await EquipModel.putOnOrOff(equipA._id, 0);
|
||||
heroB = await HeroModel.removeEquip(roleId, equipB.hid, eplaceId);
|
||||
heroBPutTNum = -1;
|
||||
}
|
||||
} else { // A=>b & 0=>a
|
||||
equipA = await EquipModel.putOnOrOff(equipA._id, 0);
|
||||
}
|
||||
} else {
|
||||
if(equipB.hid > 0) { // A=>b & B=>0
|
||||
heroB = await HeroModel.removeEquip(roleId, equipB.hid, eplaceId);
|
||||
heroBPutTNum = -1;
|
||||
}
|
||||
// A=>b
|
||||
heroAPutNum = 1;
|
||||
}
|
||||
|
||||
heroA = await HeroModel.addEquip(roleId, heroA.hid, eplaceId, equipB._id);
|
||||
equipB = await EquipModel.putOnOrOff(equipB._id, heroA.hid);
|
||||
|
||||
} else if (type == 2) { // A=>0 & 0=>a
|
||||
if (!equip.hid) return resResult(STATUS.EQUIP_NOT_EQUIPED);
|
||||
equipA = await EquipModel.putOnOrOff(equip._id, 0);
|
||||
heroA = await HeroModel.removeEquip(roleId, heroA.hid, eplaceId);
|
||||
heroAPutNum = -1;
|
||||
}
|
||||
|
||||
if(heroA) {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, heroA, {}, argsA);
|
||||
if(heroAPutNum != 0) {
|
||||
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, heroA, [heroAPutNum]);
|
||||
}
|
||||
}
|
||||
if(heroB) {
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, heroB, {}, argsB);
|
||||
if(heroBPutTNum != 0) await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, heroA, [heroBPutTNum]);
|
||||
}
|
||||
if(heroAPutNum + heroBPutTNum != 0) {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, heroAPutNum + heroBPutTNum, true, {});
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_SUM, heroAPutNum + heroBPutTNum)
|
||||
}
|
||||
|
||||
let curEquips: Array<{ seqId: number, hid: number }> = [];
|
||||
if(equipA) {
|
||||
curEquips.push(pick(equipA, ['seqId', 'hid']));
|
||||
if(equipA.hid == 0) {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equipA, [-1]); // equipA必然是脱,如果hid不为0说明从一个人穿到另一个人,不算任务
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equipA.quality });
|
||||
}
|
||||
}
|
||||
if(equipB) {
|
||||
curEquips.push(pick(equipB, ['seqId', 'hid']));
|
||||
if(equipB.hid != 0) {
|
||||
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equipB, [1]); // equipB必然是穿,如果hid为0说明没有变化,不算任务
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_QUALITY, 1, { quality: equipB.quality });
|
||||
}
|
||||
}
|
||||
|
||||
if(type == 1) {
|
||||
let { isTask, jewelLevel } = await checkTaskConditionEquipSuitJewelStage(heroA)//英雄满装备且都镶嵌相同阶数的宝石
|
||||
if (isTask) {
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (!equip.hid)
|
||||
return resResult(STATUS.EQUIP_NOT_EQUIPED);
|
||||
let curEquip = await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id, funcs);
|
||||
curEquips.push(...curEquip);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquips: curEquips });
|
||||
@@ -648,6 +709,8 @@ export class EquipHandler {
|
||||
let funcs: number[] = session.get('funcs');
|
||||
let hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_FIND);
|
||||
let args = calEquipSeids(hero);
|
||||
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let dicJob = gameData.job.get(dicHero.jobid);
|
||||
@@ -668,8 +731,8 @@ export class EquipHandler {
|
||||
let sortAttrId = equipTypeToSortAttr.get(curEPlace.id);
|
||||
let sortedAndSuitEquips = sortEquips.filter(equipInfos => { // 筛选可穿的
|
||||
let { id, lvLimited, ePlaceId } = equipInfos;
|
||||
return lv >= lvLimited && checkEquipCanPut(hid, id) && curEPlace.id == ePlaceId;
|
||||
})
|
||||
return lv >= lvLimited && checkEquipCanPut(hero, id) && curEPlace.id == ePlaceId;
|
||||
});
|
||||
console.log('sortedAndSuitEquips', JSON.stringify(sortedAndSuitEquips, null, 4))
|
||||
sortedAndSuitEquips = sortedAndSuitEquips.sort((a, b) => { // 排序按:战力 => 根据位置看个别属性 => 品质
|
||||
if (b.ce - a.ce != 0) return b.ce - a.ce;
|
||||
@@ -681,8 +744,9 @@ 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);
|
||||
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
|
||||
equip = await EquipModel.putOnOrOff(equip._id, hero.hid);
|
||||
if (!!equip) curEquips.push(pick(equip, ['seqId', 'hid']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -694,6 +758,8 @@ export class EquipHandler {
|
||||
if (isTask) {
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.EQUIP_SUIT_JEWEL_STAGE, 1, { stage: jewelLevel })
|
||||
}
|
||||
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { curEquips });
|
||||
|
||||
Reference in New Issue
Block a user