示例#1
0
def _item_contains_term(item, search_term):
    s = get_structure()
    or_items = s.get_or_items()
    if item.name in or_items:
        item = s.get_or_item_by_name(item.name)[0]
    item_name = ''
    if get_supported_language() in item.localized_names:
        item_name = item.accentless_local_names[get_supported_language()].lower()
    else:
        item_name = item.name.lower()
    return search_term in re.sub(r'\W+', '', item_name)
示例#2
0
def _order_items(item_type, char, search_term):
    structure = get_structure()
    items = structure.get_unique_items_by_type_and_level(item_type, char.level)
    search_term = search_term.lower()
    search_term = strip_accents(search_term)
    if search_term is not None:
        items = filter(lambda i: _item_contains_term(i, re.sub(r'\W+', '', search_term)),
                       items)
    items = filter(lambda i: _hide_removed_item(i), items)
    weights = pickle.loads(char.stats_weight)
    sorted_items = sorted(items, key=lambda item: _rate(structure, item, weights), reverse=True)
    return sorted_items
def get_item_stats(request):
    item_id = request.POST.get('itemId', None)
    if item_id == '':
        return HttpResponseJson(None)
    structure = get_structure()
    item = structure.get_item_by_id(int(item_id))
    result_item = ModelResultItem(item)
    evolve_result_item(result_item)

    json_response = jsonpickle.encode(result_item, unpicklable=False)

    return HttpResponseJson(json_response)
示例#4
0
def edit_item(request, item_id=None):
    structure = get_structure()
    types_list = structure.get_types_list()

    return set_response(
        request, 'chardata/edit_item.html', {
            'types': sorted(types_list),
            'stats_order': json.dumps(structure.get_stats_list_names_sorted()),
            'item_id': json.dumps(item_id),
            'non_en_languages': NON_EN_LANGUAGES,
            'languages': LANGUAGES
        })
示例#5
0
def _order_by_hits(item_type, char, search_term):
    structure = get_structure()
    items = structure.get_unique_items_by_type_and_level(item_type, char.level)
    search_term = search_term.lower()
    search_term = strip_accents(search_term)
    if search_term is not None and search_term is not '':
        items = filter(lambda i: _item_contains_term(i, re.sub(r'\W+', '', search_term)),
                       items)
    items = filter(lambda i: _hide_removed_item(i), items)
    solution = get_solution(char)
    sorted_items = sorted(items, key=lambda item: _get_weapon_rate(item, char, solution), reverse=True)
    #print sorted_items[:5]
    return sorted_items
示例#6
0
def edit_item_search_sets(request):
    name_piece = request.POST.get('name[term]', None)
    set_list = []
    if name_piece:
        name_piece = name_piece.lower()
        structure = get_structure()
        sets = structure.get_sets_list() + structure.get_sets_list(True)
        for s in sets:
            if name_piece in s.name.lower():
                set_list.append('[DT] %d %s' %
                                (s.id, s.name) if s.dofus_touch else '%d %s' %
                                (s.id, s.name))
    return HttpResponseJson(json.dumps(set_list))
示例#7
0
def get_stats_weights(char):
    weights = {}

    if char.stats_weight:
        weights = pickle.loads(char.stats_weight)

    # Fill in 0 for all stats that exist but have no weight, or a default value
    # from smart_build if it's in STATS_TO_FILL_DEFAULT.
    stats_to_calculate = []
    changed = False
    for stat in get_structure().get_stats_list():
        if stat.key not in weights:
            if stat.key in STATS_TO_FILL_DEFAULT:
                stats_to_calculate.append(stat.key)
            else:
                changed = True
                weights[stat.key] = 0

    # Call smart_build if necessary
    if stats_to_calculate:
        changed = True
        stan_w = get_standard_weights(char)
        for stat_key in stats_to_calculate:
            weights[stat_key] = stan_w[stat_key]

    # Filter out all non-existent stats.
    for stat_key in weights.keys():
        if stat_key in DEPRECATED_STATS:
            changed = True
            del weights[stat_key]
        elif stat_key not in get_structure().get_stats_list(
        ) and stat_key != 'meleeness':
            assert stat_key in STAT_KEY_TO_NAME, '%s is not a stat' % stat_key

    # Save if anything was changed
    if changed:
        set_stats_weights(char, weights)

    return weights
