创建武将
This commit is contained in:
+13
-11
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
// 全局加成
|
||||
export class GlobalAttr {
|
||||
@prop({ required: true })
|
||||
attrId: number; // 属性id
|
||||
@prop({ required: true })
|
||||
values: number[]; // 战力公式中的全局加成的数据,查表后的结果
|
||||
}
|
||||
|
||||
// 单武将加成
|
||||
export class HeroAttr {
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
lv: number;
|
||||
@prop({ required: true, type: () => HeroAttrCell, _id: false })
|
||||
attrs: HeroAttrCell[];
|
||||
}
|
||||
|
||||
export class HeroAttrCell {
|
||||
@prop({ required: true })
|
||||
attrId: number; // 属性id
|
||||
@prop({ required: true })
|
||||
values: number[]; // 战力公式中的武将加成的数据,查表后的结果
|
||||
}
|
||||
|
||||
// 装备加成
|
||||
class EquipAttr {
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
eplaceId: number; // 装备位置
|
||||
@prop({ required: true })
|
||||
attrId: number; // 属性id
|
||||
@prop({ required: true })
|
||||
values: number[]; // 战力公式中的武将加成的数据,查表后的结果
|
||||
}
|
||||
|
||||
// 百家学宫加成
|
||||
class SchoolAttr {
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
attrId: number; // 属性id
|
||||
@prop({ required: true })
|
||||
value: number; // 百家学宫有多个武将,单独拎出来方便计算,计算之后结果存到globaAttrs的global1
|
||||
}
|
||||
|
||||
// 名将谱加成
|
||||
class ScrollAttr {
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
attrId: number; // 属性id
|
||||
@prop({ required: true })
|
||||
value: number; // 百家学宫有多个武将,单独拎出来方便计算,计算之后结果存到globaAttrs的global1
|
||||
}
|
||||
|
||||
/**
|
||||
* 属性表
|
||||
*/
|
||||
|
||||
@index({ roleId: 1 })
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class RoleCe extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 角色 id
|
||||
|
||||
@prop({ required: true, type: GlobalAttr, _id: false })
|
||||
globalAttrs: GlobalAttr[]
|
||||
|
||||
@prop({ required: true, type: HeroAttr, _id: false })
|
||||
heroAttrs: HeroAttr[]
|
||||
|
||||
@prop({ required: true, type: EquipAttr, _id: false })
|
||||
equipAttrs: EquipAttr[]
|
||||
|
||||
@prop({ required: true, type: SchoolAttr, _id: false })
|
||||
schoolAttr: SchoolAttr[];
|
||||
|
||||
@prop({ required: true, type: ScrollAttr, _id: false })
|
||||
scrollAttrs: ScrollAttr[];
|
||||
|
||||
public static async findByRoleId(roleId: string) {
|
||||
let result: RoleCeType[] = await RoleCeModel.find({ roleId }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const RoleCeModel = getModelForClass(RoleCe);
|
||||
|
||||
export interface RoleCeType extends Pick<DocumentType<RoleCe>, keyof RoleCe> { };
|
||||
export type RoleCeUpdate = Partial<RoleCeType>;
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
@index({ roleId: 1, id: 1 })
|
||||
@index({ seqId: 1 })
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
@@ -28,6 +29,15 @@ export default class Skin extends BaseModel {
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static getInitInfo(hid: number): SkinUpdate {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let dicFashion = gameData.fashion.get(dicHero.initialSkin)
|
||||
const doc = new SkinModel();
|
||||
const update = { ...doc.toJSON(), id: dicFashion.id, skinId: dicFashion.heroId, skinName: dicFashion.name, hid};
|
||||
delete update._id;
|
||||
return update
|
||||
}
|
||||
|
||||
public static async insertSkins(roleId: string, roleName: string, skinInfos: SkinUpdate[]) {
|
||||
let insertInfos: SkinUpdate[] = [];
|
||||
for(let skinInfo of skinInfos) {
|
||||
|
||||
Reference in New Issue
Block a user