Compare commits

...
Sign in to create a new pull request.

6 commits

16 changed files with 816 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

View file

@ -21,4 +21,14 @@ export const routes: Routes = [
loadComponent: () => import('./feature/game/blackjack/blackjack.component'),
canActivate: [authGuard],
},
{
path: 'game/lootboxes',
loadComponent: () => import('./feature/lootboxes/lootbox-selection/lootbox-selection.component'),
canActivate: [authGuard],
},
{
path: 'game/lootboxes/open/:id',
loadComponent: () => import('./feature/lootboxes/lootbox-opening/lootbox-opening.component'),
canActivate: [authGuard],
},
];

View file

@ -68,7 +68,7 @@ export default class HomeComponent implements OnInit {
id: '6',
name: 'Lootboxen',
image: '/lootbox.webp',
route: '/game/lootbox',
route: '/game/lootboxes',
},
];

View file

@ -0,0 +1,236 @@
body {
background: linear-gradient(to bottom, #181c2a, #232c43);
}
/* Color classes */
.text-yellow-400 {
color: #facc15;
}
.text-purple-400 {
color: #a78bfa;
}
.text-blue-400 {
color: #60a5fa;
}
.border-yellow-400 {
border-color: #facc15;
}
.border-purple-400 {
border-color: #a78bfa;
}
.border-blue-400 {
border-color: #60a5fa;
}
/* Loader animation */
.loader {
border: 4px solid rgba(255, 255, 255, 0.2);
border-radius: 50%;
border-top: 4px solid #facc15;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Open button styling */
.open-btn {
background: linear-gradient(90deg, #4338ca 0%, #8b5cf6 100%);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
transition: all 0.2s ease;
}
.open-btn:hover {
background: linear-gradient(90deg, #4f46e5 0%, #a78bfa 100%);
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.3);
}
/* CSGO-style case opening display */
.case-container {
position: relative;
width: 100%;
background: rgba(26, 31, 48, 0.6);
border-radius: 8px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
overflow: hidden;
margin-bottom: 20px;
display: flex;
justify-content: center;
}
.case-indicator {
position: absolute;
top: 50%;
left: 50%; /* Back to center - we'll adjust the animation instead */
transform: translate(-50%, -50%); /* Center precisely */
width: 6px;
height: 100%;
background: #facc15;
box-shadow:
0 0 10px #facc15,
0 0 15px rgba(255, 255, 255, 0.5);
z-index: 3;
animation: indicator-pulse 1.5s ease-in-out 10s infinite alternate;
}
@keyframes indicator-pulse {
0% {
opacity: 0.6;
box-shadow:
0 0 10px #facc15,
0 0 15px rgba(255, 255, 255, 0.3);
}
100% {
opacity: 1;
box-shadow:
0 0 15px #facc15,
0 0 20px rgba(255, 255, 255, 0.7);
}
}
.case-items-container {
position: relative;
z-index: 1;
padding: 10px 5px;
margin: 0 auto;
width: 100%;
height: 150px; /* Fixed height for the horizontal row */
overflow: hidden; /* Hide scrollbar */
display: flex;
justify-content: center; /* Center the items container */
align-items: center;
}
.case-items {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 8px;
padding: 5px 0px; /* Remove horizontal padding */
height: 100%;
width: 100%;
animation: slide-in 10s cubic-bezier(0.05, 0.82, 0.17, 1) forwards;
transform: translateX(3000%); /* Extremely far initial position for 200 items */
position: relative; /* Ensure positioning context */
}
@keyframes slide-in {
0% {
transform: translateX(2000%);
}
90% {
transform: translateX(-16%); /* Single overshoot for dramatic effect */
}
100% {
transform: translateX(-8%); /* Centered position */
}
}
.case-item {
transition: all 0.2s ease;
padding: 2px;
animation: item-flash 0.3s ease-out forwards;
animation-play-state: paused;
}
@keyframes item-flash {
0% {
filter: brightness(1);
}
50% {
filter: brightness(1.8);
}
100% {
filter: brightness(1.2);
}
}
.case-item-inner {
background: #232c43;
border: 2px solid #2d3748;
border-radius: 8px;
padding: 10px 5px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 65px;
height: 100%;
}
.case-item-won {
z-index: 2;
animation: highlight-winner 1s ease-out 10s forwards;
}
/* Specific ID for the winning item to ensure it's visible */
#winning-item {
z-index: 5; /* Higher than indicator */
}
@keyframes highlight-winner {
0% {
transform: scale(1);
filter: brightness(1);
}
10% {
transform: scale(1.3);
filter: brightness(2);
}
20% {
transform: scale(1.2);
filter: brightness(1.8);
}
30% {
transform: scale(1.25);
filter: brightness(2);
}
40% {
transform: scale(1.2);
filter: brightness(1.8);
}
50% {
transform: scale(1.25);
filter: brightness(2);
}
60% {
transform: scale(1.2);
filter: brightness(1.8);
}
70% {
transform: scale(1.25);
filter: brightness(2);
}
80% {
transform: scale(1.2);
filter: brightness(1.8);
}
90% {
transform: scale(1.25);
filter: brightness(2);
}
100% {
transform: scale(1.2);
filter: brightness(1.5);
}
}
.amount {
font-size: 1rem;
font-weight: bold;
margin-bottom: 4px;
}
.rarity {
font-size: 0.75rem;
opacity: 0.7;
}

View file

@ -0,0 +1,136 @@
<app-navbar></app-navbar>
<div
class="flex flex-col items-center min-h-screen bg-gradient-to-b from-[#181c2a] to-[#232c43] py-10"
>
<div *ngIf="isLoading" class="flex flex-col items-center justify-center h-96">
<div class="loader mb-4"></div>
<div class="text-white text-lg">Lade Lootbox...</div>
</div>
<ng-container *ngIf="!isLoading && lootbox">
<h1 class="text-3xl font-bold text-white mb-2">{{ lootbox.name }}</h1>
<div class="text-lg text-blue-300 mb-6">Preis: {{ lootbox.price | currency: 'EUR' }}</div>
<!-- Before opening - show possible rewards -->
<div
*ngIf="!isOpening && !isOpen"
class="bg-[#1a1f30] p-6 rounded-lg shadow-lg w-full max-w-3xl mb-8"
>
<h2 class="text-xl font-semibold text-white mb-4">Mögliche Gewinne:</h2>
<div class="grid grid-cols-2 md:grid-cols-3 gap-4">
<div
*ngFor="let reward of lootbox.rewards"
class="bg-[#232c43] p-4 rounded-lg border border-[#2d3748] text-center"
>
<div class="text-2xl font-bold mb-1">
{{ reward.value | currency: 'EUR' }}
</div>
<div class="text-sm text-white/60">
Chance: {{ reward.probability * 100 | number: '1.0-0' }}%
</div>
</div>
</div>
</div>
<!-- Open button -->
<div *ngIf="!isOpening && !isOpen" class="flex flex-col items-center mb-8">
<button
(click)="openLootbox()"
class="open-btn text-white px-8 py-3 rounded-lg font-bold text-lg shadow-lg transition-all"
>
Öffnen
</button>
</div>
<!-- Loading state -->
<div *ngIf="isOpening" class="flex flex-col items-center">
<div class="loader mb-4"></div>
<div class="text-white text-lg">Öffne Lootbox...</div>
</div>
<!-- Case opening display - CSGO style -->
<div *ngIf="isOpen && !isOpening" class="w-full max-w-lg">
<!-- Winner display - only shown after animation completes -->
<div
class="flex flex-col items-center mb-6"
style="opacity: 0; animation: fade-in 0.5s ease-out 10.5s forwards"
>
<div class="text-2xl font-bold text-green-400 mb-2">Dein Gewinn:</div>
<div class="text-4xl font-bold text-white mb-4">
{{ wonReward?.value | currency: 'EUR' }}
</div>
</div>
<style>
@keyframes fade-in {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
<!-- CSGO-style case opening display (horizontal version) -->
<div class="case-container">
<!-- Central indicator -->
<div class="case-indicator"></div>
<!-- Horizontal row of prizes -->
<div class="case-items-container">
<div class="case-items">
<!-- Add a reference element first to help with alignment -->
<div class="case-item case-item-ref" style="opacity: 0; pointer-events: none"></div>
<div
*ngFor="let reward of prizeList; let i = index"
class="case-item"
[class.case-item-won]="isWonReward(reward)"
[id]="isWonReward(reward) ? 'winning-item' : ''"
[style.border]="'none'"
[style.animation-delay]="isWonReward(reward) ? '10s' : 8 + (i % 50) * 0.04 + 's'"
>
<div
class="case-item-inner"
[style.border]="''"
[style.background-color]="''"
[style.transform]="''"
[style.box-shadow]="''"
[style.margin-left]="isWonReward(reward) ? getCenterOffset() : '0'"
[style.transition-delay]="(i % 20) * 0.01 + 's'"
>
<div class="amount">{{ reward.value | currency: 'EUR' }}</div>
<div class="rarity">{{ reward.probability * 100 | number: '1.0-0' }}%</div>
</div>
</div>
<!-- Add another reference element at the end to help with alignment -->
<div class="case-item case-item-ref" style="opacity: 0; pointer-events: none"></div>
</div>
</div>
</div>
<!-- Action buttons - only shown after animation completes -->
<div
class="flex gap-4 justify-center mt-8"
style="opacity: 0; animation: fade-in 0.5s ease-out 10.7s forwards"
>
<button
(click)="openAgain()"
class="open-btn text-white px-6 py-2 rounded-lg font-semibold transition-all"
>
Nochmal öffnen
</button>
<button
(click)="goBack()"
class="bg-[#232c43] hover:bg-[#2d3748] text-white px-6 py-2 rounded-lg font-semibold transition"
>
Zurück zur Übersicht
</button>
</div>
</div>
</ng-container>
</div>

View file

@ -0,0 +1,176 @@
import { Component, ChangeDetectorRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { LootboxService } from '../services/lootbox.service';
import { LootBox, Reward } from 'app/model/LootBox';
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
function shuffle<T>(array: T[]): T[] {
const arr = array.slice();
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
@Component({
selector: 'app-lootbox-opening',
standalone: true,
imports: [CommonModule, NavbarComponent],
templateUrl: './lootbox-opening.component.html',
styleUrls: ['./lootbox-opening.component.css'],
})
export default class LootboxOpeningComponent {
lootbox: LootBox | null = null;
isLoading = true;
error = '';
// UI State
isOpening = false;
isOpen = false;
wonReward: Reward | null = null;
prizeList: Reward[] = [];
constructor(
private route: ActivatedRoute,
private router: Router,
private lootboxService: LootboxService,
private cdr: ChangeDetectorRef
) {
const idParam = this.route.snapshot.paramMap.get('id');
if (!idParam) {
this.error = 'Invalid lootbox ID';
this.isLoading = false;
return;
}
const lootboxId = parseInt(idParam, 10);
this.lootboxService.getAllLootBoxes().subscribe({
next: (lootboxes) => {
this.lootbox = lootboxes.find((box) => box.id === lootboxId) || null;
this.isLoading = false;
this.cdr.detectChanges();
},
error: () => {
this.error = 'Failed to load lootbox data';
this.isLoading = false;
this.cdr.detectChanges();
},
});
}
openLootbox() {
if (!this.lootbox || this.isOpening) return;
this.isOpening = true;
this.isOpen = false;
this.wonReward = null;
this.prizeList = []; // Clear previous prizes
this.cdr.detectChanges();
// Short delay to ensure animation plays from the beginning
setTimeout(() => {
this.lootboxService.purchaseLootBox(this.lootbox!.id).subscribe({
next: (reward) => {
this.wonReward = reward;
this.generateCasePrizes(reward);
this.isOpening = false;
this.isOpen = true;
this.cdr.detectChanges();
},
error: () => {
// Fallback if API fails
const rewards = this.lootbox!.rewards;
const fallback = rewards[Math.floor(Math.random() * rewards.length)];
this.wonReward = fallback;
this.generateCasePrizes(fallback);
this.isOpening = false;
this.isOpen = true;
this.cdr.detectChanges();
},
});
}, 100);
}
generateCasePrizes(wonReward: Reward) {
if (!this.lootbox) return;
// Create a case opening display with an extremely large number of prizes for a massive scrolling animation
const prizeCount = 200; // Set to 200 for an extremely long scrolling animation
const winningPosition = Math.floor(prizeCount / 2); // Position of the winning prize (middle)
// Get possible rewards from the lootbox
const possibleRewards = this.lootbox.rewards;
// Generate an array of random rewards
let items: Reward[] = [];
for (let i = 0; i < prizeCount; i++) {
// Special handling for the winning position
if (i === winningPosition) {
items.push(wonReward);
} else {
// For all other positions, choose a random reward
// Weight rarer items to appear less frequently
const randomReward = this.getWeightedRandomReward(possibleRewards);
items.push(randomReward);
}
}
this.prizeList = items;
}
getWeightedRandomReward(rewards: Reward[]): Reward {
// Create a weighted distribution based on probabilities
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 a copy of the reward
}
}
// Fallback, should never reach here
return { ...rewards[0] };
}
openAgain() {
this.isOpening = false;
this.isOpen = false;
this.wonReward = null;
this.prizeList = [];
this.cdr.detectChanges();
}
getBoxImage(id: number): string {
return `/images/${id}-box.png`;
}
goBack(): void {
this.router.navigate(['/game/lootboxes']);
}
isWonReward(reward: Reward): boolean {
if (!this.wonReward) {
return false;
}
return (
reward.id === this.wonReward.id &&
reward.value === this.wonReward.value &&
reward.probability === this.wonReward.probability
);
}
// Calculate the center position for better alignment
getCenterOffset(): string {
return '0px'; // No additional offset - using animation transform instead
}
// Check if item is at center position (100th item)
isCenterItem(index: number): boolean {
return index === Math.floor(200 / 2); // Center item at index 100 (0-indexed)
}
}

View file

@ -0,0 +1,22 @@
.loader {
border: 4px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top: 4px solid #fff;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.card {
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

View file

@ -0,0 +1,53 @@
<app-navbar></app-navbar>
<div class="container mx-auto px-4 py-6">
<h1 class="text-3xl font-bold text-white mb-6">Lootboxen</h1>
<div style="color:lime">isLoading: {{ isLoading }} | error: {{ error }} | lootboxes: {{ lootboxes?.length }}</div>
<div *ngIf="isLoading" class="flex justify-center">
<div class="loader"></div>
</div>
<div *ngIf="error" class="bg-red-500 text-white p-4 rounded mb-6">
{{ error }}
</div>
<div *ngIf="!isLoading && !error" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div *ngFor="let lootbox of lootboxes" class="card bg-deep-blue-light rounded-lg overflow-hidden shadow-lg hover:shadow-xl transition-shadow">
<div class="relative">
<img [src]="getBoxImage(lootbox.id)" [alt]="lootbox.name" class="w-full h-48 object-cover">
<div class="absolute top-2 right-2 bg-deep-blue px-2 py-1 rounded-full text-white">
{{ lootbox.price | currency:'EUR' }}
</div>
</div>
<div class="p-4">
<h2 class="text-xl font-bold text-white mb-2">{{ lootbox.name }}</h2>
<div class="mb-4">
<h3 class="text-lg font-semibold text-white mb-2">Mögliche Gewinne:</h3>
<ul class="space-y-2">
<li *ngFor="let reward of lootbox.rewards" class="flex justify-between">
<span [ngClass]="getRarityClass(reward.probability)">{{ reward.value | currency:'EUR' }}</span>
<span class="text-white">{{ formatProbability(reward.probability) }}</span>
</li>
</ul>
</div>
<div class="mt-4">
<button
(click)="openLootbox(lootbox.id)"
class="button-primary w-full py-2 rounded font-semibold">
Öffnen
</button>
</div>
</div>
<div class="px-4 pb-4">
<div class="text-sm text-text-secondary">
<p>Fairness garantiert - Alle Ergebnisse werden transparent berechnet.</p>
</div>
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,134 @@
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
import { LootboxService } from '../services/lootbox.service';
import { LootBox } from 'app/model/LootBox';
import { Router } from '@angular/router';
import { timeout } from 'rxjs';
@Component({
selector: 'app-lootbox-selection',
standalone: true,
imports: [CommonModule, NavbarComponent],
templateUrl: './lootbox-selection.component.html',
styleUrls: ['./lootbox-selection.component.css']
})
export default class LootboxSelectionComponent implements OnInit {
lootboxes: LootBox[] = [];
isLoading = true;
error = '';
// Fallback data in case the API call fails
fallbackLootboxes: LootBox[] = [
{
id: 1,
name: "Basic LootBox",
price: 2.00,
rewards: [
{
id: 1,
value: 0.50,
probability: 0.70
},
{
id: 5,
value: 5.00,
probability: 0.30
}
]
},
{
id: 2,
name: "Premium LootBox",
price: 5.00,
rewards: [
{
id: 4,
value: 2.00,
probability: 0.60
},
{
id: 5,
value: 5.00,
probability: 0.30
},
{
id: 6,
value: 15.00,
probability: 0.10
}
]
},
{
id: 3,
name: "Legendäre LootBox",
price: 15.00,
rewards: [
{
id: 4,
value: 2.00,
probability: 0.60
},
{
id: 5,
value: 5.00,
probability: 0.30
},
{
id: 6,
value: 15.00,
probability: 0.10
}
]
}
];
constructor(private lootboxService: LootboxService, private router: Router, private cdr: ChangeDetectorRef) {}
ngOnInit(): void {
this.loadLootboxes();
}
loadLootboxes(): void {
this.isLoading = true;
this.lootboxService.getAllLootBoxes().pipe(
timeout(5000)
).subscribe({
next: (data) => {
console.log('Received lootboxes:', data);
this.lootboxes = data;
this.isLoading = false;
this.cdr.detectChanges();
},
error: (err) => {
this.error = 'Konnte keine Verbindung zum Backend herstellen. Zeige Demo-Daten.';
this.lootboxes = this.fallbackLootboxes;
this.isLoading = false;
this.cdr.detectChanges();
console.error('Failed to load lootboxes:', err);
}
});
}
getBoxImage(id: number): string {
return `/images/${id}-box.png`;
}
openLootbox(lootboxId: number): void {
this.router.navigate(['/game/lootboxes/open', lootboxId]);
}
getRarityClass(probability: number): string {
if (probability <= 0.1) {
return 'text-yellow-400'; // Legendary
} else if (probability <= 0.3) {
return 'text-purple-400'; // Rare
} else {
return 'text-blue-400'; // Common
}
}
formatProbability(probability: number): string {
return (probability * 100).toFixed(0) + '%';
}
}

View file

@ -0,0 +1,33 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, catchError } from 'rxjs';
import { LootBox, Reward } from 'app/model/LootBox';
@Injectable({
providedIn: 'root',
})
export class LootboxService {
private http = inject(HttpClient);
getAllLootBoxes(): Observable<LootBox[]> {
return this.http
.get<LootBox[]>('/backend/lootboxes', { responseType: 'json' })
.pipe(
catchError((error) => {
console.error('Get lootboxes error:', error);
throw error;
})
);
}
purchaseLootBox(lootBoxId: number): Observable<Reward> {
return this.http
.post<Reward>(`/backend/lootboxes/${lootBoxId}`, {}, { responseType: 'json' })
.pipe(
catchError((error) => {
console.error('Purchase lootbox error:', error);
throw error;
})
);
}
}

View file

@ -0,0 +1,12 @@
export interface Reward {
id: number;
value: number;
probability: number;
}
export interface LootBox {
id: number;
name: string;
price: number;
rewards: Reward[];
}

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@