✨ feat(宝物): 宝物seqId修改
This commit is contained in:
+8
-10
@@ -1,15 +1,13 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER } from '../consts';
|
||||
import { RoleModel } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
|
||||
/**
|
||||
* 宝物
|
||||
*/
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
@index({ roleId: 1, seqId: 1, id: 1 })
|
||||
@index({ seqId: 1 })
|
||||
@index({ roleId: 1, quality: 1 })
|
||||
@index({ batchCode: 1 })
|
||||
@index({ status: 1 })
|
||||
@@ -18,7 +16,7 @@ export default class Artifact extends BaseModel {
|
||||
|
||||
// 主键: artifact,不同形态的宝物分开词条
|
||||
@prop({ required: true })
|
||||
seqId: number; // 唯一id
|
||||
seqId: number|string; // 唯一id
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
@@ -50,12 +48,12 @@ export default class Artifact extends BaseModel {
|
||||
@prop({ required: true, default: 1 })
|
||||
status: number; // 装备 1-生成 0-被合成删除
|
||||
|
||||
public static async findbySeqIds(roleId: string, seqIds: number[], select?: string) {
|
||||
public static async findbySeqIds(roleId: string, seqIds: (number|string)[], select?: string) {
|
||||
const result: ArtifactModelType[] = await ArtifactModel.find({ roleId, seqId: { $in: seqIds }, status: 1 }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findbySeqId(roleId: string, seqId: number, select?: string) {
|
||||
public static async findbySeqId(roleId: string, seqId: number|string, select?: string) {
|
||||
const result: ArtifactModelType = await ArtifactModel.findOne({ roleId, seqId, status: 1 }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
@@ -67,7 +65,7 @@ export default class Artifact extends BaseModel {
|
||||
}
|
||||
|
||||
public static async createArtifact(artifactInfo: ArtifactModelUpdate) {
|
||||
const seqId = await CounterModel.getNewCounter(COUNTER.ARTIFACT_ID);
|
||||
const seqId = genCode(10);
|
||||
|
||||
const doc = new ArtifactModel();
|
||||
const artifact = Object.assign(doc.toJSON(), {seqId}, artifactInfo);
|
||||
@@ -85,21 +83,21 @@ export default class Artifact extends BaseModel {
|
||||
return insertInfo;
|
||||
}
|
||||
|
||||
public static async putOnOrOff(roleId: string, seqId: number, hid: number, lv?: number) {
|
||||
public static async putOnOrOff(roleId: string, seqId: number|string, hid: number, lv?: number) {
|
||||
let update: ArtifactModelUpdate = { hid };
|
||||
if(lv != undefined) update.lv = lv;
|
||||
let rec: ArtifactModelType = await ArtifactModel.findOneAndUpdate({ roleId, seqId }, { $set: update }, { new: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async deleteBySeqIds(roleId: string, seqIds: number[]) {
|
||||
public static async deleteBySeqIds(roleId: string, seqIds: (number|string)[]) {
|
||||
let result: ArtifactModelType[] = await ArtifactModel.findbySeqIds(roleId, seqIds);
|
||||
let delResult: { n: number, nModified: number, ok: number } = await ArtifactModel.updateMany({ roleId, seqId: { $in: seqIds } }, { $set: { status: 0 } });
|
||||
await RoleModel.increaseArtifact(roleId, -1 * delResult.nModified);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateInfoBySeqId(roleId: string, seqId: number, update: ArtifactModelUpdate) {
|
||||
public static async updateInfoBySeqId(roleId: string, seqId: number|string, update: ArtifactModelUpdate) {
|
||||
let rec: ArtifactModelType = await ArtifactModel.findOneAndUpdate({ roleId, seqId }, { $set: update }, { new: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ export default class Hero extends BaseModel {
|
||||
consumes: Reward[]; // 消耗
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
artifact: number; // 宝物
|
||||
artifact: number|string; // 宝物
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
subHid: number; // 副将
|
||||
|
||||
@@ -61,7 +61,7 @@ export class HeroParam {
|
||||
skins: HeroSKinParam[] = []; // 皮肤
|
||||
ePlace: EPlace[]; // 武将装备引用数组
|
||||
|
||||
artifact: number = 0;
|
||||
artifact: number|string = 0;
|
||||
subHid: number = 0;
|
||||
subActorId: number = 0;
|
||||
talent: Talent[] = [];
|
||||
@@ -133,7 +133,7 @@ export class JewelParam {
|
||||
}
|
||||
|
||||
export class ArtifactParam {
|
||||
seqId: number; // 唯一id
|
||||
seqId: number|string; // 唯一id
|
||||
artifactId: number; // 宝物id
|
||||
id: number; // 物品id
|
||||
lv: number; // 强化等级
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface RewardInter {
|
||||
export interface ItemInter {
|
||||
id: number;
|
||||
count?: number;
|
||||
seqId?: number;
|
||||
seqId?: number|string;
|
||||
type?: number;
|
||||
isPay?: boolean;
|
||||
hid?: number;
|
||||
|
||||
@@ -746,7 +746,7 @@ export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export function arrToMap<T>(arr: T[], getKey: (obj: T) => number): Map<number, T> {
|
||||
export function arrToMap<T>(arr: T[], getKey: (obj: T) => number|string): Map<number, T> {
|
||||
let map = new Map();
|
||||
for(let obj of arr) {
|
||||
let key = getKey(obj);
|
||||
|
||||
Reference in New Issue
Block a user