This commit is contained in:
mamengke01
2020-12-26 18:42:22 +08:00
parent 3b6b8a7d01
commit 66a9bf7809
9 changed files with 148 additions and 72 deletions

View File

@@ -4,16 +4,15 @@ import { ItemInter } from "../../../pubUtils/interface";
import { resResult, parseGoodStr, getRandomByLen, deepCopy, mergeSameGoods, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
import { checkMaterialEnough } from "../../../services/equipService";
import { EquipModel, RandSe } from "../../../db/Equip";
import { EquipModel, RandSe, EquipType } from "../../../db/Equip";
import { HeroModel, EPlace } from "../../../db/Hero";
import { ItemModel } from "../../../db/Item";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../../../pubUtils/data";
import { getHeroJob, getGoodById, gameData, getSuit, getHeroEquipByClassId } from "../../../pubUtils/data";
import { EQUIP } from "../../../pubUtils/dicParam";
import { ITID, SPEICAL_ITEM, RANDOM_SE_COUNT } from "../../../consts/constModules/itemConst";
import { changeEquip } from "../../../services/equipService";
import { changeEquip, dressEquip, checkMaterialEnough, takeOffEquipAndCalPlayerCe } from "../../../services/equipService";
const _ = require('underscore');
@@ -423,7 +422,7 @@ export class EquipHandler {
let obj = ITID.get(goodInfo.itid);
let id = obj.type;
let curEquips: Array<{ seqId: number, hid: number}> = [];
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let hero = await HeroModel.getHeroEquip(roleId, hid);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
if (type == 1) {
@@ -439,23 +438,18 @@ export class EquipHandler {
let index = _.findIndex(hero.ePlace, { id });
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let objectId = <string>hero.ePlace[index].equip;
let curEquip = await changeEquip(roleId, sid, objectId, equip.hid, id, eid);
let equipOffInfo = <EquipType>hero.ePlace[index].equip;
let curEquip = await changeEquip(roleId, sid, equipOffInfo, equip.hid, id, eid);
if (!!curEquip)
curEquips.push(curEquip);
curEquip = await dressEquip(roleId, sid, hero, equip);
if (!!curEquip)
curEquips.push(curEquip);
hero = await HeroModel.addEquip(roleId, hid, id, equip._id);
await calPlayerCeAndSave(sid, roleId, [hero]);
curEquips.push({ seqId: eid, hid });
} else if (type == 2) {
if (!equip.hid)
return resResult(STATUS.EQUIP_NOT_EQUIPED);
let index = _.findIndex(hero.ePlace, { id });
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
hero.ePlace[index].equip = null;
let {seqId} = await EquipModel.updateEquipInfo(eid, { hid: 0 });
await calPlayerCeAndSave(sid, roleId, [hero]);
curEquips.push({ seqId, hid:0 });
let curEquip = await takeOffEquipAndCalPlayerCe(roleId, sid, equip.seqId, hero, id)
curEquips.push(curEquip);
}
return resResult(STATUS.SUCCESS, { curEquips: curEquips });
}
@@ -622,6 +616,7 @@ export class EquipHandler {
let goodInfo = getGoodById(jewel);
let good = ITID.get(goodInfo.itid);
let needUpdate = false;
let oldJewel;
let consumes: Array<{id: number, count: number, ratio?: number}> = [];
if (good.type != CONSUME_TYPE.JEWEL)
return resResult(STATUS.WRONG_PARMS);
@@ -630,6 +625,7 @@ export class EquipHandler {
equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes,{id});
if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
oldJewel = equip.holes[index].jewel;
equip.holes[index].jewel = jewel;
needUpdate = true;
consumes.push({id: goodInfo.composeMaterial[0].id, count: 1, ratio: 1});
@@ -645,6 +641,10 @@ export class EquipHandler {
let result = {};
if (needUpdate) {
await EquipModel.updateEquipInfo(eid, { holes: equip.holes });
if (!!equip.hid) {
let hero = await HeroModel.findByHidAndRole(equip.hid, roleId);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.JEWEL_ON, [jewel, oldJewel]);
}
return resResult(STATUS.SUCCESS, { curEquip: { seqId: eid, holes: equip.holes } });
} else {
result = await addItems(roleId, roleName, sid, [{ id: jewel, count: count }]);