略微优化伤害计算逻辑

This commit is contained in:
Kokomi 2023-11-13 05:06:03 +08:00
parent b1dc157d5c
commit 03d585484f
5 changed files with 94 additions and 58 deletions

25
models/dmg/AttrItem.js Normal file
View File

@ -0,0 +1,25 @@
export default class AttrItem {
constructor (ds) {
this.base = ds.base * 1 || 0
this.plus = ds.plus * 1 || 0
this.pct = ds.pct * 1 || 0
this.inc = ds.inc * 1 || 0
}
static create (ds) {
return new AttrItem(ds)
/*
return {
base: ds.base * 1 || 0,
plus: ds.plus * 1 || 0,
pct: ds.pct * 1 || 0,
inc: ds.inc * 1 || 0
} */
}
toString () {
return (this.base || 0) + (this.plus || 0) + ((this.base || 0) * (this.pct || 0) / 100)
}
}

View File

@ -5,6 +5,7 @@ import { eleBaseDmg } from './DmgCalcMeta.js'
import lodash from 'lodash' import lodash from 'lodash'
import DmgMastery from './DmgMastery.js' import DmgMastery from './DmgMastery.js'
import { Format, Meta } from '#miao' import { Format, Meta } from '#miao'
import AttrItem from './AttrItem.js'
let DmgAttr = { let DmgAttr = {
// 计算并返回指定属性值 // 计算并返回指定属性值
@ -13,30 +14,35 @@ let DmgAttr = {
}, },
// 获取profile对应attr属性值 // 获取profile对应attr属性值
getAttr ({ id, attr, weapon, char, game = 'gs' }) { getAttr ({ originalAttr, attr, weapon, char, game = 'gs' }) {
let ret = {} let ret = {}
if (originalAttr) {
ret = lodash.merge({}, originalAttr)
}
// 基础属性 // 基础属性
lodash.forEach('atk,def,hp'.split(','), (key) => { lodash.forEach('atk,def,hp'.split(','), (key) => {
ret[key] = { ret[key] = AttrItem.create(originalAttr?.[key] || {
base: attr[`${key}Base`] * 1 || 0, base: attr[`${key}Base`] * 1 || 0,
plus: attr[key] * 1 - attr[`${key}Base`] * 1 || 0, plus: attr[key] * 1 - attr[`${key}Base`] * 1 || 0,
pct: 0 pct: 0
} })
}) })
lodash.forEach((game === 'gs' ? 'mastery,recharge,cpct,cdmg,heal,dmg,phy' : 'speed,recharge,cpct,cdmg,heal,dmg,enemyDmg,effPct,effDef,stance').split(','), (key) => { lodash.forEach((game === 'gs' ? 'mastery,recharge,cpct,cdmg,heal,dmg,phy' : 'speed,recharge,cpct,cdmg,heal,dmg,enemyDmg,effPct,effDef,stance').split(','), (key) => {
ret[key] = { ret[key] = AttrItem.create(originalAttr?.[key] || {
base: attr[key] * 1 || 0, // 基础值 base: attr[key] * 1 || 0, // 基础值
plus: 0, // 加成值 plus: 0, // 加成值
pct: 0, // 百分比加成 pct: 0, // 百分比加成
inc: 0 // 提高:护盾增效&治疗增效 inc: 0 // 提高:护盾增效&治疗增效
} })
}) })
// 技能属性记录 // 技能属性记录
lodash.forEach((game === 'gs' ? 'a,a2,a3,e,q' : 'a,a2,a3,e,e2,q,t').split(','), (key) => { lodash.forEach((game === 'gs' ? 'a,a2,a3,e,q' : 'a,a2,a3,e,e2,q,t').split(','), (key) => {
ret[key] = { ret[key] = ret[key] || {
pct: 0, // 倍率加成 pct: 0, // 倍率加成
multi: 0, // 独立倍率乘区加成宵宫E等 multi: 0, // 独立倍率乘区加成宵宫E等
@ -51,44 +57,46 @@ let DmgAttr = {
} }
}) })
ret.enemy = { ret.enemy = ret.enemy || {
def: 0, // 降低防御 def: 0, // 降低防御
ignore: 0, // 无视防御 ignore: 0, // 无视防御
phy: 0 // 物理防御 phy: 0 // 物理防御
} }
ret.shield = { ret.shield = AttrItem.create(originalAttr?.shield || {
base: 100, // 基础 base: 100, // 基础
plus: 0, // 护盾强效 plus: 0, // 护盾强效
inc: 100 // 吸收倍率 inc: 100 // 吸收倍率
} })
ret.weapon = weapon // 武器 if (!originalAttr) {
ret.weaponTypeName = char.weaponTypeName // 武器类型 ret.weapon = weapon // 武器
ret.element = Format.elemName(char.elem) // 元素类型 ret.weaponTypeName = char.weaponTypeName // 武器类型
ret.refine = ((weapon.affix || ret.refine || 1) * 1 - 1) || 0 // 武器精炼 ret.element = Format.elemName(char.elem) // 元素类型
ret.multi = 0 // 倍率独立乘区 ret.refine = ((weapon.affix || ret.refine || 1) * 1 - 1) || 0 // 武器精炼
ret.kx = 0 // 敌人抗性降低 ret.multi = 0 // 倍率独立乘区
if (game === 'gs') { ret.kx = 0 // 敌人抗性降低
ret.vaporize = 0 // 蒸发 if (game === 'gs') {
ret.melt = 0 // 融化 ret.vaporize = 0 // 蒸发
ret.burning = 0 // 燃烧 ret.melt = 0 // 融化
ret.superConduct = 0 // 超导 ret.burning = 0 // 燃烧
ret.swirl = 0 // 扩散 ret.superConduct = 0 // 超导
ret.electroCharged = 0 // 感电 ret.swirl = 0 // 扩散
ret.shatter = 0 // 碎冰 ret.electroCharged = 0 // 感电
ret.overloaded = 0 // 超载 ret.shatter = 0 // 碎冰
ret.bloom = 0 // 绽放 ret.overloaded = 0 // 超载
ret.burgeon = 0 // 烈绽放 ret.bloom = 0 // 绽放
ret.hyperBloom = 0 // 超绽放 ret.burgeon = 0 // 烈绽放
ret.aggravate = 0 // 超激化 ret.hyperBloom = 0 // 超绽放
ret.spread = 0 // 蔓激化 ret.aggravate = 0 // 超激化
ret.fykx = 0 // 敌人反应抗性降低 ret.spread = 0 // 蔓激化
} else if (game === 'sr') { ret.fykx = 0 // 敌人反应抗性降低
// 技能持续伤害与弱点击破持续伤害 } else if (game === 'sr') {
ret.dot = { // 技能持续伤害与弱点击破持续伤害
dmg: 0, // 伤害提高 ret.dot = {
enemydmg: 0 // 承受伤害提高 dmg: 0, // 伤害提高
enemydmg: 0 // 承受伤害提高
}
} }
} }
return ret return ret
@ -103,15 +111,14 @@ let DmgAttr = {
refine: attr.refine, refine: attr.refine,
weaponTypeName: attr.weaponTypeName, weaponTypeName: attr.weaponTypeName,
weapon: attr.weapon, weapon: attr.weapon,
element: Format.elemName(attr.element) || attr.element, element: Format.elemName(attr.element) || attr.element, // 计算属性
// 计算属性
calc: DmgAttr.getAttrValue calc: DmgAttr.getAttrValue
} }
}, },
// 计算属性 // 计算属性
calcAttr ({ originalAttr, buffs, meta, params = {}, incAttr = '', reduceAttr = '', talent = '', game = 'gs' }) { calcAttr ({ originalAttr, buffs, meta, params = {}, incAttr = '', reduceAttr = '', talent = '', game = 'gs' }) {
let attr = lodash.merge({}, originalAttr) let attr = DmgAttr.getAttr({ originalAttr, game: originalAttr.game })
let msg = [] let msg = []
let { attrMap } = Meta.getMeta(game, 'arti') let { attrMap } = Meta.getMeta(game, 'arti')
@ -156,13 +163,10 @@ let DmgAttr = {
if (buff.mastery) { if (buff.mastery) {
let mKey = { let mKey = {
vaporize: '蒸发', vaporize: '蒸发', melt: '融化', swirl: '扩散'
melt: '融化',
swirl: '扩散'
} }
let mKey2 = { let mKey2 = {
aggravate: '超激化', aggravate: '超激化', spread: '蔓激化'
spread: '蔓激化'
} }
let mastery = Math.max(0, attr.mastery.base + attr.mastery.plus) let mastery = Math.max(0, attr.mastery.base + attr.mastery.plus)
@ -184,8 +188,12 @@ let DmgAttr = {
if (lodash.isFunction(val)) { if (lodash.isFunction(val)) {
val = val(ds) val = val(ds)
} }
if (!val) {
return
}
title = title.replace(`[${key}]`, Format.comma(val, 1)) title = title.replace(`[${key}]`, Format.comma(val, 1))
// 技能提高 // 技能提高
let tRet = /^(a|a2|a3|e|q|t)(Def|Ignore|Dmg|Plus|Pct|Cpct|Cdmg|Multi)$/.exec(key) let tRet = /^(a|a2|a3|e|q|t)(Def|Ignore|Dmg|Plus|Pct|Cpct|Cdmg|Multi)$/.exec(key)
if (tRet) { if (tRet) {
@ -194,6 +202,9 @@ let DmgAttr = {
} }
let aRet = /^(hp|def|atk|mastery|cpct|cdmg|heal|recharge|dmg|phy|shield|speed)(Plus|Pct|Inc)?$/.exec(key) let aRet = /^(hp|def|atk|mastery|cpct|cdmg|heal|recharge|dmg|phy|shield|speed)(Plus|Pct|Inc)?$/.exec(key)
if (aRet) { if (aRet) {
if (aRet[1] === 'hp') {
console.log(val, key, attr[aRet[1]], val)
}
attr[aRet[1]][aRet[2] ? aRet[2].toLowerCase() : 'plus'] += val * 1 || 0 attr[aRet[1]][aRet[2] ? aRet[2].toLowerCase() : 'plus'] += val * 1 || 0
return return
} }

View File

@ -79,7 +79,7 @@ const Serv = {
if (!req) { if (!req) {
return false return false
} }
let serv = Serv.getServ(e.uid, player.game) let serv = Serv.getServ(e.uid || player.uid, player.game)
let { uid } = player let { uid } = player
try { try {
player._update = [] player._update = []

View File

@ -1,29 +1,29 @@
export const details = [{ export const details = [{
title: 'E众水歌者治疗', title: 'E众水歌者治疗',
dmg: ({ talent, attr, calc }, { heal }) => dmg: ({ talent, attr }, { heal }) =>
heal(talent.e['众水的歌者治疗量2'][0] * calc(attr.hp) / 100 + talent.e['众水的歌者治疗量2'][1] * 1) heal(talent.e['众水的歌者治疗量2'][0] * attr.hp / 100 + talent.e['众水的歌者治疗量2'][1] * 1)
}, { }, {
title: 'E海薇玛夫人(海马)·伤害', title: 'E海薇玛夫人(海马)·伤害',
dmg: ({ talent, attr, calc }, { basic }) => basic(calc(attr.hp) * talent.e['海薇玛夫人伤害'] / 100 * 1.4, 'e') dmg: ({ talent, attr }, { basic }) => basic(attr.hp * talent.e['海薇玛夫人伤害'] / 100 * 1.4, 'e')
}, { }, {
title: 'E乌瑟勋爵(章鱼)·伤害', title: 'E乌瑟勋爵(章鱼)·伤害',
dmg: ({ talent, attr, calc }, { basic }) => basic(calc(attr.hp) * talent.e['乌瑟勋爵伤害'] / 100 * 1.4, 'e') dmg: ({ talent, attr }, { basic }) => basic(attr.hp * talent.e['乌瑟勋爵伤害'] / 100 * 1.4, 'e')
}, { }, {
title: 'E谢贝蕾妲小姐(螃蟹)·伤害', title: 'E谢贝蕾妲小姐(螃蟹)·伤害',
dmgKey: 'e', dmgKey: 'e',
dmg: ({ talent, attr, calc }, { basic }) => basic(calc(attr.hp) * talent.e['谢贝蕾妲小姐伤害'] / 100 * 1.4, 'e') dmg: ({ talent, attr }, { basic }) => basic(attr.hp * talent.e['谢贝蕾妲小姐伤害'] / 100 * 1.4, 'e')
}, { }, {
title: 'E谢贝蕾妲小姐(螃蟹)·蒸发', title: 'E谢贝蕾妲小姐(螃蟹)·蒸发',
dmgKey: 'e', dmgKey: 'e',
dmg: ({ talent, attr, calc }, { basic }) => basic(calc(attr.hp) * talent.e['谢贝蕾妲小姐伤害'] / 100 * 1.4, 'e', '蒸发') dmg: ({ talent, attr }, { basic }) => basic(attr.hp * talent.e['谢贝蕾妲小姐伤害'] / 100 * 1.4, 'e', '蒸发')
}, { }, {
title: 'Q万众狂欢·伤害', title: 'Q万众狂欢·伤害',
params: { talentQ: true }, params: { talentQ: true },
dmg: ({ talent, attr, calc, cons }, { basic }) => basic(calc(attr.hp) * (talent.q['技能伤害'] / 100), 'q') dmg: ({ talent, attr, cons }, { basic }) => basic(attr.hp * (talent.q['技能伤害'] / 100), 'q')
}, { }, {
title: 'Q万众狂欢伤害·蒸发', title: 'Q万众狂欢伤害·蒸发',
params: { talentQ: true }, params: { talentQ: true },
dmg: ({ talent, attr, calc, cons }, { basic }) => basic(calc(attr.hp) * (talent.q['技能伤害'] / 100), 'q', '蒸发') dmg: ({ talent, attr, cons }, { basic }) => basic(attr.hp * (talent.q['技能伤害'] / 100), 'q', '蒸发')
}] }]
export const mainAttr = 'hp,mastery,cpct,cdmg' export const mainAttr = 'hp,mastery,cpct,cdmg'
@ -40,7 +40,7 @@ export const buffs = [{
}, { }, {
title: '芙宁娜被动:基于生命值,提升召唤物伤害[eDmg]%', title: '芙宁娜被动:基于生命值,提升召唤物伤害[eDmg]%',
data: { data: {
eDmg: ({ calc, attr }) => Math.min(28, (calc(attr.hp)) / 1000 * 0.7) eDmg: ({ attr }) => Math.min(28, attr.hp / 1000 * 0.7)
} }
}, { }, {
title: '芙宁娜1命气氛值层数上限提升100', title: '芙宁娜1命气氛值层数上限提升100',

View File

@ -4,8 +4,8 @@ export const details = [{
dmg: ({ talent }, dmg) => dmg(talent.e['技能伤害'], 'e') dmg: ({ talent }, dmg) => dmg(talent.e['技能伤害'], 'e')
}, { }, {
title: 'E刹那之花伤害', title: 'E刹那之花伤害',
dmg: ({ talent, attr, calc }, { basic }) => { dmg: ({ talent, attr }, { basic }) => {
let ret = talent.e['刹那之花伤害'] * calc(attr.def) / 100 + attr.e.plus let ret = talent.e['刹那之花伤害'] * attr.def / 100 + attr.e.plus
return basic(ret, 'e') return basic(ret, 'e')
} }
}, { }, {
@ -13,8 +13,8 @@ export const details = [{
params: { params: {
half: true half: true
}, },
dmg: ({ talent, attr, calc }, { basic }) => { dmg: ({ talent, attr }, { basic }) => {
let ret = talent.e['刹那之花伤害'] * calc(attr.def) / 100 + attr.e.plus let ret = talent.e['刹那之花伤害'] * attr.def / 100 + attr.e.plus
return basic(ret, 'e') return basic(ret, 'e')
} }
}, { }, {
@ -41,6 +41,6 @@ export const buffs = [{
cons: 2, cons: 2,
sort: 9, sort: 9,
data: { data: {
qPlus: ({ params, attr, calc }) => params.buff === 0 ? 0 : calc(attr.def) * 1.2 qPlus: ({ params, attr }) => params.buff === 0 ? 0 : attr.def * 1.2
} }
}] }]