Example #1
0
def try_five_times(uid):
    gold_cost = 500
    u_action = UserAction(uid)
    if u_action.reduce_gold(gold_cost) is False:
        return False
    turntable_config_model = ConfigModel('turntable')
    turntable_config_info = turntable_config_model.get_model_info()
    random_list = []
    for key, value in turntable_config_info.items():
        random_list.extend([key] * value['chance'])
    selected_keys = random.sample(random_list, 5)
    awards = [{turntable_config_info[selected_key]['item_id']: int(turntable_config_info[selected_key]['ct'])} for selected_key in selected_keys]
    all_awards = union_dict(awards)
    res = {
        'selected': selected_keys,
        'award': inventory_logic.add_awards(uid, all_awards),
    }
    return res
Example #2
0
def try_once(uid):
    gold_cost = 100
    u_action = UserAction(uid)
    if u_action.reduce_gold(gold_cost) is False:
        return False
    turntable_config_model = ConfigModel('turntable')
    turntable_config_info = turntable_config_model.get_model_info()
    random_list = []
    for key, value in turntable_config_info.items():
        random_list.extend([key] * value['chance'])
    selected_key = random.choice(random_list)
    selected_info = turntable_config_info[selected_key]
    print(selected_info)
    award = {selected_info['item_id']: int(selected_info['ct'])}
    res = {
        'selected': [selected_info['config_id']],
        'award': inventory_logic.add_awards(uid, award),
    }
    return res
Example #3
0
def refresh_task(u_id, action_str, ct):
    t_action = TaskAction(u_id)
    cur_task = t_action.get_cur_task_group()
    cur_task_ids = [
        task_info[t_action.key_id_str]
        for index, task_info in enumerate(cur_task)
    ]
    task_data = {}
    for index, task_info in enumerate(cur_task):
        task_data[task_info[t_action.key_id_str]] = task_info
    config_model = ConfigModel('task')
    task_config_groups = config_model.get_model_info()
    task_math_ids = [
        config_id for config_id, config_data in task_config_groups.items()
        if str(config_data.get('action_type')) +
        str(config_data.get('action_target')) == action_str
        and config_data.get('mainType') != 'day' and config_id in cur_task_ids
    ]
    if len(task_math_ids) == 0:
        return 0
    task_id = task_math_ids[0]

    if task_config_groups[task_id]['mainType'] == 'guild' \
            and task_data[task_id][t_action.value_str] + ct >= task_config_groups[task_id]['action_value']:
        next_task = task_config_groups[task_id].get('next_task', False)
        #   n_model = NoteModel(u_id)
        if next_task:
            t_action.add_task(next_task)
            #   n_model.mark_new_task(next_task)
        update_data = {
            t_action.value_str: task_data[task_id][t_action.value_str] + ct,
            t_action.is_award_str: True
        }
        t_action.update_task_info_by_id(task_id, update_data)
        #   n_model.mark_complete_task(task_id)
        print('add task', task_id)
    else:
        t_action.add_value(ct, task_id)
    return task_math_ids