style: format code for better readability and consistency
All checks were successful
CI / Get Changed Files (pull_request) Successful in 10s
CI / Docker backend validation (pull_request) Successful in 17s
CI / Docker frontend validation (pull_request) Successful in 48s
CI / Checkstyle Main (pull_request) Has been skipped
CI / oxlint (pull_request) Successful in 27s
CI / eslint (pull_request) Successful in 31s
CI / prettier (pull_request) Successful in 36s
CI / test-build (pull_request) Successful in 1m1s
All checks were successful
CI / Get Changed Files (pull_request) Successful in 10s
CI / Docker backend validation (pull_request) Successful in 17s
CI / Docker frontend validation (pull_request) Successful in 48s
CI / Checkstyle Main (pull_request) Has been skipped
CI / oxlint (pull_request) Successful in 27s
CI / eslint (pull_request) Successful in 31s
CI / prettier (pull_request) Successful in 36s
CI / test-build (pull_request) Successful in 1m1s
This commit is contained in:
parent
90368dce7c
commit
c7f26c4df3
9 changed files with 175 additions and 135 deletions
|
@ -38,7 +38,7 @@ export default class LootboxOpeningComponent {
|
|||
this.isLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const lootboxId = parseInt(idParam, 10);
|
||||
this.lootboxService.getAllLootBoxes().subscribe({
|
||||
next: (lootboxes) => {
|
||||
|
@ -56,9 +56,9 @@ export default class LootboxOpeningComponent {
|
|||
|
||||
openLootbox(): void {
|
||||
if (!this.lootbox || this.isOpening) return;
|
||||
|
||||
|
||||
this.resetState(true);
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
this.lootboxService.purchaseLootBox(this.lootbox!.id).subscribe({
|
||||
next: this.handleRewardSuccess.bind(this),
|
||||
|
@ -77,7 +77,7 @@ export default class LootboxOpeningComponent {
|
|||
|
||||
private handleRewardError(): void {
|
||||
if (!this.lootbox) return;
|
||||
|
||||
|
||||
const rewards = this.lootbox.rewards;
|
||||
const fallback = rewards[Math.floor(Math.random() * rewards.length)];
|
||||
this.handleRewardSuccess(fallback);
|
||||
|
@ -99,17 +99,17 @@ export default class LootboxOpeningComponent {
|
|||
const winningPosition = Math.floor(prizeCount / 2);
|
||||
const possibleRewards = this.lootbox.rewards;
|
||||
const items: Reward[] = [];
|
||||
|
||||
|
||||
for (let i = 0; i < prizeCount; i++) {
|
||||
if (i === winningPosition) {
|
||||
items.push({...wonReward});
|
||||
items.push({ ...wonReward });
|
||||
} else {
|
||||
items.push(this.getWeightedRandomReward(possibleRewards));
|
||||
}
|
||||
}
|
||||
|
||||
this.prizeList = items;
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
this.animationCompleted = true;
|
||||
this.cdr.detectChanges();
|
||||
|
@ -120,14 +120,14 @@ export default class LootboxOpeningComponent {
|
|||
const totalProbability = rewards.reduce((sum, reward) => sum + reward.probability, 0);
|
||||
const randomValue = Math.random() * totalProbability;
|
||||
let cumulativeProbability = 0;
|
||||
|
||||
|
||||
for (const reward of rewards) {
|
||||
cumulativeProbability += reward.probability;
|
||||
if (randomValue <= cumulativeProbability) {
|
||||
return { ...reward };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return { ...rewards[0] };
|
||||
}
|
||||
|
||||
|
@ -146,27 +146,26 @@ export default class LootboxOpeningComponent {
|
|||
|
||||
isWonReward(reward: Reward): boolean {
|
||||
if (!this.wonReward || !this.prizeList.length) return false;
|
||||
|
||||
|
||||
const middleIndex = Math.floor(this.prizeList.length / 2);
|
||||
return this.prizeList.indexOf(reward) === middleIndex;
|
||||
}
|
||||
|
||||
|
||||
getRewardRarityClass(reward: Reward): string {
|
||||
if (!reward) return 'text-common';
|
||||
|
||||
|
||||
const probability = reward.probability;
|
||||
|
||||
|
||||
if (probability < 0.01) return 'text-mythic';
|
||||
if (probability < 0.05) return 'text-legendary';
|
||||
if (probability < 0.10) return 'text-epic';
|
||||
if (probability < 0.20) return 'text-rare';
|
||||
if (probability < 0.40) return 'text-uncommon';
|
||||
if (probability < 0.1) return 'text-epic';
|
||||
if (probability < 0.2) return 'text-rare';
|
||||
if (probability < 0.4) return 'text-uncommon';
|
||||
return 'text-common';
|
||||
}
|
||||
|
||||
|
||||
getRewardClass(): string {
|
||||
if (!this.wonReward || !this.lootbox) return '';
|
||||
return this.wonReward.value > (this.lootbox.price || 0) ? 'text-emerald' : 'text-accent-red';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue