64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 文件功能:猜成语游戏开始广播事件
|
||
|
|
*
|
||
|
|
* 管理员手动出题时触发,广播成语提示到聊天室,前端显示提示+答题按钮。
|
||
|
|
*
|
||
|
|
* @author ChatRoom Laravel
|
||
|
|
*
|
||
|
|
* @version 1.0.0
|
||
|
|
*/
|
||
|
|
|
||
|
|
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;
|
||
|
|
|
||
|
|
class IdiomGameStarted implements ShouldBroadcastNow
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param int $roomId 房间 ID
|
||
|
|
* @param string $hint 谜语提示
|
||
|
|
* @param int $roundId 游戏回合 ID(前端提交答案时带上)
|
||
|
|
* @param int $rewardGold 答对奖励金币
|
||
|
|
* @param int $rewardExp 答对奖励经验
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly int $roomId,
|
||
|
|
public readonly string $hint,
|
||
|
|
public readonly int $roundId,
|
||
|
|
public readonly int $rewardGold = 0,
|
||
|
|
public readonly int $rewardExp = 0,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播频道
|
||
|
|
*/
|
||
|
|
public function broadcastOn(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
new PresenceChannel('room.'.$this->roomId),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播数据
|
||
|
|
*/
|
||
|
|
public function broadcastWith(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'round_id' => $this->roundId,
|
||
|
|
'hint' => $this->hint,
|
||
|
|
'reward_gold' => $this->rewardGold,
|
||
|
|
'reward_exp' => $this->rewardExp,
|
||
|
|
'message' => "🧩 猜成语时间!{$this->hint}",
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|