def stats(request, char_id): char = get_char_or_raise(request, char_id) return set_response( request, 'chardata/stats.html', { 'char_id': char_id, 'advanced': True, 'default_weights_json': json.dumps(get_stats_weights(char)) }, char)
def stats_post(request, char_id): char = get_char_or_raise(request, char_id) stats_weight = {} for stat in get_structure().get_stats_list(): stats_weight[stat.key] = safe_int( request.POST.get('weight_%s' % stat.key, 0), 0) set_stats_weights(char, stats_weight) return HttpResponseJson(json.dumps(get_stats_weights(char)))
def set_wizard_sliders(char, slider_dict): weights = get_stats_weights(char) for slider_key in SLIDER_RANGES: form_field_name = 'slider_%s' % slider_key slider_value_string = slider_dict.get(form_field_name, None) new_slider_value = safe_int(slider_value_string) if new_slider_value is not None: set_weights_from_slider_value(slider_key, new_slider_value, weights) _post_process_weights(weights) set_stats_weights(char, weights) remove_cache_for_char(char.id)
def fashion(request, char_id, spells=False): char = get_char_or_raise(request, char_id) remove_cache_for_char(char_id) if char.stats_weight: weights = get_stats_weights(char) load_error = True for _, value in weights.iteritems(): if value != 0: load_error = False break else: load_error = True if load_error: return error( request, 'characteristics weights', reverse('chardata.stats_weights_view.stats', args=(char_id, )), char_id, char) min_stats = get_min_stats_digested(char) model_options = get_options(request, char_id) inclusions_dic = get_inclusions_dict(char) exclusions = get_all_exclusions_ids(char) base_stats_by_attr = get_base_stats_by_attr(request, char_id) if char.allow_points_distribution: stat_points_to_distribute = 5 * (char.level - 1) else: stat_points_to_distribute = 0 # TODO: Sanity check input. model_input = ModelInput(char.level, base_stats_by_attr, min_stats, inclusions_dic, set(exclusions), weights, model_options, char.char_class, stat_points_to_distribute) solved_status = None stats = None result = None memoized_result = MEMORY.get(model_input) if memoized_result is not None: solved_status, stats, result = memoized_result else: model = borrow_model() model.setup(model_input) model.run(2) solved_status = model.get_solved_status() if solved_status == 'Optimal': stats = model.get_stats() result = model.get_result_minimal() return_model(model) MEMORY.put(model_input, (model.get_solved_status(), stats, result)) if result is None: return HttpResponseRedirect( reverse('chardata.views.infeasible', args=(char.id, ))) if char.allow_points_distribution: set_stats(char, stats) set_minimal_solution(char, result) if spells: return HttpResponseRedirect( reverse('chardata.spells_view.spells', args=(char.id, ))) return HttpResponseRedirect( reverse('chardata.solution_view.solution', args=(char.id, )))
def get_wizard_sliders(char): aspects = get_char_aspects(char) elements = get_elements(aspects) race = char.char_class all_sliders = [] # Offense main_offense_slider = Slider('offense', pgettext('Slider section', 'Offense'), True) all_sliders.append(main_offense_slider) for main_stat in MAIN_STATS: if main_stat in elements: main_offense_slider.add_subslider(Slider(main_stat, _(STAT_KEY_TO_NAME[main_stat]), False)) main_offense_slider.add_subslider(Slider('pow', _('Power'), False)) for dam_type in DAMAGE_TYPES: if DAMAGE_TYPE_TO_MAIN_STAT[dam_type] in elements: dam_stat = '%sdam' % dam_type main_offense_slider.add_subslider(Slider(dam_stat, _(STAT_KEY_TO_NAME[dam_stat]), False)) main_offense_slider.add_subslider(Slider('ch', _('Critical Hits'), False)) main_offense_slider.add_subslider(Slider('cridam', _('Critical Damage'), False)) if 'pushback' in aspects or param_for_build(race, elements, 'pshdam_importance') > 0: main_offense_slider.add_subslider(Slider('pshdam', _('Pushback Damage'), False)) if 'trap' in aspects or param_for_build(race, elements, 'traps_are_important'): main_offense_slider.add_subslider(Slider('trapdam', _('Trap Damage'), False)) main_offense_slider.add_subslider(Slider('trapdamper', _('% Trap Damage'), False)) # Defense main_defense_slider = Slider('defense', pgettext('Slider section', 'Defense'), True) all_sliders.append(main_defense_slider) main_defense_slider.add_subslider(Slider('vit', _('Vitality'), False)) main_defense_slider.add_subslider(Slider('perres', _('% Resists'), False)) # if 'duel' in aspects: # main_defense_slider.add_subslider(Slider('pvpperres', _('% Resists in PVP'), False)) # main_defense_slider.add_subslider(Slider('linres', _('Linear Resists'), False)) # if 'duel' in aspects: # main_defense_slider.add_subslider(Slider('pvplinres', _('Linear Res. in PVP'), False)) main_defense_slider.add_subslider(Slider('crires', _('Critical Resist'), False)) # Mobility main_mobility_slider = Slider('mobility', pgettext('Slider section', 'Mobility'), True) all_sliders.append(main_mobility_slider) main_mobility_slider.add_subslider(Slider('lock', _('Lock'), False)) main_mobility_slider.add_subslider(Slider('dodge', _('Dodge'), False)) if 'pvp' in aspects: main_mobility_slider.add_subslider(Slider('apres', _('AP Loss Resist'), False)) main_mobility_slider.add_subslider(Slider('mpres', _('MP Loss Resist'), False)) if 'apred' in aspects or param_for_build(race, elements, 'apred_importance') > 0: main_mobility_slider.add_subslider(Slider('apred', _('AP Reduction'), False)) if 'mpred' in aspects or param_for_build(race, elements, 'mpred_importance') > 0: main_mobility_slider.add_subslider(Slider('mpred', _('MP Reduction'), False)) main_mobility_slider.add_subslider(Slider('init', _('Initiative'), False)) # Special main_special_slider = Slider('special', pgettext('Slider section', 'Special'), True) all_sliders.append(main_special_slider) if 'heal' in aspects or param_for_build(race, elements, 'heals_importance') > 0: main_special_slider.add_subslider(Slider('heals', _('Heals'), False)) if 'summon' in aspects or param_for_build(race, elements, 'summons_are_important'): main_special_slider.add_subslider(Slider('summon', _('Summons'), False)) if 'wis' in aspects: main_special_slider.add_subslider(Slider('wis', _('Wisdom'), False)) if 'pp' in aspects: main_special_slider.add_subslider(Slider('pp', _('Prospecting'), False)) weights = get_stats_weights(char) for slider in all_sliders: slider.calculate(weights) return all_sliders