优化:武将初始加载

This commit is contained in:
luying
2021-09-01 19:56:19 +08:00
parent 9d25fafbde
commit e572cb2fa5
15 changed files with 507 additions and 86 deletions
+30 -2
View File
@@ -2,11 +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, EQUIP_TYPE } from '../consts';
import { COUNTER, EQUIP_TYPE, HERO_CE_RATIO } from '../consts';
import { reduceCe } from '../pubUtils/util';
import Skin from './Skin';
class CeAttrData {
type CeAttrUpdate = Partial<CeAttrData>;
export class CeAttrData {
@prop({ required: true })
id: number = 0;
@prop({ required: true })
@@ -21,6 +22,23 @@ class CeAttrData {
constructor(id: number) {
this.id = id;
}
public updateAttr(update: { inc?: CeAttrUpdate, set?: CeAttrUpdate }) {
if(update.inc) {
let { base, equipUp, fixUp, ratioUp } = update.inc;
if(base != undefined) this.base += base * HERO_CE_RATIO;
if(equipUp != undefined) this.equipUp += equipUp * HERO_CE_RATIO;
if(fixUp != undefined) this.fixUp += fixUp * HERO_CE_RATIO;
if(ratioUp != undefined) this.ratioUp += ratioUp;
}
if(update.set) {
let { base, equipUp, fixUp, ratioUp } = update.set;
if(base != undefined) this.base = base * HERO_CE_RATIO;
if(equipUp != undefined) this.equipUp = equipUp * HERO_CE_RATIO;
if(fixUp != undefined) this.fixUp = fixUp * HERO_CE_RATIO;
if(ratioUp != undefined) this.ratioUp = ratioUp;
}
}
}
/**
@@ -207,6 +225,16 @@ export default class Hero extends BaseModel {
return hero;
}
public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
let insertInfos: HeroUpdate[] = [];
for(let hero of heroInfos) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
}
const hero: HeroType[] = await HeroModel.insertMany(insertInfos);
return hero;
}
public static async sumTopHeroCe(roleId: string, num: number) {
let ce: Array<{ historyCe: number }> = await HeroModel.aggregate([
{ $match: { roleId } },
+25 -1
View File
@@ -1,4 +1,4 @@
import { ROLE_TERAPH, ROLE_SELECT, ABI_TYPE } from './../consts';
import { ROLE_TERAPH, ROLE_SELECT, ABI_TYPE, HERO_CE_RATIO } from './../consts';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref, mongoose } from '@typegoose/typegoose';
import User from './User';
@@ -8,6 +8,7 @@ import { Figure } from '../domain/dbGeneral';
import * as dicParam from '../pubUtils/dicParam';
import Hero from './Hero';
type CeAttrUpdate = Partial<CeAttrDataRole>;
// role表属性格式
export class CeAttrDataRole {
@prop({ required: true })
@@ -20,6 +21,19 @@ export class CeAttrDataRole {
constructor(id: number) {
this.id = id;
}
public updateAttr(update: { inc?: CeAttrUpdate, set?: CeAttrUpdate }) {
if(update.inc) {
let { fixUp, ratioUp } = update.inc;
if(fixUp != undefined) this.fixUp += fixUp * HERO_CE_RATIO;
if(ratioUp != undefined) this.ratioUp += ratioUp;
}
if(update.set) {
let { fixUp, ratioUp } = update.set;
if(fixUp != undefined) this.fixUp = fixUp * HERO_CE_RATIO;
if(ratioUp != undefined) this.ratioUp = ratioUp;
}
}
}
class TopHero {
@@ -75,6 +89,7 @@ export class Teraph {
constructor(id: number) {
this.id = id;
this.attr = this.getAttr();
}
public get attr() {
@@ -86,6 +101,15 @@ export class Teraph {
return map
}
private getAttr() {
let map = new Map<number, number>();
map.set(ABI_TYPE.ABI_HP, this.hp);
map.set(ABI_TYPE.ABI_ATK, this.atk);
map.set(ABI_TYPE.ABI_DEF, this.def);
map.set(ABI_TYPE.ABI_MDEF, this.mdef);
return map
}
public set attr(value: Map<number, number>) {
value.forEach((val, id) => {
if (id == ABI_TYPE.ABI_HP) this.hp = val;
+10
View File
@@ -26,6 +26,15 @@ export default class Skin extends BaseModel {
return rec;
}
public static async insertSkins(roleId: string, roleName: string, skinInfos: SkinUpdate[]) {
let insertInfos: SkinUpdate[] = [];
for(let skinInfo of skinInfos) {
insertInfos.push({ ...skinInfo, roleId, roleName });
}
const items: SkinType[] = await SkinModel.insertMany(insertInfos);
return items;
}
public static async increaseSkin(roleId: string, id: number, info: { roleId: string, roleName: string, id: number, skinName: string, hid: number }, lean = true) {
const doc = new SkinModel();
const setOnInsert = Object.assign(doc.toJSON(), info);
@@ -39,3 +48,4 @@ export const SkinModel = getModelForClass(Skin);
export interface SkinType extends Pick<DocumentType<Skin>, keyof Skin> {
id: number;
};
export type SkinUpdate = Partial<SkinType>; // 将所有字段变成可选项