def open_pve(uid): p_action = PveAction(uid) pve_info = p_action.get_model_info() is_start = pve_info.get(p_action.is_start_str) pve_config = ConfigModel('pve') if is_start is False: pve_config_info = pve_config.get_config_by_id( pve_info.get(p_action.pve_id_str)) elif pve_info.get(p_action.is_award_str) is True: cur_pve_id = pve_info.get(p_action.pve_id_str) next_pve_id = cur_pve_id + 1 pve_config_info = pve_config.get_config_by_id(next_pve_id) else: return False if pve_config_info is None: # 已经通关 print 'pve is over' return False update_date = { p_action.pve_id_str: pve_config_info.get('config_id'), p_action.is_start_str: True, p_action.boss_hp_str: pve_config_info.get('hp', 999), } """ if update_date.get(p_action.pve_id_str) == p_action.default_pve_id: # 如果是新手 update_date[p_action.boss_hp_str] = 0 """ if p_action.set_values(update_date): return update_date return False
def set_fight(uid, fight_heroes): formation_action = FormationAction(uid) check_heroes = [i for i in fight_heroes if i != ''] # 判断有没有重复英雄 if len(check_heroes) != len(set(check_heroes)): print('is same') return False hero_action = HeroAction(uid) all_hero = hero_action.get_model_info() # 有没有根本不存在的英雄 if len(set(check_heroes) - set(all_hero.keys())) > 0: print('is not exist') return False # 读取英雄属性配置信息 hero_config = ConfigModel('doll') hero_upgrade_config = ConfigModel('doll_upgrade') # 计算战斗力 all_atk = 0 all_capacity = 0 normal_fight_per = 0.1 fight_per = 0.9 for hero_id, hero_info in all_hero.iteritems(): cur_hero_config = hero_config.get_config_by_id(hero_id) cur_lv_config = hero_upgrade_config.get_config_by_id( 70000 + int(hero_info['lv'])) if int(cur_hero_config['category'] ) != formation_action.fight_type and hero_id in check_heroes: print('is not fight hero', hero_id) return False base_atk = int(cur_hero_config['atk']) base_capacity = int(cur_hero_config['capacity']) atk_add_per = int(cur_lv_config['add_atk']) capacity_add_per = int(cur_lv_config['add_capacity']) hero_atk = base_atk * atk_add_per hero_capacity = base_capacity * capacity_add_per if hero_id in fight_heroes: all_atk += hero_atk * fight_per else: all_atk += hero_atk * normal_fight_per all_capacity += hero_capacity info = formation_action.get_model_info() cur_income = info.get(formation_action.income_str) data = { formation_action.fight_formation_str: fight_heroes, formation_action.fight_atk_str: all_atk, formation_action.capacity_str: all_capacity, } print(fight_heroes) if formation_action.set_model_info(data): print(data) return data return False
def get_award(item_id): egg_config_model = ConfigModel('egg') cur_egg_config = egg_config_model.get_config_by_id(item_id) if cur_egg_config is False: print('cur_egg_config is null') return False doll_id = cur_egg_config.get('doll_id') hero_config_model = ConfigModel('doll') hero_config = hero_config_model.get_config_by_id(doll_id) if hero_config: rand_value = random.random() if rand_value < hero_config.get('rate', 0): return {'gold': hero_config.get('gold', 1)} return {doll_id: 1} return False
def add_exp(uid, add_value): u = UserAction(uid) info = u.get_model_info() cur_lv = info.get(u.lv_str, 1) cur_exp = info.get(u.exp_str, 0) latest_exp = cur_exp + add_value lv_config_model = ConfigModel('user_lv') cur_lv_config = lv_config_model.get_config_by_id(110000 + int(cur_lv)) # 最高等级 max_lv = 50 data = dict() lv_up = False if cur_lv < max_lv and latest_exp >= cur_lv_config.get('exp', 0): data[u.lv_str] = cur_lv + 1 data[u.exp_str] = latest_exp - cur_lv_config.get('exp', 0) if info.get(u.vit_str, 0) < 100: data[u.vit_str] = 100 lv_up = True else: data[u.exp_str] = latest_exp if u.update_info(data): if lv_up: mail_logic.add_lv_up_award(uid) return data return False
def upgrade_artifact(uid, artifact): action = ArtifactAction(uid) config_model = ConfigModel('artifact') artifact_config = config_model.get_config_by_id(artifact) if artifact_config is False: print('流氓数据 错误的ID') return False check_data = action.get_model_info_by_id(artifact) if check_data is None or check_data is False or len(check_data) == 0: print('流氓数据 骗子') return False next_id = artifact_config.get('next_id') if next_id == -1: print('流氓数据 满级了') return False upgrade_item = artifact_config.get('upgrade') upgrade_items = eval(upgrade_item) item_model = ItemAction(uid) all_item_info = item_model.get_model_info() for a_id, ct in upgrade_items.iteritems(): if int(all_item_info.get(a_id, 0)) < ct: print('消耗物品不够', a_id) return False for a_id, ct in upgrade_items.iteritems(): remove_res = item_model.remove_model(a_id, ct) if remove_res is False: print(uid, '删除失败', a_id, ct) res = action.replace_model(artifact, next_id) if res: record_logic.add_record(uid, 'artifact', 1) return res
def get_artifact_akt(uid): action = ArtifactAction(uid) config_model = ConfigModel('artifact') artifact_group = action.get_model_info() all_atk = [ int(config_model.get_config_by_id(c_id)['atk']) for c_id in artifact_group ] res = {'atk': sum(all_atk)} return res
def gacha_speed_up(uid, item_id): config_id = int(item_id.split("_")[0]) item_type = config_id / 10000 if item_type is not 2 or reduce_item(uid, config_id) is not True: return 1, "使用失败" config_model = ConfigModel("config") config_info = config_model.get_config_by_id(config_id) if config_info and config_info.get('type', 0) == "speed": exp = config_info.get('exp', 0) return 0, exp else: return 1, "无效的道具"
def get_pve_atk(uid): for_action = FormationAction(uid) hero_action = HeroAction(uid) all_hero = hero_action.get_model_info() pve_heroes = for_action.get_explore_model_info() heroes = { hero_id: hero_info for hero_id, hero_info in all_hero.items() if hero_id in pve_heroes } hero_config = ConfigModel('doll') hero_upgrade_config = ConfigModel('doll_upgrade') all_atk = 0 for hero_id, hero_info in heroes.iteritems(): cur_hero_config = hero_config.get_config_by_id(hero_id) cur_lv_config = hero_upgrade_config.get_config_by_id( 70000 + int(hero_info['lv'])) base_atk = int(cur_hero_config['atk']) atk_add_per = float(cur_lv_config['add_atk']) hero_atk = base_atk * atk_add_per all_atk += hero_atk return all_atk
def get_pve_award(uid): p_action = PveAction(uid) pve_info = p_action.get_model_info() if pve_info.get(p_action.is_start_str) is not True or pve_info.get( p_action.is_award_str) is True: return False if pve_info.get(p_action.boss_hp_str, 1) > 0: return False pve_config = ConfigModel('pve') pve_config_info = pve_config.get_config_by_id( pve_info.get(p_action.pve_id_str)) award_item = pve_config_info.get('award') award_items = eval(award_item) res = dict() # 获取下一关的配置 cur_pve_id = pve_info.get(p_action.pve_id_str) next_pve_id = cur_pve_id + 1 pve_config_info = pve_config.get_config_by_id(next_pve_id) if formation_logic.set_explore(uid, ['', '', '', '', '']) is False: return False if pve_config_info is not None: update_date = { p_action.pve_id_str: pve_config_info.get('config_id'), p_action.boss_hp_str: pve_config_info.get('hp', 999), p_action.is_start_str: False, p_action.is_award_str: False, } res['pve'] = update_date else: update_date = { p_action.is_award_str: True, } pve_info[p_action.is_award_str] = update_date[p_action.is_award_str] res['pve'] = update_date if p_action.set_values(update_date): res['award'] = inventory_logic.add_awards(uid, award_items) record_logic.add_record(uid, 'pve', 1) return res
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 use_item(uid, item_id): config_id = int(item_id) print type(config_id) item_type = config_id / 10000 print('config_id', item_id, 'item_type', item_type) if item_type != 2: return False # 先判定抓到的娃娃蛋存不存在 del_res = reduce_item(uid, item_id) # 存在的话删除掉 if del_res: config_model = ConfigModel('item') config_info = config_model.get_config_by_id(item_id) fun_dict = { 'normal': use_normal, 'box': use_heal, 'heal': use_heal, } return fun_dict.get(config_info['iType'])(uid, config_info) print("item is not exits") return False
def add_model(self, item_id): # 娃娃的数据格式{'doll_id':40001,'exp':100,'lv':1,'state':0} hero_config_hero = ConfigModel('doll') hero_config_info = hero_config_hero.get_config_by_id(item_id) doll = self.get_value(item_id) if doll is None or doll == {}: data = {self.doll_id_str: item_id, 'exp': 0, 'lv': 1, 'state': 0, self.hp_str: hero_config_info.get('hp'), self.interact_str: time.time()} res = self.set_value(item_id, data) data['type'] = 'new' else: data = eval(doll) exp = 100 data['exp'] += exp res = self.set_value(item_id, data) data['type'] = 'exp' data['add_exp'] = exp print('add_model result', res) if res is not False: return data return False
def refresh_lock(uid, machine_id): config_model = ConfigModel('machine') next_book_id = machine_id + 1 book = HandBookAction(uid) if book.has_key(next_book_id): return False # 判定当前关卡是否完成 front_config = config_model.get_config_by_id(machine_id) if front_config: config_doll_group = front_config.get('itemGroup', False) config_exp = front_config.get('exp', 0) cur_exp = book.get_book_exp(machine_id) config_doll_group = config_doll_group.split(',') config_dolls = [str(i) for i in config_doll_group] doll_model = HeroAction(uid) my_doll_group = doll_model.get_doll_group() config_doll_group = set(config_dolls) # my_doll_group >= config_doll_group if my_doll_group.issuperset( config_doll_group) and cur_exp > config_exp: if book.unlock_book(next_book_id): return next_book_id return False
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
def get_box_award(uid, box_id): re_action = RecordAction(uid) re_info = re_action.get_model_info() day_box_group = re_info.get(re_action.day_box_group_str) if day_box_group is None: day_box_group = [] if str(box_id) in day_box_group: print 'box_id is haven' return False config_model = ConfigModel('box') box_config = config_model.get_config_by_id(box_id) if box_config.get('point') > re_info.get(re_action.point_str, 0): print 'point is not enough' return False res = {} day_box_group.append(box_id) if re_action.update_day_box_group(day_box_group) is True: res['update'] = box_id award = box_config.get('award', {}).encode('utf-8') award = eval(award) from grabDoll.logics import inventory_logic res['award'] = inventory_logic.add_awards(uid, award) return res
def get_task_award(uid, task_id): re_action = RecordAction(uid) re_info = re_action.get_model_info() day_task_group = re_info.get(re_action.day_task_group_str) if day_task_group is None: day_task_group = [] if str(task_id) in day_task_group: return False config_model = ConfigModel('task') cur_task_config = config_model.get_config_by_id(task_id) action_type = cur_task_config.get('action_type') action_target = cur_task_config.get('action_target') if action_target is not None and action_target != 0 and action_target != '': core_str = '%s_%s' % (action_type, action_target) else: core_str = action_type print core_str if re_info.get(core_str, 0) < cur_task_config.get('action_value', sys.maxint): return False res = {} day_task_group.append(task_id) update_data = { re_action.day_task_group_str: day_task_group, re_action.point_str: re_info.get(re_action.point_str) + cur_task_config.get('point', 0), } # if re_action.update_day_task_group(day_task_group) is True: if re_action.update_model_info(update_data) is True: res['update'] = task_id award = cur_task_config.get('award', {}).encode('utf-8') award = eval(award) from grabDoll.logics import inventory_logic res['award'] = inventory_logic.add_awards(uid, award) return res
def reset_machine_egg_info(uid, mach_id): config_model = ConfigModel('machine') mach_config = config_model.get_config_by_id(mach_id) egg_group = mach_config['eggGroup'] egg_list = eval(egg_group) random_list = [] for key, value in egg_list.items(): random_list.extend([key] * value) slice_list = random.sample(random_list, 20) mach = MachineAction(uid) data = dict() rand_x = [5, 6, 7, 8, 9] rand_y = [20, 21, 22, 23, 24, 25] for index in range(len(slice_list)): data[str(mach_id) + '_' + str(index)] = { 'id': slice_list[index], 'x': random.choice(rand_x), 'y': random.choice(rand_y), 'r': 30 } res = mach.add_egg_list(data) if res: return data return False
def open_egg(uid, egg_id): print('open_egg', egg_id) # 奖励 awards = get_award(egg_id) item_action = ItemAction(uid) hero_action = HeroAction(uid) book_action = HandBookAction(uid) user_action = UserAction(uid) res = dict() for a_id, ct in awards.iteritems(): # 如果是金币添加金币 if a_id == "gold": user_action.add_gold(ct) res[a_id] = ct # 如果是钻石添加钻石 elif a_id == "diamond": user_action.add_diamond(ct) res[a_id] = ct # 经验 elif a_id == "exp": user_action.add_gold(ct) res[a_id] = ct # 如果是道具添加道具 elif int(a_id) / 10000 == 2: item_action.add_model(a_id, ct) elif int(a_id) / 10000 == 4: if hero_action.get_doll_exist(a_id) is False: res['doll'] = hero_action.add_model(a_id) record_logic.add_record(uid, 'get_hero', 1) else: cur_hero = hero_action.get_doll_info_by_id(a_id) hero_config_model = ConfigModel('doll_upgrade') cur_lv_config = hero_config_model.get_config_by_id( 70000 + cur_hero['lv']) max_exp = cur_lv_config['exp'] max_lv = 5 add_exp = 1 # 新的经验值 exp = cur_hero['exp'] + add_exp if exp >= max_exp: if cur_hero['lv'] < max_lv: cur_hero['lv'] += 1 cur_hero['exp'] = exp - max_exp hero_action.set_value(a_id, cur_hero) res['hero_lv_up'] = True else: res['hero_lv_up'] = False # 满级了 if cur_hero['exp'] < max_exp: cur_hero['exp'] = max_exp hero_action.set_value(a_id, cur_hero) else: # 经验槽也满了已经 add_exp = 0 else: cur_hero['exp'] = exp hero_action.set_value(a_id, cur_hero) res['hero_lv_up'] = False # 如果已经有这个英雄了 就发金币吧 # user_action.add_gold(10) # res['gold'] = 10 cur_hero['add_exp'] = add_exp res['doll'] = cur_hero res['hero_exist'] = a_id else: pass # 图鉴加经验 note_model = NoteModel(uid) res['book_exp'] = book_action.add_book_exp(note_model.get_cur_machine(), 1) unlock_next_book = book_logic.refresh_lock(uid, note_model.get_cur_machine()) if unlock_next_book: res['egg'] = reset_machine_egg_info(uid, unlock_next_book) return res