mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
新增柏妮思伤害计算等
This commit is contained in:
parent
6573f1d600
commit
b51acca73e
19 changed files with 1053 additions and 164 deletions
|
|
@ -19,10 +19,21 @@ export interface skill {
|
|||
fixedMultiplier?: number
|
||||
/** 角色面板伤害统计中是否隐藏显示 */
|
||||
isHide?: boolean
|
||||
/**
|
||||
* 重定向技能伤害类型
|
||||
*
|
||||
* 当出现“X"造成的伤害被视为“Y”伤害时,可使用该参数指定Y的类型
|
||||
* 参考技能类型命名标准
|
||||
*/
|
||||
redirect?: string
|
||||
/** 禁用伤害计算cache */
|
||||
banCache?: boolean
|
||||
/** 自定义计算逻辑 */
|
||||
dmg?: (calc: Calculator) => damage
|
||||
/** 额外处理 */
|
||||
before?: ({ avatar, usefulBuffs, calc }: {
|
||||
before?: ({ skill, avatar, usefulBuffs, calc }: {
|
||||
/** 技能自身 */
|
||||
skill: skill
|
||||
avatar: ZZZAvatarInfo
|
||||
usefulBuffs: buff[]
|
||||
calc: Calculator
|
||||
|
|
@ -77,6 +88,8 @@ export interface damage {
|
|||
expectDMG: number
|
||||
}
|
||||
add?: (damage: string | damage) => void
|
||||
fnc?: (fnc: (n: number) => number) => void
|
||||
x?: (n: number) => void
|
||||
}
|
||||
|
||||
const elementType2element = (elementType: number) => elementEnum[[0, 1, 2, 3, -1, 4][elementType - 200]] as element
|
||||
|
|
@ -172,30 +185,37 @@ export class Calculator {
|
|||
if (!MySkill) return
|
||||
return this.calc_skill(MySkill)
|
||||
}
|
||||
if (this.damageCache[skill.type]) return this.damageCache[skill.type]
|
||||
logger.debug(`${logger.green(skill.type)}伤害计算:`)
|
||||
if (!skill.banCache && this.damageCache[skill.type]) return this.damageCache[skill.type]
|
||||
logger.debug(`${logger.green(skill.type)}${skill.name}伤害计算:`)
|
||||
if (skill.dmg) {
|
||||
const dmg = skill.dmg(this)
|
||||
logger.debug('自定义计算最终伤害:', dmg.result)
|
||||
return dmg
|
||||
}
|
||||
this.cache = {}
|
||||
if (skill.dmg) return skill.dmg(this)
|
||||
/** 缩小筛选范围 */
|
||||
const usefulBuffs = this.buffM.filter({
|
||||
element: skill.element,
|
||||
range: [skill.type]
|
||||
range: skill.redirect ? [skill.type, skill.redirect] : [skill.type]
|
||||
}, this)
|
||||
if (skill.before) skill.before({ avatar: this.avatar, usefulBuffs, calc: this })
|
||||
if (skill.before) skill.before({ skill, avatar: this.avatar, usefulBuffs, calc: this })
|
||||
let Multiplier = 0
|
||||
const isAnomaly = typeof anomalyEnum[skill.type as anomaly] === 'number'
|
||||
if (skill.fixedMultiplier) Multiplier = skill.fixedMultiplier
|
||||
else if (isAnomaly) {
|
||||
Multiplier = (
|
||||
skill.type === '紊乱' ?
|
||||
this.get_DiscoverMultiplier(skill, usefulBuffs) :
|
||||
this.get_AnomalyMultiplier(skill, usefulBuffs)
|
||||
this.get_DiscoverMultiplier(skill) :
|
||||
this.get_AnomalyMultiplier(skill, usefulBuffs, skill.name.includes('每') ? 1 : 0)
|
||||
) || 0
|
||||
} else {
|
||||
if (skill.skillMultiplier) Multiplier = skill.skillMultiplier[this.get_SkillLevel(skill.type[0]) - 1]
|
||||
else Multiplier = this.get_Multiplier(skill.type)
|
||||
}
|
||||
const ExtraMultiplier = this.get_ExtraMultiplier(skill, usefulBuffs)
|
||||
Multiplier += ExtraMultiplier
|
||||
if (!Multiplier) return logger.warn('技能倍率缺失:', skill)
|
||||
if (ExtraMultiplier) logger.debug(`最终倍率:${Multiplier}`)
|
||||
const ATK = this.get_ATK(skill, usefulBuffs)
|
||||
let CRITRate = 0, CRITDMG = 0, AnomalyCRITRate = 0, AnomalyCRITDMG = 0
|
||||
let AnomalyProficiencyArea = 0, AnomalyBoostArea = 0, LevelArea = 0
|
||||
|
|
@ -249,15 +269,30 @@ export class Calculator {
|
|||
damage.result.expectDMG += d.result.expectDMG
|
||||
damage.result.critDMG += d.result.critDMG
|
||||
}
|
||||
damage.fnc = (fnc) => {
|
||||
damage.result.critDMG = fnc(damage.result.critDMG)
|
||||
damage.result.expectDMG = fnc(damage.result.expectDMG)
|
||||
}
|
||||
damage.x = (n) => {
|
||||
logger.debug('伤害系数:' + n)
|
||||
damage.fnc!(v => v * n)
|
||||
}
|
||||
skill.after({ avatar: this.avatar, damage, calc: this, usefulBuffs })
|
||||
}
|
||||
logger.debug('最终伤害:', result)
|
||||
this.damageCache[skill.type] = damage
|
||||
if (!skill.banCache) this.damageCache[skill.type] = damage
|
||||
return damage
|
||||
}
|
||||
|
||||
calc() {
|
||||
return this.skills.map(skill => this.calc_skill(skill)).filter(v => v && !v.skill?.isHide)
|
||||
return this.skills.map(skill => {
|
||||
try {
|
||||
return this.calc_skill(skill)
|
||||
} catch (e) {
|
||||
logger.error('伤害计算错误:', e)
|
||||
return
|
||||
}
|
||||
}).filter(v => v && !v.skill?.isHide)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -311,13 +346,13 @@ export class Calculator {
|
|||
}
|
||||
|
||||
/** 获取属性异常倍率 */
|
||||
get_AnomalyMultiplier(skill: skill, usefulBuffs: buff[], anomalyData?: typeof AnomalyData[number]) {
|
||||
anomalyData ||= this.get_AnomalyData(skill)
|
||||
get_AnomalyMultiplier(skill: skill, usefulBuffs: buff[], times = 0) {
|
||||
const anomalyData = this.get_AnomalyData(skill)
|
||||
if (!anomalyData) return
|
||||
let Multiplier = anomalyData.multiplier
|
||||
if (anomalyData.duration && anomalyData.interval) {
|
||||
const AnomalyDuration = this.get_AnomalyDuration(skill, usefulBuffs, anomalyData.duration)
|
||||
const times = Math.floor((AnomalyDuration * 10) / (anomalyData.interval * 10))
|
||||
times ||= Math.floor((AnomalyDuration * 10) / (anomalyData.interval * 10))
|
||||
Multiplier = anomalyData.multiplier * times
|
||||
}
|
||||
logger.debug(`倍率:${Multiplier}`)
|
||||
|
|
@ -325,10 +360,14 @@ export class Calculator {
|
|||
}
|
||||
|
||||
/** 获取紊乱倍率 */
|
||||
get_DiscoverMultiplier(skill: skill, usefulBuffs: buff[], anomalyData?: typeof AnomalyData[number]) {
|
||||
anomalyData ||= this.get_AnomalyData(skill)
|
||||
get_DiscoverMultiplier(skill: skill) {
|
||||
const anomalyData = this.get_AnomalyData(skill)
|
||||
if (!anomalyData) return
|
||||
const AnomalyDuration = this.get_AnomalyDuration(skill, usefulBuffs, anomalyData.duration)
|
||||
const AnomalyDuration = this.get_AnomalyDuration({
|
||||
...skill,
|
||||
name: anomalyData.name,
|
||||
type: anomalyData.name
|
||||
}, this.buffM.buffs, anomalyData.duration)
|
||||
const times = Math.floor((AnomalyDuration * 10) / (anomalyData.interval * 10))
|
||||
const discover = anomalyData.discover!
|
||||
const Multiplier = discover.fixed_multiplier + times * discover.multiplier
|
||||
|
|
@ -360,7 +399,7 @@ export class Calculator {
|
|||
get(type: buff['type'], initial: number, skill: skill, usefulBuffs: buff[] = this.buffM.buffs, isRatio = false): number {
|
||||
return this.cache[type] ??= this.buffM._filter(usefulBuffs, {
|
||||
element: skill?.element,
|
||||
range: [skill?.type],
|
||||
range: skill?.redirect ? [skill.type, skill.redirect] : [skill?.type],
|
||||
type
|
||||
}, this).reduce((previousValue, buff) => {
|
||||
const { value } = buff
|
||||
|
|
@ -385,6 +424,13 @@ export class Calculator {
|
|||
return ATK
|
||||
}
|
||||
|
||||
/** 额外倍率 */
|
||||
get_ExtraMultiplier(skill: skill, usefulBuffs: buff[]) {
|
||||
const ExtraMultiplier = this.get('倍率', 0, skill, usefulBuffs)
|
||||
ExtraMultiplier && logger.debug(`额外倍率:${ExtraMultiplier}`)
|
||||
return ExtraMultiplier
|
||||
}
|
||||
|
||||
/** 暴击率 */
|
||||
get_CRITRate(skill: skill, usefulBuffs: buff[]) {
|
||||
let CRITRate = this.get('暴击率', this.initial_properties.CRITRate, skill, usefulBuffs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue