合成藏宝图,消耗品单独开表
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { IT_TYPE } from '../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality } from '../../../pubUtils/gamedata';
|
||||
import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality } from '../../../pubUtils/gamedata';
|
||||
import { COM_TEAM_STATUS, COM_TEAM_ENABLE_LV } from '../../../consts/consts';
|
||||
import { ComBattleTeamModel } from '../../../db/ComBattleTeam';
|
||||
import Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { Application, BackendSession, BlackListFunction } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { resResult, getRandomByLen, calculateNum } from '../../../pubUtils/util';
|
||||
import { RoleStatus } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { handleReward } from '../../../services/rewardService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -52,9 +54,10 @@ export class ComBattleHandler {
|
||||
if (!goodData || goodData.itid !== IT_TYPE.BLUEPRT) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
|
||||
|
||||
// 检查藏宝图是否足够
|
||||
let { consumeGoods, lv, headHid, topFiveCe, sHid } = await RoleModel.findByRoleId(roleId);
|
||||
let { lv, headHid, topFiveCe, sHid } = await RoleModel.findByRoleId(roleId);
|
||||
if (lv < COM_TEAM_ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||
let blueprt = consumeGoods.find(good => good.id === blueprtId && good.count >= 1);
|
||||
|
||||
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
||||
if (!blueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_FOUND);
|
||||
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
||||
let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
|
||||
@@ -410,4 +413,60 @@ export class ComBattleHandler {
|
||||
|
||||
// return resResult(STATUS.SUCCESS, { bossHp: this.bossHp});
|
||||
// }
|
||||
|
||||
|
||||
|
||||
async composeBlueprt(msg: {original: Array<{id: number, count: number}>}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const { original } = msg;
|
||||
|
||||
// 原材料检查
|
||||
let originalQuality: number, originalSum: number;
|
||||
for(let {id, count} of original) {
|
||||
const goodInfo = getGoodById(id);
|
||||
if(!originalQuality) originalQuality = goodInfo.quality;
|
||||
if(originalQuality != goodInfo.quality) {
|
||||
return resResult(STATUS.COM_BLUEPRT_QUALITY_ERROR);
|
||||
}
|
||||
|
||||
if(goodInfo.itid == IT_TYPE.BLUEPRT) {
|
||||
originalSum += count;
|
||||
}
|
||||
}
|
||||
|
||||
const dicCompose = getBlueprtComposeByQuality(originalQuality);
|
||||
if(!dicCompose) {
|
||||
return resResult(STATUS.COM_BLUEPRT_QUALITY_CANNOT_COMPOSE);
|
||||
}
|
||||
if(originalSum != dicCompose.blueprtNum) {
|
||||
return resResult(STATUS.COM_BLUEPRT_COUNT_ERROR);
|
||||
}
|
||||
// 检查元宝
|
||||
const role = await RoleModel.findByRoleId(roleId);
|
||||
const costGold = calculateNum(GOLD_COST_RATIO.BLUEPRT_COMPOSE_COST, {num: originalQuality}, 1000);
|
||||
if(!role || role.gold < costGold) {
|
||||
return resResult(STATUS.TOWER_GOLD_NOT_ENOUGH);
|
||||
}
|
||||
// 添加寻宝币
|
||||
original.push({
|
||||
id: CURRENCY_BY_TYPE[CURRENCY_TYPE.TREASURE_POINT],
|
||||
count: dicCompose.coinNum
|
||||
});
|
||||
// 消耗藏宝图和寻宝币
|
||||
const rec = await ItemModel.decreaseItems(roleId, original);
|
||||
if(!rec) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
// 消耗元宝
|
||||
await RoleModel.costGold(roleId, costGold);
|
||||
|
||||
const targetList = getBluePrtByQuality(dicCompose.targetQuality);
|
||||
const target = getRandomByLen(targetList);
|
||||
const reward = [{gid: target, count: 1}];
|
||||
const goods = await handleReward(roleId, roleName, reward);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user