def reset_machine(uid, mach_id): note_model = NoteModel(uid) cur_time = time.time() egg_refresh_time = note_model.get_machine_create_time(mach_id) cd = 600 # 剩余时间 remain_time = egg_refresh_time + cd - cur_time if remain_time > 0: cost_gold = 100 user_action = UserAction(uid) cur_gold = user_action.get_gold() if cur_gold < cost_gold: return False check_cost = user_action.reduce_gold(cost_gold) else: cost_gold = 0 check_cost = True # 需要先扣钱 if check_cost: note_model.set_machine_create_time(mach_id) res = { 'eggs': reset_machine_egg_info(uid, mach_id), 'costType': 'gold', 'costValue': cost_gold, 'mach_id': mach_id, 'cur_time': cur_time, } return res return False
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
def buy(uid, shop_id): print('buy', uid, shop_id) user_action = UserAction(uid) item_action = ItemAction(uid) shop_config_model = ConfigModel('shop') shop_info = shop_config_model.get_config_by_id(shop_id) item_config_model = ConfigModel('item') item_info = item_config_model.get_config_by_id(shop_info.get('item_id')) print shop_info price = shop_info.get('price', 10000) if shop_info.get( 'method', 'gold') == 'gold' and price >= user_action.get_value('gold', 0): return False else: user_action.reduce_gold(price) if shop_info.get('method') == 'diamond' and price >= user_action.get_value( 'diamond', 0): return False else: user_action.reduce_diamond(price) print(item_info) item_action.add_model(item_info.get('config_id'), 1) return True
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
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
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