def store_weapon_data(item_id, weapon_name, weapon_data):
    s = get_structure()
    if 'removed' in weapon_data:
        delete_item(item_id)
    else:
        new_item = Item()
        old_item = s.get_item_by_id(item_id)
        
        new_item.id = old_item.id
        new_item.name = old_item.name
        new_item.or_name = old_item.or_name
        new_item.type = old_item.type
        new_item.level = old_item.level
        new_item.set = old_item.set
        new_item.ankama_id = old_item.ankama_id
        new_item.ankama_type = old_item.ankama_type
        new_item.stats = old_item.stats
        new_item.min_stats_to_equip = old_item.min_stats_to_equip 
        new_item.max_stats_to_equip = old_item.max_stats_to_equip   
        for lang in NON_EN_LANGUAGES:
            new_item.localized_names[lang] = old_item.localized_names.get(lang)
            
        for lang in NON_EN_LANGUAGES:
            new_item.localized_extras[lang] = old_item.localized_extras.get(lang)
        new_item.localized_extras['en'] = old_item.localized_extras.get('en')
        
        
        for wc in WEIRD_CONDITIONS:
            new_item.weird_conditions[wc] = old_item.weird_conditions[wc]
        
        new_item = _convert_json_item_to_item(weapon_data, new_item, s)
        
        if '(' in old_item.name:
            new_item.name = old_item.name
        
        print 'Checking %s' % new_item.name
        
        update_item(old_item, new_item, None, False)
def store_item_set(item_name, set_id):
    s = get_structure()
    item = s.get_item_by_name(item_name, True)

    if not item:
        filetomod = open('MissingItemsInSets.txt', 'a')

        name_to_print = item_name + '\n'
        filetomod.write(name_to_print.encode('utf-8'))

        filetomod.close()
        return

    new_item = Item()
    new_item.id = item.id
    new_item.name = item.name
    new_item.or_name = item.or_name
    new_item.type = item.type
    new_item.level = item.level
    new_item.set = set_id
    new_item.ankama_id = item.ankama_id
    new_item.ankama_type = item.ankama_type
    new_item.is_one_handed = item.is_one_handed
    new_item.stats = item.stats
    new_item.min_stats_to_equip = item.min_stats_to_equip
    new_item.max_stats_to_equip = item.max_stats_to_equip
    new_item.localized_extras = item.localized_extras
    new_item.localized_names = item.localized_names
    new_item.accentless_local_names = item.accentless_local_names
    new_item.weird_conditions = item.weird_conditions
    new_item.removed = item.removed
    new_item.dofus_touch = item.dofus_touch

    weapon = s.get_weapon_by_name(item_name, True)

    update_item(item, new_item, weapon, False)
Exemple #3
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