创建武将

This commit is contained in:
陆莹
2022-03-25 14:14:36 +08:00
parent a394bae03e
commit 1bdace30f9
17 changed files with 747 additions and 357 deletions
+13 -11
View File
@@ -2,12 +2,12 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, Ref, mongoose, DocumentType } from '@typegoose/typegoose';
// import Equip, { } from './Equip';
import { CounterModel } from './Counter';
import { COUNTER, HERO_CE_RATIO } from '../consts';
import { COUNTER, DEFAULT_HERO_LV, HERO_CE_RATIO } from '../consts';
import { reduceCe } from '../pubUtils/util';
import Skin from './Skin';
import Skin, { SkinUpdate } from './Skin';
import { SearchHeroParam } from '../domain/backEndField/search';
import { Reward } from '../domain/battleField/pvp';
import { getHeroInitTalent } from '../pubUtils/data';
import { gameData, getHeroExpByLv, getHeroInitTalent } from '../pubUtils/data';
type CeAttrUpdate = Partial<CeAttrData>;
export class CeAttrData {
@@ -88,12 +88,12 @@ export class HeroSkin {
@prop({ required: true })
usedTalentPoint: number; // 已使用的天赋点数
constructor(id: number, skinId: number, skin: string, enable: boolean) {
this.id = id;
this.skinId = skinId;
this.skin = skin;
constructor(skin: SkinUpdate, enable = true) {
this.id = skin.id;
this.skinId = skin.skinId;
this.skin = skin._id;
this.enable = enable;
this.talent = getHeroInitTalent(skinId);
this.talent = getHeroInitTalent(skin.skinId);
this.usedTalentPoint = 0;
}
}
@@ -274,16 +274,18 @@ export default class Hero extends BaseModel {
return hero;
}
public static getInitInfo(heroInfo: HeroUpdate = {}): HeroUpdate {
public static getInitInfo(hid: number, heroInfo: HeroUpdate = {}): HeroUpdate {
let dicHero = gameData.hero.get(hid)
let { quality, initialStars: star, jobid: job, name: hName } = dicHero;
const doc = new HeroModel();
const update = { ...doc.toJSON(), ...heroInfo};
const update = { ...doc.toJSON(), hid, skinId: hid, hName, star, quality, job, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0, ...heroInfo};
delete update._id;
return update
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = this.getInitInfo({ ...heroInfo, seqId });
const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
return hero;
}