they handle with a thing called "item value" or gearscore. Basicly every item have a set number telling how good it is. Let's say, an item with 200 value will be always better of a 100, with some exceptions. On item of the same score is up to the player choosing the best