76 lines
3.1 KiB
TypeScript
76 lines
3.1 KiB
TypeScript
import { SHOP_REFRESH_TYPE } from '../consts/constModules/sysConst';
|
|
import { gameData } from '../pubUtils/data';
|
|
import { getZeroPointOfTimeD } from '../pubUtils/timeUtil';
|
|
import BaseModel from './BaseModel';
|
|
import { getModelForClass, prop, DocumentType, index } from '@typegoose/typegoose';
|
|
|
|
@index({ roleId: 1, limitId: 1 })
|
|
|
|
|
|
export class RewardInter {
|
|
@prop({ required: true })
|
|
id: number;
|
|
@prop({ required: true })
|
|
count: number;
|
|
@prop({ required: true })
|
|
expireTime?: number;
|
|
}
|
|
|
|
|
|
export default class RougelikeExtend extends BaseModel {
|
|
@prop({ required: true })
|
|
roleId: string;
|
|
|
|
@prop({ required: true, default: 0 })
|
|
limitId: number; // 前置试炼id,只会是已通关
|
|
|
|
@prop({ required: true, type: RewardInter, default: 0, _id: false })
|
|
firstReward: RewardInter[]; //首通奖励
|
|
|
|
@prop({ required: true, default: '' })
|
|
gameCode: string;
|
|
|
|
|
|
public static async update(roleId: string, limitId: number, firstReward: RewardInter[], gameCode: string, lean = true) {
|
|
const result: RougelikeExtendType = await RougelikeExtendModel.findOneAndUpdate({ roleId, limitId }, { firstReward, gameCode }, { new: true, upsert: true }).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async findByRoleId(roleId: string, lean = true) {
|
|
const result: RougelikeExtendType[] = await RougelikeExtendModel.find({ roleId }).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async findByRoleIdAndLimitId(roleId: string, limitId: number, lean = true) {
|
|
const result: RougelikeExtendType = await RougelikeExtendModel.findOne({ roleId, limitId }).lean(lean);
|
|
return result;
|
|
}
|
|
|
|
public static async getLastMaxLv(roleId: string) {
|
|
let endTime = getZeroPointOfTimeD(Date.now(), SHOP_REFRESH_TYPE.WEEKLY);
|
|
const result: RougelikeExtendType[] = await RougelikeExtendModel.find({ roleId, createdAt: { $lt: endTime } }).lean(true);
|
|
let lastMaxLv = 1;
|
|
for (const { limitId } of result) {
|
|
const dicData = gameData.rougeTypeGradeById.get(limitId);
|
|
lastMaxLv = Math.max(lastMaxLv, dicData.gradeIndex);
|
|
}
|
|
return lastMaxLv;
|
|
}
|
|
|
|
public static async getLastMaxLvMap(roleIds: string[]) {
|
|
let endTime = new Date(getZeroPointOfTimeD(Date.now(), SHOP_REFRESH_TYPE.WEEKLY).getTime() - 86400000 * 7);
|
|
const result: RougelikeExtendType[] = await RougelikeExtendModel.find({ roleId: { $in: roleIds }, createdAt: { $lt: endTime } }).lean(true);
|
|
let lastMaxLvMap = new Map<string, number>();
|
|
for (const { roleId, limitId } of result) {
|
|
if (!limitId) continue;
|
|
let tempLv = lastMaxLvMap.has(roleId) ? lastMaxLvMap.get(roleId) : 1;
|
|
const dicData = gameData.rougeTypeGradeById.get(limitId);
|
|
lastMaxLvMap.set(roleId, Math.max(tempLv, dicData.gradeIndex));
|
|
}
|
|
return lastMaxLvMap;
|
|
}
|
|
}
|
|
|
|
export const RougelikeExtendModel = getModelForClass(RougelikeExtend);
|
|
export interface RougelikeExtendType extends Pick<DocumentType<RougelikeExtend>, keyof RougelikeExtend> { };
|
|
export type RougelikeExtendPara = Partial<RougelikeExtendType>; // 将所有字段变成可选项
|