示例#8
0
def switch_item(request, char_id): 
    char = get_char_or_raise(request, char_id)
    item_name = request.POST.get('itemName', None)
    slot = request.POST.get('slot', None)
    assert slot in SLOTS
    
    structure = get_structure()
    result = get_solution(char)
    result.switch_item(structure.get_item_by_id(int(item_name)), slot)
    set_solution(char, result)
    remove_cache_for_char(char_id)

    return HttpResponseText('ok')
示例#9
0
def choose_set(request):
    structure = get_structure()
    set_stats = {}

    set_id = safe_int(request.POST.get('id', None))
    set_reference = request.POST.get('name', None)
    set_reference = set_reference.split(' ', 1)
    if set_id == None:
        set_id = safe_int(set_reference[0])
    set_name = set_reference[1]

    s = None
    if set_id:
        s = structure.get_set_by_id(set_id)

    if not s and set_name:
        s = structure.get_set_by_name(set_name)

    if not s:
        return HttpResponseJson(json.dumps(set_stats))

    set_stats['name'] = s.name
    set_stats['id'] = s.id
    set_stats['ankama_id'] = s.ankama_id

    for lang in NON_EN_LANGUAGES:
        set_stats['translated_name_%s' % lang] = s.localized_names.get(
            lang, '')

    stats_per_num_items = {}
    for num_items in range(2, 8 + 1):
        for stat, value in s.bonus_per_num_items.get(num_items,
                                                     {}).iteritems():
            stats_per_num_items.setdefault(STAT_KEY_TO_NAME[stat],
                                           {})[num_items] = value
    stats = []
    for stat_name in sorted(
            stats_per_num_items,
            key=lambda stat: STAT_ORDER[structure.get_stat_by_name(stat).key]):
        stats.append((stat_name, stats_per_num_items[stat_name]))
    set_stats['stats'] = stats

    items = []
    for item_id in s.items:
        item = structure.get_item_by_id(item_id)
        item_name = item.name
        items.append({'name': item_name, 'id': item_id})

    result = {'set': set_stats, 'items': items}

    return HttpResponseJson(json.dumps(result))
示例#10
0
def _get_weapon_rate(weapon, char, result):
    structure = get_structure()
    result_item = result.switch_item(weapon, 'weapon')
    new_stats = result.stats_total.copy()
    weapon_obj = structure.get_weapon_by_name(weapon.name)
    
    if result_item.is_mageable:
        result_item.mage_weapon_smartly(new_stats)
        element = result_item.element_maged
    else:
        element = NEUTRAL
        
    calculated_damage = {}
    for elementnew in DAMAGE_TYPES:
        calculated_damage[elementnew] = calculate_damage(weapon_obj.non_crit_hits[element],
                                                         new_stats, critical_hit=False, is_spell=False)
    
    total_damage = 0
    for damage in calculated_damage[element]:
        if damage.heals:
            total_damage -= (damage.min_dam + damage.max_dam)/2
        else:
            total_damage += (damage.min_dam + damage.max_dam)/2
    rating_non_crit = total_damage / float(weapon_obj.ap)
    
    
    if weapon_obj.has_crits:
        calculated_crit_damage = {}
        for elementnew in DAMAGE_TYPES:
            calculated_crit_damage[elementnew] = calculate_damage(weapon_obj.crit_hits[element],
                                                             new_stats, critical_hit=True, is_spell=False)
         
        total_damage = 0
        for damage in calculated_crit_damage[element]:
            if damage.heals:
                total_damage -= (damage.min_dam + damage.max_dam)/2
            else:
                total_damage += (damage.min_dam + damage.max_dam)/2
        rating_crit = total_damage / float(weapon_obj.ap)
    
    crits_total = new_stats['ch']
    if weapon_obj.crit_chance_percent:
        crits_total += weapon_obj.crit_chance_percent

    if weapon_obj.has_crits:
        rating = (rating_non_crit * (100 - crits_total) + rating_crit * crits_total)/100
    else:
        rating = rating_non_crit

    return rating if rating > 0 else -rating
示例#11
0
def get_item_details(request):
    item_id = request.POST.get('item', None)

    info = {}
    if item_id is not None:
        structure = get_structure()
        item = structure.get_item_by_id(int(item_id))
        info['level'] = item.level
        info['file'] = static(
            get_image_url(structure.get_type_name_by_id(item.type), item.name))

    json_response = jsonpickle.encode(info, unpicklable=False)

    return HttpResponseJson(json_response)
