Skip to content

Commit bac2bf4

Browse files
committed
feat: updated aura cmd
1 parent 7189c53 commit bac2bf4

File tree

4 files changed

+158
-159
lines changed

4 files changed

+158
-159
lines changed

src/commands/aura.ts

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import {
33
SlashCommandBuilder,
44
EmbedBuilder,
55
} from "discord.js";
6-
7-
function hashString(str: string): number {
8-
let hash = 0;
9-
for (let i = 0; i < str.length; i++) {
10-
hash = ((hash << 5) - hash + str.charCodeAt(i)) >>> 0;
11-
}
12-
return hash;
13-
}
6+
import { generateFighter, calculateAuraPercentage, calculateAuraLevel } from "../utils/fighterGenerator.js";
147

158
// prettier-ignore
169
const auraLevelNames = [
@@ -62,7 +55,7 @@ const flavorSets = [flavorSet1, flavorSet2];
6255

6356
export const data = new SlashCommandBuilder()
6457
.setName("aura")
65-
.setDescription("Calculate your aura based on your display name")
58+
.setDescription("Calculate aura and fighter stats based on one's display name")
6659
.addUserOption((option) =>
6760
option
6861
.setName("user")
@@ -83,63 +76,50 @@ export async function execute(
8376
displayName = targetUser.username;
8477
}
8578

86-
let percentage: number;
87-
let level: number;
88-
let flavorText: string;
89-
90-
const nameToLevel: { [key: string]: number } = {
91-
toru: 0,
92-
toru1: 1,
93-
toru2: 2,
94-
toru3: 3,
95-
toru4: 4,
96-
toru5: 5,
97-
toru6: 6,
98-
toru7: 7,
99-
toru8: 8,
100-
toru9: 9,
101-
toru10: 10,
102-
toru11: 11,
103-
};
104-
105-
if (displayName in nameToLevel) {
106-
level = nameToLevel[displayName];
107-
percentage = level === 0 ? -100 : level === 11 ? 100 : (level - 1) * 10 + 9;
108-
const chosenSet = flavorSets[Math.floor(Math.random() * flavorSets.length)];
109-
flavorText = chosenSet[Math.max(0, Math.min(level, chosenSet.length - 1))];
110-
} else {
111-
const chosenSet = flavorSets[Math.floor(Math.random() * flavorSets.length)];
112-
const hash = hashString(displayName);
113-
percentage = hash % 101;
114-
115-
if (percentage <= 3) {
116-
level = 0;
117-
} else if (percentage <= 9) {
118-
level = 1;
119-
} else if (percentage === 100) {
120-
level = 11;
121-
} else {
122-
level = Math.ceil((percentage - 9) / 10) + 1;
123-
if (level > 10) level = 10;
124-
}
79+
const percentage = calculateAuraPercentage(displayName);
80+
const level = calculateAuraLevel(percentage);
81+
const fighter = generateFighter(targetUser, displayName);
12582

126-
flavorText = chosenSet[Math.max(0, Math.min(level, chosenSet.length - 1))];
127-
}
83+
const chosenSet = flavorSets[Math.floor(Math.random() * flavorSets.length)];
84+
const flavorText = chosenSet[Math.max(0, Math.min(level, chosenSet.length - 1))];
12885

129-
const levelName =
130-
auraLevelNames[Math.max(0, Math.min(level, auraLevelNames.length - 1))];
86+
const levelName = auraLevelNames[Math.max(0, Math.min(level, auraLevelNames.length - 1))];
13187

13288
const embed = new EmbedBuilder()
13389
.setColor(level === 0 ? "#2F2F2F" : level === 11 ? "#ad32ffff" : "#800080")
13490
.setTitle("🔮 Aura Reading")
13591
.setDescription(`The mystical aura of **${displayName}** has been divined!`)
13692
.addFields(
137-
{ name: "Aura Strength", value: `${percentage}%`, inline: true },
138-
{ name: "Aura Level", value: `${level} (${levelName})`, inline: true },
139-
{ name: "Verdict:", value: flavorText, inline: false },
93+
{ name: "🌟 Aura Strength", value: `${percentage}%`, inline: true },
94+
{ name: "📊 Aura Level", value: `${level} (${levelName})`, inline: true },
95+
{ name: "⚔️ Fighter Class", value: getFighterClass(level), inline: true },
96+
{ name: "💪 Combat Statistics", value:
97+
`**HP:** ${fighter.hp}\n` +
98+
`**ATK:** ${fighter.attack}\n` +
99+
`**DEF:** ${fighter.defense}\n` +
100+
`**SPD:** ${fighter.speed}\n` +
101+
`**CRIT:** ${Math.round(fighter.critChance * 100)}%`,
102+
inline: true
103+
},
104+
{ name: "🎯 Special Abilities", value:
105+
`• ${fighter.abilities[0]}\n• ${fighter.abilities[1]}`,
106+
inline: true
107+
},
108+
{ name: "📝 Verdict", value: flavorText, inline: false },
140109
)
110+
.setThumbnail(targetUser.displayAvatarURL())
141111
.setFooter({ text: "Aura levels may vary based on cosmic vibrations." })
142112
.setTimestamp();
143113

144114
await interaction.reply({ embeds: [embed] });
145115
}
116+
117+
function getFighterClass(level: number): string {
118+
if (level === 0) return "Cursed Bum";
119+
if (level <= 2) return "Recruit";
120+
if (level <= 4) return "Hardened Fighter";
121+
if (level <= 6) return "Decimator";
122+
if (level <= 8) return "Egoistic Champion";
123+
if (level <= 10) return "Living Weapon";
124+
return "Ego's Chosen One";
125+
}

src/commands/deathbattle.ts

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "discord.js";
99
import { createCanvas, loadImage } from "canvas";
1010
import path from "path";
11+
import { generateFighter, Fighter } from "../utils/fighterGenerator.js";
1112

1213
export const data = new SlashCommandBuilder()
1314
.setName("deathbattle")
@@ -25,18 +26,6 @@ export const data = new SlashCommandBuilder()
2526
.setRequired(true),
2627
);
2728

