Skip to content

Commit

Permalink
Update <Player>.stats.quakecraft
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Jul 24, 2024
1 parent f99801a commit d69346c
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 74 deletions.
163 changes: 113 additions & 50 deletions src/structures/MiniGames/Quakecraft.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,55 @@
const divide = require('../../utils/divide');

class QuakecraftMode {
/**
* @param {object} data Quakecraft data
* @param {string} gamemode Gamemode Name
*/
constructor(data, gamemode) {
if (gamemode) gamemode = `_${gamemode}`;
/**
* Wins
* @type {number}
*/
this.wins = data[`wins${gamemode}`] || 0;
/**
* Kills
* @type {number}
*/
this.kills = data[`kills${gamemode}`] || 0;
/**
* Deaths
* @type {number}
*/
this.deaths = data[`deaths${gamemode}`] || 0;
/**
* Kill Death ratio
* @type {number}
*/
this.KDRatio = divide(this.kills, this.deaths);
/**
* Kill streaks
* @type {number}
*/
this.killstreaks = data[`killstreaks${gamemode}`] || 0;
/**
* Distance travelled
* @type {number}
*/
this.distanceTravelled = data[`distance_travelled${gamemode}`] || 0;
/**
* Shots fired
* @type {number}
*/
this.shotsFired = data[`shots_fired${gamemode}`] || 0;
/**
* Headshots
* @type {number}
*/
this.headshots = data[`headshots${gamemode}`] || 0;
}
}

/**
* Quakecraft class
*/
Expand All @@ -12,90 +63,102 @@ class Quakecraft {
* @type {number}
*/
this.coins = data.coins || 0;
/**
* Solo Quakecraft stats
* @type {QuakecraftMode}
*/
this.solo = new QuakecraftMode(data);
/**
* Teams Quakecraft stats
* @type {QuakecraftMode}
*/
this.teams = new QuakecraftMode(data, 'teams');
/**
* Wins
* @type {number}
*/
this.wins = this.solo.wins + this.teams.wins;
/**
* Kills
* @type {number}
*/
this.kills = (data.kills || 0) + (data.kills_teams || 0);
this.kills = this.solo.kills + this.teams.kills;
/**
* Deaths
* @type {number}
*/
this.deaths = (data.deaths || 0) + (data.deaths_teams || 0);
this.deaths = this.solo.deaths + this.teams.deaths;
/**
* Kill Death ratio
* @type {number}
*/
this.KDRatio = divide(this.kills, this.deaths);
/**
* Wins
* Kill streaks
* @type {number}
*/
this.wins = (data.wins || 0) + (data.wins_teams || 0);
this.killstreaks = this.solo.killstreaks + this.teams.killstreaks;
/**
* Distance travelled
* @type {number}
*/
this.distanceTravelled = data.distance_travelled + data.distance_travelled_teams || 0;
this.distanceTravelled = this.solo.distanceTravelled + this.teams.distanceTravelled;
/**
* Headshots
* Shots fired
* @type {number}
*/
this.headshots = (data.headshots || 0) + (data.headshots_teams || 0);
this.shotsFired = this.solo.shotsFired + this.teams.shotsFired;
/**
* Shots fired
* Headshots
* @type {number}
*/
this.shotsFired = (data.shots_fired || 0) + (data.shots_fired_teams || 0);
this.headshots = this.solo.headshots + this.teams.headshots;
/**
* Kill streaks
* @type {number}
* Instant Respawn
* @type {boolean}
*/
this.killstreaks = (data.killstreaks || 0) + (data.killstreaks_teams || 0);
this.instantRespawn = data.instantRespawn || false;
/**
* Highest killstreak
* @type {number}
* Kill Prefix Color
* @type {string}
*/
this.killPrefixColor = data.selectedKillPrefix || '';
/**
* Show Prefix
* @type {boolean}
*/
this.showPrefix = data.showKillPrefix || false;
/**
* Kill Sound
* @type {string}
*/
this.highestKillstreak = data.highest_killstreak || 0;
this.killSound = data.killsound || '';
/**
* Solo
* @type {QuakecraftModeStats}
* Barrel
* @type {string}
*/
this.solo = {
kills: data.kills || 0,
deaths: data.deaths || 0,
KDRatio: divide(data.kills, data.deaths),
wins: data.wins || 0,
distanceTravelled: data.distance_travelled || 0,
headshots: data.headshots || 0,
shotsFired: data.shots_fired || 0,
killstreaks: data.killstreaks || 0
};
this.barrel = data.barrel || '';
/**
* Teams
* @type {QuakecraftModeStats}
* Case
* @type {string}
*/
this.teams = {
kills: data.kills_teams || 0,
deaths: data.deaths_teams || 0,
KDRatio: divide(data.kills_teams, data.deaths_teams),
wins: data.wins_teams || 0,
distanceTravelled: data.distance_travelled_teams || 0,
headshots: data.headshots_teams || 0,
shotsFired: data.shots_fired_teams || 0,
killstreaks: data.killstreaks_teams || 0
};
this.case = data.case || '';
/**
* Muzzle
* @type {string}
*/
this.muzzle = data.muzzle || '';
/**
* Sight
* @type {string}
*/
this.sight = data.sight || '';
/**
* Trigger
* @type {string}
*/
this.trigger = data.trigger || '';
}
}

module.exports = Quakecraft;
/**
* @typedef {object} QuakecraftModeStats
* @property {number} kills Kills
* @property {number} deaths Deaths
* @property {number} KDRatio Kill Death ratio
* @property {number} wins Wins
* @property {number} distanceTravelled Distance travelled
* @property {number} headshots Headshots
* @property {number} killstreaks Killstreaks
* @property {number} shotsFired Shots fired
*/
49 changes: 25 additions & 24 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2007,38 +2007,39 @@ declare module 'hypixel-api-reborn' {
superluck: number;
transfusion: number;
}
class QuakecraftMode {
constructor(data: Record<string, unknown>);
wins: number;
kills: number;
deaths: number;
KDRatio: number;
killstreaks: number;
distanceTravelled: number;
shotsFired: number;
headshots: number;
}
class Quakecraft {
constructor(data: Record<string, unknown>);
coins: number;
solo: QuakecraftMode;
teams: QuakecraftMode;
wins: number;
kills: number;
deaths: number;
KDRatio: number;
wins: number;
killstreaks: number;
distanceTravelled: number;
headshots: number;
shotsFired: number;
killstreaks: number;
highestKillstreak: number;
solo: {
kills: number;
deaths: number;
KDRatio: number;
wins: number;
distanceTravelled: number;
headshots: number;
shotsFired: number;
killstreaks: number;
};
teams: {
kills: number;
deaths: number;
KDRatio: number;
wins: number;
distanceTravelled: number;
headshots: number;
shotsFired: number;
killstreaks: number;
};
headshots: number;
instantRespawn: boolean;
killPrefixColor: string;
showPrefix: boolean;
killSound: string;
barrel: string;
case: string;
muzzle: string;
sight: string;
trigger: string;
}
class TurboKartRacers {
constructor(data: Record<string, unknown>);
Expand Down

0 comments on commit d69346c

Please sign in to comment.