活动:添加节日活动-刷新商店、刷新任务
This commit is contained in:
@@ -510,7 +510,8 @@ export class ActivityHandler {
|
||||
// await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.ROLE_LV, 100)
|
||||
// await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.PVP, 1)
|
||||
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.BATTLE_TOWER_LV, 1, { towerLv: lv })
|
||||
// await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.BATTLE_TOWER_LV, 1, { towerLv: lv })
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.GASHA, 1)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -123,13 +123,14 @@ export class DailyCoinHandler {
|
||||
}
|
||||
|
||||
//免费期间
|
||||
let time = moment(new Date()).valueOf();
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, newReward)
|
||||
await ActivityDailyCoinModel.addExchangeRecord(serverId, activityId, roleId, playerData.beginTime, count, addCoin, `${count}&${consumeGold}&${addCoin}&${moment(new Date().valueOf())}`);
|
||||
await ActivityDailyCoinModel.addExchangeRecord(serverId, activityId, roleId, playerData.beginTime, count, addCoin, `${count}&${consumeGold}&${addCoin}&${time}`);
|
||||
|
||||
let exchangeCount = playerData.exchangeCount + count;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, count },
|
||||
item: { exchangeCount, recordMsg: `${count}&${consumeGold}&${addCoin}`, rateArray },
|
||||
item: { exchangeCount, recordMsg: `${count}&${consumeGold}&${addCoin}&${time}`, rateArray },
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { deltaDays, resResult } from '../../../pubUtils/util';
|
||||
import { ACTIVITY_TYPE, STATUS } from '../../../consts';
|
||||
import { getRefreshShopActivity, getPlayerRefreshShopData } from '../../../services/refreshShopService';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { ActivityRefreshShopModel } from '../../../db/ActivityRefreshShop';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import moment = require('moment');
|
||||
|
||||
export default function (app: Application) {
|
||||
return new RefreshShopHandler(app);
|
||||
}
|
||||
|
||||
export class RefreshShopHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************通用的刷新商店(分页,可刷新,限制购买次数,支持rmb与资源兑换)****************************/
|
||||
|
||||
/**
|
||||
* @description 获取商店数据
|
||||
* @param {{ activityId:number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshShopHandler
|
||||
*/
|
||||
async getRefreshShopActivity(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await getRefreshShopActivity(serverId, roleId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 购买
|
||||
* @param {{ activityId: number, roundIndex: number, id: number, pageIndex: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshShopHandler
|
||||
*/
|
||||
async buyGood(msg: { activityId: number, roundIndex: number, id: number, pageIndex: number }, session: BackendSession) {
|
||||
const { activityId, roundIndex, id, pageIndex } = 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 getPlayerRefreshShopData(activityId, serverId, roleId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
|
||||
if (playerData.roundIndex != roundIndex) {
|
||||
return resResult(STATUS.ACTIVITY_EXPIRE);
|
||||
}
|
||||
|
||||
let item = playerData.findItem(id, pageIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_ID_ERROR);
|
||||
}
|
||||
if (item.countMax > 0 && item.buyCount >= item.countMax) {
|
||||
return resResult(STATUS.ACTIVITY_MAX_COUNT);
|
||||
}
|
||||
if (item.price > 0) {
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
|
||||
//检查资源
|
||||
let consume = stringToConsumeParam(item.consume)
|
||||
let consumeResult = await handleCost(roleId, sid, consume);
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let rewardArray = stringToRewardParam(item.reward)
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
|
||||
await ActivityRefreshShopModel.addRecord(activityId, roleId, roundIndex, pageIndex, id);
|
||||
|
||||
item.buyCount += 1;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, roundIndex, id },
|
||||
item: item
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { getPlayerRefreshTaskData } from '../../../services/refreshTaskService';
|
||||
import { RefreshTaskItem } from '../../../domain/activityField/refreshTaskField';
|
||||
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityRefreshTaskModel } from '../../../db/ActivityRefreshTask';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
return new RefreshTaskHandler(app);
|
||||
}
|
||||
|
||||
export class RefreshTaskHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************通用的刷新任务(分页,可刷新,限制领取次数)****************************/
|
||||
|
||||
/**
|
||||
* @description 获取任务活动数据
|
||||
* @param {{ activityId: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshTaskHandler
|
||||
*/
|
||||
async getRefreshTaskActivity(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await getPlayerRefreshTaskData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取奖励
|
||||
* @param {{ activityId: number, roundIndex: number, pageIndex: number,id: number, type: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshTaskHandler
|
||||
*/
|
||||
async getReward(msg: { activityId: number, roundIndex: number, pageIndex: number, id: number, type: number }, session: BackendSession) {
|
||||
const { activityId, roundIndex, pageIndex, id, type } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs = session.get('funcs');
|
||||
|
||||
let playerData = await getPlayerRefreshTaskData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
if (playerData.roundIndex != roundIndex) {
|
||||
return resResult(STATUS.ACTIVITY_EXPIRE);
|
||||
}
|
||||
let dailyItemData: RefreshTaskItem = playerData.findItem(pageIndex, id, type);
|
||||
if (!dailyItemData) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
if (dailyItemData.totalCount < dailyItemData.condition) {//未完成任务
|
||||
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED);
|
||||
}
|
||||
if (dailyItemData.receiveRewardCount) {//已经领取过
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
|
||||
await ActivityRefreshTaskModel.addReceiveRecord(serverId, activityId, roleId, roundIndex, pageIndex, id, type, 1);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(dailyItemData.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
dailyItemData.receiveRewardCount += 1;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, roundIndex, pageIndex, id, type },
|
||||
item: dailyItemData,
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user