Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pit) #498

Merged
merged 15 commits into from
Mar 13, 2024
231 changes: 229 additions & 2 deletions src/structures/MiniGames/Pit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* eslint-disable max-len */
const { decode } = require('../../utils/SkyblockUtils');
const PitInventoryItem = require('./PitInventoryItem');
const { divide } = require('../../utils');
const {
pit: { Levels, Prestiges }
} = require('../../utils/Constants');

/**
* Pit Class
*/
Expand All @@ -8,12 +14,233 @@ class Pit {
* @param {Record<string,unknown>} data Data from API
*/
constructor(data) {
const stats = data.pit_stats_ptl || {};
/**
* Prestige
* @type {number}
*/
this.prestige = data.profile?.prestiges?.[data.profile?.prestiges?.length - 1].index || 0;
/**
* Xp
* @type {number}
*/
this.xp = data.profile?.xp || 0;
/**
* Level
* @type {number}
*/
this.level = Pit.calcLevel(this.prestige, this.prestige > 0 ? this.xp - Prestiges[this.prestige - 1].SumXp : this.xp).level ?? 0;
/**
* Kills
* @type {number}
*/
this.kills = data.pit_stats_ptl.kills || 0;
this.kills = stats.kills || 0;
/**
* Deaths
* @type {number}
*/
this.deaths = stats.deaths || 0;
/**
* KDR
* @type {number}
*/
this.KDRatio = divide(this.kills, this.deaths);
/**
* Assists
* @type {number}
*/
this.assists = stats.assists || 0;
/**
* Max kill streak
* @type {number}
*/
this.maxKillStreak = stats.max_streak || 0;
/**
* Playtime in SECONDS
* @type {number}
*/
this.playtime = (stats.playtime_minutes || 0) * 60;
/**
* Times the played joined Pit
* @type {number}
*/
this.joins = stats.joins || 0;

// Damage section (overall)
/**
* Damage received overall
* @type {number}
*/
this.damageReceived = stats.damage_received || 0;
/**
* Damage dealt overall
* @type {number}
*/
this.damageDealt = stats.damage_dealt || 0;
/**
* Damage dealt to damage received ratio
* @type {number}
*/
this.damageRatio = divide(this.damageDealt, this.damageReceived);
// Melee damage
/**
* Damage received in melee
* @type {number}
*/
this.meleeDamageReceived = stats.melee_damage_received || 0;
/**
* Damage dealt in melee
* @type {number}
*/
this.meleeDamageDealt = stats.melee_damage_dealt || 0;
/**
* Sword hits
* @type {number}
*/
this.swordHits = stats.sword_hits || 0;
/**
* Left Clicks (sword clicks, hit or miss)
* @type {number}
*/
this.leftClicks = stats.left_clicks || 0;
/**
* Hits divided by left clicks
* @type {number}
*/
this.meleeAccuracy = divide(this.swordHits, this.leftClicks);
/**
* Damage dealt to damage received ratio in melee
* @type {number}
*/
this.meleeDamageRatio = divide(this.meleeDamageDealt, this.meleeDamageReceived);
// Arrow damage
/**
* Damage received by arrow
* @type {number}
*/
this.bowDamageReceived = stats.bow_damage_received || 0;
/**
* Damage dealt with bow
* @type {number}
*/
this.bowDamageDealt = stats.bow_damage_dealt || 0;
/**
* Arrows hit
* @type {number}
*/
this.arrowsHit = stats.arrow_hits || 0;
/**
* Arrows fired (hit + missed)
* @type {number}
*/
this.arrowsFired = stats.arrows_fired || 0;
/**
* Hit divided by Fired
* @type {number}
*/
this.bowAccuracy = divide(this.arrowsHit, this.arrowsFired);
/**
* Damage dealt to damage received ratio in ranged (bow/arrow)
* @type {number}
*/
this.bowDamageRatio = divide(this.bowDamageDealt, this.bowDamageReceived);
/**
* Golden Heads eaten
* @type {number}
*/
this.goldenHeadsEaten = stats.ghead_eaten || 0;
/**
* Pit Player Inv
* @return {Promise<PitInventoryItem[]>}
*/
this.getInventory = async () => {
let inventory = data.profile.inv_contents;
if (!inventory) return [];

try {
inventory = await decode(inventory.data);
const edited = [];
for (let i = 1; i < inventory.length; i++) {
if (!inventory[i].id) {
continue;
}
edited.push(new PitInventoryItem(inventory[i]));
}
return edited;
} catch (e) {
return [];
}
};
/**
* Pit Player Ender Chest
* @return {Promise<PitInventoryItem[]>}
*/
this.getEnterChest = async () => {
let chest = data.profile.inv_enderchest;
if (!chest) return [];

try {
chest = await decode(chest.data);
const edited = [];
for (let i = 1; i < chest.length; i++) {
if (!chest[i].id) {
continue;
}
edited.push(new PitInventoryItem(chest[i]));
}
return edited;
} catch (e) {
return [];
}
};
/**
* Pit Player Armor
* @return {Promise<PitArmor>}
*/
this.getArmor = async () => {
const base64 = data.profile.inv_armor;
const decoded = await decode(base64.data);
const armor = {
helmet: decoded[3].id ? new PitInventoryItem(decoded[3]) : null,
chestplate: decoded[2].id ? new PitInventoryItem(decoded[2]) : null,
leggings: decoded[1].id ? new PitInventoryItem(decoded[1]) : null,
boots: decoded[0].id ? new PitInventoryItem(decoded[0]) : null
};
return armor;
};
}
// Credit https://github.com/PitPanda/PitPandaProduction/blob/b1971f56ea1aa8c829b722cbb33247c96591c0cb/structures/Pit.js
/**
* Converts XP to Level
* @param {number} prestige Prestige Level
* @param {number} xp Current xp into the prestige
* @return {number}
*/
static calcLevel(prestige, xp) {
const multiplier = Prestiges[prestige].Multiplier;
let level = 0;
while (xp > 0 && level < 120) {
const levelXp = Levels[Math.floor(level / 10)].Xp * multiplier;
if (xp >= levelXp * 10) {
xp -= levelXp * 10;
level += 10;
} else {
const gain = Math.floor(xp / levelXp);
level += gain;
xp -= gain * levelXp;
xp = 0;
}
}
return level;
}
}

