添加主线关卡和每日关卡

This commit is contained in:
luying
2020-09-29 17:03:01 +08:00
parent e448704dc7
commit 160f32bf9e
18 changed files with 743 additions and 2199 deletions
+32
View File
@@ -0,0 +1,32 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
/**
* 体力系统
*/
@index({ roleId: 1 })
export default class ActionPoint extends BaseModel {
@prop({ required: true })
roleId: string; // 角色 id
@prop({ required: true })
refTime: number; // 刷新时间,时间戳
@prop({ required: true })
ap: number; // 当前体力
public static async getAp(roleId: string, lean = true) {
let result = await ActionPointModel.findOne({roleId}).select('ap refTime').lean(lean);
if(!result) {
result = await ActionPointModel.findOneAndUpdate({roleId}, { ap: 0, refTime: 0 }, {new: true, upsert: true}).lean(lean)
}
return result;
}
public static async saveAp(roleId: string, ap: number, refTime: number, lean = true) {
let result = await ActionPointModel.findOneAndUpdate({roleId}, { ap, refTime }, {upsert: true, new: true}).lean(lean);
return result||{};
}
}
export const ActionPointModel = getModelForClass(ActionPoint);