活动:调整活动代码路径
This commit is contained in:
131
game-server/app/services/activity/refreshShopService.ts
Normal file
131
game-server/app/services/activity/refreshShopService.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, STATUS, TASK_TYPE } from '../../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityRefreshShopModel, ActivityRefreshShopModelType } from '../../db/ActivityRefreshShop';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { RefreshShopData, RefreshShopItem } from '../../domain/activityField/refreshShopField';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} type 活动类型 ACTIVITY_TYPE
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
|
||||
export async function getRefreshShopActivity(serverId: number, roleId: string) {
|
||||
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
|
||||
let activityArray: ActivityModelType[] = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.REFRESH_SHOP, new Date)
|
||||
if (activityArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
let activityData = activityArray[0];
|
||||
let playerData = new RefreshShopData(activityData);
|
||||
|
||||
let playerRecord: ActivityRefreshShopModelType = await ActivityRefreshShopModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家商店数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerRefreshShopData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerData = new RefreshShopData(activityData);
|
||||
|
||||
let playerRecord: ActivityRefreshShopModelType = await ActivityRefreshShopModel.findData(activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家商店数据(指定回合数,大富翁商店每回合刷新)
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerRefreshShopDataByRoundIndex(activityId: number, serverId: number, roleId: string, roundIndex: number) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerData = new RefreshShopData(activityData);
|
||||
playerData.roundIndex = roundIndex;
|
||||
let playerRecord: ActivityRefreshShopModelType = await ActivityRefreshShopModel.findData(activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家活动第几天
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function newPlayerActivityDays(roleId: string) {
|
||||
let { createTime } = await RoleModel.findByRoleId(roleId);
|
||||
let createDate = moment(createTime * 1000).toDate();
|
||||
let todayIndex = deltaDays(moment(createDate).startOf('d').toDate(), new Date) + 1;
|
||||
return todayIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 结算购买的奖励
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} productID 商品ID
|
||||
* @param {number} roundIndex 大富翁重置回合数
|
||||
*
|
||||
*/
|
||||
export async function makeRefreshShopReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string, roundIndex: number) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (!activityData) {
|
||||
return STATUS.ACTIVITY_MISSING;
|
||||
}
|
||||
if (activityData.type !== ACTIVITY_TYPE.REFRESH_SHOP) {
|
||||
return STATUS.ACTIVITY_TYPE_ERROR;
|
||||
}
|
||||
let playerData = new RefreshShopData(activityData);
|
||||
if (roundIndex) {
|
||||
playerData.roundIndex = roundIndex;
|
||||
}
|
||||
|
||||
let playerRecord: ActivityRefreshShopModelType = await ActivityRefreshShopModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
|
||||
let item = playerData.findItemByProductID(productID);
|
||||
if (!item) {
|
||||
return STATUS.ACTIVITY_NO_PRODUCT;
|
||||
}
|
||||
if (item.countMax > 0 && item.buyCount >= item.countMax) {
|
||||
return STATUS.ACTIVITY_MAX_COUNT;
|
||||
}
|
||||
|
||||
let rewardArray = stringToRewardParam(item.reward)
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
|
||||
await ActivityRefreshShopModel.addRecord(activityId, roleId, playerData.roundIndex, item.pageIndex, item.id);
|
||||
|
||||
item.buyCount += 1;
|
||||
return {
|
||||
code: 0,
|
||||
data: Object.assign(result, { item: item, activityId: activityId })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user