示例#12
0
def edit_item_search_item(request):
    name_piece = request.POST.get('name[term]', None)
    item_list = []
    if name_piece:
        name_piece = name_piece.lower()
        structure = get_structure()
        items = structure.get_concatenated_items_lists()
        for item in items:
            if name_piece in item.name.lower():
                item_list.append('[DT] %d %s' %
                                 (item.id,
                                  item.name) if item.dofus_touch else '%d %s' %
                                 (item.id, item.name))
    return HttpResponseJson(json.dumps(item_list))
示例#13
0
def update_item_post(request):
    item = json.loads(request.POST.get('item', None))
    if item == None:
        return HttpResponseText('not ok')

    item_id = safe_int(item['id'])
    if item_id:
        new_item, new_weapon = _convert_json_item_to_item(item)
        old_item = get_structure().get_item_by_id(item_id)
        update_item(old_item, new_item, new_weapon, True)
        return HttpResponseText('ok')
    else:
        _insert_item(item)
        return HttpResponseText('ok')
示例#14
0
def min_stats_post(request, char_id):
    char = get_char_or_raise(request, char_id)
    structure = get_structure()

    minimum_values = {}
    for stat in get_structure().get_stats_list():
        minimum = safe_int(request.POST.get('min_%s' % stat.key, ''))
        if minimum is not None:
            minimum_values[stat.name] = minimum

    minimum = safe_int(request.POST.get('min_hp'))
    if minimum is not None:
        minimum_values['HP'] = minimum

    adv_stats = structure.get_adv_mins()
    minimum_values['adv_mins'] = {}
    for stat in adv_stats:
        minimum = safe_int(request.POST.get('min_%s' % stat['key'], ''))
        if minimum is not None:
            minimum_values['adv_mins'][stat['name']] = minimum
    set_min_stats(char, minimum_values)

    return HttpResponseJson(json.dumps(_get_initial_data(char)))
示例#15
0
def store_set_data(item_id, ankama_id, set_data):
    if 'removed' in set_data:
        return
    else:
        new_set = _convert_json_item_to_item(set_data)
        old_set = get_structure().get_set_by_id(item_id)
        print 'Checking %s' % new_set.name

        new_set.items = old_set.items

        for lang in NON_EN_LANGUAGES:
            new_set.localized_names[lang] = old_set.localized_names.get(lang)

        update_set(item_id, new_set, False)
示例#16
0
def inclusions(request, char_id):
    char = get_char_or_raise(request, char_id)

    structure = get_structure()
    types_list = structure.get_types_list()
    items_by_type = {}
    items_by_type_and_name = {}
    for item_type in types_list:
        items_by_type[item_type] = {}
        items_by_type_and_name[item_type] = {}
    for item_type in items_by_type:
        for item in structure.get_unique_items_by_type_and_level(
                item_type, char.level):
            item_name = structure.get_item_name_in_language(
                item, get_supported_language())
            items_by_type[item_type][item.id] = item_name
            items_by_type_and_name[item_type][item_name] = item.id

    images_urls = {}
    for item_slot in SLOT_NAME_TO_TYPE:
        images_urls[item_slot] = static('chardata/%s.png' %
                                        SLOT_NAME_TO_TYPE[item_slot])

    inclusions = get_inclusions_dict(char)

    for slot in SLOTS:
        inclusions.setdefault(slot, '')

    return set_response(
        request, 'chardata/inclusions.html', {
            'char_id':
            char_id,
            'advanced':
            True,
            'types':
            items_by_type,
            'types_json':
            jsonpickle.encode(items_by_type, unpicklable=False),
            'names_and_types_json':
            jsonpickle.encode(items_by_type_and_name, unpicklable=False),
            'inclusions_json':
            json.dumps(inclusions),
            'images_json':
            json.dumps(images_urls),
            'slot_to_type_json':
            json.dumps(SLOT_NAME_TO_TYPE),
            'ajax_loader':
            json.dumps(get_ajax_loader_URL(request))
        }, char)
