| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\Pet\Events;
- use Illuminate\Broadcasting\InteractsWithSockets;
- use Illuminate\Foundation\Events\Dispatchable;
- use Illuminate\Queue\SerializesModels;
- /**
- * 宠物经验增加事件
- *
- * 当宠物获得经验时触发此事件,允许其他系统响应宠物经验的增加。
- * 此事件可用于更新任务进度、记录经验获得日志、处理成就解锁等。
- */
- class PetExpGainedEvent
- {
- use Dispatchable, InteractsWithSockets, SerializesModels;
- /**
- * 用户ID
- *
- * @var int
- */
- public int $userId;
- /**
- * 宠物ID
- *
- * @var int
- */
- public int $petId;
- /**
- * 增加的经验值
- *
- * @var int
- */
- public int $expGained;
- /**
- * 经验来源类型
- *
- * @var string
- */
- public string $sourceType;
- /**
- * 经验来源ID
- *
- * @var int|null
- */
- public ?int $sourceId;
- /**
- * 创建一个新的事件实例
- *
- * @param int $userId 用户ID
- * @param int $petId 宠物ID
- * @param int $expGained 增加的经验值
- * @param string $sourceType 经验来源类型
- * @param int|null $sourceId 经验来源ID
- * @return void
- */
- public function __construct(int $userId, int $petId, int $expGained, string $sourceType = 'unknown', ?int $sourceId = null)
- {
- $this->userId = $userId;
- $this->petId = $petId;
- $this->expGained = $expGained;
- $this->sourceType = $sourceType;
- $this->sourceId = $sourceId;
- }
- }
|