feat(活动): 七夕活动接口

This commit is contained in:
luying
2023-07-17 19:14:06 +08:00
parent 69abcb7c01
commit a726681d25
11 changed files with 399 additions and 1 deletions
@@ -69,6 +69,7 @@ export enum ACTIVITY_TYPE {
WEBVIEW = 54, // 平台活动页面
DRAGON_BOAT = 55, // 龙舟
ENTERTAIN = 56, // 宴请百家
QIXI = 57, // 七夕活动
}
/**
+2 -1
View File
@@ -1205,7 +1205,8 @@ export enum ITEM_CHANGE_REASON {
AUTHOR_BOOK_STAR_RETURN = 191, // 诸子列传升星并发返回
AUTHOR_BOOK_SUB_RESET = 192, // 重置列传
DECOMPOSE_SPIRIT = 193, // 分解英灵
BUY_SPIRIT = 194, // 分解英灵
BUY_SPIRIT = 194, // 购买英灵
QIXI_REWARD = 195, // 七夕活动奖励
}
export enum TA_EVENT {
+7
View File
@@ -694,6 +694,13 @@ export const STATUS = {
ACTIVITY_DRAGON_BOAT_CANNOT_BUY: { code: 50073, simStr: '不可在免费次数未用完的时候购买次数' },
ACTIVITY_ENTERTAIN_NO_NUM: { code: 50074, simStr: '宴请武将次数已满' },
ACTIVITY_ENTERTAIN_BUY_COUNT_OVER: { code: 50075, simStr: '购买次数不足' },
ACTIVITY_QIXI_NO_NUM: { code: 50076, simStr: '召唤喜鹊次数不足' },
ACTIVITY_QIXI_PROGRESS_NOT_FIT: { code: 50077, simStr: '进度数值不匹配' },
ACTIVITY_QIXI_GAMECODE_NOT_FOUND: { code: 50078, simStr: '未找到该id' },
ACTIVITY_QIXI_GAMECODE_HAS_PLAY: { code: 50079, simStr: '该挑战已结算过' },
ACTIVITY_QIXI_BUY_COUNT_OVER: { code: 50080, simStr: '购买挑战次数不足' },
ACTIVITY_QIXI_CANNOT_BUY: { code: 50081, simStr: '不可在免费次数未用完的时候购买次数' },
// GM后台相关状态 60000 - 69999
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
+75
View File
@@ -0,0 +1,75 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 七夕雀巢
*/
export class QixiRecord {
@prop({ required: true })
todayIndex: number; // 今天index
@prop({ required: true })
gameCode: string; // 唯一挑战id
@prop({ required: true })
progress: number; // 到哪个进度
@prop({ required: true })
afterProgress: number; // 到哪个进度
@prop({ required: true })
time: Date; // 时间
@prop({ required: true })
rewards: string; // 奖励
@prop({ required: true })
hasPass: boolean; // 奖励
}
@index({ roleId: 1, activityId: 1 })
export default class Activity_Qixi_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: QixiRecord, _id: false })
record: QixiRecord[]; // 记录
public static async findData(serverId: number, activityId: number, roundIndex: number, roleId: string) {
let result: ActivityQixiRecModelType = await ActivityQixiRecModel.findOne({ serverId, roleId, activityId, roundIndex }).lean();
return result;
}
public static async record(serverId: number, activityId: number, roundIndex: number, roleId: string, record: QixiRecord) {
let result: ActivityQixiRecModelType = await ActivityQixiRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $push: { record }, $setOnInsert: { buyCnt: 0 } }, { new: true, upsert: true }).lean();
return result;
}
public static async addProgress(serverId: number, activityId: number, roundIndex: number, roleId: string, gameCode: string, addProgress: number, time: Date) {
let result: ActivityQixiRecModelType = await ActivityQixiRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'record.gameCode': gameCode }, { $inc: { 'record.$.afterProgress': addProgress }, $set: { 'record.$.time': time, 'record.$.hasPass': true } }, { new: true }).lean();
return result;
}
public static async recordReward(serverId: number, activityId: number, roundIndex: number, roleId: string, gameCode: string, rewards: string) {
let result: ActivityQixiRecModelType = await ActivityQixiRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, 'record.gameCode': gameCode }, { $set: { 'record.$.rewards': rewards } }, { new: true }).lean();
return result;
}
public static async buyCnt(serverId: number, activityId: number, roundIndex: number, roleId: string, count: number) {
let result: ActivityQixiRecModelType = await ActivityQixiRecModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, { $inc: { buyCnt: count }, $setOnInsert: { record: [] } }, { new: true, upsert: true }).lean();
return result;
}
}
export const ActivityQixiRecModel = getModelForClass(Activity_Qixi_Rec);
export interface ActivityQixiRecModelType extends Pick<DocumentType<Activity_Qixi_Rec>, keyof Activity_Qixi_Rec> { }
export type ActivityQixiRecModelTypeParam = Partial<ActivityQixiRecModelType>; // 将所有字段变成可选项
+98
View File
@@ -0,0 +1,98 @@
// 节日活动 - 七夕鹊桥
import { ActivityModelType } from '../../db/Activity';
import { ActivityQixiRecModelType, QixiRecord } from '../../db/ActivityQixiRec';
import { ActivityBase } from './activityField';
// 后台格式
interface QixiDataInDb {
buyCost: string; // 购买一次宴请次数的消耗,type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCnt: number; // 每天可以免费划船的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
}
export class QixiData extends ActivityBase {
buyCost: string; // 购买一次次数的消耗,type&id&count
dailyBuyCnt: number; // 每天可以购买的次数
freeCntDaily: number; // 每天可以免费的次数
maxProgress: number; // 最大进度
rewards: string; // 奖励
freeCnt: number = 0; // 累积到现在可以免费的次数
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
buyCnt: number = 0; // 累积到现在已经购买了的次数
todayPlayCnt: number = 0; // 今天玩的次数
playCnt: number = 0; // 总玩的次数
progress: number = 0; // 当前的进度条
recordTodayIndex: number = 0;
records: QixiRecord[] = [];
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string): void {
let dataObj: QixiDataInDb = JSON.parse(data);
if (!dataObj) return;
this.buyCost = dataObj.buyCost || '&';
this.dailyBuyCnt = dataObj.dailyBuyCnt || 0;
this.freeCntDaily = dataObj.freeCnt || 0;
this.maxProgress = dataObj.maxProgress || 0;
this.rewards = dataObj.rewards || '&';
this.freeCnt = this.freeCntDaily * this.todayIndex;
this.maxBuyCnt = this.todayIndex * this.dailyBuyCnt;
this.recordTodayIndex = this.todayIndex;
}
public setPlayerRecords(playerData: ActivityQixiRecModelType) {
this.updatePlayerRecord(playerData);
if(this.progress >= this.maxProgress) this.progress = 0;
}
public updatePlayerRecord(playerData: ActivityQixiRecModelType) {
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, afterProgress, progress, hasPass } = data;
if(todayIndex == this.todayIndex && hasPass) this.todayPlayCnt ++;
if(hasPass) this.playCnt ++;
this.progress = afterProgress||progress;
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.hasPass).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,
maxProgress: this.maxProgress,
progress: this.progress,
rewards: this.rewards,
}
}
}
@@ -310,5 +310,11 @@
"activityType": 56,
"name": "ENTERTAIN",
"string": "宴请百家"
},
{
"id": 57,
"activityType": 57,
"name": "QIXI",
"string": "七夕活动"
}
]