示例#17
0
def set_exclusions_list_by_name(char, excluded_items):
    s = get_structure()

    items = []
    for item_name in excluded_items:
        item = s.get_item_by_name(item_name)
        if item is None:
            item = s.get_or_item_by_name(item_name)[0]

        if item is not None:
            item_id = item.id
            items.append(item_id)
        else:
            print 'Item %s does not exist and cannot be excluded' % item_name
    set_exclusions_list_and_check_inclusions(char, items)
示例#18
0
def min_stats(request, char_id):
    char = get_char_or_raise(request, char_id)

    initial_data = _get_initial_data(char)
    structure = get_structure()

    stats = []
    for stat in structure.get_stats_list():
        stat_to_add = {}
        stat_to_add['key'] = stat.key
        stat_to_add['name'] = _(stat.name)
        stats.append(stat_to_add)

    stats = [
        stat
        for stat in sorted(stats, key=lambda stat: STAT_ORDER[stat['key']])
    ]

    fixed_fields = []
    ap = {}
    ap['key'] = 'ap'
    ap['name'] = _('AP')
    fixed_fields.append(ap)
    mp = {}
    mp['key'] = 'mp'
    mp['name'] = _('MP')
    fixed_fields.append(mp)
    rangestat = {}
    rangestat['key'] = 'range'
    rangestat['name'] = _('Range')
    fixed_fields.append(rangestat)

    adv_min_fields = structure.get_adv_mins()

    return set_response(
        request, 'chardata/min_stats.html', {
            'advanced': True,
            'char_id': char_id,
            'stats_order': json.dumps(stats),
            'stats_fixed': json.dumps(fixed_fields),
            'stats_adv': json.dumps(adv_min_fields),
            'initial_data': json.dumps(initial_data),
            'crit_targets': CRIT_TARGETS,
            'agility_targets': AGI_TARGETS
        }, char)
def store_set_data(set_ID, ankama_id, set_data):
    if 'removed' in set_data:
        return
    else:
        new_set = _convert_json_item_to_item(set_data)
        old_set = get_structure().get_set_by_name(new_set.name, True)
        print 'Checking %s' % new_set.name

        if old_set:
            for lang in NON_EN_LANGUAGES:
                new_set.localized_names[lang] = old_set.localized_names.get(
                    lang)

        set_id = update_set(set_ID, new_set, False)

        invalidate_structure()
        for item in new_set.items:
            store_item_set(item, set_id)
示例#20
0
    def __init__(self, char, slots):
        structure = get_structure()
        self.items_by_type = {}
        self.items_by_type_and_name = {}
        for slot in slots:
            item_type = SLOT_NAME_TO_TYPE[slot]
            self.items_by_type[item_type] = {}
            self.items_by_type_and_name[item_type] = {}
            for item in structure.get_unique_items_by_type_and_level(
                    item_type, char.level):
                item_name = structure.get_item_name_in_language(
                    item, get_supported_language())
                self.items_by_type[item_type][item.id] = item_name
                self.items_by_type_and_name[item_type][item_name] = item.id

            self.images_urls = {}
            self.images_urls[slot] = static('chardata/' + item_type + '.png')
        self.slot_to_type = SLOT_NAME_TO_TYPE
def store_weapon_data(item_id, weapon_name, weapon_data):
    if item_id:
        if 'removed' in weapon_data:
            fake_delete_item(item_id, True)
        else:
            new_item, new_weapon = _convert_json_item_to_item(weapon_data)
            old_item = get_structure().get_item_by_id(item_id)
            if old_item.name == 'Gelano (#1)':
                return
            print 'Checking %s' % new_item.name
            if '(' in old_item.name:
                new_item.name = old_item.name
            new_item.ankama_type = old_item.ankama_type

            new_item.set = old_item.set

            new_item.type = old_item.type

            for wc in WEIRD_CONDITIONS:
                new_item.weird_conditions[wc] = old_item.weird_conditions[wc]

            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)

            new_item.localized_extras = old_item.localized_extras

            #new_item.is_one_handed = old_item.is_one_handed

            update_item(old_item, new_item, new_weapon, False)

    else:
        new_item, new_weapon = _convert_json_item_to_item(weapon_data)
        if new_item:
            print 'Adding %s' % new_item.name

            insert_item(new_item, new_weapon)
        else:
            print 'Could not insert item'
