From aaffc59db712e4acc4bab43a3b399c2030bc4e96 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Sep 2024 16:45:06 +0200 Subject: [PATCH] Add pity to card upgrades --- src/commands/upgrade.ts | 14 +++++++++----- src/entities/card.ts | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 085de07..79fb433 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -75,6 +75,9 @@ export class UpgradeCommand extends Command { } const upgradePrice = condition.upgradePrice * (card.foil ? 2 : 1); + const pityFactor = 0.07 * card.pity; + const upgradeChance = Math.min(card.condition.upgradeChance + pityFactor, .8); + const downgradeChance = Math.max(0.5 - pityFactor, 0.3) const imagePath = await renderCard(card, {cardCode: true}) @@ -85,8 +88,8 @@ export class UpgradeCommand extends Command { .setTitle('Upgrade card') .setThumbnail('attachment://card.png') .setDescription([ - `Upgrading the \`${card.mapper.username}\` card from from **${condition.id}** to **${condition.nextUpgrade.id}** has a ${Math.floor(condition.upgradeChance * 100)}% chance of success.`, - condition.previousUpgrade ? `If the upgrade fails, there is a 50% chance the card will be downgraded to **${condition.previousUpgrade.id}**` : `If the upgrade fails, nothing will happen.`, + `Upgrading the \`${card.mapper.username}\` card from from **${condition.id}** to **${condition.nextUpgrade.id}** has a ${Math.floor(upgradeChance * 100)}% chance of success.`, + condition.previousUpgrade ? `If the upgrade fails, there is a ${Math.floor(downgradeChance * 100)}% chance the card will be downgraded to **${condition.previousUpgrade.id}**` : `If the upgrade fails, nothing will happen.`, '', 'Attempting to upgrade will cost', '```diff', @@ -176,13 +179,14 @@ export class UpgradeCommand extends Command { } const random = Math.random(); - const success = random < condition.upgradeChance; - const downgrade = !success && Math.random() < 0.5; + const success = random < upgradeChance; + const downgrade = !success && Math.random() < downgradeChance; if (success) { currentCard.condition = condition.nextUpgrade; } else { if (condition.previousUpgrade && downgrade) { currentCard.condition = condition.previousUpgrade; + currentCard.pity++; } } @@ -208,7 +212,7 @@ export class UpgradeCommand extends Command { } else { await response.update({ embeds: [ - embed.setFooter({text: 'Upgrade failed' + (downgrade && condition.previousUpgrade ? '. Card is now `' + condition.previousUpgrade.id + '`' : '') ,}) + embed.setFooter({text: 'Upgrade failed' + (downgrade && condition.previousUpgrade ? '. Card is now `' + condition.previousUpgrade.id + '`' + '\n' + 'Your chances for future upgrades improved a little..': '') ,}) .setColor('Red') ], components: [] diff --git a/src/entities/card.ts b/src/entities/card.ts index 3914c15..43a1b36 100644 --- a/src/entities/card.ts +++ b/src/entities/card.ts @@ -61,6 +61,9 @@ export class Card { @Column('datetime', { name: 'job_mindblocked_until', nullable: true }) jobMindblockedUntil!: Date | null; + @Column('int', { name: 'pity', default: 0, nullable: false }) + pity!: number; + @BeforeInsert() @BeforeUpdate() calculateBurnValue() {