武将初始装备栏
This commit is contained in:
+26
-6
@@ -3,7 +3,8 @@ import { CeAttr } from './generalField';
|
||||
import { index, getModelForClass, prop, Ref, mongoose, DocumentType } from '@typegoose/typegoose';
|
||||
import Equip from './Equip';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER } from '../consts';
|
||||
import { COUNTER, EQUIP_TYPE } from '../consts';
|
||||
|
||||
|
||||
/**
|
||||
* 英雄表
|
||||
@@ -22,7 +23,7 @@ class Skin {
|
||||
enable: boolean;
|
||||
}
|
||||
|
||||
class EPlace {
|
||||
export class EPlace {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ ref: Equip, type: mongoose.Schema.Types.ObjectId })
|
||||
@@ -35,6 +36,22 @@ class EPlace {
|
||||
refineCount: number;
|
||||
}
|
||||
|
||||
// 初始化
|
||||
function getInitialEplace() {
|
||||
let ePlace = new Array<EPlace>();
|
||||
for(let i = EQUIP_TYPE.START; i <= EQUIP_TYPE.END; i++) {
|
||||
let p = new EPlace();
|
||||
p.id = i;
|
||||
p.equip = null;
|
||||
p.lv = 1;
|
||||
p.refineLv = 1;
|
||||
p.refineCount = 0;
|
||||
|
||||
ePlace.push(p);
|
||||
}
|
||||
return ePlace;
|
||||
}
|
||||
|
||||
interface heroUpdate {
|
||||
exp?: number;
|
||||
lv?: number;
|
||||
@@ -108,11 +125,11 @@ export default class Hero extends BaseModel {
|
||||
@prop({ required: true, type: Skin, default: [] })
|
||||
skins: Skin[]; // 皮肤
|
||||
|
||||
@prop({ required: true, type: EPlace, default:[] })
|
||||
ePlact: EPlace[]; // 武将装备引用数组
|
||||
@prop({ required: true, type: EPlace, default: getInitialEplace() })
|
||||
ePlace: EPlace[]; // 武将装备引用数组
|
||||
|
||||
public static async findByRole(roleId: string, lean = true) {
|
||||
const heros: HeroType[] = await HeroModel.find({ roleId }).populate('equips').lean(lean);
|
||||
const heros: HeroType[] = await HeroModel.find({ roleId }).lean(lean);
|
||||
return heros;
|
||||
}
|
||||
|
||||
@@ -130,7 +147,10 @@ export default class Hero extends BaseModel {
|
||||
}
|
||||
|
||||
public static async addEquip(roleId: string, hid: number, equipId: string, lean = true) {
|
||||
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, {$push: {equips: equipId}}, {new: true}).lean(lean);
|
||||
const hero: HeroType = await HeroModel.findOneAndUpdate(
|
||||
{ roleId, hid, 'ePlace.id': 1 },
|
||||
{$set: {'ePlace.$.equip': equipId}},
|
||||
{new: true}).lean(lean);
|
||||
if (hero) {
|
||||
await Equip.putOn(hero.hid, equipId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user