装备:洗练

This commit is contained in:
luying
2022-02-17 12:41:40 +08:00
parent 82b15e5792
commit 2bfc27356f
10 changed files with 1295 additions and 1992 deletions

View File

@@ -19,6 +19,7 @@ import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, ch
import { QuenchLogParam } from "../../../domain/roleField/equip";
import { calEquipSeids } from "../../../pubUtils/playerCe";
import { JewelModel, JewelType } from "../../../db/Jewel";
import { getJewelRandSe } from "../../../pubUtils/itemUtils";
export default function (app: Application) {
new HandlerService(app, {});
@@ -47,7 +48,7 @@ export class EquipHandler {
if(!dicEquip) 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);
if(!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let newEquip = new EPlace(ePlaceId, dicEquip.id);
let newEplace = hero.ePlace? [...hero.ePlace, newEquip]: [newEquip];
@@ -449,9 +450,6 @@ export class EquipHandler {
let { id, randSe, previewRandSe } = jewel;
if(previewRandSe.length <= 0) {
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.ROLE_EQUIP_HAVE_NO_RANDSE);
}
let previewRandSe = getRandSeResult(id, randSe);
if(!previewRandSe) return resResult(STATUS.DIC_DATA_NOT_FOUND);
@@ -497,11 +495,7 @@ export class EquipHandler {
if(!jewel) return resResult(STATUS.JEWEL_NOT_FOUND);
let { randSe, hid, ePlaceId, previewRandSe } = jewel;
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.JEWEL_HAVE_NO_RANDSE);
}
if(!previewRandSe) { // 没预览过
if(!previewRandSe || previewRandSe.length <= 0) { // 没预览过
return resResult(STATUS.EQUIP_RESTRENGTHEN_NOT_PREVIEW);
}
@@ -541,66 +535,67 @@ export class EquipHandler {
}
// // 淬火
// public async quench(msg: { eid: number, type: QUENCH_TYPE }, session: BackendSession) {
// let roleId: string = session.get('roleId');
// // let roleName: string = session.get('roleName');
// let sid: string = session.get('sid');
// 选择淬炼的那一条
public async chooseQuench(msg: { seqId: number, randSeId: number }, session: BackendSession) {
let { seqId, randSeId } = msg;
let jewel = await JewelModel.findbySeqId(seqId);
if(!jewel) return resResult(STATUS.JEWEL_NOT_FOUND);
let { randSe } = jewel;
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.JEWEL_HAVE_NO_RANDSE);
}
let quenchedSe = randSe.find(cur => cur.quenched);
if(!!quenchedSe) return resResult(STATUS.JEWEL_HAS_CHOOSEN_QUENCH);
let curRandSe = randSe.find(cur => cur.id == randSeId);
if(!curRandSe) return resResult(STATUS.JEWEL_HAVE_NO_CUR_RANDSE);
let jewelResult = await JewelModel.chooseQuench(seqId, randSeId);
return resResult(STATUS.SUCCESS, { curJewel: pick(jewelResult, ['seqId', 'id', 'hid', 'ePlaceId', 'randSe', 'previewRandSe']) });
}
// 淬火
public async quench(msg: { seqId: number }, session: BackendSession) {
let roleId: string = session.get('roleId');
// let roleName: string = session.get('roleName');
let sid: string = session.get('sid');
let { seqId } = msg;
let jewel = await JewelModel.findbySeqId(seqId);
if(!jewel) return resResult(STATUS.JEWEL_NOT_FOUND);
let { randSe, hid, ePlaceId } = jewel;
if (!randSe || randSe.length <= 0) {
return resResult(STATUS.JEWEL_HAVE_NO_RANDSE);
}
let quenchedSe = randSe.find(cur => cur.quenched);
if(!quenchedSe) return resResult(STATUS.JEWEL_NOT_CHOOSEN_QUENCH);
let dicJewel = gameData.jewel.get(jewel.id);
if(!dicJewel) return resResult(STATUS.DIC_DATA_NOT_FOUND);
let consumeResult = await handleCost(roleId, sid, dicJewel.quenchConsume, ITEM_CHANGE_REASON.EQUIP_QUENCH);
if(!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let newRandSe = getJewelRandSe(quenchedSe.id, quenchedSe.seid);
let isSuccess = newRandSe.rand >= quenchedSe.rand;
let newJewel = await JewelModel.quench(seqId, isSuccess, newRandSe.rand);
// 更新战力
if(isSuccess && hid > 0) {
const hero = await HeroModel.findByHidAndRole(hid, roleId);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.JEWEL_QUENCH, sid, roleId, hero, {}, [ePlaceId], { oldJewel: jewel, newJewel });
}
// TODO 任务
// await checkTask(roleId, sid, TASK_TYPE.EQUIP_RESTRENGTHEN, 1, true, {});
return resResult(STATUS.SUCCESS, { isSuccess, curJewel: pick(newJewel, ['seqId', 'id', 'hid', 'ePlaceId', 'randSe', 'previewRandSe']) });
// let { eid, type } = msg;
// let equip = await EquipModel.findbySeqId(eid);
// if (!equip) return resResult(STATUS.EQUIP_NOT_FIND);
// let { id, randMain, grade, hid, ePlaceId } = equip;
// let dicGoods = gameData.goods.get(id);
// if (!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
// let dicQuench = gameData.quenchByQuality.get(dicGoods.quality)?.get(grade);
// // console.log(dicQuench, dicGoods.quality, grade)
// if (!dicQuench) return resResult(STATUS.EQUIP_QUENCH_MAX);
// let check = new CheckMeterial(roleId);
// let logs: QuenchLogParam[] = [], times = 0;
// while(
// (type == QUENCH_TYPE.ONCE && times < 1 && !checkQuenchMaxByQualityAndGrade(dicGoods.quality, 0, randMain)) || // 淬火一次,保证不超出该品质上限
// (type == QUENCH_TYPE.ONE_GRADE && !checkQuenchMaxByQualityAndGrade(dicGoods.quality, grade, randMain)) // 淬火一品,在品相上限内淬火
// ) {
// let result = await quenchOnce(randMain, dicQuench, dicGoods);
// if(!result) break;
// let isEnough = await check.decrease(result.consumes);
// if(!isEnough) break; // 消耗不足
// result.log.setTimes(++times);
// logs.push(result.log);
// grade = result.grade;
// randMain = result.randMain;
// }
// if (times == 0) return resResult(STATUS.EQUIP_QUENCH_ERR);
// let consumes = check.getConsume();
// let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.EQUIP_QUENCH);
// if (!result)
// return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// let equipResult = await EquipModel.updateEquipInfo(eid, { randMain, grade })
// let curEquip = {
// seqId: equipResult.seqId,
// id: equipResult.id,
// randMain: equipResult.randMain,
// grade: equipResult.grade,
// }
// // 更新战力
// if(hid > 0) { // 装备中的时候
// const hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);
// await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_BASE, sid, roleId, hero, { });
// }
// return resResult(STATUS.SUCCESS, { logs, curEquip });
// }
}
// //分解装备
// public async decomposeEquip(msg: { originalEquip: Array<number> }, session: BackendSession) {