コード例 #1
0
    def generate(cls, compendium: Compendium,
                 background: Background) -> Character:
        skill_roll = dice.roll_d3()
        _, _, stamina_roll = dice.roll_2d6()
        luck_roll = dice.roll_d6()

        skills: List[Skill] = [Skill.parse(s) for s in background.skills]
        items: List[Union[Item, ItemChoice]] = [
            ItemChoice.parse(i) for i in background.items
        ]

        if background.has_base_items:
            items += [Item.parse(i) for i in compendium.base_items]

        spell_picker = RandomSpellPicker(compendium, background.spells)
        spells: List[Spell] = [
            SpellSkill.parse(s, spell_picker) for s in background.spells
        ]

        return cls(skill=skill_roll + 3,
                   stamina=stamina_roll + 12,
                   luck=luck_roll + 6,
                   background=background,
                   compendium=compendium,
                   items=items,
                   skills=skills,
                   spells=spells)
コード例 #2
0
def roll_2d6() -> dice.RollResult:
    dice1, dice2, total = dice.roll_2d6()

    dice_string = ''
    if (dice1 == 6 and dice2 == 6) or (dice1 == 1 and dice2 == 1):
        dice_string = f"**{dice1}+{dice2}**"
    else:
        dice_string = f"{dice1}+{dice2}"

    return dice.RollResult(total, f"2d6({dice_string}) = {total}")
コード例 #3
0
    async def better(self, ctx, skill: int):
        d1, d2, total = dice.roll_2d6()

        if skill < 12:
            if total > skill:
                await ctx.send(
                    f"**SUCCESS** 2d6({d1}+{d2}) = `{total}` > `{skill}`. Increase advanced skill by 1"
                )
            else:
                await ctx.send(
                    f"**FAILURE** 2d6({d1}+{d2}) = `{total}` ≤ `{skill}`. Advanced skill unchanged"
                )
        else:
            d3, d4, total2 = dice.roll_2d6()
            if total + total2 == 24:
                await ctx.send(
                    f"**SUCCESS** 2d6({d1}+{d2})+2d6({d3}+{d4}) = `{total+total2}`. Increase advanced skill by 1"
                )
            else:
                await ctx.send(
                    f"**FAILURE** 2d6({d1}+{d2})+2d6({d3}+{d4}) = `{total+total2}`. Advanced skill unchanged"
                )
コード例 #4
0
def test_roll_2d6():
    for _ in range(100):
        r1, r2, r3 = dice.roll_2d6()
        assert r1 >= 1 and r1 <= 6
        assert r2 >= 1 and r2 <= 6
        assert r3 == r1 + r2
コード例 #5
0
ファイル: dice_cog.py プロジェクト: natehole/TroikaDiscordBot
    async def roll(self, ctx, *, query: str):
        """Rolls the dice"""
        CHARACTER_REGEXP = re.compile("char(acter)?( [^0-9][^ ]*)?( [0-9]+)?")
        D2_REGEXP = re.compile("1?d2([+-][0-9]+)?$")
        D3_REGEXP = re.compile("1?d3([+-][0-9]+)?$")
        D6_REGEXP = re.compile("1?d6([+-][0-9]+)?$")
        TWO_D6_REGEXP = re.compile("2d6([+-][0-9]+)?$")
        D20_REGEXP = re.compile("1?d20([+-][0-9]+)?$")
        D66_REGEXP = re.compile("d66$")

        # initialize
        regexp_matched = False
        modifier = 0

        match = CHARACTER_REGEXP.match(query)
        if match:
            if match.group(2):
                key = match.group(2).lstrip()
            else:
                key = 'base'

            if match.group(3):
                bg_roll = int(match.group(3).lstrip())
            else:
                bg_roll = dice.roll_d66()

            regexp_matched = True
            library = self.bot.get_cog('LibraryCog')
            compendium = library.find_compendium(key)

            if compendium:
                background = compendium.lookup_background(bg_roll)
                if background:
                    character = Character.generate(compendium, background)
                    embed = EmbedCharacter(ctx, character)
                    await ctx.send(embed=embed)
                else:
                    await ctx.send(
                        "BACKGROUND d66 = `{bg_roll}`\n_No background found..._"
                    )
            else:
                await ctx.send(f"No compendium found for `{key}`")

        match = D66_REGEXP.match(query)
        if match:
            regexp_matched = True
            total = dice.roll_d66()
            await ctx.send(f"d66 = `{total}`")

        match = D2_REGEXP.match(query)
        if not regexp_matched and match:
            regexp_matched = True
            roll = dice.roll_d2()

            if match.group(1):
                modifier = int(match.group(1))

            await ctx.send(
                f"d2 ({roll}){modifier_string(modifier)} = `{roll+modifier}`")

        match = D3_REGEXP.match(query)
        if not regexp_matched and match:
            regexp_matched = True
            roll = dice.roll_d3()

            if match.group(1):
                modifier = int(match.group(1))

            await ctx.send(
                f"d3 ({roll}){modifier_string(modifier)} = `{roll+modifier}`")

        match = D6_REGEXP.match(query)
        if not regexp_matched and match:
            regexp_matched = True
            roll = dice.roll_d6()

            if match.group(1):
                modifier = int(match.group(1))

            await ctx.send(
                f"d6 ({roll}){modifier_string(modifier)} = `{roll+modifier}`")

        match = TWO_D6_REGEXP.match(query)
        if not regexp_matched and match:
            regexp_matched = True
            r1, r2, total = dice.roll_2d6()

            if match.group(1):
                modifier = int(match.group(1))

            await ctx.send(
                f"2d6 ({r1}+{r2}){modifier_string(modifier)} = `{total+modifier}`"
            )

        match = D20_REGEXP.match(query)
        if not regexp_matched and match:
            regexp_matched = True
            roll = dice.roll_d20()

            if match.group(1):
                modifier = int(match.group(1))

            await ctx.send(
                f"d20 ({roll}){modifier_string(modifier)} = `{roll+modifier}`")

        if not regexp_matched:
            raise ArgumentParsingError(
                f"Unable to understand your command: `{query}`")