dicetable.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Jumper-Cogs 作者: Redjumpman 项目源码 文件源码
def _roll_dtable(self, dice: str, times=1, modifier=0):
        """Rolls a set of die in the format 2d12
        By default only one set of die is rolled, without a
        modifier. Example 3d20 5 1 will roll three 1d20 dice for
        five seperate instances, with a +1 modifier added to the total."""

        if times < 1:
            raise RollError("You need to have at least one roll instance.")
        elif times > 20:
            raise RollError("Cannot roll more than 20 instances at a time.")

        die, maximum = self.parse_dice(dice)
        rolls_raw = list(range(times))

        if modifier < 0:
            sign = ""
        else:
            sign = "+"

        rolls = [(str("Roll {}".format(x + 1)), self.roll_dice(die, maximum), sign + str(modifier))
                 for x in rolls_raw]
        final = [x + (str(x[1] + modifier),) for x in rolls]
        headers = ["Roll", "Result", "Modifier", "Total"]
        t = tabulate(final, headers=headers)
        await self.bot.say("```{}```".format(t))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号