示例#1
0
def test_init_default_values():
    '''Test how it sets optional values by default'''
    weapon = Weapon(range(7))
    assert weapon.damage == range(7)
    assert not weapon.two_handed
    assert not weapon.ignore_armor
    assert weapon.name is None
    assert weapon.style is None
示例#2
0
    def __init__(self, ctx, weapon: Weapon, armor: str, bonus: int, **kwargs):
        super(EmbedDamage, self).__init__(ctx, **kwargs)
        roll = weapon.roll_damage(armor, bonus)
        damage_dealt = weapon.lookup_damage(roll.total)

        self.title = f"{weapon.name} Damage ({damage_dealt})"

        table = ""
        for indx, d in enumerate(weapon.damage):
            table += str(d) if indx + 1 is not roll.total else f"__**{d}**__"
            if len(weapon.damage) - 1 is not indx:
                table += " | "
        table = f" {table} "

        dmg_txt = f"Damage Dealt:\n{table}\n\n**{damage_dealt}** damage was dealt."

        roll_breakdown_txt = f"Roll Breakdown:\n{roll.result}"
        self.description = f"\n{roll_breakdown_txt}\n\n{dmg_txt}"
示例#3
0
def test_parse_defaults():
    in_weapon = {"damage": [1, 2, 3, 4, 5, 6, 7], "name": "Test Weapon"}

    weapon = Weapon.parse(in_weapon)
    assert weapon.damage == [1, 2, 3, 4, 5, 6, 7]
    assert weapon.name == "Test Weapon"
    assert weapon.style == "melee"
    assert not weapon.two_handed
    assert not weapon.ignore_armor
    assert weapon.aliases == []
示例#4
0
def test_init_set_optional_values():
    weapon = Weapon(range(7),
                    name="Vorpal Sword",
                    style="melee",
                    two_handed=True,
                    ignore_armor=True)
    assert weapon.name == "Vorpal Sword"
    assert weapon.style == "melee"
    assert weapon.two_handed
    assert weapon.ignore_armor
示例#5
0
    async def weapon(self, ctx, *, arg):
        weapon_regex = r'([^0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)( ignore)?$'

        r = re.match(weapon_regex, arg)
        if not r:
            raise ArgumentParsingError("Argument should be `weapon name 1 2 3 4 5 6 7 [ignore]`")

        weapon_name = r.group(1)
        damage_table = [int(r.group(2)), int(r.group(3)), int(r.group(4)), int(r.group(5)),
                        int(r.group(6)), int(r.group(7)), int(r.group(8))]
        ignore_armor = r.group(9) is not None

        weapon = Weapon(damage_table, name=weapon_name, ignore_armor=ignore_armor)

        library = self.bot.get_cog('LibraryCog')
        library.add_temp_weapon(weapon)
        await ctx.send(f"Added weapon `{weapon_name}` damage `{damage_table}` ignore_armor={ignore_armor}")
示例#6
0
def test_parse_explicit():
    in_weapon = {
        "damage": [1, 2, 3, 4, 5, 6, 7],
        "name": "Test Weapon",
        "style": "melee",
        "two_handed": True,
        "ignore_armor": True,
        "aliases": ["fred"]
    }

    weapon = Weapon.parse(in_weapon)
    assert weapon.damage == [1, 2, 3, 4, 5, 6, 7]
    assert weapon.name == "Test Weapon"
    assert weapon.style == "melee"
    assert weapon.two_handed
    assert weapon.ignore_armor
    assert weapon.aliases == ["fred"]
示例#7
0
    def load(cls, path: str) -> Compendium:
        yaml_data = None

        config_uri_parsed = urlparse(path)
        if config_uri_parsed.scheme in ['https', 'http']:
            url = urlopen(path)
            yaml_data = url.read()
        else:
            if not os.path.exists(path):
                path = os.path.join(os.path.dirname(__file__), '..', '..',
                                    'data', f"{path}.yaml")

            with open(file=path, mode='r', encoding='UTF-8') as file_data:
                yaml_data = file_data.read()

        infile = yaml.safe_load(yaml_data)

        key = infile['key']
        title = infile['title']
        url = infile.get('url', None)
        author = infile.get('author', None)
        inherits = infile.get('inherits', None)

        compendium = cls(key, title, url, author, inherits)
        if 'backgrounds' in infile:
            for in_bg in infile['backgrounds']:
                background = Background.parse(in_bg)
                compendium.add_background(background)

        if 'weapons' in infile:
            for in_weapon in infile['weapons']:
                weapon = Weapon.parse(in_weapon)
                compendium.add_weapon(weapon)

        if 'spells' in infile:
            for in_spell in infile['spells']:
                spell = Spell.parse(in_spell)
                compendium.add_spell(spell)

        if 'base_items' in infile:
            for base_item in infile['base_items']:
                compendium.add_base_item(base_item)

        return compendium
示例#8
0
def test_weapon_lookup_damage():
    damage = range(7)
    w = Weapon(damage)
    assert w.lookup_damage(4) == damage[3]
def sword():
    return Weapon(name='Sword', damage=[4, 6, 6, 6, 6, 8, 10])
def maul():
    return Weapon(name='Maul',
                  damage=[1, 2, 3, 6, 12, 13, 14],
                  ignore_armor=True)
示例#11
0
def test_weapon_lookup_damage_ceiling():
    damage = range(7)
    w = Weapon(damage)
    assert w.lookup_damage(9) == damage[6]
示例#12
0
def test_weapon_lookup_damage_bad_index():
    w = Weapon(range(7))
    with pytest.raises(ValueError):
        w.lookup_damage(0)
示例#13
0
def test_attack_damage_mod_roll(mocker):
    '''Sometimes there are bonuses on damage rolls'''
    mocker.patch.object(dice, 'roll_d6', return_value=2)
    w = Weapon(range(7))
    r = w.roll_damage(damage_bonus=2)
    assert r.total == 4
示例#14
0
def test_armor_offset_unarmored_roll(mocker):
    '''Ignoring armor should have no effect on unarmored foes'''
    mocker.patch.object(dice, 'roll_d6', return_value=2)
    w = Weapon(range(7), ignore_armor=True)
    r = w.roll_damage()
    assert r.total == 2
示例#15
0
def test_init_exception():
    '''Throwing an exception'''
    with pytest.raises(ValueError):
        Weapon([0, 1, 3])
示例#16
0
def test_ignore_armor_offset_roll(mocker):
    '''Some weapons ignore one point of the armor offset'''
    mocker.patch.object(dice, 'roll_d6', return_value=3)
    w = Weapon(range(7), ignore_armor=True)
    r = w.roll_damage(armor="Moderate")
    assert r.total == 2
示例#17
0
def test_basic_armor_offset_roll(mocker):
    '''Armor offset should reduce damage roll to a minimum of 1'''
    mocker.patch.object(dice, 'roll_d6', return_value=2)
    w = Weapon(range(7))
    r = w.roll_damage(armor="Medium")
    assert r.total == 1
示例#18
0
def test_basic_damage_roll(mocker):
    '''A basic test of damage rolls'''
    mocker.patch.object(dice, 'roll_d6', return_value=4)
    w = Weapon(range(7))
    r = w.roll_damage()
    assert r.total == 4