@classmethod
def add_attributes_to_map(cls, attr_iterator, stat_map):
    """Add attributes from the item to the stat map.

        Positional arguments:
        attr_iterator -- an iterator for the item attributes.
        stat_map -- add stats to this map

        First, some terminology. Nokka's d2s parser gives 'attributes' for the items.
        These 'attributes' are a little different than the 'stats' in ItemStatCost.txt.
        When referring to the stat as it exists in the JSON from the d2s parser, I will
        use the term 'attribute'. When referring to a stat consistent with ItemStatCost.txt,
        I will use the term 'stat'.

        attr_iterator must yield a map with an id and values field and can
        be created with the generator methods in the Item class. These maps are
        expected to follow the format of nokka's d2s parser. When converting from
        attribute to stat, we change a few things, notably with combined stat ranges
        (min-max dmg) and with charges.

        The stat_map will contain all item stats, keyed by stat id (ItemStatCost.txt).
        In the case of a simple stat (one value), the value for the stat id
        will be a list of all instance values of that stat. In the case of a complex
        stat, the value for the stat id will be another map, keyed by parameter.

        simple attribute:
        > stat_map[141] # deadly strike
        [20]

        complex attribute:
        > stat_map[204][62][30] # level 30 (30) hydra (62) charges (204 is the stat id)
        [2570]
        The game stores the current and max charges as one 16 bit value. In this case,
        there are 10 current charges (LSB) and 10 max (MSB): 2570 = 0x0A0A.
        """
    for attr in attr_iterator:
        for stat in cls.attribute_to_stats(attr):
            mdict = stat_map
            mkey = stat['stat']
            for value in attr['values'][:-1][::-1]:
                if mkey not in mdict:
                    mdict[mkey] = {}
                mdict = mdict[mkey]
                mkey = value
            if mkey not in mdict:
                mdict[mkey] = []
            mdict[mkey].append(attr['values'][-1])
