stat filter tweaks

This commit is contained in:
Alexander Drozdov
2020-08-15 22:28:01 +03:00
parent f323c02885
commit 6b932215eb
7 changed files with 84 additions and 38 deletions
@@ -46,12 +46,15 @@ export function initUiModFilters (item: ParsedItem): StatFilter[] {
ctx.filters.forEach(filter => { filter.disabled = true })
}
finalFilterTweaks(ctx)
return ctx.filters
}
export function itemModToFilter (mod: ItemModifier, item: ParsedItem) {
const filter: Writeable<StatFilter> = {
tradeId: mod.stat.types.find(type => type.name === mod.type)!.tradeId,
statRef: mod.stat.ref,
text: mod.stat.text,
type: mod.type,
option: mod.option,
@@ -159,3 +162,7 @@ function filterAdjustmentForNegate (
filter.invert = !filter.invert
}
}
function finalFilterTweaks (ctx: FiltersCreationContext) {
const { item } = ctx
}
@@ -72,6 +72,7 @@ export interface ItemFilters {
export interface StatFilter {
readonly tradeId: string[]
readonly statRef: string
readonly text: string
readonly roll?: number
readonly type: string
@@ -2,9 +2,10 @@ import { percentRollDelta } from '../util'
import { INTERNAL_TRADE_ID, StatFilter } from '../interfaces'
import { FiltersCreationContext, itemModToFilter } from '../create-stat-filters'
import { propAt20Quality, variablePropAt20Quality, QUALITY_STATS } from './calc-q20'
import { stat, UNIQUES } from '@/assets/data'
import { UNIQUES } from '@/assets/data'
import { ARMOUR, WEAPON } from '@/parser/meta'
import { Config } from '@/web/Config'
import { internalPropStat } from './util'
export function filterUniqueItemProp (ctx: FiltersCreationContext) {
if (ARMOUR.has(ctx.item.category!)) {
@@ -122,9 +123,11 @@ function propToFilter (
if (propInfo && isWithinBounds(totalQ20, propInfo)) {
if (propInfo.min === propInfo.max) {
return ({
tradeId: [tradeId],
text,
type,
...internalPropStat(
tradeId,
text,
type
),
disabled: true,
hidden: 'Roll is not variable',
defaultMin: totalQ20,
@@ -136,9 +139,11 @@ function propToFilter (
} else {
const percent = Config.store.searchStatRange * 2
return ({
tradeId: [tradeId],
text,
type,
...internalPropStat(
tradeId,
text,
type
),
disabled: true,
boundMin: propInfo.min,
boundMax: propInfo.max,
@@ -152,9 +157,11 @@ function propToFilter (
} else {
// missing unique (Two-Toned Boots) / stat affecting prop is variant (Atziri's Splendour) / corrupted implicit affecting prop
return ({
tradeId: [tradeId],
text,
type,
...internalPropStat(
tradeId,
text,
type
),
disabled: true,
defaultMin: totalQ20,
defaultMax: totalQ20,
@@ -1,10 +1,10 @@
import { rollToFilter } from '../util'
import { INTERNAL_TRADE_ID } from '../interfaces'
import { FiltersCreationContext, itemModToFilter } from '../create-stat-filters'
import { propAt20Quality, variablePropAt20Quality, QUALITY_STATS } from './calc-q20'
import { stat } from '@/assets/data'
import { ARMOUR, WEAPON, ItemCategory } from '@/parser/meta'
import { ParsedItem } from '@/parser'
import { internalPropStat } from './util'
export function filterItemProp (ctx: FiltersCreationContext) {
if (ARMOUR.has(ctx.item.category!)) {
@@ -32,9 +32,11 @@ function armourProps (ctx: FiltersCreationContext) {
const totalQ20 = Math.floor(propAt20Quality(item.props.armour, QUALITY_STATS.ARMOUR, item))
ctx.filters.push({
tradeId: ['armour.armour' as INTERNAL_TRADE_ID],
text: 'Armour: #',
type: 'armour',
...internalPropStat(
'armour.armour',
'Armour: #',
'armour'
),
disabled: !isSingleAttrArmour(item),
...rollToFilter(totalQ20, { neverNegated: true })
})
@@ -44,9 +46,11 @@ function armourProps (ctx: FiltersCreationContext) {
const totalQ20 = Math.floor(propAt20Quality(item.props.evasion, QUALITY_STATS.EVASION, item))
ctx.filters.push({
tradeId: ['armour.evasion_rating' as INTERNAL_TRADE_ID],
text: 'Evasion Rating: #',
type: 'armour',
...internalPropStat(
'armour.evasion_rating',
'Evasion Rating: #',
'armour'
),
disabled: !isSingleAttrArmour(item),
...rollToFilter(totalQ20, { neverNegated: true })
})
@@ -56,9 +60,11 @@ function armourProps (ctx: FiltersCreationContext) {
const totalQ20 = Math.floor(propAt20Quality(item.props.energyShield, QUALITY_STATS.ENERGY_SHIELD, item))
ctx.filters.push({
tradeId: ['armour.energy_shield' as INTERNAL_TRADE_ID],
text: 'Energy Shield: #',
type: 'armour',
...internalPropStat(
'armour.energy_shield',
'Energy Shield: #',
'armour'
),
disabled: !isSingleAttrArmour(item),
...rollToFilter(totalQ20, { neverNegated: true })
})
@@ -66,9 +72,11 @@ function armourProps (ctx: FiltersCreationContext) {
if (item.props.blockChance) {
ctx.filters.push({
tradeId: ['armour.block' as INTERNAL_TRADE_ID],
text: 'Block: #%',
type: 'armour',
...internalPropStat(
'armour.block',
'Block: #%',
'armour'
),
disabled: true,
...rollToFilter(item.props.blockChance, { neverNegated: true })
})
@@ -107,17 +115,21 @@ function weaponProps (ctx: FiltersCreationContext) {
if (item.props.elementalDamage) {
ctx.filters.push({
tradeId: ['weapon.total_dps' as INTERNAL_TRADE_ID],
text: 'DPS: #',
type: 'weapon',
...internalPropStat(
'weapon.total_dps',
'DPS: #',
'weapon'
),
disabled: false,
...rollToFilter(dps, { neverNegated: true })
})
ctx.filters.push({
tradeId: ['weapon.elemental_dps' as INTERNAL_TRADE_ID],
text: 'Elemental DPS: #',
type: 'weapon',
...internalPropStat(
'weapon.elemental_dps',
'Elemental DPS: #',
'weapon'
),
disabled: (edps / dps < 0.67),
hidden: (edps / dps < 0.67) ? 'Elemental damage is not the main source of DPS' : undefined,
...rollToFilter(edps, { neverNegated: true })
@@ -125,26 +137,32 @@ function weaponProps (ctx: FiltersCreationContext) {
}
ctx.filters.push({
tradeId: ['weapon.physical_dps' as INTERNAL_TRADE_ID],
text: 'Physical DPS: #',
type: 'weapon',
...internalPropStat(
'weapon.physical_dps',
'Physical DPS: #',
'weapon'
),
disabled: !isPdpsImportant(item) || (pdpsQ20 / dps < 0.67),
hidden: (pdpsQ20 / dps < 0.67) ? 'Physical damage is not the main source of DPS' : undefined,
...rollToFilter(pdpsQ20, { neverNegated: true })
})
ctx.filters.push({
tradeId: ['weapon.aps' as INTERNAL_TRADE_ID],
text: 'Attacks per Second: #',
type: 'weapon',
...internalPropStat(
'weapon.aps',
'Attacks per Second: #',
'weapon'
),
disabled: true,
...rollToFilter(item.props.attackSpeed!, { neverNegated: true, decimals: 2 })
})
ctx.filters.push({
tradeId: ['weapon.crit' as INTERNAL_TRADE_ID],
text: 'Critical Strike Chance: #%',
type: 'weapon',
...internalPropStat(
'weapon.crit',
'Critical Strike Chance: #%',
'weapon'
),
disabled: true,
...rollToFilter(item.props.critChance!, { neverNegated: true, decimals: 2 })
})
@@ -76,6 +76,7 @@ export function filterResists (ctx: FiltersCreationContext) {
if ((maxRes / totalRes > 0.67) || resists.filter(r => r.hasFlat).length === 1) {
ctx.filters.push({
text: '+#% total to one of Elemental Resistances',
statRef: '+#% total to one of Elemental Resistances',
tradeId: ELEMENTAL_RES.flatMap(r => r.pseudo.tradeId),
type: 'pseudo',
disabled: false,
@@ -1,16 +1,27 @@
import { STAT_BY_REF } from '@/assets/data'
import { ItemModifier } from '@/parser/modifiers'
import { INTERNAL_TRADE_ID } from '../interfaces'
export function pseudoStat (ref: string) {
const stat = STAT_BY_REF.get(ref)!
return {
text: stat.text,
statRef: stat.ref,
type: 'pseudo',
tradeId: stat.types.find(t => t.name === 'pseudo')!.tradeId
}
}
export function internalPropStat (tradeId: INTERNAL_TRADE_ID, text: string, type: 'armour' | 'weapon') {
return {
text,
statRef: text,
type,
tradeId: [tradeId]
}
}
export function sumPseudoStats (modifiers: ItemModifier[], stats: string[]): number | undefined {
return modifiers.reduce((res, mod) => stats.includes(mod.stat.ref)
? (res || 0) + mod.values![0]
@@ -336,6 +336,7 @@ export function createTradeRequest (filters: ItemFilters, stats: StatFilter[], i
for (const statRef of refs) {
stats.push({
disabled: filters.veiled.disabled,
statRef: undefined!,
text: undefined!,
type: undefined!,
min: undefined,