Skip to content

Commit

Permalink
implement quest condition for gear categories
Browse files Browse the repository at this point in the history
  • Loading branch information
soolar committed Apr 17, 2023
1 parent bb3c2d2 commit 646fa62
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
11 changes: 7 additions & 4 deletions mafia/data/chitter_gear_categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@
"name": "rollover",
"mods": [
{ "mod": "Adventures" },
{ "mod": "PVP Fights", "conditions": { "list": [{ "type": "pvp", "value": true }] } }
{
"mod": "PVP Fights",
"conditions": { "list": [{ "type": "pvp", "value": true }] }
}
],
"conditions": { "list": [{ "type": "overdrunk", "value": true }] }
},
Expand Down Expand Up @@ -223,7 +226,7 @@
"type": "quest",
"pref": "questS02Monkees",
"value": "finished",
"inverted": "true"
"comparison": "!"
}
]
}
Expand Down Expand Up @@ -275,7 +278,7 @@
"type": "quest",
"pref": "questL11Black",
"value": "unstarted",
"inverted": true
"comparison": "!"
},
{
"type": "quest",
Expand Down Expand Up @@ -334,7 +337,7 @@
"type": "quest",
"pref": "questL11Manor",
"value": "unstarted",
"inverted": true
"comparison": "!"
},
{
"type": "quest",
Expand Down
35 changes: 30 additions & 5 deletions src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
Stat,
StatType,
storageAmount,
toInt,
toSlot,
weaponHands,
} from 'kolmafia'
Expand All @@ -32,7 +31,6 @@ import {
numericProperties,
stringProperties,
} from 'libram/dist/propertyTypes'
import { weapon } from 'libram/dist/resources/2008/Stickers'
import { FieldValue, fieldValueToJSString } from './fieldValue'
import { BrowserItem, foldableAmount } from './guidelines'

Expand Down Expand Up @@ -232,10 +230,13 @@ interface GearOverdrunkCondition {
value: boolean
}

type ComparisonStr = '>' | '>=' | '<' | '<=' | '!'

interface GearQuestCondition {
type: 'quest'
pref: string
value: string
comparison?: ComparisonStr
inverted?: boolean
}

Expand Down Expand Up @@ -289,16 +290,40 @@ interface GearCategory {

const evaluateGearCondition = (cond: GearCondition) => {
switch (cond.type) {
case 'quest':
break
case 'quest': {
const prefVal = get(cond.pref)
if (cond.comparison) {
const questStepNum = (stepStr: string) =>
stepStr === 'finished'
? 999
: stepStr === 'started'
? 0
: stepStr.startsWith('step')
? Number(stepStr.substring(5))
: -1
const compStepNum = questStepNum(cond.value)
const realStepNum = questStepNum(prefVal)
return cond.comparison === '>'
? realStepNum > compStepNum
: cond.comparison === '>='
? realStepNum >= compStepNum
: cond.comparison === '<'
? realStepNum < compStepNum
: cond.comparison === '<='
? realStepNum <= compStepNum
: cond.comparison === '!'
? realStepNum !== compStepNum
: false
}
return prefVal === cond.value
}
case 'mainstat':
return (myPrimestat() === Stat.get(cond.value)) === !cond.inverted
case 'overdrunk':
return myInebriety() > inebrietyLimit() === cond.value
case 'pvp':
return hippyStoneBroken() === cond.value
}
return true
}

const evaluateGearConditions = (
Expand Down

0 comments on commit 646fa62

Please sign in to comment.