活动:寻宝骑兵领取奖励接口
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../../consts';
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData } from '../../../services/treasureHuntService';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData } from '../../../services/treasureHuntService';
|
||||
import { ActivityTreasureHuntShopModel } from '../../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel } from '../../../db/ActivityTreasureHuntTask';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityTreasureHuntTreasureShopModel } from '../../../db/ActivityTreasureHuntTreasureShop';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -92,4 +94,130 @@ export class TreasureHuntHandler {
|
||||
item: item,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵获取寻宝备战的任务奖励
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async getTaskReward(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, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntTaskData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.tasks.getItem(cellIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (item.condition > item.totalCount) {
|
||||
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED, {});
|
||||
}
|
||||
if (item.isReceive) {
|
||||
return resResult(STATUS.ACTIVITY_REWARDED, {});
|
||||
}
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTaskModel.receiveReward(serverId, activityId, roleId, huntRoundIndex, cellIndex, 1);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
item.isReceive = true;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, cellIndex },
|
||||
item: item,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵寻宝大冒险挑战
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async challenge(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, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntChallengeData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, Object.assign({}, {
|
||||
param: { activityId, cellIndex },
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵购买天子宝库商店中的商品
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async buyTreasureShopGoods(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, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntTreasureShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.treasureShop.getItem(cellIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (item.buyCount >= item.countMax) {
|
||||
return resResult(STATUS.ACTIVITY_MAX_COUNT, {});
|
||||
}
|
||||
|
||||
let consumeStr = item.consume;
|
||||
let consume = stringToConsumeParam(consumeStr)
|
||||
let resourceResult = await handleCost(roleId, sid, consume);
|
||||
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTreasureShopModel.addRecord(activityId, roleId, huntRoundIndex, 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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME, TASK_TYPE } from '../consts';
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModel, ActivityTreasureHuntTreasureShopModelType } from '../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
|
||||
import { RewardParam } from '../domain/activityField/rewardField';
|
||||
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
|
||||
import { deltaDays } from '../pubUtils/util';
|
||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -45,7 +45,12 @@ export async function getPlayerTreasureHuntData(activityId: number, serverId: nu
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerRecords(playerShopRecord);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
let playerTreasureShopRecord: ActivityTreasureHuntTreasureShopModelType = await ActivityTreasureHuntTreasureShopModel.findData(activityId, roleId, huntRoundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
@@ -59,7 +64,47 @@ export async function getPlayerTreasureHuntShopData(activityId: number, serverId
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerRecords(playerShopRecord);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTaskData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntChallengeData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTreasureShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerTreasureShopRecord: ActivityTreasureHuntTreasureShopModelType = await ActivityTreasureHuntTreasureShopModel.findData(activityId, roleId, huntRoundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user