武将:职业天赋接口

This commit is contained in:
陆莹
2022-03-22 20:46:17 +08:00
parent 3c24e54350
commit 5d0040b8a8
20 changed files with 2811 additions and 1199 deletions

View File

@@ -1,9 +1,9 @@
import { Application, BackendSession, ChannelService, HandlerService, } from 'pinus';
import { handleCost, addItems, unlockFigure, getCoinObject, getGoldObject } from '../../../services/role/rewardService';
import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService';
import { resResult, deepCopy, reduceCe } from '../../../pubUtils/util';
import { resResult, deepCopy, reduceCe, parseGoodStr } from '../../../pubUtils/util';
import { STATUS } from '../../../consts/statusCode';
import { HeroModel, Connect, HeroSkin, HeroUpdate, EPlace } from '../../../db/Hero';
import { HeroModel, Connect, HeroSkin, HeroUpdate, EPlace, Talent } from '../../../db/Hero';
import { CURRENCY_BY_TYPE, CURRENCY_TYPE, CONSUME_TYPE, HERO_GROW_MAX, HERO_SYSTEM_TYPE, ABI_STAGE, DEBUG_MAGIC_WORD, HERO_INITIAL_QUALITY, REDIS_KEY, TASK_TYPE, ITEM_CHANGE_REASON } from '../../../consts';
import { RoleModel } from '../../../db/Role';
import { ItemModel } from '../../../db/Item';
@@ -16,10 +16,10 @@ import { PvpDefenseModel } from '../../../db/PvpDefense';
import { checkTask, checkTaskInHeroQUalityUp, checkTaskInHeroStarUp, checkTaskInHeroTrain, checkTaskInHeroWakeUp } from '../../../services/task/taskService';
import { isNumber, pick } from 'underscore';
import { updateEplaces } from '../../../services/equipService';
import { addConsumeToHero } from '../../../services/roleService';
import { addConsumeToHero, checkUnlockTalentCondition, initSkinTalent, updateSkinTalent } from '../../../services/roleService';
import { JewelModel, jewelUpdate } from '../../../db/Jewel';
import { CalHeroCe } from '../../../domain/roleField/calCe';
import { REBORN } from '../../../pubUtils/dicParam';
import { HERO, REBORN } from '../../../pubUtils/dicParam';
import { createHero, createHeroes } from '../../../services/role/createHero';
import { CheckMeterial } from '../../../services/role/checkMaterial';
@@ -685,6 +685,100 @@ export class HeroHandler {
return resResult(STATUS.SUCCESS, { curHero: { ...curHero, ce: reduceCe(curHero.ce) }, curJewels, goods });
}
// 解锁天赋
public async unlockTalent(msg: { hid: number, id: number }, session: BackendSession) {
let roleId = session.get('roleId');
let sid = session.get('sid');
let { hid, id } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
let dicHeroTalent = gameData.heroTalent.get(id);
if(!dicHeroTalent) return resResult(STATUS.WRONG_PARMS);
let skins = hero.skins||[];
let curSkin = skins.find(cur => cur.enable);
if(!curSkin) return resResult(STATUS.HERO_SKIN_NOT_FIND);
let talent = curSkin.talent.find(cur => cur.id == id);
if(talent) return resResult(STATUS.TALENT_HAS_UNLOCKED);
let usedTalentPoint = curSkin.usedTalentPoint;
if(!checkUnlockTalentCondition(hid, id, curSkin.talent, usedTalentPoint)) {
return resResult(STATUS.TALENT_CONDITION_NOT_FIT);
}
let totalTalentPoint = gameData.talentPointOfJob.get(hero.job);
let needTalentPoint = dicHeroTalent.level.find(cur => cur.lv == 1)?.cost||0;
if(totalTalentPoint - usedTalentPoint - needTalentPoint < 0) {
return resResult(STATUS.TALENT_POINT_NOT_ENOUGH);
}
let { newSkins, newTalents } = updateSkinTalent(skins, new Talent(id), usedTalentPoint + needTalentPoint);
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.TALENT, sid, roleId, hero, { skins: newSkins });
return resResult(STATUS.SUCCESS, { curHero: {...pick(hero, ['hid', 'skins', 'skinId']) }});
}
// 升级天赋
public async upgradeTalent(msg: { hid: number, id: number }, session: BackendSession) {
let roleId = session.get('roleId');
let sid = session.get('sid');
let { hid, id } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
let skins = hero.skins||[];
let curSkin = skins.find(cur => cur.enable);
if(!curSkin) return resResult(STATUS.HERO_SKIN_NOT_FIND);
let talent = curSkin.talent.find(cur => cur.id == id);
if(!talent) return resResult(STATUS.TALENT_NOT_UNLOCKED);
let dicHeroTalent = gameData.heroTalent.get(id);
if(!dicHeroTalent) return resResult(STATUS.WRONG_PARMS);
let usedTalentPoint = curSkin.usedTalentPoint;
let totalTalentPoint = gameData.talentPointOfJob.get(hero.job);
let nextLv = dicHeroTalent.level.find(cur => cur.lv == talent.level + 1);
if(!nextLv) return resResult(STATUS.TALENT_LEVEL_MAX);
let needTalentPoint = nextLv.cost||0;
if(totalTalentPoint - usedTalentPoint - needTalentPoint < 0) {
return resResult(STATUS.TALENT_POINT_NOT_ENOUGH);
}
let { newSkins, newTalents } = updateSkinTalent(skins, new Talent(id, talent.level + 1), usedTalentPoint + needTalentPoint);
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.TALENT, sid, roleId, hero, { skins: newSkins });
return resResult(STATUS.SUCCESS, { curHero: {...pick(hero, ['hid', 'skins', 'skinId']) }});
}
// 洗点
public async resetTalent(msg: { hid: number }, session: BackendSession) {
let roleId = session.get('roleId');
let sid = session.get('sid');
let { hid } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
if(!hero) return resResult(STATUS.HERO_NOT_FIND);
let skins = hero.skins||[];
let curSkin = skins.find(cur => cur.enable);
if(!curSkin) return resResult(STATUS.HERO_SKIN_NOT_FIND);
let costItem = parseGoodStr(HERO.HERO_TALENTPOINT_RESET);
let consumeResult = await handleCost(roleId, sid, costItem, ITEM_CHANGE_REASON.RESET_TALENT);
if(!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let newSkins = initSkinTalent(skins);
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.TALENT, sid, roleId, hero, { skins: newSkins });
return resResult(STATUS.SUCCESS, { curHero: {...pick(hero, ['hid', 'skins', 'skinId']) }});
}
// ! debug接口 一键全武将
public async debugGetAllHeroes(msg: { magicWord: string }, session: BackendSession) {
let roleId: string = session.get('roleId');