示例#22
0
def get_items_of_type(request, char_id):
    char = get_char_or_raise(request, char_id)
        
    page = int(request.POST.get('page', None))
    search_term = request.POST.get('search_term', None)
    slot = request.POST.get('slot', None)
    
    itype = SLOT_NAME_TO_TYPE[slot]
    structure = get_structure()
    
    cache_key = ('%s-%s-%s' % (char_id, structure.get_type_id_by_name(itype), search_term)) 
    cache_key = re.sub(r"\s+", '_', cache_key) 
    items = cache.get(cache_key)
    
    if items == None:
        items = _order_items(itype, char, search_term)
    cache.set(cache_key, items, 300)
    max_page = math.ceil(len(items) / 10.0)
    items_to_return = items[(page - 1) * 10 : page * 10]
    
    
    itemResults = []
    for item in items_to_return:
        if item.name in structure.or_items:
            for or_item in structure.get_or_item_by_name(item.name):
                result_item = ModelResultItem(or_item)
                evolve_result_item(result_item)
                itemResults.append(result_item)
        else:  
            result_item = ModelResultItem(item)
            evolve_result_item(result_item)
            itemResults.append(result_item)
        
    response = {'items': itemResults,
                'violations': None,
                'page': page,
                'max_page': max_page,
                'differences': None}
    
    json_response = jsonpickle.encode(response, unpicklable=False)
    
    return HttpResponseJson(json_response)  
示例#23
0
def options_post(request, char_id):
    char = get_char_or_raise(request, char_id)

    options = parse_options_post(request)
    set_options(char, options)

    too_high = get_dofus_not_for_char(char)
    forbidden_dofus = []
    allowed_dofus = []
    for (red, item) in DOFUS_OPTIONS.iteritems():
        if red not in too_high:
            forbidden = request.POST.get(red) is None
            structure = get_structure()
            item_id = structure.get_item_by_name(item).id
            if forbidden:
                forbidden_dofus.append(int(item_id))
            else:
                allowed_dofus.append(int(item_id))
    add_items_to_exclusions(char, forbidden_dofus)
    remove_items_from_exclusions(char, allowed_dofus)

    return HttpResponseJson(json.dumps(get_options(char)))
示例#24
0
def wizard_post(request, char_id):
    char = get_char_or_raise(request, char_id)

    minimum_values = get_min_stats(char)
    for stat_name in STATS_WITH_CONFIG_MINS:
        minimum = safe_int(request.POST.get('min_%s' % stat_name, ''))
        minimum_values[stat_name] = minimum

    set_min_stats(char, minimum_values)

    weapon_to_lock = request.POST.get('weapon', None)
    if weapon_to_lock:
        set_item_included(char, weapon_to_lock, 'weapon', True)
    else:
        inclusions = get_inclusions_dict(char)
        weapon = inclusions.get('weapon')
        if weapon:
            set_item_included(char, weapon, 'weapon', False)

    options = get_options(char)
    options.update(parse_options_post(request))
    set_options(char, options)

    for (red, item) in DOFUS_OPTIONS.iteritems():
        forbidden = request.POST.get(red) is None
        s = get_structure()
        item_id = s.get_item_by_name(item).id
        set_excluded(char, item_id, forbidden)

    set_wizard_sliders(char, request.POST)

    scroll = request.POST.get('scrolling', 'leave')
    if scroll == 'fully':
        _full_scroll_char(char)
    elif scroll == 'clean':
        _clean_scroll_char(char)

    return HttpResponseRedirect(
        reverse('chardata.fashion_action.fashion', args=(char.id, )))
示例#25
0
def set_item_forbidden(request, char_id):
    char = get_char_or_raise(request, char_id)
        
    slot = request.POST.get('slot', None)
    item_name = request.POST.get('equip', None)
    forbidden = request.POST.get('forbidden', None)
    
    structure = get_structure()
    item = structure.get_item_by_name(item_name)
    if item is None:
        or_item = structure.get_or_item_by_name(item_name)
        item_id = or_item[0].id
    else:
        item_id = structure.get_item_by_name(item_name).id
    
    if forbidden == 'true':
        set_excluded(char, item_id, True)
    elif forbidden == 'false':
        set_excluded(char, item_id, False)

    return HttpResponseText('char_id %s, slot %s, equip %s, forbidden %s'
            % (char_id, slot, item_name, str(forbidden)))
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)
示例#28
0
def set_item_locked(request, char_id):
    char = get_char_or_raise(request, char_id)
        
    slot = request.POST.get('slot', None)
    item_name = request.POST.get('equip', None)
    locked = request.POST.get('locked', None)
    
    
    assert slot in SLOTS
    
    structure = get_structure()
    item = structure.get_item_by_name(item_name)
    if item is None:
        or_item = structure.get_or_item_by_name(item_name)
        item_id = or_item[0].id
    else:
        item_id = structure.get_item_by_name(item_name).id
    if locked == 'true':
        set_item_included(char, item_id, slot, True)
    elif locked == 'false':
        set_item_included(char, item_id, slot, False)
    
    return HttpResponseText('char_id %s, slot %s, equip %s, locked %s'
            % (char_id, slot, item_name, str(locked)))
