武将:一键训练

This commit is contained in:
luying
2021-08-14 17:57:46 +08:00
parent 8fd9aeb25b
commit e86e51c456
2 changed files with 26 additions and 22 deletions
@@ -8,7 +8,7 @@ import { CURRENCY_BY_TYPE, CURRENCY_TYPE, CONSUME_TYPE, HERO_GROW_MAX, HERO_SYST
import { RoleModel } from '../../../db/Role'; import { RoleModel } from '../../../db/Role';
import { ItemModel } from '../../../db/Item'; import { ItemModel } from '../../../db/Item';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById, getFavourLvByExp, reloadDicParam } from '../../../pubUtils/data'; import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getFriendShipById, getFavourLvByExp, reloadDicParam } from '../../../pubUtils/data';
import { RewardInter } from '../../../pubUtils/interface'; import { ItemInter, RewardInter } from '../../../pubUtils/interface';
import { getDropItems, FIGURE_UNLOCK_CONDITION } from '../../../consts/constModules/itemConst' import { getDropItems, FIGURE_UNLOCK_CONDITION } from '../../../consts/constModules/itemConst'
import { pushComposeOrangeHero, pushHeroQualityUpMsg, pushHeroStarMax, pushHeroWakeUp } from '../../../services/chatService'; import { pushComposeOrangeHero, pushHeroQualityUpMsg, pushHeroStarMax, pushHeroWakeUp } from '../../../services/chatService';
import { calculatetopLineup } from '../../../pubUtils/playerCe'; import { calculatetopLineup } from '../../../pubUtils/playerCe';
@@ -396,12 +396,12 @@ export class HeroHandler {
} }
//训练 //训练
async heroJobTrain(msg: { hid: number }, session: BackendSession) { async heroJobTrain(msg: { hid: number, isOneClick: boolean }, session: BackendSession) {
let roleId: string = session.get('roleId'); let roleId: string = session.get('roleId');
let sid: string = session.get('sid'); let sid: string = session.get('sid');
let funcs: number[] = session.get('funcs'); let funcs: number[] = session.get('funcs');
const serverId = session.get('serverId'); const serverId = session.get('serverId');
let { hid } = msg; let { hid, isOneClick } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId); let hero = await HeroModel.findByHidAndRole(hid, roleId);
if (!hero) return resResult(STATUS.HERO_NOT_FIND); if (!hero) return resResult(STATUS.HERO_NOT_FIND);
@@ -413,18 +413,21 @@ export class HeroHandler {
if (hero.job >= getMaxGradeByjobClass(dicJob.job_class)) if (hero.job >= getMaxGradeByjobClass(dicJob.job_class))
return resResult(STATUS.HERO_JOB_REACH_MAX_STAGE); return resResult(STATUS.HERO_JOB_REACH_MAX_STAGE);
let consume = new Array<RewardInter>(); let newJobStage = 0;
if (dicJob.trainingConsume[hero.jobStage]) { let max = isOneClick ? dicJob.maxStage: hero.jobStage + 1;
consume.push(dicJob.trainingConsume[hero.jobStage]); for(let i = 0; i < max; i++) {
} let singleConsume = dicJob.trainingConsume[hero.jobStage];
let result = await handleCost(roleId, sid, consume); if(!singleConsume) break; // 每天消耗不可训练
if (!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); let result = await handleCost(roleId, sid, [singleConsume]);
if (!result) break; // 材料不足
newJobStage ++;
} }
if (newJobStage == 0) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
//重算战力并下发 //重算战力并下发
hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.TRAIN, sid, roleId, hero, { hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.TRAIN, sid, roleId, hero, {
jobStage: hero.jobStage + 1 jobStage: newJobStage
}); });
// 任务 // 任务
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_TRAIN, hero); await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.HERO_TRAIN, hero);
+12 -11
View File
@@ -463,17 +463,18 @@ export function calHeroTrainIncAttr(originHero: HeroType, update: HeroUpdate) {
let { job = oldJob, jobStage = oldJobStage } = update; let { job = oldJob, jobStage = oldJobStage } = update;
let dicJob = gameData.job.get(job); let dicJob = gameData.job.get(job);
let lastJob = getJobByGradeAndClass(dicJob.job_class, dicJob.grade - 1);
if (dicJob.grade >= 1) { let dicLastJob = lastJob? gameData.job.get(lastJob.jobid): null;
let jobGradeAndClass = getJobByGradeAndClass(dicJob.job_class, dicJob.grade - 1);
let lastJob = gameData.job.get(jobGradeAndClass.jobid); for(let i = 1; i <= dicJob.maxStage; i++) {
let targetAttrId = dicJob.ceAttr.get(jobStage).id; if(oldJobStage < i && jobStage >= i) {
let inc = (dicJob.ceAttr.get(jobStage).attr - lastJob.ceAttr.get(jobStage).attr) * HERO_CE_RATIO; let lastAttr = dicLastJob? dicLastJob.ceAttr.get(i).attr: 0;
updateHeroAttr(heroAttrs, targetAttrId, { inc: { fixUp: inc } }); let targetAttrId = dicJob.ceAttr.get(i).id;
} else { let targetAttrValue = dicJob.ceAttr.get(i).attr;
let targetAttrId = dicJob.ceAttr.get(jobStage).id; let inc = (targetAttrValue - lastAttr) * HERO_CE_RATIO;
let inc = dicJob.ceAttr.get(jobStage).attr * HERO_CE_RATIO; console.log('*******', targetAttrId, targetAttrValue, lastAttr, inc )
updateHeroAttr(heroAttrs, targetAttrId, { inc: { fixUp: inc } }); updateHeroAttr(heroAttrs, targetAttrId, { inc: { fixUp: inc } });
}
} }
return heroAttrs; return heroAttrs;
} }