def _default_start_battle(data, dungeon, battle_level, now): """默认开始战斗方法""" user = data.user.get(True) status = dungeon.status(user.level, now) if status != dungeon.ACTIVE: return dungeon_pb2.DUNGEON_NOT_OPEN if dungeon.get_remain_num() <= 0: return dungeon_pb2.DUNGEON_NO_ENTER_NUM node_basic_id = dungeon.node_basic_id() node_id = NodeInfo.generate_id(data.id, node_basic_id) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, node_basic_id) data.node_list.add(node) node.set_expand_dungeon() user = data.user.get(True) rival = data.rival_list.get(node_id) if rival is None: rival = RivalInfo.create(node_id, data.id) data.rival_list.add(rival) rival.set_expand_dungeon(dungeon.basic_id, dungeon.level(user.level), battle_level) return dungeon_pb2.DUNGEON_OK
def start_battle(data, teams, heroes, rival_user_id, rival, now, force=False): """开始战斗 """ user = data.user.get(True) union = data.union.get() node_id = NodeInfo.generate_id(data.id, union.get_battle_mapping_node_basic_id()) battle = data.battle_list.get(node_id) if battle is None: battle = BattleInfo.create(node_id, data.id) data.battle_list.add(battle) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, union.get_battle_mapping_node_basic_id()) data.node_list.add(node) r = data.rival_list.get(node_id) if r is None: r = RivalInfo.create(node_id, data.id) data.rival_list.add(r) #标记敌对玩家 r.set_union_battle_enemy_detail(rival_user_id, rival) #消耗攻击次数 union.consume_battle_attack() #消耗粮草 resource = data.resource.get() resource.update_current_resource(now) need_food = battle_business._calc_food_consume(heroes) if not resource.cost_food(need_food): return False battle.set_food_consume(need_food) #消耗兵力 if not battle_business._consume_soldier(data, battle, now, heroes, force): return False #计算战利品 reward_money = 0 reward_food = 0 reward_user_exp = 0 reward_hero_exp = data_loader.MonarchLevelBasicInfo_dict[ user.level].heroBattleExp reward_items = reward_module.random_battle_gift(user.level) battle.set_reward(reward_money, reward_food, reward_hero_exp, reward_user_exp, reward_items) return battle.start(None, r, None, teams, heroes, now, user.vip_level)
def start_battle(data, arena, now): """开始战斗""" user = data.user.get(True) if not arena.is_able_to_open(user, now): logger.warning("arena is not open[user_id=%d]" % data.id) #return -1 node_basic_id = arena.get_node_basic_id() node_id = NodeInfo.generate_id(data.id, node_basic_id) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, node_basic_id) data.node_list.add(node) node.set_arena() return node_id
def update_worldboss(data, basic_data, worldboss, user_level, now): """更新世界boss """ if not worldboss.is_unlock(): return True if worldboss.is_arised(): #如果查不到世界boss的基础信息,表示已删除,直接结束 basic_boss = None for boss_basic in basic_data.worldboss_list.get_all(): if boss_basic.boss_id == worldboss.boss_id and \ boss_basic.get_arise_time() == worldboss.arise_time: basic_boss = boss_basic break if basic_boss is None: logger.debug("basic worldboss info not exist[boss_id=%d]" % worldboss.boss_id) worldboss.clear() if worldboss.is_overdue(now): logger.debug("worldboss is overdue[boss_id=%d]" % worldboss.boss_id) #若已有过期世界boss事件,则先清除 worldboss.clear() else: #当天已有世界boss #更新一下时间、描述、boss血量等,有可能会临时修改 start_time = utils.get_spec_second(now, basic_boss.start_time) end_time = utils.get_spec_second(now, basic_boss.end_time) total_soldier_num = basic_boss.total_soldier_num description = basic_boss.description worldboss.update_basic_info(start_time, end_time, total_soldier_num, description) node_basic_id = worldboss.get_node_basic_id() node_id = NodeInfo.generate_id(data.id, node_basic_id) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, node_basic_id) data.node_list.add(node) node.set_world_boss() _update_worldboss_rival(data, worldboss, node_id) return True basic_worldboss_list = basic_data.worldboss_list.get_all() for basic_worldboss in basic_worldboss_list: start_second = utils.get_start_second_by_timestring(basic_worldboss.date) is_same_day = utils.is_same_day(now, start_second) if is_same_day: boss_id = basic_worldboss.boss_id start_time = utils.get_spec_second(now, basic_worldboss.start_time) end_time = utils.get_spec_second(now, basic_worldboss.end_time) total_soldier_num = basic_worldboss.total_soldier_num description = basic_worldboss.description node_basic_id = worldboss.get_node_basic_id() node_id = NodeInfo.generate_id(data.id, node_basic_id) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, node_basic_id) data.node_list.add(node) node.set_world_boss() _update_worldboss_rival(data, worldboss, node_id) if not worldboss.arise(now, boss_id, start_time, end_time, total_soldier_num, description, user_level): logger.warning("arise worldboss failed") return True logger.debug("Arise worldboss[boss_id=%d][arise_time=%d]" % (worldboss.boss_id, worldboss.arise_time)) break return True
def start_battle(data, boss_id, array_index, teams, heroes, now, cost_gold): """开始联盟boss战""" boss = get_boss_by_id(data, boss_id) if boss is None: logger.warning("non-existent boss[user_id=%d][boss_id=%d]" % (data.id, boss_id)) raise Exception("non-existent boss") if array_index > 3 or array_index < 1: logger.warning( "boss team index out of range[user_id=%d][array_index=%d]" % (data.id, array_index)) return (union_pb2.UNION_BOSS_TEAM_UNATTACKABLE, battle_pb2.BATTLE_OK) if boss.get_can_attack_arrays_index()[array_index - 1] != 1: logger.warning("boss team cannot attack[user_id=%d][array_index=%d]" % (data.id, array_index)) return (union_pb2.UNION_BOSS_TEAM_UNATTACKABLE, battle_pb2.BATTLE_OK) node_id = NodeInfo.generate_id( data.id, UserUnionInfo.get_union_boss_node_basic_id()) battle = data.battle_list.get(node_id) if battle is None: battle = BattleInfo.create(node_id, data.id) data.battle_list.add(battle) node = data.node_list.get(node_id) if node is None: node = NodeInfo.create(data.id, UserUnionInfo.get_union_boss_node_basic_id()) data.node_list.add(node) rival = data.rival_list.get(node_id) if rival is None: rival = RivalInfo.create(node_id, data.id) data.rival_list.add(rival) rival.set_unionboss(boss_id) #消耗粮草 resource = data.resource.get() resource.update_current_resource(now) need_food = battle_business._calc_food_consume(heroes) if not resource.cost_food(need_food): logger.warning("no enough food[user_id=%d]" % data.id) return (union_pb2.UNION_OK, battle_pb2.BATTLE_RESOURCE_SHORTAGE) battle.set_food_consume(need_food) #消耗兵力 need_soldier_num = 0 for hero in heroes: need_soldier_num += battle_business._calc_soldier_consume( hero.soldier_basic_id, hero.soldier_level) conscripts = data.conscript_list.get_all() total_soldier_num = 0 for conscript in conscripts: conscript.update_current_soldier(now) total_soldier_num += (conscript.soldier_num - conscript.lock_soldier_num) if total_soldier_num < need_soldier_num: if cost_gold <= 0: logger.warning("no enough soldier[user_id=%d]" % data.id) return (union_pb2.UNION_OK, battle_pb2.BATTLE_RESOURCE_SHORTAGE) else: gold = resource.soldier_to_gold(need_soldier_num - total_soldier_num) if gold != cost_gold: logger.warning( "exchange soldier gold error[user_id=%d][gold=%d][real_gold=%d]" % (data.id, cost_gold, gold)) if not battle_business._consume_soldier(data, battle, now, heroes, cost_gold > 0): logger.warning("no enough soldier[user_id=%d]" % data.id) return (union_pb2.UNION_OK, battle_pb2.BATTLE_RESOURCE_SHORTAGE) #计算战利品 user = data.user.get() reward_money = 0 reward_food = 0 reward_user_exp = 0 reward_hero_exp = data_loader.MonarchLevelBasicInfo_dict[ user.level].heroBattleExp reward_items = reward_module.random_battle_gift(user.level) battle.set_reward(reward_money, reward_food, reward_hero_exp, reward_user_exp, reward_items) boss.start_battle(array_index) battle.start(node, rival, None, teams, heroes, now, user.vip_level) return (union_pb2.UNION_OK, battle_pb2.BATTLE_OK)
def init_map(data, pattern, now): """初始化地图 创建新用户时,调用 Args: data[UserData]: 用户数据 pattern[int]: 初始化模式 now[int]: 时间戳 Returns: True False """ user = data.user.get() #创建地图信息 map = MapInfo.create(data.id) data.map.add(map) #创建问答, 副本信息 question = QuestionInfo.create(data.id) data.question.add(question) dungeon = DungeonInfo.create(data.id) data.dungeon.add(dungeon) #创建所有节点信息 for basic_id in MapGraph(): node = NodeInfo.create(data.id, basic_id) data.node_list.add(node) #第一次刷新,占领自己主城 own_basic_id = NodeInfo.get_own_node_basic_id() own_id = NodeInfo.generate_id(data.id, own_basic_id) own = data.node_list.get(own_id) own.update_own_city_level(user.level) ##开启主城邻接关键点 #for basic_id in MapGraph().get_neighbors(own.basic_id): # neighbor_id = NodeInfo.generate_id(data.id, basic_id) # neighbor = data.node_list.get(neighbor_id) # if not neighbor.is_visible(): # respawn_enemy_key_node(data, neighbor, now) ##为新刷出的敌方节点匹配敌人:只有 PVE #node_enemy_scores = [100, 101, 102] #硬编码,初始三个node上固定敌人 #i = 0 #matcher = RivalMatcher(user.level, [data.id]) #for node in data.node_list.get_all(): # if node.is_lack_enemy_detail(): # node.rival_score_min = node_enemy_scores[i] # node.rival_score_max = node_enemy_scores[i] # i = i + 1 # matcher.add_condition(data, node) #matcher.match(only_pve = True) ##为初次刷新的敌人添加 debuff 效果,为了让玩家初次攻击可以轻易取胜 #for node in data.node_list.get_all(): # if node.is_enemy_complete(): # rival_id = node.rival_id # rival = data.rival_list.get(rival_id) # buff_id = data_loader.InitUserBasicInfo_dict[pattern].enemyBuffId # rival.set_buff(buff_id) map.update_next_war_time(now) # map.update_next_luck_time(now) return True