活动:成长基金-主线
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, ACTIVITY_RESOURCES_TYPE } 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';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
return new SevenDaysHandler(app);
|
||||
}
|
||||
|
||||
export class SevenDaysHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************成长基金****************************/
|
||||
|
||||
/**
|
||||
* @description 获取成长基金活动数据
|
||||
* @param {{ type: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthFundActivity(msg: { type: number }, session: BackendSession) {
|
||||
const { type } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await growthFundActivity(type, 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 SevenDaysHandler
|
||||
*/
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
await ActivityGrowthFundModel.addRecord(activityId, roleId, pageIndex, cellIndex);
|
||||
let reward = growthFundItemData.goodReward();
|
||||
let goods = await addItems(roleId, roleName, sid, reward);
|
||||
let heroReward = growthFundItemData.heroReward();
|
||||
let addHeros = [];
|
||||
if (heroReward.length > 0) {
|
||||
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||
goods = goods.concat(heroResult.goods)
|
||||
addHeros = addHeros.concat(heroResult.heroes);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods, addHeros });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user