PetServiceProvider.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Module\Pet\Providers;
  3. use App\Module\Pet\Commands\GeneratePetJsonCommand;
  4. use App\Module\Pet\Console\ProcessActiveSkillsCommand;
  5. use App\Module\Pet\Events\PetBattleEvent;
  6. use App\Module\Pet\Events\PetCreatedEvent;
  7. use App\Module\Pet\Events\PetLevelUpEvent;
  8. use App\Module\Pet\Events\PetRemouldEvent;
  9. use App\Module\Pet\Events\PetSkillUsedEvent;
  10. use App\Module\Pet\Events\PetStatusChangedEvent;
  11. use App\Module\Pet\Events\PetUpdateEvent;
  12. use App\Module\Pet\Listeners\ItemChangedListener;
  13. use App\Module\Pet\Listeners\LoginSuccessListener;
  14. use App\Module\Pet\Logic\PetLogic;
  15. use Illuminate\Support\Facades\Event;
  16. use Illuminate\Support\ServiceProvider;
  17. /**
  18. * 宠物模块服务提供者
  19. *
  20. * 负责注册宠物模块的服务、事件监听器、命令等
  21. */
  22. class PetServiceProvider extends ServiceProvider
  23. {
  24. /**
  25. * 事件到监听器的映射
  26. *
  27. * @var array
  28. */
  29. protected $listen = [
  30. // 监听来自其他模块的事件
  31. \App\Module\AppGame\Events\LoginSuccessEvent::class => [
  32. LoginSuccessListener::class,
  33. ]
  34. ];
  35. /**
  36. * 注册服务
  37. *
  38. * @return void
  39. */
  40. public function register()
  41. {
  42. }
  43. /**
  44. * 启动服务
  45. *
  46. * @return void
  47. */
  48. public function boot()
  49. {
  50. // 注册事件监听器
  51. $this->registerEventListeners();
  52. // 注册命令
  53. if ($this->app->runningInConsole()) {
  54. $this->commands([
  55. \App\Module\Pet\Commands\GeneratePetJsonCommand::class, // 生成宠物配置JSON数据命令
  56. \App\Module\Pet\Console\ProcessActiveSkillsCommand::class, // 处理宠物激活技能命令
  57. ]);
  58. }
  59. }
  60. /**
  61. * 注册事件监听器
  62. *
  63. * @return void
  64. */
  65. protected function registerEventListeners()
  66. {
  67. foreach ($this->listen as $event => $listeners) {
  68. foreach ($listeners as $listener) {
  69. Event::listen($event, $listener);
  70. }
  71. }
  72. }
  73. }