添加主线关卡和每日关卡
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user