武将养成
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus';
|
import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus';
|
||||||
import { handleCost } from '../../../services/rewardService';
|
import { handleCost } from '../../../services/rewardService';
|
||||||
import { calPlayerCeAndSave } from '../../../services/playerCeService';
|
import { calPlayerCeAndSave } from '../../../services/playerCeService';
|
||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult, getItems } from '../../../pubUtils/util';
|
||||||
import { STATUS } from '../../../consts/statusCode';
|
import { STATUS } from '../../../consts/statusCode';
|
||||||
import {HeroModel} from '../../../db/Hero';
|
import {HeroModel} from '../../../db/Hero';
|
||||||
import { getJobInfoById, getMaxGradeByjobClass, getHeroInfoById, getGoodById } from '../../../pubUtils/gamedata';
|
import {CURRENCY_BY_TYPE, CURRENCY_TYPE, ITID, CONSUME_TYPE} from '../../../consts/const';
|
||||||
|
import {getJobInfoById, getMaxGradeByjobClass , getJobByGradeAndClass, getFriendShipById, getHeroInfoById, getFriendShipLevels, getGoodById} from '../../../pubUtils/gamedata';
|
||||||
import { ITID, CONSUME_TYPE } from '../../../consts/consts';
|
import { ITID, CONSUME_TYPE } from '../../../consts/consts';
|
||||||
|
|
||||||
|
const _ = require('underscore');
|
||||||
|
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new HeroHandler(app);
|
return new HeroHandler(app);
|
||||||
}
|
}
|
||||||
@@ -109,49 +113,192 @@ export class HeroHandler {
|
|||||||
// 升品,满品3级
|
// 升品,满品3级
|
||||||
// handleCost
|
// handleCost
|
||||||
}
|
}
|
||||||
//训练 TODO
|
//训练
|
||||||
async heroJobTrain (msg: {hid:number}, session: BackendSession) {
|
async heroJobTrain (msg: {hid:number}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
let { hid } = msg;
|
let { hid } = msg;
|
||||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
if (!hero)
|
if (!hero)
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
return resResult(STATUS.HERO_NOT_FIND);
|
||||||
let heroJob = getJobInfoById(hero.job);
|
let heroJob = getJobInfoById(hero.job);
|
||||||
|
let nextHeroJob = getJobByGradeAndClass(heroJob.job_class, heroJob.grade + 1);
|
||||||
|
if (nextHeroJob.unlockLevel > hero.lv)
|
||||||
|
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
|
||||||
if (hero.jobStage >= 6)
|
if (hero.jobStage >= 6)
|
||||||
return resResult(STATUS.HERO_JOB_STAGE_REACH_MAX_STAGE);
|
return resResult(STATUS.HERO_JOB_STAGE_REACH_MAX_STAGE);
|
||||||
if (hero.job >= getMaxGradeByjobClass(heroJob.job_class))
|
if (hero.job >= getMaxGradeByjobClass(heroJob.job_class))
|
||||||
return resResult(STATUS.HERO_JOB_REACH_MAX_STAGE);
|
return resResult(STATUS.HERO_JOB_REACH_MAX_STAGE);
|
||||||
//消耗物品TODO
|
let cousumeGoods = getItems(heroJob.trainingConsume);
|
||||||
|
let result = await handleCost(roleId, sid, cousumeGoods);
|
||||||
|
if(!result) {
|
||||||
|
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
|
}
|
||||||
hero.jobStage = hero.jobStage ++;
|
hero.jobStage = hero.jobStage ++;
|
||||||
//重算战力并下发
|
//重算战力并下发
|
||||||
let sid: string = session.get('sid');
|
|
||||||
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
|
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||||
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, job : heros[0].job, jobStage : heros[0].jobStage});
|
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, job : heros[0].job, jobStage : heros[0].jobStage});
|
||||||
}
|
}
|
||||||
//进阶 TODO
|
//进阶
|
||||||
async heroJobStageUp() {
|
async heroJobStageUp(msg: {hid:number}, session: BackendSession) {
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
|
let { hid } = msg;
|
||||||
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
|
if (!hero)
|
||||||
|
return resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
let heroJob = getJobInfoById(hero.job);
|
||||||
|
let nextHeroJob = getJobByGradeAndClass(heroJob.job_class, heroJob.grade + 1);
|
||||||
|
if (nextHeroJob.unlockLevel > hero.lv)
|
||||||
|
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
|
||||||
|
if (hero.job >= getMaxGradeByjobClass(heroJob.job_class))
|
||||||
|
return resResult(STATUS.HERO_JOB_REACH_MAX_STAGE);
|
||||||
|
let cousumeGoods = getItems(heroJob.upGradeConsume);
|
||||||
|
let result = await handleCost(roleId, sid, cousumeGoods);
|
||||||
|
if(!result) {
|
||||||
|
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
hero.job = nextHeroJob.job;
|
||||||
|
hero.jobStage = 0;
|
||||||
|
//重算战力并下发
|
||||||
|
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||||
|
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, job : heros[0].job, jobStage : heros[0].jobStage});
|
||||||
}
|
}
|
||||||
|
|
||||||
//激活羁绊 TODO
|
//激活羁绊
|
||||||
async heroConectionActivate() {
|
async heroConectionActivate(msg: {hid:number, id:number}, session: BackendSession) {
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
|
let { hid, id } = msg;
|
||||||
|
let friendShip = getFriendShipById(id);
|
||||||
|
if (friendShip.actorId != hid)
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
|
if (!hero)
|
||||||
|
return resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
if (!!_.findWhere(hero.conections, {id:id}))
|
||||||
|
return resResult(STATUS.HERO_CONECTION_IS_EXIT);
|
||||||
|
if (hero.star < friendShip.level)
|
||||||
|
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
|
||||||
|
let heroIds = friendShip.memberId.split('|');
|
||||||
|
for (let heroId of heroIds) {
|
||||||
|
let member = await HeroModel.findByHidAndRole(heroId, roleId);
|
||||||
|
if(!member)
|
||||||
|
return resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
if (member.star < friendShip.level)
|
||||||
|
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
|
||||||
|
}
|
||||||
|
let result = await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN), count:5000}]);
|
||||||
|
if(!result) {
|
||||||
|
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
hero.conections.push({
|
||||||
|
id : id
|
||||||
|
});
|
||||||
|
//重算战力并下发
|
||||||
|
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||||
|
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, conections : heros[0].conections});
|
||||||
}
|
}
|
||||||
|
|
||||||
//赠送(包括一键赠送)TODO
|
//赠送(包括一键赠送)
|
||||||
async heroGiveFavor() {
|
async heroGiveFavor(msg: {hid:number, items:Array<{id : number,count : number}>}, session: BackendSession) {
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
|
let { hid, items } = msg;
|
||||||
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
|
if (!hero)
|
||||||
|
return resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
let friendShipLevels = getFriendShipLevels();
|
||||||
|
if (friendShipLevels[friendShipLevels.lenth - 1].level <= hero.favourLv)
|
||||||
|
return resResult(STATUS.HERO_FAVOUR_LEVEL_REACH_MAXT);
|
||||||
|
//计算消耗物品转化的经验
|
||||||
|
let exp:number = 0;
|
||||||
|
for (let item of items) {
|
||||||
|
let itemInfo = getGoodById(item.id);
|
||||||
|
if (itemInfo.itid == CONSUME_TYPE.FAVOUR) {
|
||||||
|
exp += itemInfo.value;
|
||||||
|
} else {
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hero.favour += exp;
|
||||||
|
for (let friendShipLevel of friendShipLevels) {
|
||||||
|
if (friendShipLevel.level < hero.favourLv)
|
||||||
|
continue;
|
||||||
|
if (friendShipLevel.exp > hero.favour)
|
||||||
|
break;
|
||||||
|
hero.favour -= friendShipLevel.exp;
|
||||||
|
hero.favourLv++;
|
||||||
|
}
|
||||||
|
let result = await handleCost(roleId, sid, items);
|
||||||
|
if(!result) {
|
||||||
|
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
//重算战力并下发
|
||||||
|
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||||
|
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, favour : heros[0].favour, favourLv : heros[0].favourLv});
|
||||||
}
|
}
|
||||||
|
|
||||||
//购买时装
|
//购买时装
|
||||||
async buyHeroSkin() {
|
async buyHeroSkin(msg: {id:number}, session: BackendSession) {
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
|
let { id } = msg;
|
||||||
|
let skinInfo;//TODO查询时装
|
||||||
|
if (!skinInfo)
|
||||||
|
resResult(STATUS.HERO_SKIN_NOT_FIND);
|
||||||
|
let hid;//TODO获得时装的武将id
|
||||||
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
|
if (!hero)
|
||||||
|
resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
if (!!_.findWhere(hero.skins, {id:id}))
|
||||||
|
resResult(STATUS.HERO_SKIN_IS_EXIST);
|
||||||
|
let items;//TODO物品消耗
|
||||||
|
let result = await handleCost(roleId, sid, items);
|
||||||
|
if(!result) {
|
||||||
|
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
hero.skins.push({
|
||||||
|
id:id,
|
||||||
|
enable:false
|
||||||
|
});
|
||||||
|
let heros = await HeroModel.findByRole(roleId);
|
||||||
|
for (let i = 0; i < heros.lenth; i++) {
|
||||||
|
if (heros[i].hid == hero.hid) {
|
||||||
|
heros[i] = hero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//重算战力并下发
|
||||||
|
await calPlayerCeAndSave(sid, roleId, heros);
|
||||||
|
return resResult(STATUS.SUCCESS, { hid : hero.hid, skins : hero.skins});
|
||||||
}
|
}
|
||||||
|
|
||||||
//穿带时装
|
//穿带时装
|
||||||
async heroWearSkin() {
|
async heroWearSkin(msg: {id:number}, session: BackendSession) {
|
||||||
|
let roleId: string = session.get('roleId');
|
||||||
|
let sid: string = session.get('sid');
|
||||||
|
let { id } = msg;
|
||||||
|
let skinInfo;//TODO查询时装
|
||||||
|
if (!skinInfo)
|
||||||
|
resResult(STATUS.HERO_SKIN_NOT_FIND);
|
||||||
|
let hid;
|
||||||
|
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||||
|
if (!hero)
|
||||||
|
resResult(STATUS.HERO_NOT_FIND);
|
||||||
|
let result = false;
|
||||||
|
for (let skin of hero.skins) {
|
||||||
|
if (skin.id == id) {
|
||||||
|
skin.enable = true;
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
skin.enable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!result) {
|
||||||
|
resResult(STATUS.HERO_SKIN_NOT_FIND);
|
||||||
|
}
|
||||||
|
await calPlayerCeAndSave(sid, roleId, [hero]);
|
||||||
|
return resResult(STATUS.SUCCESS, { hid : hero.hid, skins : hero.skins});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user