体力:等级体力接口

This commit is contained in:
luying
2022-05-18 15:08:37 +08:00
parent 464f8175ce
commit 2d8e252a4a
3 changed files with 40 additions and 8 deletions

View File

@@ -1,6 +1,15 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
class LvRecord {
@prop({ required: true })
lv: number;
@prop({ required: true })
apBefore: number;
@prop({ required: true })
ap: number;
}
/**
* 体力系统
*/
@@ -22,8 +31,11 @@ export default class ActionPoint extends BaseModel {
@prop({ required: true })
buyTimes: number; // 当前体力
@prop({ required: true, type: LvRecord, _id: false })
lvRecords: LvRecord[]; // 当前体力
public static async getAp(roleId: string, lean = true) {
let result: ActionPointType = await ActionPointModel.findOne({roleId}).select('ap refTime buyRefTime buyTimes apBefore').lean(lean);
let result: ActionPointType = await ActionPointModel.findOne({roleId}).select('ap refTime buyRefTime buyTimes apBefore lvRecords').lean(lean);
if(!result) {
result = await ActionPointModel.findOneAndUpdate({roleId}, { $setOnInsert: { ap: 0, refTime: 0, buyRefTime: 0, buyTimes: 0 } }, {new: true, upsert: true}).lean(lean)
}
@@ -35,6 +47,11 @@ export default class ActionPoint extends BaseModel {
return result;
}
public static async setLvRecord(roleId: string, lv: number, ap: number, apBefore: number) {
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({ roleId }, { $push: {lvRecords: { lv, ap, apBefore }}}, {new: true}).lean();
return result;
}
public static async saveBuyTimes(roleId: string, buyTimes: number, buyRefTime: number) {
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({ roleId }, { $set: {buyTimes, buyRefTime}, $setOnInsert: { ap: 0, refTime: 0 } }, {upsert: true, new: true}).lean();
return result;