mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 22:32:08 +00:00
big shot
This commit is contained in:
@@ -17,6 +17,7 @@ class PaperBallThrown implements ShouldBroadcastNow
|
||||
public readonly string $roomId,
|
||||
public readonly int $fromPlayerId,
|
||||
public readonly int $targetPlayerId,
|
||||
public readonly int $chargeLevel,
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): Channel
|
||||
@@ -30,7 +31,7 @@ class PaperBallThrown implements ShouldBroadcastNow
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id: string, from_player_id: int, target_player_id: int}
|
||||
* @return array{id: string, from_player_id: int, target_player_id: int, charge_level: int}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
@@ -38,6 +39,7 @@ class PaperBallThrown implements ShouldBroadcastNow
|
||||
'id' => $this->id,
|
||||
'from_player_id' => $this->fromPlayerId,
|
||||
'target_player_id' => $this->targetPlayerId,
|
||||
'charge_level' => $this->chargeLevel,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class RoomEmoteController extends Controller
|
||||
$room,
|
||||
$player,
|
||||
(int) $request->validated('target_player_id'),
|
||||
(int) ($request->validated('charge_percentage') ?? 0),
|
||||
);
|
||||
|
||||
return response()->noContent();
|
||||
|
||||
@@ -19,6 +19,7 @@ class ThrowPaperBallRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'target_player_id' => ['required', 'integer'],
|
||||
'charge_percentage' => ['sometimes', 'integer', 'between:0,300'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ use Illuminate\Validation\ValidationException;
|
||||
|
||||
class RoomEmoteService
|
||||
{
|
||||
public function throwPaperBall(Room $room, Player $player, int $targetPlayerId): void
|
||||
{
|
||||
public function throwPaperBall(
|
||||
Room $room,
|
||||
Player $player,
|
||||
int $targetPlayerId,
|
||||
int $chargePercentage,
|
||||
): void {
|
||||
if ($targetPlayerId === $player->id) {
|
||||
throw ValidationException::withMessages([
|
||||
'target_player_id' => 'Du kannst dich nicht selbst abwerfen.',
|
||||
@@ -39,11 +43,19 @@ class RoomEmoteService
|
||||
|
||||
RateLimiter::hit($rateLimitKey, 10);
|
||||
|
||||
$chargeLevel = match (true) {
|
||||
$chargePercentage >= 300 => 3,
|
||||
$chargePercentage >= 200 => 2,
|
||||
$chargePercentage >= 100 => 1,
|
||||
default => 0,
|
||||
};
|
||||
|
||||
PaperBallThrown::dispatch(
|
||||
Str::uuid()->toString(),
|
||||
$room->id,
|
||||
$player->id,
|
||||
$targetPlayerId,
|
||||
$chargeLevel,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user