Browse Source

属性计算代码优化

2.0
许孟阳 2 months ago
parent
commit
834c935ced
  1. 11
      src/config/equips/base.ts
  2. 2
      src/config/equips/bean.ts
  3. 179
      src/config/equips/constant.ts

11
src/config/equips/base.ts

@ -1,22 +1,21 @@
import { Categorys, Equip, EquipBase, Quality } from './bean'; import { Categorys, Equip, EquipBase, Quality } from './bean';
import { entry_initor, extra_entry_num, qualitys } from './constant'; import { entry_initor, EntryInitor, extra_entry_num, qualitys } from './constant';
export const createBase = (quality, lv, category, coefficient) => { export const createBase = (quality, lv, category, coefficient) => {
const entry = new Array(); const entry = new Array();
category.entry.forEach((item) => { category.entry.forEach((item) => {
const initor = entry_initor[item.type]; const initor: EntryInitor = entry_initor[item.type];
const qualityCoefficient = coefficient[quality]; const qualityCoefficient = coefficient[quality];
entry.push(initor(lv, qualityCoefficient, item.valCoefficient)); entry.push(initor.init(lv, qualityCoefficient, item.valCoefficient));
}); });
return new EquipBase(category.name, category.icon, entry, category.skill); return new EquipBase(category.name, category.icon, entry, category.skill);
}; };
export const createExtraEntry = (quality, lv, extraEntrys, coefficient) => { export const createExtraEntry = (quality, lv, extraEntrys, coefficient) => {
const type = extraEntrys[Math.floor(Math.random() * extraEntrys.length)]; const type = extraEntrys[Math.floor(Math.random() * extraEntrys.length)];
const initor = entry_initor[type]; const initor: EntryInitor = entry_initor[type];
const qualityCoefficient = coefficient[quality]; const qualityCoefficient = coefficient[quality];
const entry = initor(lv, qualityCoefficient); return initor.init(lv, qualityCoefficient);
return entry;
}; };
export const createSamples = (categorys: Categorys[], uniqueCategorys: Categorys[], colorfulCategorys: Categorys[], type, coefficient) => { export const createSamples = (categorys: Categorys[], uniqueCategorys: Categorys[], colorfulCategorys: Categorys[], type, coefficient) => {

2
src/config/equips/bean.ts

@ -14,7 +14,7 @@ export class Entry {
this.showVal = showVal; this.showVal = showVal;
this.max = max; this.max = max;
this.min = min; this.min = min;
this.percent = Math.round(((value - min) / (max - min)) * 100); this.percent = value == max ? 100 : Math.round(((value - min) / (max - min)) * 100);
} }
} }

179
src/config/equips/constant.ts

