Rarity comparison. A simpler way?

Hello I’m working with custom inventories and items. The player has multiple inventories, where items can be placed and in some UI’s Like a sell/buy I want to get the items count of them by rarity.
I solved this by checking item rarities with the next code:

IsRarityValid(Rarity:rarity, RarityType:concrete_subtype(rarity), IncludeSubRarities:logic)<decides>:void=
        if:
            IncludeSubRarities?
            RarityType[Rarity]
        then:
            true?
        else if:
            not IncludeSubRarities?
            Type : concrete_subtype(rarity) = RarityType
            Instance := Type{}
            TryGetRarityAsInt[Rarity] = TryGetRarityAsInt[Instance]
        then:
            true?
        else:
            false?

    TryGetRarityAsInt<public>(Rarity:rarity)<decides><reads>:int=
        if(legendary_rarity[Rarity]):
            4
        else if(epic_rarity[Rarity]):
            3
        else if(rare_rarity[Rarity]):
            2
        else if(uncommon_rarity[Rarity]):
            1
        else if(common_rarity[Rarity]):
            0
        else:
            false?
            -1

Is there a simpler way to approach this? I would like to use just subtype(rarity) but that doesn’t seem feasible as it’s not posible to compare.

Your two-branch design is already the Verse way. subtype(rarity) is not a value you can compare; concrete_subtype(rarity) plus a type predicate is.

If you only need “is this rarity X, including custom children of X”:

IsRarity(Rarity:rarity, RarityType:concrete_subtype(rarity))<decides>:void=
    RarityType[Rarity]

That is the whole check. epic_rarity[Item.GetRarity[]] is enough for a count-by-rarity UI.

The int map is only useful when you want an order (“rare or better”), because Verse will not give you Rarity >= rare_rarity. Keep TryGetRarityAsInt for that, drop it for exact buckets.

IncludeSubRarities only matters if you defined your own rarities as children of the built-ins. The five stock ones (commonlegendary) are siblings, so RarityType[Rarity] is already exact.

I would not fight subtype. Store the wanted rarity as concrete_subtype(rarity) on the shop widget and filter with the predicate. The int helper stays as a small private function for sort / “at least this tier”.