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
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 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