演武台:鼓舞,次数限制,掉落修改,结构修改
This commit is contained in:
+45
-37
@@ -1,7 +1,8 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { getZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_BOSS_STATUS } from '../consts';
|
||||
|
||||
class Rank {
|
||||
@prop({ required: true })
|
||||
@@ -34,71 +35,73 @@ export default class BossInstance extends BaseModel {
|
||||
@prop({ required: true, type: Rank, default:[]})
|
||||
ranks:Array<Rank>;
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: true, default: nowSeconds })
|
||||
startTime: number;
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
num: number; //重置次数
|
||||
@prop({ required: true, default: 0 })
|
||||
killTime: number;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
encourageCnt: number; // 鼓舞次数
|
||||
|
||||
@prop({ required: true, default:[], type: String, _id: false})
|
||||
roleIdRecords: Array<string>; //记录提示过胜利boss关的玩家
|
||||
|
||||
@prop({ required: true })
|
||||
winWarId: number; //记录上一次通关的关卡,boss被压制成功后,首次点开boss界面会提示文字,boss已被压制
|
||||
status: GUILD_BOSS_STATUS; // 状态 1:等待团长开启,2:今日已开启,且boss通关,3:开启中
|
||||
|
||||
@prop({ required: true })
|
||||
winBossLv: number; //记录上一次通关的boss等级
|
||||
|
||||
@prop({ required: true })
|
||||
winTime: number; //记录上一次通关的时间
|
||||
|
||||
@prop({ required: true, default: 0})
|
||||
winNum: number; //记录上一次重置次数
|
||||
|
||||
@prop({ required: true, type: Rank, default:[]})
|
||||
recordRanks:Array<Rank>;//上一场排名信息
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
winSettled: boolean; //胜利是否结算过
|
||||
|
||||
public static async findBossInstance(guildCode: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOne({ guildCode }).lean(lean);
|
||||
public static async findByCode(code: string) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOne({ code }).lean();
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async openBossInstance(guildCode: string, bossHp: number, warId: number, bossLv: number, lean = true) {
|
||||
public static async findBossInstance(guildCode: string) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOne({ guildCode, status: GUILD_BOSS_STATUS.OPEN }).lean();
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async findLastOverBossInstance(guildCode: string) {
|
||||
let today = getZeroPoint();
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOne({ guildCode, status: GUILD_BOSS_STATUS.CLEAR, killTime: { $gt: today } }).sort({ _id: -1 }).lean();
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async openBossInstance(guildCode: string, bossHp: number, warId: number, bossLv: number) {
|
||||
let code = genCode(10);
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode },{ $setOnInsert: { code }, ranks:[], time: nowSeconds(), bossHp, bossLv, warId, $inc: { num: 1 }}, {new: true, upsert: true}).lean(lean);
|
||||
let doc = new BossInstanceModel();
|
||||
let update = Object.assign(doc.toJSON(), { guildCode, bossHp, bossLv, warId });
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code },{ $set: update }, {new: true, upsert: true}).lean();
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
//记录玩家boss通关后首次查看boss关卡
|
||||
public static async recordRoleIdWhenCheck(guildCode: string, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode }, { $push:{ roleIdRecords: roleId } }, { new: true }).lean(lean);
|
||||
public static async recordRoleIdWhenCheck(code: string, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code }, { $push:{ roleIdRecords: roleId } }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async pushRecordRanks(guildCode: string, recordRank: Rank, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode }, { $push:{ recordRanks: recordRank } }, { new: true }).lean(lean);
|
||||
public static async pushRecordRanks(code: string, recordRank: Rank, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code }, { $push:{ recordRanks: recordRank } }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async pushRanks(guildCode: string, rank: Rank, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode }, { $push:{ ranks: rank } }, { new: true }).lean(lean);
|
||||
public static async pushRanks(code: string, rank: Rank, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code }, { $push:{ ranks: rank } }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async updateBossInstance(guildCode: string, update:BossInstanceTypeParam, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode }, { $set:update }, { new: true }).lean(lean);
|
||||
public static async updateBossInstance(code: string, update:BossInstanceTypeParam, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code }, { $set:update }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async updateBossHp(guildCode: string, hp: number, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode, 'ranks.roleId': roleId, bossHp: { $gte: hp } }, { $inc: { bossHp: - hp ,'ranks.$.score': hp}, }, { new: true }).lean(lean);
|
||||
public static async updateBossHp(code: string, hp: number, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code, 'ranks.roleId': roleId, bossHp: { $gte: hp } }, { $inc: { bossHp: - hp ,'ranks.$.score': hp}, }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
public static async updateRank(guildCode: string, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ guildCode, 'ranks.roleId': roleId }, { $set:{ 'ranks.$.time': nowSeconds() } }, { new: true }).lean(lean);
|
||||
public static async updateRank(code: string, roleId: string, lean = true) {
|
||||
const bossInstance: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code, 'ranks.roleId': roleId }, { $set:{ 'ranks.$.time': nowSeconds() } }, { new: true }).lean(lean);
|
||||
return bossInstance;
|
||||
}
|
||||
|
||||
@@ -109,9 +112,14 @@ export default class BossInstance extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findBySourceCode(guildCode: string, sourceCode: string) {
|
||||
const rec = await BossInstanceModel.findOne({ guildCode, code: sourceCode }).select('ranks').lean();
|
||||
const rec: BossInstanceType = await BossInstanceModel.findOne({ guildCode, code: sourceCode }).select('ranks').lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async encourage(code: string, count: number, maxCount: number) {
|
||||
const rec: BossInstanceType = await BossInstanceModel.findOneAndUpdate({ code, encourageCnt: { $lte: maxCount - count } }, { $inc: { encourageCnt: count } }).lean();
|
||||
return rec
|
||||
}
|
||||
}
|
||||
|
||||
export const BossInstanceModel = getModelForClass(BossInstance);
|
||||
|
||||
Reference in New Issue
Block a user