2026-04-28 23:42:48 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-29 13:35:20 +08:00
|
|
|
* 文件功能:猜谜活动开始广播事件
|
2026-04-28 23:42:48 +08:00
|
|
|
*
|
2026-04-29 13:35:20 +08:00
|
|
|
* 管理员手动出题或系统自动出题时触发,广播提示到聊天室。
|
2026-04-28 23:42:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
|
|
|
use Illuminate\Broadcasting\PresenceChannel;
|
|
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
2026-04-29 13:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* 类功能:向指定房间广播新一轮猜谜活动题目。
|
|
|
|
|
*/
|
|
|
|
|
class RiddleGameStarted implements ShouldBroadcastNow
|
2026-04-28 23:42:48 +08:00
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-29 13:35:20 +08:00
|
|
|
* 方法功能:构造新回合广播事件载荷。
|
2026-04-28 23:42:48 +08:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
public readonly int $roomId,
|
2026-04-29 13:35:20 +08:00
|
|
|
public readonly string $quizType,
|
2026-04-28 23:42:48 +08:00
|
|
|
public readonly string $hint,
|
|
|
|
|
public readonly int $roundId,
|
|
|
|
|
public readonly int $rewardGold = 0,
|
|
|
|
|
public readonly int $rewardExp = 0,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-29 13:35:20 +08:00
|
|
|
* 方法功能:声明广播频道。
|
2026-04-28 23:42:48 +08:00
|
|
|
*/
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
new PresenceChannel('room.'.$this->roomId),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-29 13:35:20 +08:00
|
|
|
* 方法功能:声明广播数据。
|
2026-04-28 23:42:48 +08:00
|
|
|
*/
|
|
|
|
|
public function broadcastWith(): array
|
|
|
|
|
{
|
2026-04-29 13:35:20 +08:00
|
|
|
$quizTypeLabel = \App\Models\Riddle::labelForType($this->quizType);
|
|
|
|
|
|
2026-04-28 23:42:48 +08:00
|
|
|
return [
|
|
|
|
|
'round_id' => $this->roundId,
|
2026-04-29 13:35:20 +08:00
|
|
|
'quiz_type' => $this->quizType,
|
|
|
|
|
'quiz_type_label' => $quizTypeLabel,
|
|
|
|
|
'quiz_round_id' => $this->roundId,
|
|
|
|
|
'quiz_hint' => $this->hint,
|
|
|
|
|
'quiz_reward_gold' => $this->rewardGold,
|
|
|
|
|
'quiz_reward_exp' => $this->rewardExp,
|
2026-04-28 23:42:48 +08:00
|
|
|
'hint' => $this->hint,
|
|
|
|
|
'reward_gold' => $this->rewardGold,
|
|
|
|
|
'reward_exp' => $this->rewardExp,
|
2026-04-29 13:35:20 +08:00
|
|
|
'message' => "📣 【猜谜活动·{$quizTypeLabel}】第 #{$this->roundId} 题开始!题面:{$this->hint}",
|
2026-04-28 23:42:48 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|