/ config/rarities.js - Enhanced with emojis for visual representation
const RARITY_ORDER = [ 'SPECIAL', 'LIMITED', 'DIAMOND', 'LEGENDARY', 'MYTHICAL', 'EXTREMELY_RARE', 'VERY_RARE', 'RARE', 'UNCOMMON', 'COMMON' ];
module.exports = { // Rarities and their drop rates (in percentage) with added emojis rarities: [ { name: 'COMMON', dropRate: 50, color: '#adadad', emoji: '<:Bezna:1371601032714518559>', displayName: 'Běžná' }, { name: 'UNCOMMON', dropRate: 25, color: '#19ce07', emoji: '<:Neobvykla:1371601614682722444>', displayName: 'Neobvyklá' }, { name: 'RARE', dropRate: 12, color: '#09ceff', emoji: '<:Vzacna:1371601619858362488>', displayName: 'Vzácná' }, { name: 'VERY_RARE', dropRate: 6, color: '#7739d3', emoji: '<:Velmivzacna:1371601617647833219>', displayName: 'Velmi vzácná' }, { name: 'EXTREMELY_RARE', dropRate: 3, color: '#ec66da', emoji: '<:Extremnevzacna:1371601608034619422>', displayName: 'Extrémně vzácná' }, { name: 'MYTHICAL', dropRate: 2, color: '#911212', emoji: '<:Myticka:1371601613172772974>', displayName: 'Mýtická' }, { name: 'LEGENDARY', dropRate: 1, color: '#ffd300', emoji: '<:Legendarni:1371601609909342389>', displayName: 'Legendární' }, { name: 'DIAMOND', dropRate: 0.5, color: '#d9ffff', emoji: '<:Diamantova:1371601605312385166>', displayName: 'Diamantová' }, { name: 'LIMITED', dropRate: 0, color: '#d66b17', emoji: '<:Limitovana:1371601611679600670>', displayName: 'Limitovaná' }, // Manual only { name: 'SPECIAL', dropRate: 0, color: '#461d49', emoji: '<:Specialni:1371601615974564061>', displayName: 'Speciální' } // Manual only ],
// Get random rarity based on drop rates getRandomRarity: function() { // Validate drop rates const totalWeight = this.rarities.reduce((sum, rarity) => sum + rarity.dropRate, 0); if (totalWeight <= 0) { console.error('Invalid total weight in rarity selection:', totalWeight); return 'COMMON'; }
const random = Math.random() * totalWeight; let cumulativeWeight = 0;
for (const rarity of this.rarities) { cumulativeWeight += rarity.dropRate; if (random < cumulativeWeight) { return rarity.name; } }
return 'COMMON'; },
// Helper functions getRarity: function(name) { if (!name) return null; try { const upperName = name.toUpperCase(); return this.rarities.find(r => r.name === upperName); } catch (error) { console.error(Error getting rarity for "${name}":, error); return null; } },
getRarityColor: function(name) { const rarity = this.getRarity(name); return rarity ? rarity.color : '#FFFFFF'; },
getRarityEmoji: function(name) { const rarity = this.getRarity(name); return rarity ? rarity.emoji : '•'; },
getRarityWithEmoji: function(name) { const rarity = this.getRarity(name); if (!rarity) return name || 'Unknown'; return
r
a
r
i
t
y
.
e
m
o
j
i
rarity.emoji{rarity.displayName}; },
getRarityDisplayName: function(name) { const rarity = module.exports.getRarity(name); return rarity ? rarity.displayName : name; },
getAllRarityNames: function() { return module.exports.rarities.map(r => r.name); },
isValidRarity: function(name) { if (!name) return false; try { const upperName = name.toUpperCase(); return this.rarities.some(r => r.name === upperName); } catch (error) { console.error(Error validating rarity "${name}":, error); return false; } },
RARITY_ORDER };
module.exports.RARITY_ORDER = RARITY_ORDER;
Can you make this code more performant? Also include a benchmark at the end