Exemple #1
0
def _convert_json_item_to_item(json_item):
    structure = get_structure()

    item = Item()
    item.name = json_item['name']
    item.ankama_id = json_item['ankama_id']
    item.ankama_type = json_item['ankama_type']
    item.level = json_item['level']
    item.removed = json_item['removed']
    item.dofus_touch = json_item['dofus_touch']
    item.type = structure.get_type_id_by_name(json_item['type'])
    if json_item['set']:
        item_set = json_item['set']
        if '[DT]' in item_set:
            set_reference = item_set.split(' ', 2)
            item.set = safe_int(set_reference[1])
        else:
            item.set = structure.get_set_id_by_name(item_set)

    item.weird_conditions = json_item['weird_conditions']

    for stat in json_item['stats']:
        if stat['stat'] == '' or stat['stat'] == None:
            continue
        _add_to_old_stat(item,
                         structure.get_stat_by_name(stat['stat']).id,
                         int(stat['value']))

    for cond in json_item['conditions']:
        if cond['stat'] == '' or cond['stat'] == None:
            continue
        new_value = (int(cond['value']) -
                     1 if cond['min_max'] == '<' else int(cond['value']) + 1)
        _add_to_old_cond(item,
                         structure.get_stat_by_name(cond['stat']).id,
                         cond['min_max'] == '>', new_value)

    for lang, extras in json_item['extras'].iteritems():
        for extra in extras:
            if extra == '':
                continue
            _add_to_old_extra(item, lang, extra)

    for lang in NON_EN_LANGUAGES:
        name_translated = json_item['translated_name_%s' % lang]
        if not name_translated.startswith('[!]'):
            item.localized_names[lang] = name_translated

    weapon = None
    if json_item['type'] == 'Weapon':
        weapon = Weapon()
        weapon.ap = int(json_item['ap'])
        weapon.crit_chance = int(json_item['crit_chance'])
        weapon.crit_bonus = int(json_item['crit_bonus'])
        #        item.is_one_handed = json_item['one_handed']
        weapon.weapon_type = structure.get_weapon_type_by_name(
            json_item['weapon_type']).id

        for hit in json_item['hits']:
            if hit['min_hit'] == '':
                continue
            index = int(hit['index'])

            weapon.hits_dict[index] = DamageDigest(
                int(hit['min_hit']), int(hit['max_hit']),
                ELEMENT_NAME_TO_KEY[hit['stat']], hit['steals'], hit['heals'])

    return item, weapon
def _convert_json_item_to_item(json_item):
    structure = get_structure()

    item = Item()
    item.removed = False
    item.name = json_item['name']
    item.ankama_id = json_item['ankama_id']
    item.ankama_type = 'equipment'
    item.level = json_item['level']
    item.dofus_touch = 1 if json_item['dofustouch'] else 0
    if json_item['w_type'] == 'Trophy':
        json_item['w_type'] = 'Dofus'
    if json_item['w_type'] == 'Backpack':
        json_item['w_type'] = 'Cloak'
    if json_item['w_type'] == 'Petsmount':
        json_item['w_type'] = 'Pet'
    item_type = structure.get_type_id_by_name(json_item['w_type'])
    if item_type:
        item.type = item_type
    else:
        item.type = structure.get_type_id_by_name('Weapon')

    weapon = None
    if item.type == structure.get_type_id_by_name('Weapon'):
        weapon = Weapon()
        print item.name
        weapon.ap = int(json_item['ap'])
        weapon.crit_chance = int(json_item['crit_chance'])
        weapon.crit_bonus = int(json_item.get('crit_bonus')) if json_item.get(
            'crit_bonus') else None
        wtype = structure.get_weapon_type_by_name(json_item['w_type'])
        if wtype:
            weapon.weapon_type = wtype.id
        else:
            print 'COULD NOT FIND TYPE: %s' % json_item['w_type']
            return None, None

    index = 0
    for stat in json_item['stats']:
        if stat[2].startswith('('):
            hit_name = stat[2].strip('()')
            hit_element = hit_name.split()[0]
            hit_type = hit_name.split()[1]
            if hit_name != 'Hunting weapon':
                element = (ELEMENT_NAME_TO_KEY[hit_element]
                           if hit_element != 'HP' else
                           ELEMENT_NAME_TO_KEY['Fire'])
                if weapon == None:
                    weapon = Weapon()
                weapon.hits_dict[index] = DamageDigest(
                    (stat[0]), (stat[1] if stat[1] else stat[0]), element,
                    True if hit_type == 'steal' else False,
                    False if hit_element != 'HP' else True)
                index = index + 1
        elif (stat[0] or stat[1]):
            if structure.get_stat_by_name(stat[2]):
                if stat[1] == None:
                    stat_value = stat[0]
                else:
                    if stat[0] >= 0:
                        stat_value = stat[1]
                    else:
                        stat_value = stat[0]
                _add_to_old_stat(item,
                                 structure.get_stat_by_name(stat[2]).id,
                                 stat_value)
            else:
                filetomod = open('HPitems.txt', 'a')

                filetomod.write(item.name + ': ' + stat[2] + '\n')

                print 'COULD NOT FIND STAT %s' % stat[2]

                filetomod.close()
    return item, weapon