Beispiel #1
0
 def save_battle_log(self, this_boss, damage):
     for log in this_boss.logs:
         if log.char_id == self.char_id:
             log.damage += damage
             break
     else:
         boss_log = MongoEmbeddedUnionBossLog()
         boss_log.char_id = self.char_id
         boss_log.damage = damage
         this_boss.logs.append(boss_log)
Beispiel #2
0
 def save_battle_log(self, this_boss, damage):
     for log in this_boss.logs:
         if log.char_id == self.char_id:
             log.damage += damage
             break
     else:
         boss_log = MongoEmbeddedUnionBossLog()
         boss_log.char_id = self.char_id
         boss_log.damage = damage
         this_boss.logs.append(boss_log)
Beispiel #3
0
    def battle(self, boss_id):
        try:
            this_boss = self.mongo_boss.opened[str(boss_id)]
        except KeyError:
            raise SanguoException(
                errormsg.UNION_BOSS_NOT_STARTED,
                self.char_id,
                "UnionBoss Battle",
                "boss not started {0}".format(boss_id)
            )

        if this_boss.hp <= 0:
            raise SanguoException(
                errormsg.UNION_BOSS_DEAD,
                self.char_id,
                "UnionBoss Battle",
                "boss dead {0}".format(boss_id)
            )

        # TODO boss times limit


        msg = protomsg.Battle()
        battle = UnionBossBattle(self.char_id, boss_id, msg, this_boss.hp)
        remained_hp = battle.start()

        if remained_hp == 0:
            killer = self.char_id
        else:
            killer = 0

        this_boss.hp = remained_hp
        this_boss.killer = killer

        eubl = MongoEmbeddedUnionBossLog()
        eubl.char_id = self.char_id
        eubl.damage = battle.get_total_damage()

        this_boss.logs.append(eubl)
        self.mongo_boss.save()

        self.incr_battle_times()
        self.after_battle(eubl.damage)

        if killer:
            self.boss_has_been_killed(boss_id)

        return msg