86 lines
3.4 KiB
TypeScript
86 lines
3.4 KiB
TypeScript
import { Application, BackendSession } from 'pinus';
|
|
import { resResult } from '../../../pubUtils/util';
|
|
import { STATUS } from '../../../consts';
|
|
import { getPlayerGrowthFundData, growthFundActivity } from '../../../services/growthFundService';
|
|
import { GrowthFundItem } from '../../../domain/activityField/growthFundField';
|
|
import { addItems, createHeroes } from '../../../services/rewardService';
|
|
import { ActivityGrowthFundModel } from '../../../db/ActivityGrowthFund';
|
|
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
|
|
import { RewardParam } from '../../../domain/activityField/rewardField';
|
|
|
|
|
|
export default function (app: Application) {
|
|
return new GrowthFundHandler(app);
|
|
}
|
|
|
|
export class GrowthFundHandler {
|
|
constructor(private app: Application) {
|
|
}
|
|
|
|
/************************成长基金****************************/
|
|
|
|
/**
|
|
* @description 获取成长基金活动数据
|
|
* @param {{ activityId: number}} msg
|
|
* @param {BackendSession} session
|
|
* @memberof GrowthFundHandler
|
|
*/
|
|
async getGrowthFundActivity(msg: { activityId: number }, session: BackendSession) {
|
|
const { activityId } = msg;
|
|
const roleId = session.get('roleId');
|
|
const serverId = session.get('serverId');
|
|
|
|
let playerData = await getPlayerGrowthFundData(activityId, serverId, roleId);
|
|
|
|
if (!playerData) return resResult(STATUS.ACTIVITY_GROWTH_FUND_END);
|
|
|
|
return resResult(STATUS.SUCCESS, playerData);
|
|
}
|
|
|
|
/**
|
|
* @description 获取成长基金奖励
|
|
* @param {{ activityId: number, pageIndex: number, cellIndex: number}} msg
|
|
* @param {BackendSession} session
|
|
* @memberof GrowthFundHandler
|
|
*/
|
|
async getGrowthFundCellReward(msg: { activityId: number, pageIndex: number, cellIndex: number }, session: BackendSession) {
|
|
const { activityId, pageIndex, 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 playerData = await getPlayerGrowthFundData(activityId, serverId, roleId)
|
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
|
|
|
if (playerData.isVipActivity() && !playerData.isBuy(pageIndex)) {//vip高阶活动,需要购买
|
|
return resResult(STATUS.ACTIVITY_NEED_BUY);
|
|
}
|
|
|
|
let growthFundItemData: GrowthFundItem = playerData.findGrowthFundItem(pageIndex, cellIndex);
|
|
if (!growthFundItemData) {
|
|
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
|
}
|
|
if (!growthFundItemData.isComplete) {//未完成任务
|
|
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED);
|
|
}
|
|
if (growthFundItemData.isReceive) {//已经领取过
|
|
return resResult(STATUS.ACTIVITY_REWARDED);
|
|
}
|
|
|
|
growthFundItemData.isReceive = true;
|
|
|
|
await ActivityGrowthFundModel.addRecord(activityId, roleId, pageIndex, cellIndex);
|
|
|
|
let rewardParamArr: Array<RewardParam> = stringToRewardParam(growthFundItemData.reward);
|
|
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
|
|
|
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
|
param: { activityId, pageIndex, cellIndex },
|
|
item: growthFundItemData
|
|
}));
|
|
}
|
|
|
|
}
|