活动:神州探秘活动
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { ITEM_CHANGE_REASON, STATUS, } from '../../../consts';
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData, getPlayerTreasureHuntFirstPageData } from '../../../services/activity/treasureHuntService';
|
||||
import { getPlayerTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData, getPlayerTreasureHuntFirstPageData } from '../../../services/activity/treasureHuntService';
|
||||
import { ActivityTreasureHuntShopModel } from '../../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel } from '../../../db/ActivityTreasureHuntTask';
|
||||
import { handleCost } from '../../../services/role/rewardService';
|
||||
@@ -37,11 +37,7 @@ export class TreasureHuntHandler {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
let playerData = await getPlayerTreasureHuntData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime);
|
||||
let playerData = await getPlayerTreasureHuntData(activityId, serverId, roleId);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
@@ -58,17 +54,8 @@ export class TreasureHuntHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntFirstPageData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
let playerData = await getPlayerTreasureHuntFirstPageData(activityId, serverId, roleId);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
if (playerData.firstPage.isReceive) {
|
||||
@@ -76,7 +63,7 @@ export class TreasureHuntHandler {
|
||||
}
|
||||
|
||||
//添加领取记录
|
||||
await ActivityTreasureHuntFirstPageModel.receiveReward(serverId, activityId, roleId, huntRoundIndex);
|
||||
await ActivityTreasureHuntFirstPageModel.receiveReward(serverId, activityId, roleId, playerData.roundIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(playerData.firstPage.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.TREASURE_HUNT_FIRST_PAGE_REWARD)
|
||||
@@ -100,16 +87,7 @@ export class TreasureHuntHandler {
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.shop.getItem(cellIndex);
|
||||
if (!item) {
|
||||
@@ -128,7 +106,7 @@ export class TreasureHuntHandler {
|
||||
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, huntRoundIndex, playerData.todayIndex, cellIndex);
|
||||
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, playerData.roundIndex, playerData.todayIndex, cellIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.TREASURE_HUNT_SHOP_BUY)
|
||||
@@ -151,17 +129,8 @@ export class TreasureHuntHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
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,);
|
||||
let playerData = await getPlayerTreasureHuntTaskData(activityId, serverId, roleId);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.tasks.getItem(cellIndex);
|
||||
if (!item) {
|
||||
@@ -175,7 +144,7 @@ export class TreasureHuntHandler {
|
||||
}
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTaskModel.receiveReward(serverId, activityId, roleId, huntRoundIndex, cellIndex, 1);
|
||||
await ActivityTreasureHuntTaskModel.receiveReward(serverId, activityId, roleId, playerData.roundIndex, cellIndex, 1);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.TREASURE_HUNT_TASK_REWARD)
|
||||
@@ -198,17 +167,8 @@ export class TreasureHuntHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
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,);
|
||||
let playerData = await getPlayerTreasureHuntChallengeData(activityId, serverId, roleId,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let challengeData = playerData.challenge;
|
||||
//消耗资源
|
||||
@@ -222,7 +182,7 @@ export class TreasureHuntHandler {
|
||||
let warId = playerData.challenge.resultWarId;
|
||||
if(!warId) {
|
||||
warId = playerData.challenge.randomGK();
|
||||
await ActivityTreasureHuntChallengeModel.setWarId(serverId, activityId, roleId, huntRoundIndex, warId);
|
||||
await ActivityTreasureHuntChallengeModel.setWarId(serverId, activityId, roleId, playerData.roundIndex, warId);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, Object.assign({ warId }, {
|
||||
@@ -241,17 +201,8 @@ export class TreasureHuntHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
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,);
|
||||
let playerData = await getPlayerTreasureHuntTreasureShopData(activityId, serverId, roleId,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.treasureShop.getItem(cellIndex);
|
||||
if (!item) {
|
||||
@@ -267,7 +218,7 @@ export class TreasureHuntHandler {
|
||||
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTreasureShopModel.addRecord(activityId, roleId, huntRoundIndex, cellIndex);
|
||||
await ActivityTreasureHuntTreasureShopModel.addRecord(activityId, roleId, playerData.roundIndex, cellIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.TREASURE_HUNT_SP_SHOP_BUY)
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getPlayerVipRechargeMoneyData, } from './vipRechargeMoneyService';
|
||||
import { getPlayerActivityData, } from './selfServiceShopActivityService';
|
||||
import { ActivitySelfServiceGoodsModel } from '../../db/ActivitySelfServiceGoods';
|
||||
import moment = require('moment');
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData } from './treasureHuntService';
|
||||
import { getPlayerTreasureHuntDataShow } from './treasureHuntService';
|
||||
import { getPopUpShopDataShow } from './popUpShopService';
|
||||
import { getPlayerSevenDaysData } from './sevenDaysService';
|
||||
import { getPlayerDailyMealData } from './dailyMealService';
|
||||
@@ -123,8 +123,7 @@ export async function getActivity(serverId: number, roleId: string, guildCode: s
|
||||
}
|
||||
case ACTIVITY_TYPE.TREASURE_HUNT://寻宝骑兵活动 23
|
||||
{
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getTreasureHuntData(serverId, roleId);
|
||||
activityData = await getPlayerTreasureHuntData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime);
|
||||
activityData = await getPlayerTreasureHuntDataShow(activityId, serverId, roleId);
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.POP_UP_SHOP://弹出商店 24
|
||||
|
||||
@@ -1,86 +1,23 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, ITEM_CHANGE_REASON, SERVER_OPEN_TIME, STATUS } 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 { ActivityTreasureHuntFirstPageModel, ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasureHuntFirstPage';
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { ServerTempModel, ServerTempModelType } from '../../db/ServerTemp';
|
||||
import { ITEM_CHANGE_REASON, STATUS, TREASURE_HUNT_DATA_TYPE } from '../../consts';
|
||||
import { ActivityTreasureHuntShopModel } from '../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel } from '../../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModel } from '../../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ActivityTreasureHuntFirstPageModel } from '../../db/ActivityTreasureHuntFirstPage';
|
||||
import { TreasureHuntData } from '../../domain/activityField/treasureHuntField';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from './giftPackageService';
|
||||
import { RewardParam } from '../../domain/activityField/rewardField';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { getActivitiesByType, getActivityById } from './activityService';
|
||||
import { getActivityById, getActivityByServerId } from './activityService';
|
||||
import { getRoleCreateTime, getServerCreateTime } from '../redisService';
|
||||
import { handleCost } from '../role/rewardService';
|
||||
import { ActivityTreasureHuntChallengeModel } from '../../db/ActivityTreasureHuntChallenge';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} type 活动类型 ACTIVITY_TYPE
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
|
||||
export async function treasureHuntActivity(serverId: number, roleId: string) {
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return null;
|
||||
export async function getPlayerTreasureHuntDataShow(activityId: number, serverId: number, roleId: string) {
|
||||
let playerData = await getPlayerTreasureHuntData(activityId, serverId, roleId);
|
||||
if(playerData && playerData.canShow && playerData.canShow()) {
|
||||
return playerData.getShowResult();
|
||||
}
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 playerTreasureFirstPageecord: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityData.activityId, roleId, huntRoundIndex);
|
||||
playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageecord);
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityData.activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityData.activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
let playerTreasureShopRecord: ActivityTreasureHuntTreasureShopModelType = await ActivityTreasureHuntTreasureShopModel.findData(activityData.activityId, roleId, huntRoundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
|
||||
return playerData;
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} type 活动类型 ACTIVITY_TYPE
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
|
||||
export async function treasureHuntTaskActivity(serverId: number, roleId: string) {
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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, activityData.activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家活动数据
|
||||
*
|
||||
@@ -89,234 +26,56 @@ export async function treasureHuntTaskActivity(serverId: number, roleId: string)
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerTreasureHuntData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
export async function getPlayerTreasureHuntData(activityId: number, serverId: number, roleId: string, dataType: TREASURE_HUNT_DATA_TYPE = TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 playerTreasureFirstPageecord: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageecord);
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
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);
|
||||
if(dataType == TREASURE_HUNT_DATA_TYPE.FIRST_PAGE || dataType == TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let playerTreasureFirstPageRecord = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityId, roleId, playerData.roundIndex);
|
||||
playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageRecord);
|
||||
}
|
||||
if (dataType == TREASURE_HUNT_DATA_TYPE.SHOP || dataType == TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let playerShopRecord = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, playerData.roundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
}
|
||||
if (dataType == TREASURE_HUNT_DATA_TYPE.TASK || dataType == TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let playerTaskRecord = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, playerData.roundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
}
|
||||
if(dataType == TREASURE_HUNT_DATA_TYPE.TREASURE_SHOP || dataType == TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let playerTreasureShopRecord = await ActivityTreasureHuntTreasureShopModel.findData(activityId, roleId, playerData.roundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
}
|
||||
if(dataType == TREASURE_HUNT_DATA_TYPE.CHALLENGE || dataType == TREASURE_HUNT_DATA_TYPE.ALL) {
|
||||
let playerRecord = await ActivityTreasureHuntChallengeModel.findData(serverId, activityId, roleId, playerData.roundIndex);
|
||||
playerData.challenge.setChallengeRecord(playerRecord)
|
||||
}
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntFirstPageData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 playerTreasureFirstPageecord: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageecord);
|
||||
return playerData;
|
||||
export async function getPlayerTreasureHuntFirstPageData(activityId: number, serverId: number, roleId: string) {
|
||||
return await getPlayerTreasureHuntData(activityId, serverId, roleId, TREASURE_HUNT_DATA_TYPE.FIRST_PAGE);
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
return playerData;
|
||||
export async function getPlayerTreasureHuntShopData(activityId: number, serverId: number, roleId: string) {
|
||||
return await getPlayerTreasureHuntData(activityId, serverId, roleId, TREASURE_HUNT_DATA_TYPE.SHOP);
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTaskData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 getPlayerTreasureHuntTaskData(activityId: number, serverId: number, roleId: string) {
|
||||
return await getPlayerTreasureHuntData(activityId, serverId, roleId, TREASURE_HUNT_DATA_TYPE.TREASURE_SHOP);
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntChallengeData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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 playerRecord = await ActivityTreasureHuntChallengeModel.findData(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.challenge.setChallengeRecord(playerRecord)
|
||||
|
||||
return playerData;
|
||||
export async function getPlayerTreasureHuntChallengeData(activityId: number, serverId: number, roleId: string) {
|
||||
return await getPlayerTreasureHuntData(activityId, serverId, roleId, TREASURE_HUNT_DATA_TYPE.CHALLENGE);
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTreasureShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new TreasureHuntData(activityData, createTime, serverTime);
|
||||
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;
|
||||
export async function getPlayerTreasureHuntTreasureShopData(activityId: number, serverId: number, roleId: string) {
|
||||
return await getPlayerTreasureHuntData(activityId, serverId, roleId, TREASURE_HUNT_DATA_TYPE.TREASURE_SHOP);
|
||||
}
|
||||
|
||||
//获取当前活动的周期等数据
|
||||
export async function getTreasureHuntData(serverId: number, roleId: string) {
|
||||
let tempData: ServerTempModelType = await ServerTempModel.findData(serverId);
|
||||
let now = moment(new Date()).toDate();
|
||||
let activityData: ActivityModelType = null; //当前活动数据
|
||||
|
||||
if (!tempData) {//开始新周期
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = await getNewActivityData(serverId, roleId);
|
||||
if (huntActivityId === 0) {
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
|
||||
}
|
||||
tempData = await ServerTempModel.updateTreasureHuntData(serverId, huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex);
|
||||
activityData = await getActivityById(huntActivityId);
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
|
||||
}
|
||||
if (now > tempData.huntEndTime) {//活动过期
|
||||
let data = await getNextActivityData(serverId, roleId, tempData.huntActivityId, tempData.huntEndTime, tempData.huntRoundIndex);
|
||||
if(!data) {
|
||||
return { activityData: null }
|
||||
}
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } = data;
|
||||
if (huntActivityId === 0) {
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
|
||||
}
|
||||
tempData = await ServerTempModel.updateTreasureHuntData(serverId, huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex);
|
||||
activityData = await getActivityById(huntActivityId);
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData }
|
||||
}
|
||||
if (!activityData) {
|
||||
activityData = await getActivityById(tempData.huntActivityId);
|
||||
}
|
||||
return {
|
||||
huntActivityId: tempData.huntActivityId,
|
||||
huntBeginTime: tempData.huntBeginTime,
|
||||
huntEndTime: tempData.huntEndTime,
|
||||
huntRoundIndex: tempData.huntRoundIndex,
|
||||
activityData
|
||||
}
|
||||
}
|
||||
|
||||
async function getNewActivityData(serverId: number, roleId: string) {
|
||||
let huntActivityId: number = 0; // 寻宝骑兵-活动Id
|
||||
let huntEndTime: Date = null; // 寻宝骑兵-结束时间
|
||||
let huntRoundIndex: number = 0; // 寻宝骑兵-周期数
|
||||
let activityArray = await getActivitiesByType(serverId, ACTIVITY_TYPE.TREASURE_HUNT);
|
||||
let treasureHuntDataArray: TreasureHuntData[] = [];
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
for (let obj of activityArray) {
|
||||
treasureHuntDataArray.push(new TreasureHuntData(obj, createTime, serverTime));
|
||||
}
|
||||
let isOver = false;
|
||||
let huntBeginTime = moment(SERVER_OPEN_TIME).startOf('d').add(1, 'd').toDate();
|
||||
let curDate = moment(new Date()).toDate()
|
||||
while (!isOver) {
|
||||
huntRoundIndex++;
|
||||
for (let data of treasureHuntDataArray) {
|
||||
let endTime = moment(huntBeginTime).add(data.day, 'd').toDate();
|
||||
if (huntBeginTime < curDate && curDate < endTime) {
|
||||
huntEndTime = moment(endTime).add(-1, 'm').toDate()
|
||||
huntActivityId = data.activityId;
|
||||
isOver = true;
|
||||
} else {
|
||||
huntBeginTime = endTime;
|
||||
}
|
||||
}
|
||||
if (huntRoundIndex >= 365) {//max
|
||||
isOver = true;
|
||||
}
|
||||
}
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex }
|
||||
}
|
||||
|
||||
async function getNextActivityData(serverId: number, roleId: string, oldHuntActivityId: number, oldHuntEndTime: Date, oldHuntRoundIndex: number) {
|
||||
let huntActivityId: number = 0; // 寻宝骑兵-活动Id
|
||||
let huntEndTime: Date = null; // 寻宝骑兵-结束时间
|
||||
let huntRoundIndex: number = oldHuntRoundIndex; // 寻宝骑兵-周期数
|
||||
let activityArray = await getActivitiesByType(serverId, ACTIVITY_TYPE.TREASURE_HUNT);
|
||||
let treasureHuntDataArray: TreasureHuntData[] = [];
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
for (let obj of activityArray) {
|
||||
treasureHuntDataArray.push(new TreasureHuntData(obj, createTime, serverTime));
|
||||
}
|
||||
let isOver = false;
|
||||
let huntBeginTime = moment(oldHuntEndTime).add(1, 'd').startOf('d').toDate();
|
||||
let curDate = moment(new Date()).toDate()
|
||||
|
||||
let index = treasureHuntDataArray.findIndex(obj => { return obj && obj.activityId === oldHuntActivityId });
|
||||
if(index == -1) {
|
||||
return null
|
||||
}
|
||||
for (; index < treasureHuntDataArray.length; index++) {
|
||||
let data = treasureHuntDataArray[index];
|
||||
let endTime = moment(huntBeginTime).add(data.day, 'd').toDate();
|
||||
if (huntBeginTime < curDate && curDate < endTime) {
|
||||
huntEndTime = moment(endTime).add(-1, 'm').toDate()
|
||||
huntActivityId = data.activityId;
|
||||
isOver = true;
|
||||
} else {
|
||||
huntBeginTime = endTime;
|
||||
}
|
||||
}
|
||||
|
||||
while (!isOver) {
|
||||
huntRoundIndex++;
|
||||
for (let data of treasureHuntDataArray) {
|
||||
let endTime = moment(huntBeginTime).add(data.day, 'd').toDate();
|
||||
if (huntBeginTime < curDate && curDate < endTime) {
|
||||
huntEndTime = moment(endTime).add(-1, 'm').toDate()
|
||||
huntActivityId = data.activityId;
|
||||
isOver = true;
|
||||
} else {
|
||||
huntBeginTime = endTime;
|
||||
}
|
||||
}
|
||||
if (huntRoundIndex >= 365) {//max
|
||||
isOver = true;
|
||||
}
|
||||
}
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 购买每日物资
|
||||
*
|
||||
@@ -329,14 +88,7 @@ async function getNextActivityData(serverId: number, roleId: string, oldHuntActi
|
||||
export async function makeShop(roleId: string, roleName: string, sid: string, serverId: number,
|
||||
activityId: number, productID: string) {
|
||||
// let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
}
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId,);
|
||||
if (!playerData) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
@@ -358,7 +110,7 @@ export async function makeShop(roleId: string, roleName: string, sid: string, se
|
||||
let cellIndex = item.cellIndex;
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, huntRoundIndex, playerData.todayIndex, cellIndex);
|
||||
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, playerData.roundIndex, playerData.todayIndex, cellIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.TREASURE_HUNT_SHOP_BUY)
|
||||
@@ -371,22 +123,22 @@ export async function makeShop(roleId: string, roleName: string, sid: string, se
|
||||
}
|
||||
|
||||
export async function treasureHuntChallengeConsume(serverId: number, roleId: string, sid: string) {
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId, roleId);
|
||||
if (!activityData) {
|
||||
return false;
|
||||
let activities = await getActivityByServerId(serverId);
|
||||
for(let { activityId } of activities) {
|
||||
let playerData = await getPlayerTreasureHuntChallengeData(activityId, serverId, roleId,);
|
||||
if (!playerData) return false;
|
||||
|
||||
if(playerData.canShow()) {
|
||||
let challengeData = playerData.challenge;
|
||||
//消耗资源
|
||||
let consumeStr = challengeData.consume;
|
||||
let consume = stringToConsumeParam(consumeStr)
|
||||
let resourceResult = await handleCost(roleId, sid, consume, ITEM_CHANGE_REASON.TREASURE_HUNT_CHALLENGE);
|
||||
if (!resourceResult) return false;
|
||||
|
||||
let warId = playerData.challenge.randomGK();
|
||||
await ActivityTreasureHuntChallengeModel.setWarId(serverId, activityId, roleId, playerData.roundIndex, warId);
|
||||
}
|
||||
}
|
||||
let playerData = await getPlayerTreasureHuntChallengeData(huntActivityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return false;
|
||||
|
||||
let challengeData = playerData.challenge;
|
||||
//消耗资源
|
||||
let consumeStr = challengeData.consume;
|
||||
let consume = stringToConsumeParam(consumeStr)
|
||||
let resourceResult = await handleCost(roleId, sid, consume, ITEM_CHANGE_REASON.TREASURE_HUNT_CHALLENGE);
|
||||
if (!resourceResult) return false;
|
||||
|
||||
let warId = playerData.challenge.randomGK();
|
||||
await ActivityTreasureHuntChallengeModel.setWarId(serverId, huntActivityId, roleId, huntRoundIndex, warId);
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import { ActivityRefreshTaskModel } from "../../db/ActivityRefreshTask";
|
||||
import { ActivityThirtyDaysModel } from "../../db/ActivityThirtyDays";
|
||||
import { ActivityTreasureHuntTaskModel } from "../../db/ActivityTreasureHuntTask";
|
||||
import { RoleModel, RoleType } from "../../db/Role";
|
||||
import { ServerTempModel, ServerTempModelType } from "../../db/ServerTemp";
|
||||
import { UserTaskRecModel } from "../../db/UserTaskRec";
|
||||
import { GrowthFundData } from "../../domain/activityField/growthFundField";
|
||||
import { RefreshTaskData } from "../../domain/activityField/refreshTaskField";
|
||||
@@ -36,7 +35,6 @@ export class CheckTask {
|
||||
taskPushMessages: TaskListReturn[] = [];
|
||||
activityTaskPushMessages = [];
|
||||
|
||||
treasureHuntTemp: ServerTempModelType;
|
||||
tasks: CheckSingleTask[] = [];
|
||||
|
||||
constructor(serverId: number, roleId: string) {
|
||||
@@ -86,19 +84,6 @@ export class CheckTask {
|
||||
return this.roleCreateTime;
|
||||
}
|
||||
|
||||
// 神州探秘活动
|
||||
async getTreasureHuntTemp() {
|
||||
if(this.treasureHuntTemp) return this.treasureHuntTemp;
|
||||
|
||||
let tempData: ServerTempModelType = await ServerTempModel.findData(this.serverId);
|
||||
if (tempData) {
|
||||
this.treasureHuntTemp = tempData;
|
||||
return tempData
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// 推送
|
||||
public async pushMessage(sid?: string) {
|
||||
let roleId = this.roleId;
|
||||
@@ -259,20 +244,17 @@ export class CheckSingleTask {
|
||||
case ACTIVITY_TYPE.TREASURE_HUNT:
|
||||
{
|
||||
// 寻宝奇兵任务
|
||||
let tempData = await this.parent.getTreasureHuntTemp();
|
||||
if(tempData && tempData.huntActivityId == activityId) {
|
||||
let playerData = new TreasureHuntData(activity, roleCreateTime, serverCreateTime);
|
||||
let taskArray = playerData.tasks.findItemByTaskType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
|
||||
let data = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activityId, roleId, tempData.huntRoundIndex, task.cellIndex);
|
||||
return data?.records ?? [];
|
||||
});
|
||||
if(taskUpdateParam) {
|
||||
let rec = await ActivityTreasureHuntTaskModel.setOrIncTask(serverId, activityId, roleId, tempData.huntRoundIndex, task.cellIndex, taskType, taskUpdateParam);
|
||||
if(!rec) continue;
|
||||
this.addActivityTaskPushMessage({ ...task, totalCount: rec.totalCount, activityId });
|
||||
}
|
||||
let playerData = new TreasureHuntData(activity, roleCreateTime, serverCreateTime);
|
||||
let taskArray = playerData.tasks.findItemByTaskType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
|
||||
let data = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activityId, roleId, playerData.roundIndex, task.cellIndex);
|
||||
return data?.records ?? [];
|
||||
});
|
||||
if(taskUpdateParam) {
|
||||
let rec = await ActivityTreasureHuntTaskModel.setOrIncTask(serverId, activityId, roleId, playerData.roundIndex, task.cellIndex, taskType, taskUpdateParam);
|
||||
if(!rec) continue;
|
||||
this.addActivityTaskPushMessage({ ...task, totalCount: rec.totalCount, activityId });
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user