PetBattleEvent.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 PetBattleEvent
  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. * 1: 偷菜战斗
  30. * 2: 守护战斗
  31. * 3: 争霸赛战斗
  32. *
  33. * @var int
  34. */
  35. public int $battleType;
  36. /**
  37. * 对手ID(可为空)
  38. *
  39. * @var int|null
  40. */
  41. public ?int $opponentId;
  42. /**
  43. * 战斗结果
  44. * 0: 失败
  45. * 1: 胜利
  46. *
  47. * @var int
  48. */
  49. public int $result;
  50. /**
  51. * 战斗奖励
  52. *
  53. * @var array|null
  54. */
  55. public ?array $reward;
  56. /**
  57. * 创建一个新的事件实例
  58. *
  59. * @param int $userId 用户ID
  60. * @param int $petId 宠物ID
  61. * @param int $battleType 战斗类型
  62. * @param int|null $opponentId 对手ID
  63. * @param int $result 战斗结果
  64. * @param array|null $reward 战斗奖励
  65. * @return void
  66. */
  67. public function __construct(int $userId, int $petId, int $battleType, ?int $opponentId, int $result, ?array $reward = null)
  68. {
  69. $this->userId = $userId;
  70. $this->petId = $petId;
  71. $this->battleType = $battleType;
  72. $this->opponentId = $opponentId;
  73. $this->result = $result;
  74. $this->reward = $reward;
  75. }
  76. }