Original logic from SMZ3 is:
items.KeyPD >= (GetLocation("Palace of Darkness - Harmless Hellway").ItemIs(KeyPD, World) ?
(items.Hammer && items.Bow && items.Lamp) || config.Keysanity ? 4 : 3 :
(items.Hammer && items.Bow && items.Lamp) || config.Keysanity ? 6 : 5))
I believe these parentheses are needed to correctly replicate this logic