feat(节日活动): 中秋活动

This commit is contained in:
luying
2023-08-15 17:52:11 +08:00
parent 4be52d3dfe
commit 7c3a98bb9d
11 changed files with 442 additions and 8 deletions

View File

@@ -70,6 +70,7 @@ export enum ACTIVITY_TYPE {
DRAGON_BOAT = 55, // 龙舟
ENTERTAIN = 56, // 宴请百家
QIXI = 57, // 七夕活动
MID_AUTUMN = 58, // 中秋活动
}
/**

View File

@@ -1208,6 +1208,7 @@ export enum ITEM_CHANGE_REASON {
DECOMPOSE_SPIRIT = 193, // 分解英灵
BUY_SPIRIT = 194, // 购买英灵
QIXI_REWARD = 195, // 七夕活动奖励
MID_AUTUMN_REWARD = 196, // 中秋活动奖励
}
export enum TA_EVENT {

View File

@@ -706,7 +706,7 @@ export const STATUS = {
ACTIVITY_QIXI_BUY_COUNT_OVER: { code: 50080, simStr: '购买挑战次数不足' },
ACTIVITY_QIXI_CANNOT_BUY: { code: 50081, simStr: '不可在免费次数未用完的时候购买次数' },
ACTIVITY_QIXI_CANNOT_SWEEP: { code: 50082, simStr: '必须在当天手动玩一次后才可以碾压' },
ACTIVITY_MID_AUTUMN_NO_NUM: { code: 50083, simStr: '游戏次数不足' },
// GM后台相关状态 60000 - 69999
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },

View File

@@ -0,0 +1,70 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 中秋找茬
*/
export class MidAutumnRecord {
@prop({ required: true })
todayIndex: number; // 今天index
@prop({ required: true })
gameCode: string; // 唯一挑战id
@prop({ required: true })
time: Date; // 时间
@prop({ required: true })
rewards: string; // 奖励
@prop({ required: true })
isSuccess: boolean; // 是否通过
@prop({ required: true })
hasPass: boolean; // 是否通过
@prop({ required: true })
isSkip: boolean; // 是否跳过
}
@index({ roleId: 1, activityId: 1 })
export default class Activity_MidAutumn_Rec extends BaseModel {
@prop({ required: true })
serverId: number; // 服Id
@prop({ required: true })
activityId: number; // 活动Id
@prop({ required: true })
roundIndex: number; // 第几轮
@prop({ required: true })
roleId: string; // 用户Id
@prop({ required: true })
buyCnt: number; // 购买次数
@prop({ required: true, type: MidAutumnRecord, _id: false })
record: MidAutumnRecord[]; // 记录
public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) {
let result: ActivityMidAutumnRecModelType = await ActivityMidAutumnRecModel.findOne({ serverId, roleId, activityId, roundIndex }).lean();
return result;
}
public static async record(serverId: number, activityId: number, roundIndex: number, roleId: string, record: MidAutumnRecord) {
let result: ActivityMidAutumnRecModelType = await ActivityMidAutumnRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { record }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean();
return result;
}
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, count: number) {
let result: ActivityMidAutumnRecModelType = await ActivityMidAutumnRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $inc: { buyCnt: count }, $setOnInsert: { record: [] } }, { new: true, upsert: true }).lean();
return result;
}
public static async gameEnd(serverId: number, activityId: number, roundIndex: number, roleId: string, gameCode: string, isSuccess: boolean, time: Date, rewards: string) {
let result: ActivityMidAutumnRecModelType = await ActivityMidAutumnRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'record.gameCode': gameCode }, { $set: { 'record.$.time': time, 'record.$.hasPass': true, 'record.$.isSuccess': isSuccess, 'record.$.rewards': rewards } }, { new: true }).lean();
return result;
}
}
export const ActivityMidAutumnRecModel = getModelForClass(Activity_MidAutumn_Rec);
export interface ActivityMidAutumnRecModelType extends Pick<DocumentType<Activity_MidAutumn_Rec>, keyof Activity_MidAutumn_Rec> { }
export type ActivityMidAutumnRecModelTypeParam = Partial<ActivityMidAutumnRecModelType>; // 将所有字段变成可选项