/**
* @typedef {object} PitArmor Equipped armor
* @property {PitInventoryItem|null} helmet Helmet
* @property {PitInventoryItem|null} chestplate Chestplate
* @property {PitInventoryItem|null} leggings Leggings
* @property {PitInventoryItem|null} boots Boots
*/

module.exports = Pit;
43 changes: 43 additions & 0 deletions src/structures/MiniGames/PitInventoryItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Item class
*/
class PitInventoryItem {
/**
* @param {object} data Item data
*/
constructor(data) {
/**
* Item ID
* @type {number}
*/
this.itemId = data.id || 0;
/**
* Item count
* @type {number}
*/
this.count = data.Count || 0;
/**
* Item name
* @type {string|null}
*/
this.name = data?.tag?.display?.Name ? data.tag.display.Name.toString().replace(/§([1-9]|[a-f])|§/gm, '') : null;
/**
* Item lore
* @type {string|null}
*/
this.lore = data?.tag?.display?.Lore ? data.tag.display.Lore.join('\n') : null;
/**
* Item lore
* @type {string[]|[]}
*/
this.loreArray = data?.tag?.display?.Lore ?? [];
/**
* Item Extra Attributes
* @type {object|null}
*/

this.extraAttributes = data?.tag?.ExtraAttributes ?? null;
}
}