28-
interface Fighter {
29-
user: User;
30-
name: string;
31-
hp: number;
32-
maxHp: number;
33-
attack: number;
34-
defense: number;
35-
speed: number;
36-
critChance: number;
37-
abilities: string[];
38-
}
39-
4029
interface BattleEvent {
4130
attacker: string;
4231
defender: string;
@@ -413,97 +402,6 @@ async function simulateBattleStep(
413402
};
414403
}
415404

416-
function generateFighter(user: User, displayName: string): Fighter {
417-
function hashString(str: string): number {
418-
let hash = 0;
419-
for (let i = 0; i < str.length; i++) {
420-
hash = ((hash << 5) - hash + str.charCodeAt(i)) >>> 0;
421-
}
422-
return hash;
423-
}
424-
425-
const nameToLevel: { [key: string]: number } = {
426-
toru: 0,
427-
toru1: 1,
428-
toru2: 2,
429-
toru3: 3,
430-
toru4: 4,
431-
toru5: 5,
432-
toru6: 6,
433-
toru7: 7,
434-
toru8: 8,
435-
toru9: 9,
436-
toru10: 10,
437-
toru11: 11,
438-
};
439-
440-
let percentage: number;
441-
442-
if (displayName in nameToLevel) {
443-
const level = nameToLevel[displayName];
444-
percentage = level === 0 ? -100 : level === 11 ? 100 : (level - 1) * 10 + 9;
445-
} else {
446-
const hash = hashString(displayName);
447-
percentage = hash % 101;
448-
}
449-
450-
const auraMultiplier = Math.max(0, (percentage + 100) / 200);
451-
452-
// Base stats + aura bonus
453-
const baseHp = Math.floor(80 + auraMultiplier * 40); // 80-120 HP
454-
const baseAttack = Math.floor(15 + auraMultiplier * 10); // 15-25 ATK
455-
const baseDefense = Math.floor(5 + auraMultiplier * 10); // 5-15 DEF
456-
const baseSpeed = Math.floor(10 + auraMultiplier * 10); // 10-20 SPD
457-
const critChance = 0.1 + auraMultiplier * 0.2; // 0.1-0.3 crit chance
458-
459-
const abilities = [
460-
"Alter Ego Burst",
461-
"Divine Shield",
462-
"Shadow Clone",
463-
"Healing Light",
464-
"Berserker Rage",
465-
"Time Slow",
466-
"Soul Strike",
467-
"Phoenix Rising",
468-
"Relic of Exo",
469-
"Ego's Blessing",
470-
"Cleansing",
471-
"Raise the Dead",
472-
"Warrior's Call",
473-
"Drop the Beat",
474-
"Call to Arms",
475-
"Airstrike",
476-
"Divine Intervention",
477-
"Great Will",
478-
"Toxic Fumes",
479-
];
480-
481-
let seed = Math.abs(percentage) + 1000;
482-
const random = () => {
483-
seed = (seed * 9301 + 49297) % 233280;
484-
return seed / 233280;
485-
};
486-
487-
const selectedAbilities = [];
488-
const abilityPool = [...abilities];
489-
for (let i = 0; i < 2; i++) {
490-
const index = Math.floor(random() * abilityPool.length);
491-
selectedAbilities.push(abilityPool.splice(index, 1)[0]);
492-
}
493-
494-
return {
495-
user,
496-
name: displayName,
497-
hp: baseHp,
498-
maxHp: baseHp,
499-
attack: baseAttack,
500-
defense: baseDefense,
501-
speed: baseSpeed,
502-
critChance,
503-
abilities: selectedAbilities,
504-
};
505-
}
506-
507405
export async function execute(
508406
interaction: ChatInputCommandInteraction,
509407
): Promise<void> {

src/commands/help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const commands: CommandInfo[] = [
7575
// Basic
7676
{
7777
name: "/aura [@user]",
78-
value: "Calculate thy aura based on one's display name",
78+
value: "Calculate thy aura and view fighter profile based on one's display name",
7979
category: "basic",
8080
},
8181
{

src/utils/fighterGenerator.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { User } from "discord.js";
2+
3+
export interface Fighter {
4+
user: User;
5+
name: string;
6+
hp: number;
7+
maxHp: number;
8+
attack: number;
9+
defense: number;
10+
speed: number;
11+
critChance: number;
12+
abilities: string[];
13+
}
14+
15+
function hashString(str: string): number {
16+
let hash = 0;
17+
for (let i = 0; i < str.length; i++) {
18+
hash = ((hash << 5) - hash + str.charCodeAt(i)) >>> 0;
19+
}
20+
return hash;
21+
}
22+
23+
const nameToLevel: { [key: string]: number } = {
24+
toru: 0,
25+
toru1: 1,
26+
toru2: 2,
27+
toru3: 3,
28+
toru4: 4,
29+
toru5: 5,
30+
toru6: 6,
31+
toru7: 7,
32+
toru8: 8,
33+
toru9: 9,
34+
toru10: 10,
35+
toru11: 11,
36+
};
37+
38+
export function calculateAuraPercentage(displayName: string): number {
39+
if (displayName in nameToLevel) {
40+
const level = nameToLevel[displayName];
41+
return level === 0 ? -100 : level === 11 ? 100 : (level - 1) * 10 + 9;
42+
} else {
43+
const hash = hashString(displayName);
44+
return hash % 101;
45+
}
46+
}
47+
48+
export function calculateAuraLevel(percentage: number): number {
49+
if (percentage <= 3) {
50+
return 0;
51+
} else if (percentage <= 9) {
52+
return 1;
53+
} else if (percentage === 100) {
54+
return 11;
55+
} else {
56+
const level = Math.ceil((percentage - 9) / 10) + 1;
57+
return level > 10 ? 10 : level;
58+
}
59+
}
60+
61+
export function generateFighter(user: User, displayName: string): Fighter {
62+
const percentage = calculateAuraPercentage(displayName);
63+
64+
// Convert percentage to stats (higher aura = better stats)
65+
// Scale percentage from -100 to 100 range to 0-1 multiplier
66+
const auraMultiplier = Math.max(0, (percentage + 100) / 200);
67+
68+
// Base stats + aura bonus
69+
const baseHp = Math.floor(80 + (auraMultiplier * 40)); // 80-120 HP
70+
const baseAttack = Math.floor(15 + (auraMultiplier * 10)); // 15-25 ATK
71+
const baseDefense = Math.floor(5 + (auraMultiplier * 10)); // 5-15 DEF
72+
const baseSpeed = Math.floor(10 + (auraMultiplier * 10)); // 10-20 SPD
73+
const critChance = 0.1 + (auraMultiplier * 0.2); // 0.1-0.3 crit chance
74+
75+
const abilities = [
76+
"Alter Ego Burst",
77+
"Divine Shield",
78+
"Shadow Clone",
79+
"Healing Light",
80+
"Berserker Rage",
81+
"Time Slow",
82+
"Soul Strike",
83+
"Phoenix Rising",
84+
"Relic of Exodus",
85+
"Ego's Blessing",
86+
"Cleansing",
87+
"Raise the Dead",
88+
"Warrior's Call",
89+
"Drop the Beat",
90+
"Call to Arms",
91+
"Airstrike",
92+
"Divine Intervention",
93+
"Great Will",
94+
"Toxic Fumes",
95+
];
96+
97+
let seed = Math.abs(percentage) + 1000;
98+
const random = () => {
99+
seed = (seed * 9301 + 49297) % 233280;
100+
return seed / 233280;
101+
};
102+
103+
const selectedAbilities = [];
104+
const abilityPool = [...abilities];
105+
for (let i = 0; i < 2; i++) {
106+
const index = Math.floor(random() * abilityPool.length);
107+
selectedAbilities.push(abilityPool.splice(index, 1)[0]);
108+
}
109+
110+
return {
111+
user,
112+
name: displayName,
113+
hp: baseHp,
114+
maxHp: baseHp,
115+
attack: baseAttack,
116+
defense: baseDefense,
117+
speed: baseSpeed,
118+
critChance,
119+
abilities: selectedAbilities,
120+
};
121+
}

0 commit comments

Comments
 (0)