活动:每日免费午饭、晚饭活动
This commit is contained in:
@@ -34,6 +34,7 @@ export enum ACTIVITY_TYPE {
|
||||
SEVEN_DAY = 27, // 七天乐活动(每日特惠礼包,成长任务活动,今日挑战活动)
|
||||
FOURTEEN_DAY = 28, // 十四天乐活动
|
||||
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
|
||||
DAILY_MEAL = 30, // 每日领取免费午饭、晚饭活动
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +102,15 @@ export enum ORDER_STATE {
|
||||
RESULT_FAIL = 3, // 订单失败
|
||||
}
|
||||
|
||||
/**
|
||||
* 每日免费领取午饭、晚饭类型
|
||||
*/
|
||||
export enum DAILY_MEAL_TYPE {
|
||||
LUNCH = 1, // 午饭
|
||||
DINNER = 2, // 晚饭
|
||||
}
|
||||
|
||||
|
||||
//服务器开服时间
|
||||
export const SERVER_OPEN_TIME = '2021-06-06T20:03:16.637+08:00';
|
||||
//玩家等级大于等于15级才能开启vip签到
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 每日免费午餐、晚餐
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Daily_Meal extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
receiveTime: number; // 领取时间
|
||||
@prop({ required: true })
|
||||
type: number; // 1午餐、2晚餐类型
|
||||
|
||||
|
||||
//领取记录
|
||||
public static async addReceiveRecord(serverId: number, activityId: number, roleId: string, type: number, receiveTime: number) {
|
||||
await ActivityDailyMealModel.insertMany([
|
||||
{
|
||||
serverId,
|
||||
activityId,
|
||||
roleId,
|
||||
receiveTime,
|
||||
type
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
//根据活动时间查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, type: number, beginTime: number, endTime: number) {
|
||||
let result: ActivityDailyMealModelType[] = await ActivityDailyMealModel.find({
|
||||
serverId, roleId, activityId, type,
|
||||
receiveTime: { $gt: beginTime, $lt: endTime }
|
||||
}).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, type: number, beginTime: number, endTime: number) {
|
||||
await ActivityDailyMealModel.deleteMany({ serverId, roleId, activityId, type, receiveTime: { $gt: beginTime, $lt: endTime } });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityDailyMealModel = getModelForClass(Activity_Daily_Meal);
|
||||
|
||||
export interface ActivityDailyMealModelType extends Pick<DocumentType<Activity_Daily_Meal>, keyof Activity_Daily_Meal> { }
|
||||
export type ActivityDailyMealModelTypeParam = Partial<ActivityDailyMealModelType>; // 将所有字段变成可选项
|
||||
@@ -0,0 +1,73 @@
|
||||
import moment = require('moment');
|
||||
import { REFRESH_TIME, TASK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyMealModelType } from '../../db/ActivityDailyMeal';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class DailyMealItem {
|
||||
name: string; // 名称
|
||||
beginTime: number; // 开始时间
|
||||
endTime: number; // 结束时间
|
||||
type: number; // 午饭晚饭类型,DAILY_MEAL_TYPE 1.午饭 2晚饭
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
consume: string; //补签消耗资源
|
||||
|
||||
isReceive: boolean = false; //是否领取过
|
||||
|
||||
constructor(data: any) {
|
||||
this.beginTime = moment(new Date()).startOf('d').add(data.beginHour, 'h').valueOf();
|
||||
this.endTime = moment(new Date()).startOf('d').add(data.endHour, 'h').valueOf();
|
||||
this.type = data.type;
|
||||
this.reward = data.reward;
|
||||
this.consume = data.consume;
|
||||
this.name = data.name;
|
||||
|
||||
this.isReceive = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每日免费午餐、晚餐活动数据
|
||||
export class DailyMealData extends ActivityBase {
|
||||
list: Array<DailyMealItem> = [];
|
||||
name: string = ''//名字
|
||||
|
||||
public findItem(type: number) {
|
||||
let index = this.list.findIndex(obj => { return obj.type === type })
|
||||
return (index != -1) ? this.list[index] : null
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityDailyMealModelType[]) {
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.type == record.type })
|
||||
if (index != -1) {
|
||||
obj.isReceive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
let arr = dataObj.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new DailyMealItem(obj))
|
||||
}
|
||||
let curDate = moment(new Date());
|
||||
if (curDate.hour() < REFRESH_TIME) {
|
||||
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
|
||||
} else {
|
||||
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -172,9 +172,9 @@ export class TreasureHuntTaskData {
|
||||
|
||||
public setPlayerTaskRecords(record: ActivityTreasureHuntTaskModelType[]) {
|
||||
for (let item of this.list) {
|
||||
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex && obj.type === item.taskType });
|
||||
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex });
|
||||
if (index != -1) {
|
||||
item.totalCount = record[index].totalCount;
|
||||
item.totalCount = record[index].totalCount ? record[index].totalCount : 0;
|
||||
item.isReceive = record[index].receiveRewardCount ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user