重构猜谜活动并统一聊天室答题通知
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:猜成语答题结果广播事件
|
||||
* 文件功能:猜谜活动答题结果广播事件
|
||||
*
|
||||
* 用户答对成语时广播,通知房间内所有用户结果。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
* 用户答对题目时广播,通知房间内所有用户结果。
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
@@ -18,27 +14,29 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class IdiomGameAnswered implements ShouldBroadcastNow
|
||||
/**
|
||||
* 类功能:向指定房间广播猜谜活动答题结果。
|
||||
*/
|
||||
class RiddleGameAnswered implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param int $roomId 房间 ID
|
||||
* @param int $roundId 游戏回合 ID
|
||||
* @param string $answer 正确答案
|
||||
* @param string $winnerUsername 答对的用户名
|
||||
* @param int $rewardGold 获得的金币
|
||||
* @param int $rewardExp 获得的经验
|
||||
* 方法功能:构造答题成功广播事件载荷。
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly int $roundId,
|
||||
public readonly string $quizType,
|
||||
public readonly string $answer,
|
||||
public readonly string $winnerUsername,
|
||||
public readonly int $rewardGold = 0,
|
||||
public readonly int $rewardExp = 0,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 方法功能:声明广播频道。
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
@@ -46,10 +44,22 @@ class IdiomGameAnswered implements ShouldBroadcastNow
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:声明广播数据。
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$quizTypeLabel = \App\Models\Riddle::labelForType($this->quizType);
|
||||
|
||||
return [
|
||||
'round_id' => $this->roundId,
|
||||
'quiz_type' => $this->quizType,
|
||||
'quiz_type_label' => $quizTypeLabel,
|
||||
'quiz_round_id' => $this->roundId,
|
||||
'quiz_answer' => $this->answer,
|
||||
'quiz_reward_gold' => $this->rewardGold,
|
||||
'quiz_reward_exp' => $this->rewardExp,
|
||||
'quiz_round_ended_id' => $this->roundId,
|
||||
'answer' => $this->answer,
|
||||
'winner_username' => $this->winnerUsername,
|
||||
'reward_gold' => $this->rewardGold,
|
||||
@@ -1,13 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:猜成语游戏开始广播事件
|
||||
* 文件功能:猜谜活动开始广播事件
|
||||
*
|
||||
* 管理员手动出题时触发,广播成语提示到聊天室,前端显示提示+答题按钮。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
* 管理员手动出题或系统自动出题时触发,广播提示到聊天室。
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
@@ -18,19 +14,19 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class IdiomGameStarted implements ShouldBroadcastNow
|
||||
/**
|
||||
* 类功能:向指定房间广播新一轮猜谜活动题目。
|
||||
*/
|
||||
class RiddleGameStarted 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 $quizType,
|
||||
public readonly string $hint,
|
||||
public readonly int $roundId,
|
||||
public readonly int $rewardGold = 0,
|
||||
@@ -38,7 +34,7 @@ class IdiomGameStarted implements ShouldBroadcastNow
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播频道
|
||||
* 方法功能:声明广播频道。
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
@@ -48,16 +44,24 @@ class IdiomGameStarted implements ShouldBroadcastNow
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据
|
||||
* 方法功能:声明广播数据。
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$quizTypeLabel = \App\Models\Riddle::labelForType($this->quizType);
|
||||
|
||||
return [
|
||||
'round_id' => $this->roundId,
|
||||
'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,
|
||||
'hint' => $this->hint,
|
||||
'reward_gold' => $this->rewardGold,
|
||||
'reward_exp' => $this->rewardExp,
|
||||
'message' => "🧩 猜成语时间!{$this->hint}",
|
||||
'message' => "📣 【猜谜活动·{$quizTypeLabel}】第 #{$this->roundId} 题开始!题面:{$this->hint}",
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user