View File

@@ -0,0 +1,106 @@
// 节日活动 - 七夕鹊桥
import { ActivityModelType } from '../../db/Activity';
import { ActivityMidAutumnRecModelType, MidAutumnRecord } from '../../db/ActivityMidAutumnRec';
import { ActivityBase } from './activityField';
// 后台格式
interface MidAutumnSceneDataInDb {
dayIndex: number; // 第几天
id: number; // 场景
img: string; // 图片
}
interface MidAutumnDataInDb {
buyCost: string; // 购买一次次数的消耗type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCnt: number; // 每天可以免费的次数
scenes: MidAutumnSceneDataInDb[];
rewards: string; // 单局奖励
}
export class MidAutumnData extends ActivityBase {
buyCost: string; // 购买一次次数的消耗type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCntDaily: number; // 每天可以免费的次数
rewards: string; // 奖励
freeCnt: number = 0; // 累积到现在可以免费的次数
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
buyCnt: number = 0; // 累积到现在已经购买了的次数
todayPlayCnt: number = 0; // 今天玩的次数
playCnt: number = 0; // 总玩的次数
sceneId: number = 0; // 今天玩的场景id
img: string = '&'; // 场景的图片
recordTodayIndex: number = 0;
records: MidAutumnRecord[] = [];
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string): void {
let dataObj: MidAutumnDataInDb = JSON.parse(data);
if (!dataObj) return;
this.buyCost = dataObj.buyCost || '&';
this.dailyBuyCnt = dataObj.dailyBuyCnt || 0;
this.freeCntDaily = dataObj.freeCnt || 0;
this.rewards = dataObj.rewards || '&';
this.freeCnt = this.freeCntDaily * this.todayIndex;
this.maxBuyCnt = this.todayIndex * this.dailyBuyCnt;
this.recordTodayIndex = this.todayIndex;
let curScene = dataObj.scenes.find(cur => cur.dayIndex == this.todayIndex);
if(curScene) {
this.sceneId = curScene.id;
this.img = curScene.img;
}
}
public setPlayerRecords(playerData: ActivityMidAutumnRecModelType) {
this.updatePlayerRecord(playerData);
}
public updatePlayerRecord(playerData: ActivityMidAutumnRecModelType) {
if (!playerData) return;
this.buyCnt = playerData.buyCnt || 0;
this.todayPlayCnt = 0;
this.playCnt = 0;
this.recordTodayIndex = this.todayIndex;
if(playerData.record) {
playerData.record.sort((a, b) => a.time.getTime() - b.time.getTime());
for(let data of playerData.record) {
let { todayIndex, isSuccess } = data;
if(todayIndex == this.todayIndex && isSuccess) this.todayPlayCnt ++;
if(isSuccess) this.playCnt ++;
this.records.push(data);
}
if(this.todayPlayCnt >= this.freeCntDaily && this.playCnt < this.freeCnt) {
for(let i = 1; i <= this.todayIndex; i++) {
let times = playerData.record.filter(cur => cur.todayIndex == i && cur.isSuccess).length;
if(times < this.freeCntDaily) {
this.recordTodayIndex = i; break;
}
}
}
}
}
public getShowResult() {
return {
...this.getBaseKeys(),
buyCost: this.buyCost,
dailyBuyCnt: this.dailyBuyCnt,
freeCnt: this.freeCnt,
maxBuyCnt: this.maxBuyCnt,
buyCnt: this.buyCnt,
todayPlayCnt: this.todayPlayCnt,
playCnt: this.playCnt,
sceneId: this.sceneId,
img: this.img,
rewards: this.rewards,
}
}
}

View File

@@ -316,5 +316,11 @@
"activityType": 57,
"name": "QIXI",
"string": "七夕活动"
},
{
"id": 58,
"activityType": 58,
"name": "MID_AUTUMN",
"string": "中秋活动"
}
]