예제 #1
0
def use_box(uid, config_info):
    # 奖励
    awards = get_award(config_info)
    item_model = ItemAction(uid)
    doll_model = HeroAction(uid)
    hatch_action = HatchAction(uid)
    user = UserAction(uid)
    res = dict()
    for a_id, ct in awards.iteritems():
        # 如果是金币添加金币
        if a_id == "gold":
            user.add_gold(ct)
            res[a_id] = ct
        # 如果是钻石添加钻石
        elif a_id == "diamond":
            user.add_diamond(ct)
            res[a_id] = ct
        # 经验
        elif a_id == "exp":
            user.add_gold(ct)
            res[a_id] = ct
        # 如果是道具添加道具
        elif int(a_id) / 10000 == 2:
            if item_model.add_model(a_id, ct):
                res[a_id] = ct
        elif int(a_id) / 10000 == 3:
            hatch_action.add_model(a_id)
        elif int(a_id) / 10000 == 4:
            res['doll'] = doll_model.add_model(a_id)
        else:
            pass
    return res
예제 #2
0
def hatch_discard(uid, index):
    action = HatchAction(uid)
    data = action.get_model_info_by_index(index)
    egg_id = data['key_id']
    if egg_id != '':
        return action.remove_model(index)
    return False
예제 #3
0
def hatch_speed(uid, index):
    user_action = UserAction(uid)
    cost = 100
    if user_action.reduce_gold(cost):
        action = HatchAction(uid)
        return action.add_exp(index, 300)
    print 'not gold'
    return False
예제 #4
0
def hatch_unlock(uid, index):
    user_action = UserAction(uid)
    cost = 100
    if user_action.reduce_diamond(cost):
        action = HatchAction(uid)
        return action.hatch_unlock(index)
    print 'not diamond'
    return False
예제 #5
0
def grab_egg(uid, key_id, eggs):
    mach_action = MachineAction(uid)
    egg = mach_action.get_egg_info(key_id)
    eggs = eggs.encode('utf-8')
    eggs = eval(eggs)
    if egg is False:
        print("egg  is not exits")
        return False
    item_id = egg.get('id', False)
    if item_id is False:
        return False
    '''如果是新手的话 必出娃娃'''
    hero_action = HeroAction(uid)
    cur_hero_keys = hero_action.get_doll_keys()
    if len(cur_hero_keys) == 0:
        res = dict()
        a_id = 40001
        res['doll'] = hero_action.add_model(a_id)
        record_logic.add_record(uid, 'get_hero', 1)
        return res
    '''新手判定结束'''
    config = ConfigModel('egg').get_config_by_id(item_id)
    print(config)
    # 需要一个判定 如果是新手 直接给一个固定的娃娃
    if config['lv'] < 2:
        if mach_action.delete_egg(key_id):
            res = open_egg(uid, item_id)
        else:
            return False
    else:
        print('is hatch')
        hatch_action = HatchAction(uid)
        available_hatch = hatch_action.get_hatch_available()
        if available_hatch is None:
            return False
        elif mach_action.delete_egg(key_id):
            res = {
                'hatch':
                hatch_action.add_model_index(item_id, available_hatch['pos'])
            }
        else:
            return False
    # 更新保存蛋的位置
    note_model = NoteModel(uid)
    mach_id = note_model.get_cur_machine()
    cur_eggs_keys = mach_action.get_egg_group(mach_id)
    values = {
        k: v
        for k, v in eggs.items() if k in cur_eggs_keys and k != key_id
    }
    mach_action.add_egg_list(values)
    res['update_exp'] = user_logic.add_exp(uid, 1)
    return res
예제 #6
0
def hatch_open(uid, index):
    action = HatchAction(uid)
    # 这里需要验证时间的
    data = action.get_model_info_by_index(index)
    cur_time = time.time()
    need_time = 3000  # 需要的时间 先写死
    finish_time = int(data['mark_at']) - int(data['ad']) + need_time
    if cur_time < finish_time:
        # 时间没到
        print('not ready', cur_time, finish_time, finish_time - cur_time)
        return False
    egg_id = data['key_id']
    if action.remove_model(index):
        return machine_logic.open_egg(uid, egg_id)
    else:
        return False
예제 #7
0
def open_egg_by_cost(uid, index):
    action = HatchAction(uid)
    data = action.get_model_info_by_index(index)
    egg_id = data['key_id']
    egg_config_model = ConfigModel('egg')
    cur_egg_config = egg_config_model.get_config_by_id(egg_id)
    if cur_egg_config is False:
        return False
    open_type = cur_egg_config.get('open_type')
    open_cost = cur_egg_config.get('open_cost')
    print(open_type, open_cost)
    user_action = UserAction(uid)
    if open_type == 'gold':
        check_cost = user_action.reduce_gold(open_cost)
    else:
        check_cost = user_action.reduce_diamond(open_cost)
    if check_cost is False:
        return False
    action = HatchAction(uid)
    if action.remove_model(index):
        return machine_logic.open_egg(uid, egg_id)
    else:
        return False
예제 #8
0
def get_hatch_info(uid):
    action = HatchAction(uid)
    res = action.get_model_info()
    return res
예제 #9
0
def reduce_hatch(uid, item_id):
    hatch_action = HatchAction(uid)
    return hatch_action.remove_model(item_id)