装备:获得天晶石&合成装备

This commit is contained in:
luying
2022-02-15 15:36:49 +08:00
parent ecc55b3063
commit 465cc15e43
30 changed files with 506 additions and 283 deletions

View File

@@ -8,12 +8,12 @@ import { EquipModel, EquipType } from "../../../db/Equip";
import { HeroModel, EPlace, HeroType } from "../../../db/Hero";
import Role from "../../../db/Role";
import { calPlayerCeAndSave } from "../../../services/playerCeService";
import { getGoodById, gameData } from "../../../pubUtils/data";
import { getGoodById, gameData, getEquipByJobClassAndEPlace } from "../../../pubUtils/data";
import { BAG, EQUIP } from "../../../pubUtils/dicParam";
import { ITID, QUALITY_TYPE, equipTypeToSortAttr, IT_TYPE, QUENCH_TYPE, REFINE_TYPE } from "../../../consts";
import { checkMaterialEnough, checkEquipCanPut, quenchOnce, checkQuenchMaxByQualityAndGrade, getRandSeResult, refineOnce, checkRefineReachNextLv, calEquipCe } from "../../../services/equipService";
import { findIndex, pick } from 'underscore';
import { findIndex, isNumber, pick } from 'underscore';
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, checkActivityTask } from "../../../services/taskService";
import { QuenchLogParam } from "../../../domain/roleField/equip";
@@ -29,72 +29,38 @@ export class EquipHandler {
constructor(private app: Application) {
}
public async composeEquip(msg: { hid: number, eplaceId: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid, eplaceId } = msg;
if(!isNumber(eplaceId) || eplaceId > 4 || eplaceId < 1) return resResult(STATUS.WRONG_PARMS);
// // test接口添加任意道具
// public async addItem(msg: { id: number, count: number }, session: BackendSession) {
// let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
// let sid: string = session.get('sid');
// let { id, count } = msg;
// let goods = await addItems(roleId, roleName, sid, [{ id, count }], ITEM_CHANGE_REASON.DEBUG);
// return resResult(STATUS.SUCCESS, { goods });
// }
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
// // 合成装备
// public async composeEquip(msg: { gid: number, originalEquip: number[] }, session: BackendSession) {
// let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
// let sid: string = session.get('sid');
// const serverId: number = session.get('serverId');
// // 消耗材料
// // 获得装备
// let { gid, originalEquip } = msg;
let curEquip = hero.ePlace?.find(equip => equip.id == eplaceId );
if(curEquip) return resResult(STATUS.EQUIP_HAS_COMPOSE);
let dicHero = gameData.hero.get(hid);
let dicEquip = getEquipByJobClassAndEPlace(dicHero?.jobClass, eplaceId);
if(!dicEquip) return resResult(STATUS.DIC_DATA_NOT_FOUND);
// let targetGood = gameData.goods.get(gid);
// if (!targetGood) return resResult(STATUS.DIC_DATA_NOT_FOUND);
let consumeResult = await handleCost(roleId, sid, dicEquip.composeMaterial, ITEM_CHANGE_REASON.EQUIP_COMPOSE);
if(!consumeResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// let cost: ItemInter[] = [];
// let jewels: ItemInter[] = []; // 需要返还的镶嵌在装备上的宝石
// if (targetGood.suitId > 0) { // 套装
// cost = cost.concat(targetGood.composeMaterial);
// let specialMaterial = targetGood.specialMaterial;
// let costCount = 0;
// let equips = await EquipModel.getEquips(roleId, originalEquip);
// for (let equip of equips) {
// let { id, seqId, holes } = equip;
// if (specialMaterial.ids.includes(id)) {
// costCount++;
// cost.push({ id, seqId, count: 1 });
// for (let { jewel } of holes) {
// if (jewel > 0) jewels.push({ id: jewel, count: 1 });
// }
// }
// }
// if (specialMaterial.count > costCount) {
// return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
// }
let newEquip = new EPlace(eplaceId, dicEquip.id);
let newEplace = hero.ePlace? [...hero.ePlace, newEquip]: [newEquip];
// } else { // 普通装备
// cost.push({
// id: targetGood.pieceId,
// count: targetGood.pieces
// });
// }
// let result = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.EQUIP_COMPOSE);
// if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.COMPOSE_EQUIP, sid, roleId, hero, { ePlace: newEplace }, [eplaceId]);
// await addItems(roleId, roleName, sid, jewels, ITEM_CHANGE_REASON.EQUIP_DEL_RETURN_JEWEL); // 宝石返还
// let items = [{ id: gid, count: 1 }];
// let goods = await addItems(roleId, roleName, sid, items, ITEM_CHANGE_REASON.EQUIP_COMPOSE);
// if (targetGood.suitId) {
// pushNormalEquipMsg(roleId, roleName, serverId, MSG_SOURCE.EQUIP_COMPOSE_SUIT, gid, targetGood.name, targetGood.quality);
// }
// if (targetGood.quality >= QUALITY_TYPE.ORANGE) {
// pushNormalEquipMsg(roleId, roleName, serverId, MSG_SOURCE.EQUIP_COMPOSE_ORANGE, gid, targetGood.name, targetGood.quality);
// }
// return resResult(STATUS.SUCCESS, { goods });
// }
return resResult(STATUS.SUCCESS, {
curHero: {
hid: hero.hid,
ePlace: [newEquip]
}
})
}
// // 装备栏强化
// public async strengthen(msg: { hid: number, ePlaceId: number, type: number }, session: BackendSession) {