活动:修改七天乐-成长活动的数据结构
This commit is contained in:
@@ -3,7 +3,7 @@ import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, ACTIVITY_RESOURCES_TYPE } from '../../../consts';
|
||||
import { getPlayerGrowthData } from '../../../services/growthService';
|
||||
import { getPlayerDailyChallengesData } from '../../../services/dailyChallengesService';
|
||||
import { GrowthItem } from '../../../domain/activityField/growthField';
|
||||
import { GrowthItem, PointRewardItem } from '../../../domain/activityField/growthField';
|
||||
import { addItems, createHeroes, handleCost } from '../../../services/rewardService';
|
||||
import { ActivityGrowthModel } from '../../../db/ActivityGrowth';
|
||||
import { DailyItem } from '../../../domain/activityField/dailyChallengesField';
|
||||
@@ -13,6 +13,7 @@ import { ActivityDailyGiftsModel } from '../../../db/ActivityDailyGifts';
|
||||
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityDailyChallengesModel } from '../../../db/ActivityDailyChallenges';
|
||||
import { ActivityGrowthPointModel } from '../../../db/ActivityGrowthPoint';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -76,23 +77,20 @@ export class SevenDaysHandler {
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
growthItemData.receiveRewardCount = 1;
|
||||
growthItemData.addPointCount = growthItemData.point;
|
||||
playerData.totalPoint += growthItemData.point;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, dayIndex, cellIndex, type },
|
||||
item: growthItemData,
|
||||
totalPoint: playerData.totalPoint
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 成长任务每天奖章兑换奖励
|
||||
* @param {{ activityId: number, dayIndex: number}} msg
|
||||
* @param {{ activityId: number, id: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthDayReward(msg: { activityId: number, dayIndex: number }, session: BackendSession) {
|
||||
const { activityId, dayIndex } = msg;
|
||||
async getGrowthDayReward(msg: { activityId: number, id: number }, session: BackendSession) {
|
||||
const { activityId, id } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
@@ -102,32 +100,27 @@ export class SevenDaysHandler {
|
||||
let playerData = await getPlayerGrowthData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
let dayItemData: GrowthItem = playerData.findDayItem(dayIndex);
|
||||
if (!dayItemData) {
|
||||
let pointItemData: PointRewardItem = playerData.findPointItem(id);
|
||||
if (!pointItemData) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
if (playerData.totalPoint - playerData.totalConsumePoint < dayItemData.consumePoint) {
|
||||
if (playerData.getTotalPoint() < pointItemData.progress) {
|
||||
return resResult(STATUS.ACTIVITY_NO_POINT);
|
||||
}
|
||||
if (dayItemData.getPointReward) {//已经领取过
|
||||
if (pointItemData.getPointReward) {//已经领取过
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
// if (playerData.today() != dayIndex) {
|
||||
// return resResult(STATUS.ACTIVITY_TIME_ERROR);
|
||||
// }
|
||||
|
||||
await ActivityGrowthModel.addDayRecord(serverId, activityId, roleId, dayIndex, 1);
|
||||
await ActivityGrowthPointModel.addRecord(serverId, activityId, roleId, id);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(dayItemData.reward);
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(pointItemData.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
|
||||
dayItemData.getPointReward = true;
|
||||
playerData.totalConsumePoint += dayItemData.consumePoint;
|
||||
pointItemData.getPointReward = true;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, dayIndex },
|
||||
item: dayItemData,
|
||||
totalPoint: playerData.totalPoint
|
||||
param: { activityId, id },
|
||||
item: pointItemData,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ACTIVITY_TYPE } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityGrowthModel, ActivityGrowthModelType } from '../db/ActivityGrowth';
|
||||
import { ActivityGrowthPointModel, ActivityGrowthPointModelType } from '../db/ActivityGrowthPoint';
|
||||
import { GrowthData, GrowthItem } from '../domain/activityField/growthField';
|
||||
|
||||
/**
|
||||
@@ -27,9 +28,11 @@ export async function getGrowthActivityData(serverId: number, roleId: string) {
|
||||
export async function getPlayerGrowthData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(serverId, activityId, true);
|
||||
let playerRecords: ActivityGrowthModelType[] = await ActivityGrowthModel.findData(serverId, activityId, roleId);
|
||||
let playerPointRecord: ActivityGrowthPointModelType = await ActivityGrowthPointModel.findData(serverId, activityId, roleId);
|
||||
|
||||
let playerData = new GrowthData(activityData);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
playerData.setPlayerPointRecord(playerPointRecord);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
41
shared/db/ActivityGrowthPoint.ts
Normal file
41
shared/db/ActivityGrowthPoint.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 成长任务活动积分点兑换奖励
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Growth_Point extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
ids: number[]; // id数组,领取过的奖励id
|
||||
|
||||
//当日奖章领取记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
let result: ActivityGrowthPointModelType = await ActivityGrowthPointModel.findOneAndUpdate({ serverId, roleId, activityId, id },
|
||||
{ $push: { ids: id } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string) {
|
||||
let result: ActivityGrowthPointModelType = await ActivityGrowthPointModel.findOne({ serverId, roleId, activityId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
await ActivityGrowthPointModel.deleteMany({ serverId, roleId, activityId, id });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityGrowthPointModel = getModelForClass(Activity_Growth_Point);
|
||||
|
||||
export interface ActivityGrowthPointModelType extends Pick<DocumentType<Activity_Growth_Point>, keyof Activity_Growth_Point> { }
|
||||
export type ActivityGrowthPointModelTypeParam = Partial<ActivityGrowthPointModelType>; // 将所有字段变成可选项
|
||||
@@ -1,14 +1,36 @@
|
||||
import { TASK_TYPE, ACTIVITY_RESOURCES_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { ActivityGrowthPointModelType } from '../../db/ActivityGrowthPoint';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
|
||||
import { CreateHeroParam } from '../roleField/hero';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 积分兑换奖励数据
|
||||
export class PointRewardItem {
|
||||
id: number; // 第几天,从1开始
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
progress: number; // 需要的奖章数量
|
||||
quality: string; //
|
||||
star: number; //
|
||||
|
||||
getPointReward: boolean = false; // 是否兑换领取奖章奖励
|
||||
|
||||
constructor(data: any) {
|
||||
this.id = data.id;
|
||||
this.reward = data.reward;
|
||||
this.progress = data.progress;
|
||||
this.quality = data.quality;
|
||||
this.star = data.star;
|
||||
this.getPointReward = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 每日配置数据
|
||||
export class GrowthItem {
|
||||
id: number;
|
||||
dayIndex: number; // 第几天,从1开始
|
||||
cellIndex: number; // 当天第几行,从1开始
|
||||
name: string; // 任务名称
|
||||
@@ -17,13 +39,9 @@ export class GrowthItem {
|
||||
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
|
||||
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
consumePoint: number; // 奖章兑换奖品,需要消耗的奖章个数
|
||||
pointReward: string; // 奖章兑换奖品,奖励内容,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
|
||||
totalCount: number = 0; //完成任务累计次数
|
||||
receiveRewardCount: number = 0; //领取奖励次数
|
||||
addPointCount: number = 0; // 获得奖章个数
|
||||
getPointReward: boolean = false; // 是否兑换领取奖章奖励
|
||||
|
||||
constructor(data: any) {
|
||||
this.dayIndex = data.dayIndex;
|
||||
@@ -34,8 +52,8 @@ export class GrowthItem {
|
||||
this.condition = data.condition;
|
||||
this.point = data.point;
|
||||
this.reward = data.reward;
|
||||
this.consumePoint = data.consumePoint;
|
||||
this.pointReward = data.pointReward;
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
}
|
||||
|
||||
public heroReward(): CreateHeroParam[] {
|
||||
@@ -113,13 +131,22 @@ export class GrowthItem {
|
||||
// 成长活动数据
|
||||
export class GrowthData extends ActivityBase {
|
||||
list: Array<GrowthItem> = [];
|
||||
totalPoint: number = 0;//获得奖章总数
|
||||
totalConsumePoint: number = 0;//消耗奖章总数
|
||||
pointRewardList: Array<PointRewardItem> = [];
|
||||
|
||||
public getTotalPoint() {
|
||||
let total = 0;
|
||||
for (let obj of this.list) {
|
||||
if (obj.receiveRewardCount) {
|
||||
total += obj.point;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
//第几天的奖章兑换
|
||||
public findDayItem(dayIndex: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == 1 })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
public findPointItem(id: number) {
|
||||
let index = this.pointRewardList.findIndex(obj => { return obj && obj.id === id })
|
||||
return (index != -1) ? this.pointRewardList[index] : null;
|
||||
}
|
||||
|
||||
public findGrowthItem(dayIndex: number, cellIndex: number, type: number) {
|
||||
@@ -133,35 +160,41 @@ export class GrowthData extends ActivityBase {
|
||||
})
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerPointRecord(data: ActivityGrowthPointModelType) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
for (let obj of this.pointRewardList) {
|
||||
let index = data.ids.findIndex(id => { return id === obj.id })
|
||||
if (index != -1) {
|
||||
obj.getPointReward = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityGrowthModelType[]) {
|
||||
this.totalPoint = 0;
|
||||
this.totalConsumePoint = 0;
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||
if (index != -1) {
|
||||
obj.totalCount = data[index].totalCount ? data[index].totalCount : 0;
|
||||
obj.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
|
||||
obj.addPointCount = data[index].addPointCount ? data[index].addPointCount : 0;
|
||||
obj.getPointReward = data[index].getPointReward ? data[index].getPointReward : false;
|
||||
this.totalPoint += obj.addPointCount;
|
||||
if (data[index].getPointReward) {
|
||||
this.totalConsumePoint += obj.addPointCount;
|
||||
}
|
||||
} else {
|
||||
obj.totalCount = 0;
|
||||
obj.receiveRewardCount = 0;
|
||||
obj.addPointCount = 0;
|
||||
obj.getPointReward = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
let objData = JSON.parse(data);
|
||||
|
||||
let arr = objData.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new GrowthItem(obj))
|
||||
}
|
||||
let pointRewardArray = objData.pointReward;
|
||||
for (let obj of pointRewardArray) {
|
||||
this.pointRewardList.push(new PointRewardItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
|
||||
Reference in New Issue
Block a user