体力:等级体力接口
This commit is contained in:
@@ -214,6 +214,25 @@ export class ItemHandler {
|
|||||||
return resResult(STATUS.SUCCESS, { apJson });
|
return resResult(STATUS.SUCCESS, { apJson });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getApByLv(msg: { lv: number }, session: BackendSession) {
|
||||||
|
const { lv } = msg;
|
||||||
|
let roleId = session.get('roleId');
|
||||||
|
let ip = session.get('ip');
|
||||||
|
|
||||||
|
let { lvRecords = [] } = await ActionPointModel.getAp(roleId);
|
||||||
|
let lvRecord = lvRecords.find(cur => cur.lv == lv);
|
||||||
|
let ap = 0, apBefore = 0;
|
||||||
|
if(!lvRecord) {
|
||||||
|
let role = await RoleModel.findByRoleId(roleId, 'lv');
|
||||||
|
let apJson = await getAp(roleId, ip, role.lv);
|
||||||
|
ap = apJson.ap;
|
||||||
|
apBefore = apJson.ap;
|
||||||
|
} else {
|
||||||
|
({ ap, apBefore } = lvRecord);
|
||||||
|
}
|
||||||
|
return resResult(STATUS.SUCCESS, { ap, apBefore });
|
||||||
|
}
|
||||||
|
|
||||||
public async debugResetBuyTimes(msg: { magicWord: string }, session: BackendSession) {
|
public async debugResetBuyTimes(msg: { magicWord: string }, session: BackendSession) {
|
||||||
const { magicWord } = msg;
|
const { magicWord } = msg;
|
||||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { uniq } from 'underscore';
|
|||||||
import { checkPopUpCondition } from './activity/popUpShopService';
|
import { checkPopUpCondition } from './activity/popUpShopService';
|
||||||
import { calculateCeWithRole } from './playerCeService';
|
import { calculateCeWithRole } from './playerCeService';
|
||||||
import { sendMessageToUserWithSuc } from './pushService';
|
import { sendMessageToUserWithSuc } from './pushService';
|
||||||
|
import { ActionPointModel } from '../db/ActionPoint';
|
||||||
|
|
||||||
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
|
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
|
||||||
const serverId = session.get('serverId');
|
const serverId = session.get('serverId');
|
||||||
@@ -30,12 +31,6 @@ export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kin
|
|||||||
let ratio = gameData.kingExpRaio.get(lv)?.get(type)||0;
|
let ratio = gameData.kingExpRaio.get(lv)?.get(type)||0;
|
||||||
let newExp = canGetExp ? exp + Math.floor(kingExp * ratio) : exp;
|
let newExp = canGetExp ? exp + Math.floor(kingExp * ratio) : exp;
|
||||||
let newLv = getLvByExp(newExp);
|
let newLv = getLvByExp(newExp);
|
||||||
// 等级超过最高级之后,经验依然可以稍微溢出一些,以备下一次提升等级
|
|
||||||
// let nextExpObj = getExpByLv(newLv + 1);
|
|
||||||
// let curExpObj = getExpByLv(newLv);
|
|
||||||
// if(curExpObj && !nextExpObj && newExp > curExpObj.sum) {
|
|
||||||
// newExp = curExpObj.sum;
|
|
||||||
// }
|
|
||||||
|
|
||||||
role = await RoleModel.levelup(roleId, newLv, newExp);
|
role = await RoleModel.levelup(roleId, newLv, newExp);
|
||||||
if (newLv > lv) { // 升级
|
if (newLv > lv) { // 升级
|
||||||
@@ -74,7 +69,8 @@ export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kin
|
|||||||
});
|
});
|
||||||
if(i != lv) { // 升级加体力
|
if(i != lv) { // 升级加体力
|
||||||
let dicAp = getDicApByLv(i);
|
let dicAp = getDicApByLv(i);
|
||||||
await setAp(serverId, roleId, ip, i, dicAp.restoreAp, sid, ITEM_CHANGE_REASON.LV_UP);
|
let { ap, apBefore } = await setAp(serverId, roleId, ip, i, dicAp.restoreAp, sid, ITEM_CHANGE_REASON.LV_UP);
|
||||||
|
await ActionPointModel.setLvRecord(roleId, i, ap, apBefore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 推送
|
// 推送
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
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 })
|
@prop({ required: true })
|
||||||
buyTimes: number; // 当前体力
|
buyTimes: number; // 当前体力
|
||||||
|
|
||||||
|
@prop({ required: true, type: LvRecord, _id: false })
|
||||||
|
lvRecords: LvRecord[]; // 当前体力
|
||||||
|
|
||||||
public static async getAp(roleId: string, lean = true) {
|
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) {
|
if(!result) {
|
||||||
result = await ActionPointModel.findOneAndUpdate({roleId}, { $setOnInsert: { ap: 0, refTime: 0, buyRefTime: 0, buyTimes: 0 } }, {new: true, upsert: true}).lean(lean)
|
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;
|
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) {
|
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();
|
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({ roleId }, { $set: {buyTimes, buyRefTime}, $setOnInsert: { ap: 0, refTime: 0 } }, {upsert: true, new: true}).lean();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user