This commit is contained in:
DeSqBlocki
2026-08-22 22:29:16 +02:00
parent ca823726e3
commit 9e0870c1ed
6 changed files with 797 additions and 2946 deletions
+45 -16
View File
@@ -1,34 +1,63 @@
const { SlashCommandBuilder } = require("discord.js");
const {
SlashCommandBuilder
} = require(
"discord.js"
);
const {
buildProfileOverview,
buildProfileButtons,
ensureGuildBadges
} = require("../../utils/profileSystem");
buildProfileButtons
} = require(
"../../utils/profileSystem"
);
module.exports = {
data: new SlashCommandBuilder()
.setName("profile")
.setDescription("View a player profile")
.addUserOption(option =>
data:
new SlashCommandBuilder()
.setName(
"profile"
)
.setDescription(
"View a player profile"
)
.addUserOption(
option =>
option
.setName("user")
.setDescription("Player to view")
.setName(
"user"
)
.setDescription(
"Player to view"
)
),
async execute(interaction) {
const user = interaction.options.getUser("user") ?? interaction.user;
await ensureGuildBadges(interaction.guildId);
async execute(
interaction
) {
const user =
interaction.options.getUser(
"user"
)
??
interaction.user;
const embed = await buildProfileOverview(
const embed =
await buildProfileOverview(
interaction.guildId,
user
);
return interaction.reply({
embeds: [embed],
components: buildProfileButtons()
embeds: [
embed
],
components:
buildProfileButtons()
});
}
};
+47 -280
View File
@@ -18,83 +18,41 @@ const {
trackProfileEvent
} = require("./profileSystem");
const HEIST_COOLDOWN =
60 * 60;
const HEIST_METHODS = {
Sneak: {
baseChance:
0.65,
minStealPercent:
0.01,
maxStealPercent:
0.03,
maxStealAmount:
1500,
minPenaltyPercent:
0.01,
maxPenaltyPercent:
0.04,
maxPenaltyAmount:
750
baseChance: 0.65,
minStealPercent: 0.01,
maxStealPercent: 0.03,
maxStealAmount: 1500,
minPenaltyPercent: 0.01,
maxPenaltyPercent: 0.04,
maxPenaltyAmount: 750
},
Hack: {
baseChance:
0.45,
minStealPercent:
0.03,
maxStealPercent:
0.06,
maxStealAmount:
3500,
minPenaltyPercent:
0.03,
maxPenaltyPercent:
0.07,
maxPenaltyAmount:
2000
baseChance: 0.45,
minStealPercent: 0.03,
maxStealPercent: 0.06,
maxStealAmount: 3500,
minPenaltyPercent: 0.03,
maxPenaltyPercent: 0.07,
maxPenaltyAmount: 2000
},
Smash: {
baseChance:
0.25,
minStealPercent:
0.06,
maxStealPercent:
0.12,
maxStealAmount:
7500,
minPenaltyPercent:
0.06,
maxPenaltyPercent:
0.12,
maxPenaltyAmount:
5000
baseChance: 0.25,
minStealPercent: 0.06,
maxStealPercent: 0.12,
maxStealAmount: 7500,
minPenaltyPercent: 0.06,
maxPenaltyPercent: 0.12,
maxPenaltyAmount: 5000
}
};
async function resolveCookieHeist(
interaction,
methodName
@@ -105,20 +63,13 @@ async function resolveCookieHeist(
?.footer
?.text;
const [
type,
ownerId
] =
footer?.split(":")
??
[];
] = footer?.split(":") ?? [];
if (
type !==
"cookieHeist"
||
type !== "cookieHeist" ||
ownerId !==
interaction.user.id
) {
@@ -131,13 +82,11 @@ async function resolveCookieHeist(
);
}
const method =
HEIST_METHODS[
methodName
];
if (!method) {
return temporaryEphemeralReply(
interaction,
@@ -148,7 +97,6 @@ async function resolveCookieHeist(
);
}
const cooldown =
await claimCooldown(
interaction.user.id,
@@ -157,10 +105,7 @@ async function resolveCookieHeist(
HEIST_COOLDOWN
);
if (
!cooldown.claimed
) {
if (!cooldown.claimed) {
return temporaryEphemeralReply(
interaction,
{
@@ -171,7 +116,6 @@ async function resolveCookieHeist(
);
}
await interaction.update({
embeds: [
new EmbedBuilder()
@@ -188,40 +132,26 @@ async function resolveCookieHeist(
`cookieHeist:${interaction.user.id}`
})
],
components: []
});
const playerId =
interaction.user.id;
const vaultId =
interaction.client.user.id;
const [
playerCookies,
vaultCookies
] =
await Promise.all([
getCookieBalance(
playerId
),
getCookieBalance(
vaultId
)
] = await Promise.all([
getCookieBalance(playerId),
getCookieBalance(vaultId)
]);
if (
playerCookies <
1
||
vaultCookies <
1
playerCookies < 1 ||
vaultCookies < 1
) {
return interaction.editReply({
embeds: [
@@ -235,7 +165,6 @@ async function resolveCookieHeist(
.addFields({
name:
"Next Heist",
value:
`<t:${cooldown.next}:R>`
})
@@ -244,38 +173,29 @@ async function resolveCookieHeist(
`cookieHeist:${playerId}`
})
],
components:
buildReturnButton()
});
}
await sleep(
1200
);
await sleep(1200);
const securityPenalty =
getVaultSecurityPenalty(
vaultCookies
);
const successChance =
Math.max(
0.10,
method.baseChance -
securityPenalty
);
const success =
Math.random() <
successChance;
if (success) {
const rolledPercent =
randomFloat(
@@ -283,31 +203,25 @@ async function resolveCookieHeist(
method.maxStealPercent
);
const amount =
Math.max(
1,
Math.min(
Math.floor(
vaultCookies *
rolledPercent
),
method.maxStealAmount,
vaultCookies
)
);
try {
await transferCookies(
vaultId,
playerId,
amount
);
} catch (error) {
if (
error.message ===
@@ -325,7 +239,6 @@ async function resolveCookieHeist(
.addFields({
name:
"Next Heist",
value:
`<t:${cooldown.next}:R>`
})
@@ -334,90 +247,68 @@ async function resolveCookieHeist(
`cookieHeist:${playerId}`
})
],
components:
buildReturnButton()
});
}
throw error;
}
await trackProfileEvent(
interaction,
playerId,
{
type:
"game_result",
game:
"heist",
result:
"win",
profit:
amount
}
);
await trackProfileEvent(
interaction,
playerId,
{
type:
"vault_steal",
amount
}
);
await trackProfileEvent(
interaction,
playerId,
{
type:
"cookie_gain",
amount
}
);
const [
playerAfter,
vaultAfter
] =
await Promise.all([
getCookieBalance(
playerId
),
getCookieBalance(
vaultId
)
] = await Promise.all([
getCookieBalance(playerId),
getCookieBalance(vaultId)
]);
const actualPercentage =
(
amount /
vaultCookies
)
*
100;
) * 100;
const embed =
new EmbedBuilder()
.setTitle(
"💥 Vault Breached!"
)
.setDescription(
getSuccessText(
methodName,
@@ -425,134 +316,101 @@ async function resolveCookieHeist(
amount
)
)
.addFields(
{
name:
"Approach",
value:
methodName,
inline:
true
},
{
name:
"Success Chance",
value:
`**${formatPercentage(successChance)}**`,
inline:
true
},
{
name:
"Vault Taken",
value:
`**${actualPercentage.toFixed(2)}%**`,
inline:
true
},
{
name:
"Cookies Stolen",
value:
`**${amount.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"Your Vault",
value:
`**${playerAfter.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"House Vault",
value:
`**${vaultAfter.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"Next Heist",
value:
`<t:${cooldown.next}:R>`,
inline:
false
}
)
.setFooter({
text:
`cookieHeist:${playerId}`
});
return interaction.editReply({
embeds: [
embed
],
embeds: [embed],
components:
buildReturnButton()
});
}
const penaltyPercent =
randomFloat(
method.minPenaltyPercent,
method.maxPenaltyPercent
);
const penalty =
Math.max(
1,
Math.min(
Math.floor(
playerCookies *
penaltyPercent
),
method.maxPenaltyAmount,
playerCookies
)
);
try {
await transferCookies(
playerId,
vaultId,
penalty
);
} catch (error) {
if (
error.message ===
@@ -570,7 +428,6 @@ async function resolveCookieHeist(
.addFields({
name:
"Next Heist",
value:
`<t:${cooldown.next}:R>`
})
@@ -579,79 +436,59 @@ async function resolveCookieHeist(
`cookieHeist:${playerId}`
})
],
components:
buildReturnButton()
});
}
throw error;
}
await trackProfileEvent(
interaction,
playerId,
{
type:
"game_result",
game:
"heist",
result:
"loss",
profit:
-penalty
}
);
await trackProfileEvent(
interaction,
playerId,
{
type:
"cookie_loss",
amount:
penalty
}
);
const [
playerAfter,
vaultAfter
] =
await Promise.all([
getCookieBalance(
playerId
),
getCookieBalance(
vaultId
)
] = await Promise.all([
getCookieBalance(playerId),
getCookieBalance(vaultId)
]);
const actualPenaltyPercentage =
(
penalty /
playerCookies
)
*
100;
) * 100;
const embed =
new EmbedBuilder()
.setTitle(
"🚨 HEIST FAILED"
)
.setDescription(
getFailureText(
methodName,
@@ -659,103 +496,76 @@ async function resolveCookieHeist(
penalty
)
)
.addFields(
{
name:
"Approach",
value:
methodName,
inline:
true
},
{
name:
"Success Chance",
value:
`**${formatPercentage(successChance)}**`,
inline:
true
},
{
name:
"Fine",
value:
`**${penalty.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"Vault Lost",
value:
`**${actualPenaltyPercentage.toFixed(1)}%**`,
inline:
true
},
{
name:
"Your Vault",
value:
`**${playerAfter.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"House Vault",
value:
`**${vaultAfter.toLocaleString()} 🍪**`,
inline:
true
},
{
name:
"Next Heist",
value:
`<t:${cooldown.next}:R>`,
inline:
false
}
)
.setFooter({
text:
`cookieHeist:${playerId}`
});
return interaction.editReply({
embeds: [
embed
],
embeds: [embed],
components:
buildReturnButton()
});
}
function buildReturnButton() {
return [
new ActionRowBuilder()
@@ -767,9 +577,7 @@ function buildReturnButton() {
.setLabel(
"Back to Crumb Saucer"
)
.setEmoji(
"◀️"
)
.setEmoji("◀️")
.setStyle(
ButtonStyle.Secondary
)
@@ -777,63 +585,47 @@ function buildReturnButton() {
];
}
function getVaultSecurityPenalty(
vaultCookies
) {
return Math.min(
Math.log10(
vaultCookies +
1
)
*
0.025,
vaultCookies + 1
) * 0.025,
0.15
);
}
function getHeistProgressText(
methodName
) {
switch (
methodName
) {
switch (methodName) {
case "Sneak":
return [
"🥷 You slip through the service entrance...",
"",
"The Cookie Vault guards haven't noticed you yet."
].join("\n");
case "Hack":
return [
"💻 You connect to the vault terminal...",
"",
"Several extremely suspicious progress bars appear."
].join("\n");
case "Smash":
return [
"💥 You charge directly at the vault...",
"",
"Subtlety has been abandoned."
].join("\n");
default:
return "The heist is underway...";
}
}
function getSuccessText(
methodName,
user,
@@ -842,40 +634,29 @@ function getSuccessText(
const cookies =
`**${amount.toLocaleString()} Cookies**`;
switch (
methodName
) {
switch (methodName) {
case "Sneak":
return (
`🥷 ${user} slipped through security and quietly escaped with ${cookies}.`
);
case "Hack":
return (
`💻 ${user} convinced the vault terminal that ${cookies} belonged to them.`
);
case "Smash":
return (
`💥 ${user} smashed through the Cookie Vault and escaped with ${cookies}!`
);
default:
return (
`${user} escaped with ${cookies}.`
);
}
}
function getFailureText(
methodName,
user,
@@ -884,49 +665,36 @@ function getFailureText(
const cookies =
`**${penalty.toLocaleString()} Cookies**`;
switch (
methodName
) {
switch (methodName) {
case "Sneak":
return [
`🚨 ${user} stepped directly on the world's loudest Cookie wrapper.`,
"",
`The ShaiBot Vault collected a ${cookies} fine.`
].join("\n");
case "Hack":
return [
`🚨 ${user} entered the password incorrectly one too many times.`,
"",
`The ShaiBot Vault collected a ${cookies} security fee.`
].join("\n");
case "Smash":
return [
`🚨 ${user} discovered that the vault door is significantly stronger than expected.`,
"",
`Repairs cost ${cookies}. Naturally, you're paying.`
].join("\n");
default:
return (
`The heist failed and cost ${user} ${cookies}.`
);
}
}
function sleep(
ms
) {
function sleep(ms) {
return new Promise(
resolve =>
setTimeout(
@@ -936,7 +704,6 @@ function sleep(
);
}
module.exports = {
resolveCookieHeist,
HEIST_COOLDOWN
+118 -588
View File
File diff suppressed because it is too large Load Diff
+86 -368
View File
File diff suppressed because it is too large Load Diff
+74 -374
View File
File diff suppressed because it is too large Load Diff
+366 -1259
View File
File diff suppressed because it is too large Load Diff