module.exports = PitInventoryItem;
4 changes: 3 additions & 1 deletion src/structures/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Quakecraft = require('./MiniGames/Quakecraft');
const Walls = require('./MiniGames/Walls');
const Warlords = require('./MiniGames/Warlords');
const WoolWars = require('./MiniGames/WoolWars');
const Pit = require('./MiniGames/Pit');
/**
* Player class
*/
Expand Down Expand Up @@ -223,7 +224,8 @@ class Player {
turbokartracers: data.stats.GingerBread ? new TurboKartRacers(data.stats.GingerBread) : null,
walls: data.stats.Walls ? new Walls(data.stats.Walls) : null,
warlords: data.stats.Battleground ? new Warlords(data.stats.Battleground) : null,
woolwars: data.stats.WoolGames ? new WoolWars(data.stats.WoolGames) : null
woolwars: data.stats.WoolGames ? new WoolWars(data.stats.WoolGames) : null,
pit: data.stats.Pit ? new Pit(data.stats.Pit) : null
}
: null;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/structures/SkyBlock/SkyblockInventoryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SkyblockInventoryItem {
* Item lore
* @type {string}
*/
this.lore = data.tag.display.Lore.join('<br>');
this.lore = data.tag.display.Lore.join('\n');
/**
* Item lore
* @type {string[]}
Expand Down
57 changes: 57 additions & 0 deletions src/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2815,5 +2815,62 @@ module.exports = {
5: [1, 2, 3, 5, 7, 10, 15, 20, 25, 30, 60, 120, 200, 300, 400, 500, 600, 720, 860, 1000, 2000, 4000, 6000, 8000, 10000],
6: [1, 2, 3, 5, 7, 9, 14, 17, 21, 25, 50, 80, 125, 175, 250, 325, 425, 525, 625, 750, 1500],
7: [1, 2, 3, 5, 7, 9, 11, 14, 17, 20, 30, 40, 55, 75, 100, 150, 200, 275, 375, 500, 1000]
},
// Credits (pit) https://github.com/PitPanda/PitPandaProduction/blob/b1971f56ea1aa8c829b722cbb33247c96591c0cb/structures/Pit.js
pit: {
Prestiges: [
{ Multiplier: 1, TotalXp: 65950, SumXp: 65950, GoldReq: 10000, Renown: 0 },
{ Multiplier: 1.1, TotalXp: 72560, SumXp: 138510, GoldReq: 20000, Renown: 10 },
{ Multiplier: 1.2, TotalXp: 79170, SumXp: 217680, GoldReq: 20000, Renown: 10 },
{ Multiplier: 1.3, TotalXp: 85750, SumXp: 303430, GoldReq: 20000, Renown: 10 },
{ Multiplier: 1.4, TotalXp: 92330, SumXp: 395760, GoldReq: 30000, Renown: 10 },
{ Multiplier: 1.5, TotalXp: 98940, SumXp: 494700, GoldReq: 35000, Renown: 10 },
{ Multiplier: 1.75, TotalXp: 115440, SumXp: 610140, GoldReq: 40000, Renown: 20 },
{ Multiplier: 2, TotalXp: 131900, SumXp: 742040, GoldReq: 45000, Renown: 20 },
{ Multiplier: 2.5, TotalXp: 164890, SumXp: 906930, GoldReq: 50000, Renown: 20 },
{ Multiplier: 3, TotalXp: 197850, SumXp: 1104780, GoldReq: 60000, Renown: 20 },
{ Multiplier: 4, TotalXp: 263800, SumXp: 1368580, GoldReq: 70000, Renown: 20 },
{ Multiplier: 5, TotalXp: 329750, SumXp: 1698330, GoldReq: 80000, Renown: 30 },
{ Multiplier: 6, TotalXp: 395700, SumXp: 2094030, GoldReq: 90000, Renown: 30 },
{ Multiplier: 7, TotalXp: 461650, SumXp: 2555680, GoldReq: 100000, Renown: 30 },
{ Multiplier: 8, TotalXp: 527600, SumXp: 3083280, GoldReq: 125000, Renown: 30 },
{ Multiplier: 9, TotalXp: 593550, SumXp: 3676830, GoldReq: 150000, Renown: 30 },
{ Multiplier: 10, TotalXp: 659500, SumXp: 4336330, GoldReq: 175000, Renown: 40 },
{ Multiplier: 12, TotalXp: 791400, SumXp: 5127730, GoldReq: 200000, Renown: 40 },
{ Multiplier: 14, TotalXp: 923300, SumXp: 6051030, GoldReq: 250000, Renown: 40 },
{ Multiplier: 16, TotalXp: 1055200, SumXp: 7106230, GoldReq: 300000, Renown: 40 },
{ Multiplier: 18, TotalXp: 1187100, SumXp: 8293330, GoldReq: 350000, Renown: 40 },
{ Multiplier: 20, TotalXp: 1319000, SumXp: 9612330, GoldReq: 400000, Renown: 50 },
{ Multiplier: 24, TotalXp: 1582800, SumXp: 11195130, GoldReq: 500000, Renown: 50 },
{ Multiplier: 28, TotalXp: 1846600, SumXp: 13041730, GoldReq: 600000, Renown: 50 },
{ Multiplier: 32, TotalXp: 2110400, SumXp: 15152130, GoldReq: 700000, Renown: 50 },
{ Multiplier: 36, TotalXp: 2374200, SumXp: 17526330, GoldReq: 800000, Renown: 50 },
{ Multiplier: 40, TotalXp: 2638000, SumXp: 20164330, GoldReq: 900000, Renown: 75 },
{ Multiplier: 45, TotalXp: 2967750, SumXp: 23132080, GoldReq: 1000000, Renown: 75 },
{ Multiplier: 50, TotalXp: 3297500, SumXp: 26429580, GoldReq: 1000000, Renown: 75 },
{ Multiplier: 75, TotalXp: 4946250, SumXp: 31375830, GoldReq: 1000000, Renown: 75 },
{ Multiplier: 100, TotalXp: 6595000, SumXp: 37970830, GoldReq: 1000000, Renown: 250 },
{ Multiplier: 101, TotalXp: 6660950, SumXp: 44631780, GoldReq: 1000000, Renown: 100 },
{ Multiplier: 101, TotalXp: 6660950, SumXp: 51292730, GoldReq: 1000000, Renown: 100 },
{ Multiplier: 101, TotalXp: 6660950, SumXp: 57953680, GoldReq: 1000000, Renown: 100 },
{ Multiplier: 101, TotalXp: 6660950, SumXp: 64614630, GoldReq: 1000000, Renown: 100 },
{ Multiplier: 101, TotalXp: 6660950, SumXp: 71275580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 200, TotalXp: 13190000, SumXp: 84465580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 300, TotalXp: 19785000, SumXp: 104250580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 400, TotalXp: 26380000, SumXp: 130630580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 500, TotalXp: 32975000, SumXp: 163605580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 750, TotalXp: 49462500, SumXp: 213068080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 1000, TotalXp: 65950000, SumXp: 279018080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 1250, TotalXp: 82437500, SumXp: 361455580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 1500, TotalXp: 98925000, SumXp: 460380580, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 1750, TotalXp: 115412500, SumXp: 575793080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 2000, TotalXp: 131900000, SumXp: 707693080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 3000, TotalXp: 197850000, SumXp: 905543080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 5000, TotalXp: 329750000, SumXp: 1235293080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 10000, TotalXp: 659500000, SumXp: 1894793080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 50000, TotalXp: 3297500000, SumXp: 5192293080, GoldReq: 2000000, Renown: 100 },
{ Multiplier: 100000, TotalXp: 6595000000, SumXp: 11787293080, GoldReq: 0, Renown: 100 }
],
Levels: [{ Xp: 15 }, { Xp: 30 }, { Xp: 50 }, { Xp: 75 }, { Xp: 125 }, { Xp: 300 }, { Xp: 600 }, { Xp: 800 }, { Xp: 900 }, { Xp: 1000 }, { Xp: 1200 }, { Xp: 1500 }, { Xp: 0 }]
}
};
Loading
Loading