コード例 #1
0
ファイル: game.py プロジェクト: fregaham/manaclash
    def doDealDamage(self, list, combat=False):

        dr = DamageReplacement(list, combat)
        self.raise_event("damage_replacement", dr)

        for a_lki_id, b_lki_id, n in dr.list:
            if not self.lki(b_lki_id).is_moved():

                # go through all applicable damage prevention effects
                applicable = []
                for damage_prevention in self.damage_preventions:
                    if damage_prevention.canApply(self, (a_lki_id, b_lki_id, n), combat):
                        applicable.append (damage_prevention)

                while len(applicable) > 0:
                    # do we have a unique applicable effect?
                    if len(applicable) == 1:
                        a_lki_id,b_lki_id,n = applicable[0].apply(self, (a_lki_id, b_lki_id, n), combat)
                        applicable = []
                    else:
                        # we let the reciever's controller choose
                        # TODO: make threadless
                        controller = self.objects[self.lki(b_lki_id).get_controller_id()]

                        actions = []
                        for damage_prevention in applicable:
                            action = Action()
                            action.text = damage_prevention.getText()
                            action.damage_prevention = damage_prevention
                            actions.append(action)

                        _as = ActionSet (self, controller, "Which damage prevention effect apply first for %d damage to %s?" % (n, str(self.lki(b_lki_id))), actions)
                        action = self.input.send (_as)

                        damage_prevention = action.damage_prevention

                        a_lki_id,b_lki_id,n = damage_prevention.apply(self, (a_lki_id,b_lki_id,n), combat)
                        applicable.remove(damage_prevention)

                        if n <= 0:
                            break

                        new_applicable = []
                        for damage_prevention in applicable[:]:
                            if damage_prevention.canApply(self, (a_lki_id,b_lki_id,n), combat):
                                new_applicable.append(damage_prevention)
                        applicable = new_applicable


                if n <= 0:
                    continue

                if combat:
                     self.raise_event("pre_deal_combat_damage", a_lki_id, b_lki_id, n)

                self.raise_event("pre_deal_damage", a_lki_id, b_lki_id, n)

                a = self.lki(a_lki_id)
                b = self.lki(b_lki_id)
                if "player" in b.get_state().types:
                    if "damage that would reduce your life total to less than 1 reduces it to 1 instead" in b.get_state().tags and (b.get_object().life - n < 1):
                        b.get_object().life = 1
                    else:
                        b.get_object().life -= n
                else:
                    b.get_object().damage += n

                self.output.damage(a.get_object(), b.get_object, n)

                if combat:
                     self.raise_event("post_deal_combat_damage", a_lki_id, b_lki_id, n)

                self.raise_event("post_deal_damage", a_lki_id, b_lki_id, n)