体力:添加购买体力功能

This commit is contained in:
luying
2021-06-28 15:40:01 +08:00
parent 29eb2e239c
commit 621bf3d82a
7 changed files with 158 additions and 23 deletions

View File

@@ -449,7 +449,8 @@ export const FILENAME = {
DIC_SERVER_NAME: 'dic_zyz_serverName',
DIC_SERVER_GROUP_NAME: 'dic_zyz_serverGropName',
DIC_GK_FES: 'dic_zyz_gk_activity_festival',
DIC_AP: 'dic_zyz_ap'
DIC_AP: 'dic_zyz_ap',
DIC_AP_BUY_COST: 'dic_zyz_daliyAp'
}
export const WAR_RELATE_TABLES = [

View File

@@ -221,6 +221,7 @@ export const STATUS = {
NOT_CONSUME_GOODS: { code: 30004, simStr: '非消耗品' },
AP_IS_FULL: { code: 30005, simStr: '满体力不可使用道具' },
ROLE_IS_NOT_INIT: { code: 30006, simStr: '玩家未初始化' },
AP_BUY_TIMES_LACK: { code: 30007, simStr: '购买次数不足' },
// 武将养成通用 30100 - 30199

View File

@@ -15,16 +15,31 @@ export default class ActionPoint extends BaseModel {
@prop({ required: true })
ap: number; // 当前体力
@prop({ required: true })
buyRefTime: number; // 购买刷新时间,时间戳
@prop({ required: true })
buyTimes: number; // 当前体力
public static async getAp(roleId: string, lean = true) {
let result: ActionPointType = await ActionPointModel.findOne({roleId}).select('ap refTime').lean(lean);
let result: ActionPointType = await ActionPointModel.findOne({roleId}).select('ap refTime buyRefTime buyTimes').lean(lean);
if(!result) {
result = await ActionPointModel.findOneAndUpdate({roleId}, { ap: 0, refTime: 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)
}
return result;
}
public static async saveAp(roleId: string, ap: number, refTime: number, lean = true) {
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({roleId}, { ap, refTime }, {upsert: true, new: true}).lean(lean);
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({roleId}, { $set: {ap, refTime}, $setOnInsert: {buyRefTime: 0, buyTimes: 0} }, {upsert: true, new: true}).lean(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;
}
public static async resetBuyTimes(roleId: string) {
let result: ActionPointType = await ActionPointModel.findOneAndUpdate({ roleId }, { $set: { buyRefTime: 0 } }).lean();
return result;
}

View File

@@ -86,6 +86,7 @@ import { dicActivityType, loadActivityType } from './dictionary/DicActivityType'
import { dicTaskTypeDesc, loadTaskType } from './dictionary/DicTaskType';
import { dicServerName, dicServerGroupName, loadServerName } from "./dictionary/DicServerName";
import { dicAp, loadAp, dicApMaxLevel } from './dictionary/DicAp';
import { dicApBuy, dicApMaxBuyTimes, loadApBuy } from "./dictionary/DicApBuy";
export const gameData = {
blurprtCompose: dicBlueprtCompose,
@@ -210,7 +211,9 @@ export const gameData = {
serverNames: dicServerName,
serverGroupNames: dicServerGroupName,
ap: dicAp,
apMaxLevel: dicApMaxLevel
apMaxLevel: dicApMaxLevel,
apBuy: dicApBuy,
apMaxBuyTimes: dicApMaxBuyTimes
};
// 在此提供一些原先在gamedata中提供的方法以便更方便获取gameData数据
@@ -811,6 +814,7 @@ function loadDatas() {
loadTaskType();
loadServerName();
loadAp();
loadApBuy();
}
// 重载dicParam

View File

@@ -0,0 +1,22 @@
import { readFileAndParse, parseGoodStr } from '../util'
import { FILENAME } from '../../consts'
import { RewardInter } from '../interface';
export interface DicApBuy {
// 购买次数
readonly times: number;
// 消耗
readonly cost: RewardInter[];
}
export const dicApMaxBuyTimes = { max: 0 };
export const dicApBuy = new Map<number, RewardInter[]>();
export function loadApBuy() {
let arr = readFileAndParse(FILENAME.DIC_AP_BUY_COST);
arr.forEach(o => {
o.cost = parseGoodStr(o.cost);
dicApBuy.set(o.times, o.cost);
if(o.times > dicApMaxBuyTimes.max) dicApMaxBuyTimes.max = o.times;
});
arr = undefined;
}