Esempio n. 1
0
    async def test_complex_resistances(self, avrae, dhttp):
        character = await active_character(avrae)
        for combatant in (character.name, "KO1", "TEST1"):
            avrae.message(f"!i opt \"{combatant}\" -resist \"magical foobar\"")
            await dhttp.drain()
            resistances = (
                await
                active_combat(avrae)).get_combatant(combatant).resistances
            assert Resistance('foobar', only=['magical']) in resistances.resist

            avrae.message(f"!i opt \"{combatant}\" -vuln \"magical foobar\"")
            await dhttp.drain()
            resistances = (
                await
                active_combat(avrae)).get_combatant(combatant).resistances
            assert Resistance('foobar',
                              only=['magical']) not in resistances.resist
            assert Resistance('foobar', only=['magical']) in resistances.vuln

            avrae.message(
                f"!i opt \"{combatant}\" -neutral \"magical foobar\"")
            await dhttp.drain()
            resistances = (
                await
                active_combat(avrae)).get_combatant(combatant).resistances
            assert Resistance('foobar',
                              only=['magical']) not in resistances.vuln
Esempio n. 2
0
def test_resistance_complex():
    fire = Resistance('fire', unless=['magical'],
                      only=['cold'])  # nonmagical cold fire

    assert not fire.applies_to_str('fire')
    assert not fire.applies_to_str('magical fire')
    assert not fire.applies_to_str("everything's on fire")
    assert not fire.applies_to_str('fire truck')
    assert not fire.applies_to_str('cold')
    assert fire.applies_to_str('cold fire')
    assert not fire.applies_to_str('cold magical fire')
Esempio n. 3
0
def test_simple_resistance():
    fire = Resistance('fire')

    assert fire.applies_to_str('fire')
    assert fire.applies_to_str('magical fire')
    assert fire.applies_to_str("everything's on fire")
    assert fire.applies_to_str('fire truck')
    assert not fire.applies_to_str('cold')
Esempio n. 4
0
def test_resistance_only():
    fire = Resistance('fire', only=['magical'])  # magical fire

    assert not fire.applies_to_str('fire')
    assert fire.applies_to_str('magical fire')
    assert not fire.applies_to_str("everything's on fire")
    assert not fire.applies_to_str('fire truck')
    assert not fire.applies_to_str('cold')
Esempio n. 5
0
    def set_resist(self, damage_type: str, resist_type: str):
        if resist_type not in RESIST_TYPES:
            raise ValueError("Resistance type is invalid")

        for rt in RESIST_TYPES:
            for resist in reversed(self._resistances[rt]):
                if resist.dtype == damage_type:
                    self._resistances[rt].remove(resist)

        if resist_type != 'neutral':
            resistance = Resistance.from_str(damage_type)
            self._resistances[resist_type].append(resistance)
Esempio n. 6
0
    def set_resist(self, damage_type: str, resist_type: str):
        if resist_type not in RESIST_TYPES:
            raise ValueError("Resistance type is invalid")

        resistance = Resistance.from_str(damage_type)

        for rt in RESIST_TYPES:
            for resist in reversed(self._resistances[rt]):
                # remove any existing identical resistances, or any filtered variant of a given non-complex resistance
                if resist == resistance or (not resistance.is_complex and resist.dtype == resistance.dtype):
                    self._resistances[rt].remove(resist)

        if resist_type != 'neutral' or resistance.is_complex:
            self._resistances[resist_type].append(resistance)
Esempio n. 7
0
def parse_resist_str(resist_list):
    return ', '.join([str(Resistance.from_dict(r)) for r in resist_list])
Esempio n. 8
0
def parse_resist_arg(arg, _):
    return [Resistance.from_dict(r).to_dict() for r in arg]
Esempio n. 9
0
def test_resistance_from_str():
    assert Resistance('fire') == Resistance.from_str('fire')
    assert Resistance('fire',
                      unless=['magical'
                              ]) == Resistance.from_str('nonmagical fire')
    assert Resistance('fire',
                      only=['magical']) == Resistance.from_str('magical fire')
    assert Resistance('fire', unless=['abc'],
                      only=['def']) == Resistance.from_str('nonabc def fire')
    assert Resistance('fire',
                      only=['cold']) == Resistance.from_str('cold fire')
    assert Resistance('cold',
                      only=['fire']) == Resistance.from_str('fire cold')
Esempio n. 10
0
def test_resistance_equality():
    assert Resistance('fire') == Resistance('fire')
    assert Resistance('cold') != Resistance('fire')

    assert Resistance('fire',
                      unless=['magical']) == Resistance('fire',
                                                        unless={'magical'})
    assert Resistance('fire', unless=['magical']) != Resistance('fire')
    assert Resistance('fire', unless=['magical']) != Resistance(
        'fire', only=['magical'])

    assert Resistance('fire', unless=['abc'],
                      only=['def']) == Resistance('fire',
                                                  unless={'abc'},
                                                  only=['def'])
    assert Resistance('fire', unless=['abc'], only=['def']) != Resistance(
        'fire', only=['def'])