@ -2,6 +2,9 @@ import { Entry } from './bean';
//装备质量 //装备质量
export const qualitys = ['shabby', 'ordinary', 'artifact', 'epic', 'unique', 'colorful']; export const qualitys = ['shabby', 'ordinary', 'artifact', 'epic', 'unique', 'colorful'];
export const extra_quality = ['yuangu', 'taigu'];
export const extra_quality_rate = [0.1, 0.1];
export const extra_quality_lv = 20;
//装备颜色 //装备颜色
export const quality_collor = { export const quality_collor = {
@ -42,104 +45,82 @@ export const attr_unitys = {
export const strengthen_rates = [1, 1, 1, 1, 1, 1, 0.8, 0.65, 0.45, 0.3, 0.2]; export const strengthen_rates = [1, 1, 1, 1, 1, 1, 0.8, 0.65, 0.45, 0.3, 0.2];
export const strengthen_factor = { shabby: 1, ordinary: 1, artifact: 1, epic: 1, unique: 1.5, colorful: 2 }; export const strengthen_factor = { shabby: 1, ordinary: 1, artifact: 1, epic: 1, unique: 1.5, colorful: 2 };
export const entry_initor = { export interface EntryInitor {
atk: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { init(lv: number, qualityCoefficient: number, valCoefficient?: number, extraQuality?: string): Entry;
valCoefficient = valCoefficient || 1; }
const value = Math.round((lv * valCoefficient + ((Math.random() * lv) / 2 + 1)) * qualityCoefficient) || 1; class BaseInitor implements EntryInitor {
const max = Math.round((lv * valCoefficient + (lv / 2 + 1)) * qualityCoefficient) || 1; type: string;
const min = Math.round((lv * valCoefficient + 1) * qualityCoefficient) || 1; factor1: number;
return new Entry('atk', value, '+' + value, max, min); factor2: number;
}, constant: number;
atkPercent: (lv: number, qualityCoefficient: number) => { defCoefficient: number = 1;
const value = Math.round((lv * 0.11 + ((Math.random() * lv) / 10 + 4)) * qualityCoefficient) || 1; constructor(type: string, factor1: number, factor2: number, constant: number) {
const max = Math.round((lv * 0.11 + (lv / 10 + 4)) * qualityCoefficient) || 1; this.type = type;
const min = Math.round((lv * 0.11 + 4) * qualityCoefficient) || 1; this.factor1 = factor1;
return new Entry('atkPercent', value, '+' + value + '%', max, min); this.factor2 = factor2;
}, this.constant = constant;
hp: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { }
valCoefficient = valCoefficient || 0.3; init(lv: number, qualityCoefficient: number, valCoefficient?: number, extraQuality?: string): Entry {
const value = Math.round(lv * valCoefficient * 10 + ((Math.random() * lv) / 2 + 1) * qualityCoefficient) || 1; valCoefficient = valCoefficient || this.defCoefficient;
const max = Math.round(lv * valCoefficient * 10 + (lv / 2 + 1) * qualityCoefficient) || 1; const num1 = lv * valCoefficient * this.factor1;
const min = Math.round(lv * valCoefficient * 10 + qualityCoefficient) || 1; const num2 = Math.random() * lv * this.factor2 + this.constant;
return new Entry('hp', value, '+' + value, max, min); const manNum2 = lv * this.factor2 + this.constant;
}, const minNum2 = this.constant;
hpPercent: (lv: number, qualityCoefficient: number) => { const value = Math.round((num1 + num2) * qualityCoefficient) || 1;
const value = Math.round((lv * 0.1 + ((Math.random() * lv) / 10 + 4)) * qualityCoefficient) || 1; const max = Math.round((num1 + manNum2) * qualityCoefficient) || 1;
const max = Math.round((lv * 0.1 + (lv / 10 + 4)) * qualityCoefficient) || 1; const min = Math.round((num1 + minNum2) * qualityCoefficient) || 1;
const min = Math.round((lv * 0.1 + 4) * qualityCoefficient) || 1; return new Entry(this.type, value, '+' + value, max, min);
return new Entry('hpPercent', value, '+' + value + '%', max, min); }
}, }
def: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { class PercentInitor extends BaseInitor {
valCoefficient = valCoefficient || 0.2; init(lv: number, qualityCoefficient: number, valCoefficient?: number, extraQuality?: string): Entry {
const value = Math.round((lv * valCoefficient + ((Math.random() * lv) / 2 + 1)) * qualityCoefficient) || 1; const entry = super.init(lv, qualityCoefficient, valCoefficient, extraQuality);
const max = Math.round((lv * valCoefficient + (lv / 2 + 1)) * qualityCoefficient) || 1; entry.showVal += '%';
const min = Math.round((lv * valCoefficient + 1) * qualityCoefficient) || 1; return entry;
return new Entry('def', value, '+' + value, max, min); }
}, }
defPercent: (lv: number, qualityCoefficient: number) => { class CritInitor extends BaseInitor {
const value = Math.round((lv * 0.13 + (Math.random() * lv) / 10 + 4) * qualityCoefficient) || 1; constructor(type: string, factor1: number, factor2: number, constant: number) {
const max = Math.round((lv * 0.13 + lv / 10 + 4) * qualityCoefficient) || 1; super(type, factor1, factor2, constant);
const min = Math.round((lv * 0.13 + 4) * qualityCoefficient) || 1; this.defCoefficient = 0;
return new Entry('defPercent', value, '+' + value + '%', max, min); }
}, init(lv: number, qualityCoefficient: number, valCoefficient?: number, extraQuality?: string): Entry {
bloc: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { valCoefficient = valCoefficient || this.defCoefficient;
valCoefficient = valCoefficient || 0.6; const value = this.call(Math.random() * this.factor1, lv, valCoefficient, qualityCoefficient);
const value = Math.round((lv * valCoefficient) / 2 + ((Math.random() * lv) / 3 + 1) * qualityCoefficient) || 1; const max = this.call(this.factor1, lv, valCoefficient, qualityCoefficient);
const max = Math.round((lv * valCoefficient) / 2 + (lv / 3 + 1) * qualityCoefficient) || 1; const min = this.call(0, lv, valCoefficient, qualityCoefficient);
const min = Math.round((lv * valCoefficient) / 2 + 1 * qualityCoefficient) || 1; return new Entry(this.type, value, '+' + value + '%', max, min);
return new Entry('bloc', value, '+' + value, max, min); }
}, call(num1, lv, valCoefficient, qualityCoefficient): number {
blocPercent: (lv: number, qualityCoefficient: number) => { const lvFactor = (0.5 * lv) / 100 + 0.5;
const value = Math.round((lv * 0.1 + ((Math.random() * lv) / 10 + 4)) * qualityCoefficient) || 1; const num2 = this.factor2 * valCoefficient + this.constant;
const max = Math.round((lv * 0.1 + (lv / 10 + 4)) * qualityCoefficient) || 1; return Math.round(lvFactor * (num1 + num2) * qualityCoefficient) || 1;
const min = Math.round((lv * 0.1 + 4) * qualityCoefficient) || 1; }
return new Entry('blocPercent', value, '+' + value + '%', max, min); }
}, class DmgInitor extends BaseInitor {
crit: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { init(lv: number, qualityCoefficient: number, valCoefficient?: number, extraQuality?: string): Entry {
valCoefficient = valCoefficient || 0;
const value = Math.round(((0.5 * lv) / 100 + 0.5) * (Math.random() * 5 + 5 + 2 * valCoefficient) * qualityCoefficient) || 1;
const max = Math.round(((0.5 * lv) / 100 + 0.5) * (5 + 5 + 2 * valCoefficient) * qualityCoefficient) || 1;
const min = Math.round(((0.5 * lv) / 100 + 0.5) * (5 + 2 * valCoefficient) * qualityCoefficient) || 1;
return new Entry('crit', value, '+' + value + '%', max, min);
},
critDmg: (lv: number, qualityCoefficient: number, valCoefficient?: number) => {
valCoefficient = valCoefficient || 0;
const value = Math.round(((0.5 * lv) / 100 + 0.5) * (Math.random() * (12 + 6 * valCoefficient) + 20) * qualityCoefficient) || 1;
const max = Math.round(((0.5 * lv) / 100 + 0.5) * (12 + 6 * valCoefficient + 20) * qualityCoefficient) || 1;
const min = Math.round(((0.5 * lv) / 100 + 0.5) * 20 * qualityCoefficient) || 1;
return new Entry('critDmg', value, '+' + value + '%', max, min);
},
dmgPercent: (lv: number, qualityCoefficient: number, valCoefficient?: number) => {
valCoefficient = valCoefficient || 1; valCoefficient = valCoefficient || 1;
const value = Math.round(((Math.random() + 1) * lv * 0.05 + 3) * valCoefficient * qualityCoefficient) || 1; const value = Math.round((lv * this.factor1 * (Math.random() + this.factor2) + this.constant) * qualityCoefficient * valCoefficient) || 1;
const max = Math.round((lv * 0.1 + 3) * valCoefficient * qualityCoefficient) || 1; const max = Math.round((lv * this.factor1 * (1 + this.factor2) + this.constant) * qualityCoefficient * valCoefficient) || 1;
const min = Math.round((lv * 0.05 + 3) * valCoefficient * qualityCoefficient) || 1; const min = Math.round((lv * this.factor1 * this.factor2 + this.constant) * qualityCoefficient * valCoefficient) || 1;
return new Entry('dmgPercent', value, '+' + value + '%', max, min); return new Entry(this.type, value, '+' + value + '%', max, min);
}, }
dmgReduc: (lv: number, qualityCoefficient: number) => { }
const value = Math.round((Math.random() * lv * 0.05 + 6) * qualityCoefficient) || 1;
const max = Math.round((lv * 0.05 + 6) * qualityCoefficient) || 1; export const entry_initor = {
const min = Math.round(6 * qualityCoefficient) || 1; atk: new BaseInitor('atk', 1, 0.5, 1),
return new Entry('dmgReduc', value, '+' + value + '%', max, min); atkPercent: new PercentInitor('atkPercent', 0.11, 0.1, 4),
}, hp: new BaseInitor('hp', 5, 0.5, 1),
critAvoid: (lv: number, qualityCoefficient: number) => { hpPercent: new PercentInitor('hpPercent', 0.1, 0.1, 4),
const value = Math.round(((0.5 * lv) / 100 + 0.5) * (Math.random() * 5 + 5 + 2) * qualityCoefficient) || 1; def: new BaseInitor('def', 1, 0.5, 1),
const max = Math.round(((0.5 * lv) / 100 + 0.5) * (5 + 5 + 2) * qualityCoefficient) || 1; defPercent: new PercentInitor('defPercent', 0.13, 0.1, 4),
const min = Math.round(((0.5 * lv) / 100 + 0.5) * (5 + 2) * qualityCoefficient) || 1; bloc: new BaseInitor('bloc', 0.25, 1 / 3, 1),
return new Entry('critAvoid', value, '+' + value + '%', max, min); blocPercent: new PercentInitor('blocPercent', 0.1, 0.1, 4),
}, crit: new CritInitor('crit', 5, 2, 5),
critDmgReduc: (lv: number, qualityCoefficient: number, valCoefficient?: number) => { critDmg: new CritInitor('critDmg', 15, 7, 16),
valCoefficient = valCoefficient || 0; critAvoid: new CritInitor('critAvoid', 5, 0, 7),
const value = Math.round(((0.5 * lv) / 100 + 0.5) * (Math.random() * (12 + 6 * valCoefficient) + 20) * qualityCoefficient) || 1; critDmgReduc: new CritInitor('critDmgReduc', 15, 7, 16),
const max = Math.round(((0.5 * lv) / 100 + 0.5) * (12 + 6 * valCoefficient + 20) * qualityCoefficient) || 1; dmgPercent: new DmgInitor('dmgPercent', 0.05, 1, 3),
const min = Math.round(((0.5 * lv) / 100 + 0.5) * 20 * qualityCoefficient) || 1; dmgReduc: new DmgInitor('dmgReduc', 0.05, 0, 6),
return new Entry('critDmgReduc', value, '+' + value + '%', max, min); moveSpeed: new CritInitor('moveSpeed', 8, 6, 17),
},
moveSpeed: (lv: number, qualityCoefficient: number, valCoefficient?: number) => {
valCoefficient = valCoefficient || 0;
const value = Math.round(((0.5 * lv) / 100 + 0.5) * (Math.random() * (5 + 6 * valCoefficient) + 20) * qualityCoefficient) || 1;
const max = Math.round(((0.5 * lv) / 100 + 0.5) * (5 + 6 * valCoefficient + 20) * qualityCoefficient) || 1;
const min = Math.round(((0.5 * lv) / 100 + 0.5) * 20 * qualityCoefficient) || 1;
return new Entry('moveSpeed', value, '+' + value + '%', max, min);
},
}; };

Loading…
Cancel
Save