feature/in deptch pvp stats

This commit is contained in:
SowinskiBraeden committed 2023-11-01 13:47:04 -07:00
1 parent 160979e6e7
commit e3fa17fec6
6 files changed
+414 -72

No files matched your search

+83 -29
View File
@@ -1,3 +1,27 @@
const { weapons } = require('./weapons');
// Creates a copy of an object to prevent mutation of parent (i.e BodyParts, createWeaponsObject)
const copy = (obj) => JSON.parse(JSON.stringify(obj));
const BodyParts = {
Head: 0,
Torso: 0,
RightArm: 0,
LeftArm: 0,
RightLeg: 0,
LeftLeg: 0,
};
const createWeaponsObject = (value) => {
const defaultWeapons = {};
for (const [_, weaponNames] of Object.entries(weapons)) {
for (const [name, _] of Object.entries(weaponNames)) {
defaultWeapons[name] = value;
}
}
return copy(defaultWeapons);
};
module.exports = {
UpdatePlayer: async (client, player, interaction=null) => {
return await client.dbo.collection("players").updateOne({"playerID": player.playerID}, {$set: player}, (err, _) => {
@@ -10,38 +34,68 @@ module.exports = {
getDefaultPlayer(gt, pID, NSID) {
return {
gamertag: gt,
playerID: pID,
discordID: "",
nitradoServerID: NSID,
// Identifiers
gamertag: gt,
playerID: pID,
discordID: "",
nitradoServerID: NSID,
KDR: 0.00,
kills: 0,
deaths: 0,
killStreak: 0,
bestKillStreak: 0,
longestKill: 0,
deathStreak: 0,
worstDeathStreak: 0,
// General PVP Stats
KDR: 0.00,
kills: 0,
deaths: 0,
killStreak: 0,
bestKillStreak: 0,
longestKill: 0,
deathStreak: 0,
worstDeathStreak: 0,
pos: [],
lastPos: [],
time: null,
lastTime: null,
// In depth PVP Stats
shotsLanded: 0,
timesShot: 0,
shotsLandedPerBodyPart: copy(BodyParts),
timesShotPerBodyPart: copy(BodyParts),
weaponStats: createWeaponsObject({
shotsLanded: 0,
timesShot: 0,
shotsLandedPerBodyPart: copy(BodyParts),
timesShotPerBodyPart: copy(BodyParts),
}),
lastConnectionDate: null,
lastDisconnectionDate: null,
lastDamageDate: null,
lastDeathDate: null,
lastHitBy: null,
connected: false,
// General Session Data
lastConnectionDate: null,
lastDisconnectionDate: null,
lastDamageDate: null,
lastDeathDate: null,
lastHitBy: null,
connected: false,
pos: [],
lastPos: [],
time: null,
lastTime: null,
totalSessionTime: 0,
lastSessionTime: 0,
longestSessionTime: 0,
connections: 0,
bounties: [],
// Session Stats
totalSessionTime: 0,
lastSessionTime: 0,
longestSessionTime: 0,
connections: 0,
// Other
bounties: [],
}
},
insertPVPstats(player) {
player.shotsLanded = 0;
player.timesShot = 0;
player.shotsLandedPerBodyPart = copy(BodyParts);
player.timesShotPerBodyPart = copy(BodyParts);
player.weaponStats = createWeaponsObject({
shotsLanded: 0,
timesShot: 0,
shotsLandedPerBodyPart: copy(BodyParts),
timesShotPerBodyPart: copy(BodyParts),
});
return player;
}
}
}