Example #1
0
File: cards.py Project: Kile/Killua
    async def exec(self) -> None:
        author = User(self.ctx.author.id)
        try:
            self._has_effect_check(author, str(self.id))
        except CheckFailure:
            if not author.count_card(self.id) > 1:
                raise CheckFailure("You don't have another copy of this card to renew the effect")
            view = ConfirmButton(user_id=self.ctx.author.id)
            msg = await self.ctx.send(f"You still have {author.has_effect(str(self.id))[1]} protections left. Do you really want to use this card now and overwrite the current protection?", view=view)
            await view.wait()
            await view.disable(msg)

            if view.timed_out:
                raise CheckFailure("Timed out!")
            elif view.value is False:
                raise CheckFailure("Successfully canceled!")

        if author.has_effect(str(self.id)):
            author.remove_effect(str(self.id))

        # if (amount:=author.count_card(self.id)) > 1:
        #     for i in range(amount):
        #         author.remove_card(self.id)

        author.add_effect(str(self.id), 10)

        await self.ctx.send('Done, you will be automatically protected from the next 10 attacks! You need to keep the card in your inventory until all 10 defenses are used up')
Example #2
0
    async def hunt(self, ctx, end:str=None):
        """Go on a hunt! The longer you are on the hunt, the better the rewards!"""
        
        user = User(ctx.author.id)
        has_effect, value = user.has_effect('hunting')

        if end:

            if end.lower() == 'time':
                if not has_effect:
                    return await ctx.send('You are not on a hunt yet!')
                
                return await ctx.send(f'You\'ve started hunting <t:{int(value.timestamp())}:R>.')

            if not end.lower() == 'end':
                pass
            elif has_effect is True:
                difference = datetime.utcnow() - value
                if int(difference.seconds/60/60+difference.days*24*60*60) < 12: # I don't think timedelta has an hours or minutes property :c
                    return await ctx.send('You must be at least hunting for twelve hours!')

                minutes = int(difference.seconds/60+difference.days*24*60)
                score = minutes/10080 # There are 10080 minutes in a week if I'm not completely wrong
                
                rewards = self._construct_rewards(score)
                formatted_rewards, formatted_text, hit_limit = self._format_rewards(rewards, user, score)
                text = f'You\'ve started hunting <t:{int(value.timestamp())}:R>. You brought back the following items from your hunt: \n\n'
                if hit_limit:
                    text += f":warning: Your free slot limit has been reached! Sell some cards with `{self.client.command_prefix(self.client, ctx.message)[2]}sell` :warning:\n\n"

                if hit_limit and len(user.fs_cards) == 40:
                    text += f"Could not carry anything from your hunt in your free slots so you gained no cards.."

                embed = discord.Embed.from_dict({
                    'title': 'Hunt returned!',
                    'description': text + "\n".join(formatted_text),
                    'color': 0x1400ff
                })
                user.remove_effect('hunting')
                user.add_multi(*formatted_rewards)
                return await ctx.send(embed=embed)
                
            elif end.lower() == 'end': 
                return await ctx.send(f'You aren\'t on a hunt yet! Start one with `{self.client.command_prefix(self.client, ctx.message)[2]}hunt`', allowed_mentions=discord.AllowedMentions.none())

        if has_effect:
            return await ctx.send(f'You are already on a hunt! Get the results with `{self.client.command_prefix(self.client, ctx.message)[2]}hunt end`', allowed_mentions=discord.AllowedMentions.none())
        user.add_effect('hunting', datetime.utcnow())
        await ctx.send('You went hunting! Make sure to claim your rewards at least twelve hours from now, but remember, the longer you hunt, the more you get')
Example #3
0
File: cards.py Project: Kile/Killua
    async def _attack_defense_check(self, ctx: commands.Context, other: User, target_card:int) -> None:
        if target_card in [x[0] for x in other.rs_cards]: # A list of cards that steal from restricted slots
            if f'page_protection_{int((target_card-10)/18+2)}' in other.effects and not target_card in [x[0] for x in other.fs_cards]:
                raise SuccessfullDefense('The user has protected the page this card is in against spells!')

        if other.has_effect('1026')[0]:
            if 1026 in [x[0] for x in other.all_cards]: # Card has to remain in posession
                if other.effects['1026']-1 == 0:
                    other.remove_effect('1026')
                    other.remove_card(1026) 
                else:
                    other.add_effect('1026', other.effects['1026']-1)
                raise SuccessfullDefense('The user had remaining protection from card 1026 thus your attack failed')

        effects = []
        for c in other.fs_cards:
            if c[0] in DEF_SPELLS and not c[0] in effects:
                if c[0] == 1019 and not self.range == 'SR':
                    continue
                if c[0] == 1004 and self.ctx.author.id not in other.met_user:
                    continue
                effects.append(c[0])

        await self._wait_for_defense(ctx, other, effects)
Example #4
0
File: cards.py Project: Kile/Killua
 def _has_effect_check(self, user:User, effect:str) -> None:
     if user.has_effect(effect)[0]:
         raise CheckFailure("You already have this effect in place!")