bounty system

This commit is contained in:
SowinskiBraeden committed 2023-03-20 14:25:15 -07:00
1 parent 972c16557a
commit 6a9c74af68
3 files changed
+138 -1

No files matched your search

+84
View File
@@ -47,10 +47,94 @@ module.exports = {
if (args[0].name == 'set') {
let playerStat = GuildDB.playerstats.find(stat => stat.player == args[0].options[0].value);
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription('**Not Found** This player cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least ` 5 minutes `.')] });
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
let banking = await client.dbo.collection("users").findOne({"user.userID": interaction.member.user.id}).then(banking => banking);
if (!banking) {
banking = {
userID: interaction.member.user.id,
guilds: {
[GuildDB.serverID]: {
bankAccount: {
balance: GuildDB.startingBalance,
cash: 0.00,
}
}
}
}
// Register inventory for user
let newBank = new User();
newBank.createBank(interaction.member.user.id, GuildDB.serverID, GuildDB.startingBalance, 0);
newBank.save().catch(err => {
if (err) return client.sendInternalError(interaction, err);
});
} else banking = banking.banking;
if (!client.exists(banking.guilds[GuildDB.serverID])) {
const success = addUser(banking.guilds, GuildDB.serverID, interaction.member.user.id, client, GuildDB.startingBalance);
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
}
if (args[0].options[0].value > banking.guilds[GuildDB.serverID].bankAccount.balance) {
let nsf = new EmbedBuilder()
.setDescription('**Bank Notice:** NSF. Non sufficient funds')
.setColor(client.config.Colors.Red);
return interaction.send({ embeds: [nsf] });
}
const newBalance = banking.guilds[GuildDB.serverID].bankAccount.balance - args[0].options[1].value;
client.dbo.collection("users").updateOne({ "user.userID": interaction.member.user.id }, {
$set: {
[`banking.guilds.${GuildDB.serverID}.bankAccount.balance`]: newBalance,
}
}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
playerStat.bounties.push({
setBy: interaction.member.user.id,
value: args[0].options[1].value,
});
GuildDB.playerstats[playerStatIndex] = playerStat;
client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, {
$set: {
'server.playerstats': GuildDB.playerstats,
}
}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
const successEmbed = new EmbedBuilder()
.setTitle('Success')
.setDescription(`Successfully set a **$${args[0].options[1].value.toFixed(2)}** bounty on \` ${playerStat.gamertag} \`\nThis can be viewed using </bounty view:1086786904671924267>`)
.setColor(client.config.Colors.Green);
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == 'view') {
let activeBounties = GuildDB.playerstats.filter((p) => p.bounties.length > 0);
let bountiesEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setDescription('**Active Boutnies**');
for (let i = 0; i < activeBounties.length; i++) {
for (let j = 0; j < activeBounties[i].bounties.length; j++) {
bountiesEmbed.addFields({ name: `${activeBounties[i].gamertag} has a:`, value: `**$${activeBounties[i].bounties[j].value.toFixed(2)}** bounty set by <@${activeBounties[i].bounties[j].setBy}>`, inline: false });
}
}
return interaction.send({ embeds: [bountiesEmbed] });
}
},
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dayz-armbands",
"version": "5.5.3.7",
"version": "5.6.3.7",
"description": "A General Purpose Discord Bot for DayZ Servers.",
"main": "index.js",
"nodemonConfig": {
+53
View File
@@ -156,6 +156,57 @@ class DayzArmbands extends Client {
if (victimStat.killStreak>0) victimStat.killStreak = 0;
if (killerStat.deathStreak>0) killerStat.deathStreak = 0;
let receivedBounty = null;
if (victimStat.bounties.length > 0 && killerStat.discordID != "") {
let totalBounty = 0;
for (let i = 0; i < victimStat.bounties.length; i++) {
totalBounty += victimStat.bounties[i].value;
}
let banking = await this.dbo.collection("users").findOne({"user.userID": killerStat.discordID}).then(banking => banking);
if (!banking) {
banking = {
userID: interaction.member.user.id,
guilds: {
[guild.serverID]: {
bankAccount: {
balance: guild.startingBalance,
cash: 0.00,
}
}
}
}
// Register inventory for user
let newBank = new User();
newBank.createBank(interaction.member.user.id, guild.serverID, guild.startingBalance, 0);
newBank.save().catch(err => {
if (err) return client.sendInternalError(interaction, err);
});
} else banking = banking.banking;
if (!this.exists(banking.guilds[guild.serverID])) {
const success = addUser(banking.guilds, guild.serverID, interaction.member.user.id, this, guild.startingBalance);
if (!success) return this.sendError(guild.connectionLogsChannel, 'Failed to add bank');
}
const newBalance = banking.guilds[guild.serverID].bankAccount.balance + totalBounty;
this.dbo.collection("users").updateOne({ "user.userID": killerStat.discordID }, {
$set: {
[`banking.guilds.${guild.serverID}.bankAccount.balance`]: newBalance,
}
}, function(err, res) {
if (err) return this.sendError(guild.connectionLogsChannel, err);
});
receivedBounty = new EmbedBuilder()
.setColor(this.config.Colors.Default)
.setDescription(`<@${killerStat.discordID}> received **$${totalBounty.toFixed(2)}** in bounty rewards.`);
}
if (killerStatIndex == -1) guild.playerstats.push(killerStat);
else guild.playerstats[killerStatIndex] = killerStat;
if (victimStatIndex == -1) guild.playerstats.push(victimStat);
@@ -178,6 +229,7 @@ class DayzArmbands extends Client {
.setDescription(`**Kill Event** - <t:${unixTime}>\n**${info.killer}** killed **${info.victim}**\n> **__Kill Data__**\n> **Weapon:** \` ${info.weapon} \`\n> **Distance:** \` ${info.distance} \`\n> **Body Part:** \` ${info.bodyPart.split('(')[0]} \`\n> **Damage:** \` ${info.damage} \`\n **Killer\n${killerStat.KDR} K/D - ${killerStat.kills} Kills - Killstreak: ${killerStat.killStreak}\nVictim\n${victimStat.KDR} K/D - ${victimStat.deaths} Deaths - Deathstreak: ${victimStat.deathStreak}**`);
if (this.exists(channel)) channel.send({ embeds: [killEvent] });
if (this.exists(receivedBounty) && this.exists(channel)) channel.send({ content: `<@${killerStat.discordID}>`, embeds: [receivedBounty] });
}
async handleAlarms(guildId, data) {
@@ -572,6 +624,7 @@ class DayzArmbands extends Client {
pos: [],
lastConnectionDate: null,
connected: false,
bounties: [],
}
}