def play_charm(self, allies, enimies, turn_num): self.actions += 1 charm = self.charm_list.next() if turn_num not in self.charm_used_each_turn: self.charm_used_each_turn[turn_num] = [] self.charm_used_each_turn[turn_num].append(charm) battlelog.log("%s uses [%s]\n" %(self.name, charm.name)) charm.execute(self, allies, enimies)
def normalize(self): battlelog.log("%s is normalized\n" %(self.name)) self.melee_CPB = 0 self.melee_NPB = 0 self.magic_CPB = 0 self.magic_NPB = 0 self.spirit_CPB = 0 self.spirit_NPB = 0 return
def gain_willpower(self, willpower, is_cumul): current_willpower = self.willpower if is_cumul: self.willpower += willpower else: self.willpower = max(self.willpower, willpower) if current_willpower < self.willpower: battlelog.log("%s's willpower raises to %d\n" %(self.name, self.willpower)) else: battlelog.log("%s's willpower remains at %d\n" %(self.name, self.willpower))
def gain_armor(self, armor, is_cumul): current_armor = self.armor if is_cumul: self.armor += armor else: self.armor = max(self.armor, armor) if current_armor < self.armor: battlelog.log("%s's armor raises to %d\n" %(self.name, self.armor)) else: battlelog.log("%s's armor remains at %d\n" %(self.name, self.armor))
def gain_ward(self, ward, is_cumul): current_ward = self.ward if is_cumul: self.ward += ward else: self.ward = max(self.ward, ward) if current_ward < self.ward: battlelog.log("%s's ward raises to %d\n" %(self.name, self.ward)) else: battlelog.log("%s's ward remains at %d\n" %(self.name, self.ward))
def cleanse(self): battlelog.log("%s is cleansed\n" %(self.name)) from effect import Bane for long_time_effect in self.long_time_effect_list[:]: if isinstance(long_time_effect, Bane): battlelog.log("%s disappears\n" %(long_time_effect.attach_charm.name)) self.long_time_effect_list.remove(long_time_effect) self.melee_CPB = max(0, self.melee_CPB) self.melee_NPB = max(0, self.melee_NPB) self.magic_CPB = max(0, self.magic_CPB) self.magic_NPB = max(0, self.magic_NPB) self.spirit_CPB = max(0, self.spirit_CPB) self.spirit_NPB = max(0, self.spirit_NPB) return
def purge(self): battlelog.log("%s is purged\n" %(self.name)) from effect import Aura for long_time_effect in self.long_time_effect_list[:]: if isinstance(long_time_effect, Aura): battlelog.log("%s disappears\n" %(long_time_effect.attach_charm.name)) self.long_time_effect_list.remove(long_time_effect) self.melee_CPB = min(0, self.melee_CPB) self.melee_NPB = min(0, self.melee_NPB) self.magic_CPB = min(0, self.magic_CPB) self.magic_NPB = min(0, self.magic_NPB) self.spirit_CPB = min(0, self.spirit_CPB) self.spirit_NPB = min(0, self.spirit_NPB) return
def play_turn(self): self.turn_num += 1 player = self.action_player allies = self.action_party enimies = self.opposite_party(allies) if player.is_stun(): player.play_stun(self.turn_num) self.focus_turn_decrease(enimies) player.trigger_effects_stun(allies, enimies) return player.turn_begin() while player.has_action(): player.play_charm(allies, enimies, self.turn_num) self.focus_turn_decrease(enimies) self.check_players_state() if self.end() or not player.is_alive(): battlelog.log("\n") break if player.has_extra_action(): player.trigger_effects_extra_action(allies, enimies) else: player.trigger_effects_normal(allies, enimies) self.check_players_state() if self.end() or not player.is_alive(): battlelog.log("\n") break player.reduce_spirit(1) self.check_players_state() if self.end() or not player.is_alive(): battlelog.log("\n") break battlelog.log("\n") player.turn_end() self.log_state() return
def log_state(self): battlelog.log("** Battle status **\n") for player in self.attackers: player.log_state() battlelog.log("------\n") for player in self.defenders: player.log_state() battlelog.log("\n")
def test_vs(name1, gear1, name2, gear2): battlelog.log_close() player1_win_cnt = 0 player2_win_cnt = 0 for cnt in xrange(simulating_times): if cnt == 0: battlelog.log_open() else: battlelog.log_close() player1 = DataHandler.load_player_from_id(name1) player2 = DataHandler.load_player_from_id(name2) player1.import_gear(Gear.from_string(gear1)) player2.import_gear(Gear.from_string(gear2)) attackers = [player1] defenders = [player2] env = Envioronment(attackers, defenders) result = env.start() if result == EnvioronmentType.Win: player1_win_cnt += 1 else: player2_win_cnt += 1 battlelog.log_open() battlelog.log("%s vs %s, total %d times: %s win probability = %f%%, %s win probability = %f%%\n" %(player1.name, player2.name, simulating_times, player1.name, float(player1_win_cnt*100)/simulating_times, player2.name, float(player2_win_cnt*100)/simulating_times))
def take_magic_damage(self, magic, penetrating): if magic > self.ward: pierced = self.ward * penetrating / 100 absorbed = self.ward - pierced damage = magic - self.ward + pierced self.ward = 0 else: pierced = magic * penetrating / 100 absorbed = magic - pierced damage = pierced self.ward -= magic if pierced > 0: battlelog.log("%s takes %d magic damage (%d absorbed, %d pierced)\n" %(self.name, damage, absorbed, pierced)) elif absorbed > 0: battlelog.log("%s takes %d magic damage (%d absorbed)\n" %(self.name, damage, absorbed)) else: battlelog.log("%s takes %d magic damage\n" %(self.name, damage)) self.reduce_hp(damage) return damage, absorbed, pierced
def take_melee_damage(self, melee, penetrating): if melee > self.armor: pierced = self.armor * penetrating / 100 absorbed = self.armor - pierced damage = melee - self.armor + pierced self.armor = 0 else: pierced = melee * penetrating / 100 absorbed = melee - pierced damage = pierced self.armor -= melee if pierced > 0: battlelog.log("%s takes %d melee damage (%d absorbed, %d pierced)\n" %(self.name, damage, absorbed, pierced)) elif absorbed > 0: battlelog.log("%s takes %d melee damage (%d absorbed)\n" %(self.name, damage, absorbed)) else: battlelog.log("%s takes %d melee damage\n" %(self.name, damage)) self.reduce_hp(damage) return damage, absorbed, pierced
def take_spirit_damage(self, spirit, penetrating): if spirit > self.willpower: pierced = self.willpower * penetrating / 100 absorbed = self.willpower - pierced damage = spirit - self.willpower + pierced self.willpower = 0 else: pierced = spirit * penetrating / 100 absorbed = spirit - pierced damage = pierced self.willpower -= spirit if pierced > 0: battlelog.log("%s takes %d spirit damage (%d absorbed, %d pierced)\n" %(self.name, damage, absorbed, pierced)) elif absorbed > 0: battlelog.log("%s takes %d spirit damage (%d absorbed)\n" %(self.name, damage, absorbed)) else: battlelog.log("%s takes %d spirit damage\n" %(self.name, damage)) while damage > 0 and self.spirit > 0: damage -= 1 self.spirit -= 1 self.charm_thrown_each_turn.append(self.charm_list.next()) return damage, absorbed, pierced
def out_of_spirit(self): battlelog.log("\n%s collapses of exhaustion.\n" %(self.name)) self.alive_state = PlayerType.Out_of_Spirit self.reset()
def die(self): battlelog.log("\n%s is defeated.\n" %(self.name)) self.alive_state = PlayerType.Dead self.reset()
def lose_ward(self, ward): self.ward = max(0, self.ward - ward) battlelog.log("%s's ward drops to %d\n" %(self.name, self.ward))
def gain_spirit_CPB(self, boost): self.spirit_CPB += boost battlelog.log("%s's ongoing spirit attack is increase by up to %d\n" %(self.name, boost))
def attach_log(self, player_name): battlelog.log("%s is affected by %s\n" %(player_name, self.description))
def attach_log(self, player_name): battlelog.log("%s gains %s\n" %(player_name, self.description))
def play_stun(self, turn_num): self.stun_turn -= 1 battlelog.log("%s is stunned\n" %(self.name)) if turn_num not in self.charm_used_each_turn: self.charm_used_each_turn[turn_num] = []
def heal(self, hp): battlelog.log("%s heals %d damage\n" %(self.name, hp)) self.increase_hp(hp)
def life_lose(self, hp): battlelog.log("%s lose %d life\n" %(self.name, hp)) self.reduce_hp(hp)
def log_state(self): battlelog.log("%s : %d/%d HP, %d armor, %d ward, %d willpower, %d/%d Charm(s) left, Melee CPB/Next: %d/%d, Magic CPB/Next: %d/%d, Spirit CPB/Next: %d/%d\n" %(self.name, self.hp, self.max_hp, self.armor, self.ward, self.willpower, self.spirit, self.max_spirit, self.melee_CPB, self.melee_NPB, self.magic_CPB, self.magic_NPB, self.spirit_CPB, self.spirit_NPB))
def attach_log(self, player_name): battlelog.log("%s summons a %s\n" %(player_name, self.description))
def trigger_log(self): battlelog.log("Because of %s(%s, %d turns left), " %(self.description, self.name, self.turn))
def gain_melee_NPB(self, boost): self.melee_NPB += boost battlelog.log("%s's next melee attack is increase by up to %d\n" %(self.name, boost))
def trigger_log(self): battlelog.log("%s(%s, %d turns left) takes effect, " %(self.description, self.name, self.turn))
def gain_magic_CPB(self, boost): self.magic_CPB += boost battlelog.log("%s's ongoing magic attack is increase by up to %d\n" %(self.name, boost))
def trigger_log(self): battlelog.log("%s(%s, %d turns left) attacks, " %(self.description, self.name, self.turn))
def lose_willpower(self, willpower): self.willpower = max(0, self.willpower - willpower) battlelog.log("%s's willpower drops to %d\n" %(self.name, self.willpower))