Files
chatroom/app/Jobs/AiFishingJob.php

46 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能AI小班长钓鱼动作异步任务
*
* 模拟 AI 抛竿等待一定时间后收竿的过程。
* 收竿时自动调用 FishingService 结算结果并播报。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Jobs;
use App\Models\User;
use App\Services\FishingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class AiFishingJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @param User $aiUser AI小班长
* @param int $roomId 此事件广播的房间ID
*/
public function __construct(
public readonly User $aiUser,
public readonly int $roomId,
) {}
/**
* 任务执行
*/
public function handle(FishingService $fishingService): void
{
// 通过业务服务计算钓鱼结果并广播,标记 isAi 为 true
$fishingService->processCatch($this->aiUser, $this->roomId, true);
}
}