活动:寻宝骑兵-每日物资

This commit is contained in:
qiaoxin
2021-05-25 22:05:28 +08:00
parent ebeb22f630
commit f8f9d9d120
4 changed files with 98 additions and 17 deletions

View File

@@ -1,7 +1,11 @@
import { Application, BackendSession } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { STATUS, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../../consts';
import { getPlayerTreasureHuntData, getTreasureHuntData } from '../../../services/treasureHuntService';
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData } from '../../../services/treasureHuntService';
import { ActivityTreasureHuntShopModel } from '../../../db/ActivityTreasureHuntShop';
import { handleCost } from '../../../services/rewardService';
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
import { RewardParam } from '../../../domain/activityField/rewardField';
export default function (app: Application) {
@@ -38,10 +42,14 @@ export class TreasureHuntHandler {
* @param {BackendSession} session
* @memberof TreasureHuntHandler
*/
async buyGoods(msg: { activityId: number }, session: BackendSession) {
const { activityId } = msg;
async buyGoods(msg: { activityId: number, cellIndex: number }, session: BackendSession) {
const { activityId, cellIndex } = msg;
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const sid = session.get('sid');
const roleName = session.get('roleName');
const funcs: number[] = session.get('funcs');
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
if (!activityData) {
return resResult(STATUS.ACTIVITY_MISSING, {});
@@ -50,9 +58,34 @@ export class TreasureHuntHandler {
return resResult(STATUS.ACTIVITY_MISSING, {});
}
let playerData = await getPlayerTreasureHuntData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
let item = playerData.shop.getItem(cellIndex);
if (!item) {
return resResult(STATUS.ACTIVITY_MISSING, {});
}
if (item.price >= 0) {
return resResult(STATUS.ACTIVITY_NEED_PAY, {});
}
if (item.buyCount >= item.countMax) {
return resResult(STATUS.ACTIVITY_MAX_COUNT, {});
}
return resResult(STATUS.SUCCESS, playerData);
let consumeStr = item.getConsume();
let consume = stringToConsumeParam(consumeStr)
let resourceResult = await handleCost(roleId, sid, consume);
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
//添加购买记录
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, huntRoundIndex, playerData.todayIndex, cellIndex);
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
item.buyCount += 1;
return resResult(STATUS.SUCCESS, Object.assign(result, {
param: { activityId, cellIndex },
item: item,
}));
}
}