def execute_pure_demage(attacker, target, skill_buff_info): """ 纯伤害:3 """ actual_demage = 0 if skill_buff_info.valueType == 2: actual_demage = attacker.atk * skill_buff_info.valueEffect / 100 elif skill_buff_info.valueType == 1: actual_demage = attacker.level * skill_buff_info.valueEffect / 100 logger.debug_cal("纯伤害 %s", actual_demage) target.hp -= actual_demage
def remove(self): """docstring for remove""" for k, value in self._buffs.items(): temp = [] for buff in value: buff.perform_buff(self._owner) buff.continue_num -= 1 if buff.continue_num > 0: temp.append(buff) else: logger.debug_cal("去除buff %s", buff.skill_buff_info.id) self._buffs[k] = temp
def perform_best_skill(self, army, enemy, skill): """执行技能:无双""" if not skill.is_full(): return for skill_buff_info in skill.skill_buffs: target_units = find_target_units(None, army, enemy, skill_buff_info, None) demage_hp = skill.player_level * skill_buff_info.levelEffectValue for target_unit in target_units: target_unit.hp -= demage_hp logger.debug_cal("无双的伤害值为 %s" % demage_hp) skill.reset_mp()
def init_round(self, red_units, red_best_skill, blue_units, blue_best_skill, friend_skill): self._red_units = copy.deepcopy(red_units) # copy.deepcopy(red_units) self._red_best_skill = red_best_skill self._blue_units = copy.deepcopy(blue_units) self._blue_best_skill = blue_best_skill self._friend_skill = friend_skill if len(self._blue_units) == 0: logger.debug_cal("敌方人数为0!") return False self.enter_battle() return True
def perform_round(self): """ perform mock battle, logger.debug_cal(battle process.) """ for i in range(1, 7): red_unit = self._red_units.get(i) blue_unit = self._blue_units.get(i) self.handle_mock_special_skill(self._red_best_skill) if red_unit: logger.debug_cal(("red_%d" % i) + "-" * 20 + "我方攻击" + "-" * 20) self.perform_one_skill(self._red_units, self._blue_units, red_unit.skill) self._red_best_skill.add_mp() self._blue_best_skill.add_mp() logger.debug_cal(" ") self.handle_mock_special_skill(self._blue_best_skill) if blue_unit: logger.debug_cal(("blue_%d" % i) + "-" * 20 + "敌方攻击" + "-" * 20) self.perform_one_skill(self._blue_units, self._red_units, blue_unit.skill) self._red_best_skill.add_mp() self._blue_best_skill.add_mp() logger.debug_cal(" ") self.remove_buff(self._red_units) self.remove_buff(self._blue_units) return self._red_units, self._blue_units
def process(self): """docstring for process""" battle_round = BattleRound() battle_round.init_round(self._red_units, self._red_best_skill, self._blue_groups.pop(0), friend_skill=self._friend_skill) while True: battle_round.perform_round() result = battle_round.result if result == 0: continue if result == 1 and self.blue_groups: battle_round.init_round(self._red_units, self._red_best_skill, self._blue_groups.pop(0), friend_skill=self._friend_skill) continue if result == 1: logger.debug_cal("I finally win the battle.") break if result == -1: logger.debug_cal("I finally lose the battle.") break
def execute_treat(attacker, target, skill_buff_info): """ 治疗:26 """ is_cri = False if get_random_int(1, 100) < attacker.cri - target.ductility: is_cri = True cri_coeff = (attacker.cri_coeff - target.cri_ded_coeff) / 100 # 暴击伤害系数 if not is_cri: cri_coeff = 1 total_treat = attacker.atk * cri_coeff # 总治疗值 actual_treat = 0 # 实际治疗值 if skill_buff_info.effectId == 26 and skill_buff_info.valueType == 1: actual_treat = total_treat + skill_buff_info.valueEffect + skill_buff_info.levelEffectValue * attacker.level elif skill_buff_info.effectId == 26 and skill_buff_info.valueType == 2: actual_treat = total_treat * ( skill_buff_info.valueEffect / 100 + skill_buff_info.levelEffectValue / 100 * attacker.level) logger.debug_cal("治疗值 %s", actual_treat) target.hp += actual_treat
def enter_battle(self): """ 在战斗开始前,进行触发类别为2的突破技能buff """ logger.debug_cal(" 进入战场,添加的buff...") for temp in self._red_units.values(): for skill_buff_info in temp.skill.begin_skill_buffs(): target_units = find_target_units(temp, self._red_units, self._blue_units, skill_buff_info) self.handle_skill_buff(temp, self._red_units, self._blue_units, skill_buff_info, target_units) if DEBUG: target_nos = [] for temp in target_units: target_nos.append(temp.slot_no) logger.debug_cal(" 作用目标: %s" % (target_nos)) for temp in self._blue_units.values(): for skill_buff_info in temp.skill.begin_skill_buffs(): target_units = find_target_units(temp, self._blue_units, self._red_units, skill_buff_info) self.handle_skill_buff(temp, self._blue_units, self._red_units, skill_buff_info, target_units) if DEBUG: target_nos = [] for temp in target_units: target_nos.append(temp.slot_no) logger.debug_cal(" 作用目标: %s" % (target_nos))
def process(self): """docstring for process""" battle_round = BattleRound() if not battle_round.init_round(self._red_units, self._red_best_skill, self._blue_units, self._blue_best_skill, self._firent_skill): return True logger.debug_cal("开始战斗...") blue_units = None for i in range(base_config.get("max_times_fight")): i = i + 1 logger.debug_cal("第%d回合......" % i) red_units, blue_units = battle_round.perform_round() result = battle_round.result if result == 0: continue if result == 1: logger.debug_cal("我赢了。") return True, blue_units.get(5).hp if result == -1: logger.debug_cal("我输了。") return False, blue_units.get(5).hp logger.debug_cal("我输了。") return False, blue_units.get(5).hp
def add(self, buff): """ add a buff. """ buff.perform_buff(self._owner) if buff.continue_num == 0: return logger.debug_cal("添加buff: %s" % buff.skill_buff_info.id) effect_id = buff.skill_buff_info.effectId if effect_id not in self._buffs: self._buffs[effect_id] = [] self._buffs[effect_id].append(buff) elif buff.skill_buff_info.overlay: self._buffs[effect_id].append(buff) elif not buff.skill_buff_info.overlay: if self._buffs[effect_id]: temp = self._buffs[effect_id][0] if temp.skill_buff_info.replace <= buff.skill_buff_info.replace: self._buffs[effect_id] = [buff] else: self._buffs[effect_id].append(buff)
def handle_skill_buff(self, attacker, army, enemy, skill_buff_info, target_units): """ 根据作用位置找到攻击目标,然后执行技能或者添加buff """ logger.debug_cal("-" * 80) for target_unit in target_units: buff = Buff(attacker, skill_buff_info) target_unit.buff_manager.add(buff) if target_unit.hp <= 0: # 如果血量为0,则去掉该unit target_side = find_side(skill_buff_info, army, enemy) if target_unit.slot_no in target_side: del target_side[target_unit.slot_no] logger.debug_cal(" 技能或buffID:%s, 受击后的状态:" % (skill_buff_info.id)) for temp in target_units: if temp.hp > 0: logger.debug_cal(" %s" % temp) logger.debug_cal("-" * 80)
# -*- coding:utf-8 -*- """ """ from gfirefly.server.logobj import logger, log_init_debug_cal if __name__ == '__main__': str = '但是感到舒服' if __name__ == '__main__': print 1 print 1 print 23 log_init_debug_cal() logger.debug_cal("I am log in debug cal.")
def execute_demage(attacker, target, skill_buff_info, is_block): """ 执行技能[1,2] """ logger.debug_cal( " 攻方 no(%d), unit_no(%d), name(%s), hp(%f), mp(%f), buff(%s)" % (attacker.slot_no, attacker.unit_no, attacker.unit_name, attacker.hp, attacker.mp, attacker.buff_manager)) logger.debug_cal( " 守方 no(%d), unit_no(%d), name(%s), hp(%f), mp(%f), buff(%s)" % (target.slot_no, target.unit_no, target.unit_name, target.hp, target.mp, target.buff_manager)) is_cri = False # 是否暴击 is_trigger = False # 是否trigger if get_random_int(1, 100) <= skill_buff_info.triggerRate: is_trigger = True if not is_trigger: logger.debug_cal(" 技能未触发。") if get_random_int(1, 100) < attacker.cri - target.ductility: is_cri = True cri_coeff = (attacker.cri_coeff - target.cri_ded_coeff) / 100 # 暴击伤害系数 k1 = attacker.atk # 攻方总实际攻击力 k2 = 0 # 守方总物理或者魔法防御 if skill_buff_info.effectId == 1: k2 = target.physical_def elif skill_buff_info.effectId == 2: k2 = target.magic_def k3_k4 = base_config.get("a3") # 基础伤害值调整参数 k3 = k3_k4[0] k4 = k3_k4[1] base_demage_value = (k1 * k1 / (k1 + k3 * k2)) * k4 # 基础伤害值 block_demage_coeff = base_config.get("a4") # 格挡受伤比参数 # level_coeff = 1 # 等级压制系数 k1 = attacker.level # 攻方等级 k2 = target.level # 守方等级 temp = base_config.get("a5") # 等级压制调整参数 k3, k4, k5 = temp[0], temp[1], temp[2] # 等级压制调整参数 if (k2 - k1) > 5: if (1 - k3 / k4 * ((k2 - k1) * (k2 - k1) + (k2 - k1) + k5)) > 0.1: level_coeff = 1 - k3 / k4 * ((k2 - k1) * (k2 - k1) + (k2 - k1) + k5) else: level_coeff = 0.1 else: level_coeff = 1 # temp = base_config.get("a6") # 伤害浮动调整参数 k1, k2 = temp[0], temp[1] # demage_fluct_coeff = random.uniform(k1, k2) # 伤害浮动系数 if not is_cri: cri_coeff = 1 if not is_block: block_demage_coeff = 1 total_demage = base_demage_value * cri_coeff * block_demage_coeff * level_coeff * demage_fluct_coeff # 总伤害值 # actual_demage = 0 # 实际伤害值 if (skill_buff_info.effectId == 1 or skill_buff_info.effectId == 2) and skill_buff_info.valueType == 1: actual_demage = total_demage + skill_buff_info.valueEffect + skill_buff_info.levelEffectValue * attacker.level #logger.debug_cal(actual_demage, total_demage, skill_buff_info.valueEffect, skill_buff_info.levelEffectValue, attacker.level, type(skill_buff_info.valueType)) elif (skill_buff_info.effectId == 1 or skill_buff_info.effectId == 2) and skill_buff_info.valueType == 2: actual_demage = total_demage * ( skill_buff_info.valueEffect / 100 + skill_buff_info.levelEffectValue / 100 * attacker.level) #logger.debug_cal(actual_demage, total_demage, skill_buff_info.valueEffect, skill_buff_info.levelEffectValue, attacker.level, skill_buff_info.valueType) #logger.debug_cal(skill_buff_info.valueEffect/100 + skill_buff_info.levelEffectValue/100 * attacker.level) logger.debug_cal(" 技能ID(%d),暴击(%s),格挡(%s),基础伤害值(%s),暴击伤害系数(%s),等级压制系数(%s),伤害浮动系数(%s),总伤害值(%s),攻方实际伤害值(%s)" \ % (skill_buff_info.id, is_cri, is_block, base_demage_value, cri_coeff, level_coeff, demage_fluct_coeff, total_demage, actual_demage)) target.hp = target.hp - actual_demage
def __init__(self, red_units, red_player_level, red_best_skill_no, blue_units, debuff_no=0): self._red_units = red_units self._blue_units = blue_units # add debuff skill_info = skill_config.get(debuff_no) if skill_info: for k, v in blue_units.items(): for temp in skill_info.group: skill_buff_info = skill_buff_config.get(temp) if not skill_buff_info: continue buff = Buff(None, skill_buff_info) v.buff_manager.add(buff) self._red_best_skill = BestSkill(red_best_skill_no, red_player_level) if red_best_skill_no else BestSkillNone() self._blue_best_skill = BestSkillNone() self._firent_skill = FriendSkillNone() logger.debug_cal("我方阵容:") for k, v in self._red_units.items(): logger.debug_cal("%d %s" % (k, v)) logger.debug_cal("-" * 80) logger.debug_cal("敌方阵容:") for k, v in self._blue_units.items(): logger.debug_cal("%d %s" % (k, v)) logger.debug_cal("-" * 80)
def perform_one_skill(self, army, enemy, skill): """执行技能:普通技能或者怒气技能""" attacker = skill.owner logger.debug_cal(" 进行攻击: 攻击者位置(%d), 攻击者(%d), 主技能ID(%d), buff(%s)" % \ (attacker.slot_no, attacker.unit_no, skill.main_skill_buff.id, attacker.buff_manager)) if not attacker.can_attack: logger.debug_cal(" 攻击者在buff中,无法攻击!") main_target_units = find_target_units(attacker, army, enemy, skill.main_skill_buff, None) # 主技能作用目标 # 1.计算命中, 格挡 # 规则:主技能作用多个目标,只要有一个命中的,则判定命中 is_main_hit = False main_target_unit_infos = [] for target_unit in main_target_units: if check_hit(skill.main_skill_buff, attacker.hit, target_unit.dodge): is_main_hit = True block_or_not = check_block(attacker, target_unit, skill.main_skill_buff) main_target_unit_infos.append((target_unit, block_or_not)) logger.debug_cal(" 是否命中:%s" % is_main_hit) # 2.主技能释放前,触发的buff logger.debug_cal(" 1. 攻击前, 添加的buff") for skill_buff_info in skill.before_skill_buffs(is_main_hit): target_units = find_target_units(attacker, army, enemy, skill_buff_info, main_target_units) self.handle_skill_buff(attacker, army, enemy, skill_buff_info, target_units) # 3.触发攻击技能 logger.debug_cal(" 2. 攻击...") for skill_buff_info in skill.attack_skill_buffs(): if not is_main_hit and skill_buff_info.skill_key and skill_buff_info.effectId in ( 1, 2, 3): # 当攻击主技能没有命中,则退出 break if skill_buff_info.skill_key: self.handle_skill_buff(attacker, army, enemy, skill_buff_info, main_target_units) continue target_units = find_target_units(attacker, army, enemy, skill_buff_info, main_target_units) self.handle_skill_buff(attacker, army, enemy, skill_buff_info, target_units) # 在攻击技能触发完成后,处理mp skill.set_mp() # 4.主技能释放后,触发的buff logger.debug_cal(" 3. 攻击后的buff...") for skill_buff_info in skill.after_skill_buffs(is_main_hit): target_units = find_target_units(attacker, army, enemy, skill_buff_info, main_target_units) self.handle_skill_buff(attacker, army, enemy, skill_buff_info, target_units) # 5. 反击 for backer, is_block in main_target_unit_infos: for skill_buff_info in backer.skill.back_skill_buffs( is_main_hit, is_block): target_units = find_target_units(backer, army, enemy, skill_buff_info, None, attacker) target_nos = [] for temp in target_units: target_nos.append(temp.slot_no) logger.debug_cal(" 反击目标: %s" % (target_nos)) buff = Buff(attacker, skill_buff_info, is_block) target_unit.buff_manager.add(buff)
def __init__(self, red_units, red_best_skill, red_player_level, blue_groups, blue_player_level, friend_skill): super(BattlePVEProcess, self).__init__() self._red_units = red_units self._blue_groups = blue_groups self._red_best_skill = red_best_skill self._friend_skill = friend_skill logger.debug_cal("我方阵容:") for k, v in self._red_units.items(): logger.debug_cal(k, v) logger.debug_cal("-" * 80) logger.debug_cal("敌方阵容:") for item in blue_groups: for k, v in item.items(): logger.debug_cal(k, v) logger.debug_cal('next group:') logger.debug_cal("-" * 80)
def __init__(self, red_units, red_best_skill_no, red_player_level, blue_units, blue_best_skill_no, blue_player_level): self._red_units = red_units self._blue_units = blue_units self._red_best_skill = BestSkill(red_best_skill_no, red_player_level) if red_best_skill_no else BestSkillNone() self._blue_best_skill = BestSkill(blue_best_skill_no, blue_player_level) if blue_best_skill_no else BestSkillNone() self._firent_skill = FriendSkillNone() logger.debug_cal("我方阵容:") for k, v in self._red_units.items(): logger.debug_cal("%d %s" % (k, v)) logger.debug_cal("-" * 80) logger.debug_cal("敌方阵容:") for k, v in self._blue_units.items(): logger.debug_cal("%d %s" % (k, v)) logger.debug_cal("-" * 80)