体力:添加购买体力功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, HERO_GROW_MAX, MSG_SOURCE, JEWEL_PUSH_LV, TASK_TYPE } from "../../../consts";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { STATUS, EQUIP_STRENGTHEN_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, CONSUME_TYPE, HERO_GROW_MAX, MSG_SOURCE, JEWEL_PUSH_LV, TASK_TYPE, DEBUG_MAGIC_WORD } from "../../../consts";
|
||||
import { ItemInter, RewardInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult, parseGoodStr, getRandValueByMinMax, getRandEelm } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost, decreaseItems } from "../../../services/rewardService";
|
||||
@@ -17,7 +17,8 @@ import { indexOf, findIndex } from 'underscore';
|
||||
import { pushEquipRefineSucMsg, pushNormalEquipMsg, pushNormalItemMsg } from "../../../services/chatService";
|
||||
import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, checkTaskConditionEquipSuitJewelStage, checkActivityTask } from "../../../services/taskService";
|
||||
import { useGiftPackage } from "../../../services/activity/giftPackageService";
|
||||
import { getAp, setAp } from "../../../services/actionPointService";
|
||||
import { getAp, setAp, setApBuyTimes } from "../../../services/actionPointService";
|
||||
import { ActionPointModel } from "../../../db/ActionPoint";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new ItemHandler(app);
|
||||
@@ -100,7 +101,52 @@ export class ItemHandler {
|
||||
|
||||
}
|
||||
|
||||
public async debugIncAp(msg: { ap: number }, session: BackendSession) {
|
||||
// 购买体力道具
|
||||
public async buyApItem(msg: { id: number, count: number }, session: BackendSession) {
|
||||
let { id, count } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
|
||||
if(count <= 0) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
if (!dicGoods) {
|
||||
return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
}
|
||||
let dicItid = ITID.get(dicGoods.itid);
|
||||
if (!dicItid) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (dicItid.type != CONSUME_TYPE.AP) {
|
||||
return resResult(STATUS.ROLE_METERIAL_ERROR);
|
||||
}
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId, 'lv');
|
||||
let { buyTimes = 0 } = await getAp(roleId, role.lv);
|
||||
if(buyTimes + count > gameData.apMaxBuyTimes.max) return resResult(STATUS.AP_BUY_TIMES_LACK);
|
||||
|
||||
let cost: RewardInter[] = [];
|
||||
for(let i = 0; i < count; i++) {
|
||||
let curCost = gameData.apBuy.get(++buyTimes);
|
||||
if(curCost) cost = cost.concat(curCost);
|
||||
}
|
||||
|
||||
let consumeResult = await handleCost(roleId, sid, cost);
|
||||
if (!consumeResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, [{id, count}]);
|
||||
let apJson = await setApBuyTimes(roleId, role.lv, sid, count);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
goods, apJson
|
||||
});
|
||||
}
|
||||
|
||||
public async debugIncAp(msg: { magicWord: string, ap: number }, session: BackendSession) {
|
||||
const { magicWord } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
|
||||
const roleId = session.get('roleId');
|
||||
const sid = session.get('sid');
|
||||
const funcs = session.get('funcs');
|
||||
@@ -110,11 +156,28 @@ export class ItemHandler {
|
||||
if(!apJson) return resResult(STATUS.BATTLE_ACTION_POINT_LACK)
|
||||
return resResult(STATUS.SUCCESS, { apJson });
|
||||
}
|
||||
public async debugGetAp(msg: { }, session: BackendSession) {
|
||||
|
||||
public async debugGetAp(msg: { magicWord: string }, session: BackendSession) {
|
||||
const { magicWord } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId, 'lv');
|
||||
let apJson = await getAp(roleId, role.lv);
|
||||
return resResult(STATUS.SUCCESS, { apJson });
|
||||
}
|
||||
|
||||
public async debugResetBuyTimes(msg: { magicWord: string }, session: BackendSession) {
|
||||
const { magicWord } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
return resResult(STATUS.TOKEN_ERR);
|
||||
}
|
||||
let roleId = session.get('roleId');
|
||||
let role = await RoleModel.findByRoleId(roleId, 'lv');
|
||||
await ActionPointModel.resetBuyTimes(roleId);
|
||||
let apJson = await getAp(roleId, role.lv);
|
||||
return resResult(STATUS.SUCCESS, { apJson });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user