PetExpGainedEvent.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Module\Pet\Events;
  3. use Illuminate\Broadcasting\InteractsWithSockets;
  4. use Illuminate\Foundation\Events\Dispatchable;
  5. use Illuminate\Queue\SerializesModels;
  6. /**
  7. * 宠物经验增加事件
  8. *
  9. * 当宠物获得经验时触发此事件,允许其他系统响应宠物经验的增加。
  10. * 此事件可用于更新任务进度、记录经验获得日志、处理成就解锁等。
  11. */
  12. class PetExpGainedEvent
  13. {
  14. use Dispatchable, InteractsWithSockets, SerializesModels;
  15. /**
  16. * 用户ID
  17. *
  18. * @var int
  19. */
  20. public int $userId;
  21. /**
  22. * 宠物ID
  23. *
  24. * @var int
  25. */
  26. public int $petId;
  27. /**
  28. * 增加的经验值
  29. *
  30. * @var int
  31. */
  32. public int $expGained;
  33. /**
  34. * 经验来源类型
  35. *
  36. * @var string
  37. */
  38. public string $sourceType;
  39. /**
  40. * 经验来源ID
  41. *
  42. * @var int|null
  43. */
  44. public ?int $sourceId;
  45. /**
  46. * 创建一个新的事件实例
  47. *
  48. * @param int $userId 用户ID
  49. * @param int $petId 宠物ID
  50. * @param int $expGained 增加的经验值
  51. * @param string $sourceType 经验来源类型
  52. * @param int|null $sourceId 经验来源ID
  53. * @return void
  54. */
  55. public function __construct(int $userId, int $petId, int $expGained, string $sourceType = 'unknown', ?int $sourceId = null)
  56. {
  57. $this->userId = $userId;
  58. $this->petId = $petId;
  59. $this->expGained = $expGained;
  60. $this->sourceType = $sourceType;
  61. $this->sourceId = $sourceId;
  62. }
  63. }