镇念塔调整

This commit is contained in:
luying
2020-11-04 20:12:54 +08:00
parent 4effd85f2a
commit 6020037aa6
17 changed files with 844 additions and 511 deletions
+8 -3
View File
@@ -159,10 +159,10 @@ export default class Role extends BaseModel {
public static async hangUpSpdUp(roleId: string, cnt: number, curTime: Date, lean = true) {
if (cnt < 0) return null;
const result = await RoleModel.findOneAndUpdate({roleId}, {$inc: {hangUpSpdUpCnt: -cnt}, lastSpdUpTime: curTime}, {new: true}).lean(lean);
const lastSpdUpTime = result?result.lastSpdUpTime: curTime;
const result = await RoleModel.findOne({roleId}).lean(lean);
const lastSpdUpTime = result?.lastSpdUpTime;
let role = null;
if (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && cnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT) {
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && cnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
role = await RoleModel.findOneAndUpdate({roleId}, {hangUpSpdUpCnt: HANG_UP_CONSTS.MAX_SPD_UP_CNT - cnt, lastSpdUpTime: curTime}, {new: true}).lean(lean);
} else {
role = await RoleModel.findOneAndUpdate({roleId, hangUpSpdUpCnt: {$gte: cnt}}, {$inc: {hangUpSpdUpCnt: -cnt}, lastSpdUpTime: curTime}, {new: true}).lean(lean);
@@ -221,6 +221,11 @@ try {
return result;
}
public static async costGold(roleId: string, cnt: number, lean = true) {
let result = await RoleModel.findOneAndUpdate({roleId, gold: {$gte: cnt}}, { $inc: { gold: -cnt, totalCost: cnt } }, { "new": true}).lean(lean);
return result;
}
public static async pushWarStar(roleId: string, battleId: number, warType: number, star: number, lean = true) {
let result = await RoleModel.findOneAndUpdate({roleId}, { $addToSet: { warStar: {id: battleId, warType, star }} }, { "new": true, "upsert": true}).lean(lean);
return result;