示例#29
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
示例#30
0
def choose_item(request):
    structure = get_structure()

    item_id = safe_int(request.POST.get('id', None))
    item_reference = request.POST.get('name', None)
    item_name = None
    if item_reference:
        if '[DT]' in item_reference:
            item_reference = item_reference.split(' ', 2)
            if item_id == None:
                item_id = safe_int(item_reference[1])
            item_name = item_reference[2]
            dofus_touch = True
        else:
            item_reference = item_reference.split(' ', 1)
            if item_id == None:
                item_id = safe_int(item_reference[0])
            item_name = item_reference[1]
            dofus_touch = False

    item = None

    if item_id:
        item = structure.get_item_by_id(item_id)
        dofus_touch = item.dofus_touch

    if not item and item_name:
        item = structure.get_item_by_name(item_name, dofus_touch)

    if not item:
        return HttpResponseJson(json.dumps({}))

    item_stats = {}
    item_stats['name'] = item.name
    item_stats['id'] = item.id
    item_stats['ankama_id'] = item.ankama_id
    item_stats['ankama_type'] = item.ankama_type
    item_stats['level'] = item.level
    item_stats['type'] = structure.get_type_name_by_id(item.type)
    item_stats['removed'] = item.removed
    item_stats['dofus_touch'] = item.dofus_touch
    if item.set:
        item_stats['set'] = structure.get_set_by_id(item.set).name

    item_stats['weird_conditions'] = item.weird_conditions

    stats = []
    for stat, value in sorted(item.stats,
                              key=lambda stats: STAT_ORDER[
                                  structure.get_stat_by_id(stats[0]).key]):
        stats.append((structure.get_stat_by_id(stat).name, value))
    item_stats['stats'] = stats

    conditions = {}
    if item.min_stats_to_equip:
        for stat, value in item.min_stats_to_equip:
            conditions[structure.get_stat_by_id(stat).name] = ('>', value - 1)
    if item.max_stats_to_equip:
        for stat, value in item.max_stats_to_equip:
            conditions[structure.get_stat_by_id(stat).name] = ('<', value + 1)
    item_stats['conditions'] = conditions

    item_stats['extras'] = {
        lang: item.localized_extras.get(lang, [])
        for lang in LANGUAGES
    }

    if item_stats['type'] == 'Weapon':
        weapon = structure.get_weapon_by_name(item.name, dofus_touch)
        #        item_stats['one_handed'] = item.is_one_handed
        item_stats['ap'] = weapon.ap
        item_stats['crit_chance'] = weapon.crit_chance
        item_stats['crit_bonus'] = weapon.crit_bonus
        item_stats['weapon_type'] = structure.get_weapon_type_by_id(
            weapon.weapon_type).name
        hits = {}
        for key, value in weapon.hits_dict.iteritems():
            hits[key] = (value.min_dam, value.max_dam,
                         ELEMENT_KEY_TO_NAME[value.element], value.steals,
                         value.heals)
        item_stats['hits'] = hits

    for lang in NON_EN_LANGUAGES:
        item_stats['translated_name_%s' % lang] = item.localized_names.get(
            lang, '')

    or_items = []

    # Handle artificial items(Gelano, Turquoise Dofus)
    for alt_item in structure.get_items_by_or_name(item.or_name, dofus_touch):
        if alt_item.id != item.id:
            or_items.append({'id': alt_item.id, 'name': alt_item.name})

    result = {'item': item_stats, 'or_items': or_items}
    return HttpResponseJson(json.dumps(result))