Beispiel #1
0
    async def send_automation(self, ctx, character, ability_name,
                              automation_result):
        """
        Attacks, casting, etc (any result from the automation engine)

        :type ctx: discord.ext.commands.Context
        :type character: cogs5e.models.character.Character
        :type ability_name: str
        :type automation_result: cogs5e.models.automation.AutomationResult
        """
        campaign_id, ddb_user = await self._send_preflight(ctx, character)
        if ddb_user is None:
            return

        roll_request_rolls = []

        # dfs over the automation result tree, looking for results w/ dice that we care about
        def dfs(node):
            if isinstance(node, AttackResult):
                if node.to_hit_roll is not None:
                    roll_request_rolls.append(
                        RollRequestRoll.from_d20(
                            node.to_hit_roll,
                            roll_type=RollType.TO_HIT,
                            roll_kind=RollKind.from_d20_adv(node.adv)))
            elif isinstance(node, SaveResult):
                if node.save_roll is not None:
                    roll_request_rolls.append(
                        RollRequestRoll.from_d20(
                            node.save_roll,
                            roll_type=RollType.SAVE,
                            roll_kind=RollKind.from_d20_adv(node.adv)))
            elif isinstance(node, DamageResult):
                roll_request_rolls.append(
                    RollRequestRoll.from_d20(node.damage_roll,
                                             roll_type=RollType.DAMAGE,
                                             roll_kind=RollKind.CRITICAL_HIT if
                                             node.in_crit else RollKind.NONE))
            elif isinstance(node, TempHPResult):
                roll_request_rolls.append(
                    RollRequestRoll.from_d20(node.amount_roll,
                                             roll_type=RollType.HEAL))
            elif isinstance(node, RollResult):
                if not node.hidden:
                    roll_request_rolls.append(
                        RollRequestRoll.from_d20(
                            node.roll,
                            roll_type=RollType.SPELL
                            if automation_result.is_spell else RollType.ROLL))
            for child in node.get_children():
                dfs(child)

        dfs(automation_result)
        if not roll_request_rolls:
            return
        roll_request = RollRequest.new(roll_request_rolls,
                                       RollContext.from_character(character),
                                       ability_name)
        await self._send_roll_request(campaign_id, ddb_user, character,
                                      roll_request)
Beispiel #2
0
    async def send_roll(self, ctx, result):
        """
        Send the result of a basic roll the user made, with no knowledge of character or context

        :type ctx: discord.ext.commands.Context
        :type result: d20.RollResult
        """
        # while roll doesn't require character, sendback to ddb does
        try:
            character = await Character.from_ctx(ctx)
        except NoCharacter:
            return
        campaign_id, ddb_user = await self._send_preflight(ctx, character)
        if ddb_user is None:
            return

        rrr = RollRequestRoll.from_d20(
            result,
            roll_type=RollType.ROLL,
            roll_kind=RollKind.guess_from_d20(result))
        comment = result.comment or 'Custom'
        roll_request = RollRequest.new([rrr],
                                       RollContext.from_character(character),
                                       comment)
        await self._send_roll_request(campaign_id, ddb_user, character,
                                      roll_request)
Beispiel #3
0
    async def send_save(self, ctx, character, ability, rolls):
        """
        :type ctx: discord.ext.commands.Context
        :type character: cogs5e.models.character.Character
        :type ability: str
        :type rolls: list of d20.RollResult
        """
        campaign_id, ddb_user = await self._send_preflight(ctx, character)
        if ddb_user is None:
            return

        roll_request_rolls = [
            RollRequestRoll.from_d20(r,
                                     roll_type=RollType.SAVE,
                                     roll_kind=RollKind.guess_from_d20(r))
            for r in rolls
        ]
        roll_request = RollRequest.new(roll_request_rolls,
                                       RollContext.from_character(character),
                                       ability)
        await self._send_roll_request(campaign_id, ddb_user, character,
                                      roll_request)