活动:寻宝骑兵活动固定关卡id

This commit is contained in:
luying
2022-04-15 13:55:47 +08:00
parent 19a448a578
commit 629af03645
4 changed files with 59 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import { RewardParam } from '../../../domain/activityField/rewardField';
import { ActivityTreasureHuntTreasureShopModel } from '../../../db/ActivityTreasureHuntTreasureShop';
import { ActivityTreasureHuntFirstPageModel } from '../../../db/ActivityTreasureHuntFirstPage';
import { CheckMeterial } from '../../../services/role/checkMaterial';
import { ActivityTreasureHuntChallengeModel } from '../../../db/ActivityTreasureHuntChallenge';
export default function (app: Application) {
@@ -218,7 +219,11 @@ export class TreasureHuntHandler {
let isEnough = await check.decrease(consume);
if (!isEnough) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let warId = playerData.challenge.randomGK();
let warId = playerData.challenge.resultWarId;
if(!warId) {
warId = playerData.challenge.randomGK();
await ActivityTreasureHuntChallengeModel.setWarId(serverId, activityId, roleId, huntRoundIndex, warId);
}
return resResult(STATUS.SUCCESS, Object.assign({ warId }, {
param: { activityId },

View File

@@ -15,6 +15,7 @@ import { RoleModel } from '../../db/Role';
import { getActivitiesByType, getActivityById } from './activityService';
import { getRoleCreateTime, getServerCreateTime } from '../redisService';
import { handleCost } from '../role/rewardService';
import { ActivityTreasureHuntChallengeModel } from '../../db/ActivityTreasureHuntChallenge';
/**
* 获取活动数据
@@ -170,6 +171,9 @@ export async function getPlayerTreasureHuntChallengeData(activityId: number, ser
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;
}
@@ -373,5 +377,9 @@ export async function treasureHuntChallengeConsume(serverId: number, roleId: str
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
}

View File

@@ -0,0 +1,36 @@
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 活动系统 - 寻宝骑兵-挑战
*/
@index({ roleId: 1 })
export default class Activity_Treasure_Hunt_Challenge {
@prop({ required: true })
serverId: number; // 区Id
@prop({ required: true })
activityId: number; // 活动Id
@prop({ required: true })
roleId: string; // 用户Id
@prop({ required: true })
roundIndex: number; // 回合数
@prop({ required: true })
warId: number; // 挑战关卡
//根据活动id查询活动数据
public static async findData(serverId: number, activityId: number, roleId: string, roundIndex: number) {
let result: ActivityTreasureHuntChallengeModelType = await ActivityTreasureHuntChallengeModel.findOne({ serverId, roleId, activityId, roundIndex }).lean(true);
return result;
}
public static async setWarId(serverId: number, activityId: number, roleId: string, roundIndex: number, warId: number) {
let result: ActivityTreasureHuntChallengeModelType = await ActivityTreasureHuntChallengeModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex },
{ $set: { warId }}, { new: true, upsert: true }).lean();
return result;
}
}
export const ActivityTreasureHuntChallengeModel = getModelForClass(Activity_Treasure_Hunt_Challenge);
export interface ActivityTreasureHuntChallengeModelType extends Pick<DocumentType<Activity_Treasure_Hunt_Challenge>, keyof Activity_Treasure_Hunt_Challenge> { }
export type ActivityTreasureHuntChallengeModelTypeParam = Partial<ActivityTreasureHuntChallengeModelType>; // 将所有字段变成可选项

View File

@@ -6,6 +6,7 @@ import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTrea
import { ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasureHuntFirstPage';
import { parseNumberList, splitString } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
import { ActivityTreasureHuntChallengeModelTypeParam } from '../../db/ActivityTreasureHuntChallenge';
// 进入活动首页的数据
@@ -216,6 +217,8 @@ export class TreasureHuntChallengeData {
jackpotReward: string = '';//客户端显示奖励
imageName: string = '';
resultWarId: number = 0; // 玩家随机出的关卡id
public randomGK() {
let gkArray = splitString(this.warid, '&');
let index = random(gkArray.length - 1);
@@ -232,6 +235,12 @@ export class TreasureHuntChallengeData {
this.imageName = data.imageName;
}
public setChallengeRecord(record: ActivityTreasureHuntChallengeModelTypeParam) {
if(record) {
this.resultWarId = record.warId;
}
}
constructor(data: any) {
this.initData(data)
}