GameServiceProvider.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace App\Module\Game\Providers;
  3. use App\Module\Game\Commands\CleanExpiredRewardLogsCommand;
  4. use App\Module\Game\Commands\ImportRewardGroupsCommand;
  5. use App\Module\Game\Commands\TestConditionCommand;
  6. use App\Module\Game\Commands\TestConsumeCommand;
  7. use App\Module\Game\Commands\TestItemTempCommand;
  8. use App\Module\Game\Events\RewardGrantedEvent;
  9. // 这些事件类需要在 Farm 模块中定义
  10. // 如果 Farm 模块中尚未定义这些事件类,请先在 Farm 模块中创建它们
  11. use App\Module\Farm\Events\CropGrowthStageChangedEvent;
  12. use App\Module\Farm\Events\CropPlantedEvent;
  13. use App\Module\Farm\Events\DisasterClearedEvent;
  14. use App\Module\Farm\Events\HouseDowngradedEvent;
  15. use App\Module\Farm\Events\HouseUpgradedEvent;
  16. use App\Module\Farm\Events\LandUpgradedEvent;
  17. use App\Module\Fund\Events\FundChangedEvent;
  18. use App\Module\Game\Listeners\CropGrowthStageChangedListener;
  19. use App\Module\Game\Listeners\CropPlantedListener;
  20. use App\Module\Game\Listeners\DisasterClearedListener;
  21. use App\Module\Game\Listeners\FundChangedListener;
  22. use App\Module\Game\Listeners\HouseDowngradedListener;
  23. use App\Module\Game\Listeners\HouseUpgradedListener;
  24. use App\Module\Game\Listeners\ItemQuantityChangedListener;
  25. use App\Module\Game\Listeners\LandUpgradedListener;
  26. use App\Module\Game\Listeners\LogRewardGrantedListener;
  27. use App\Module\Game\Listeners\NotifyRewardGrantedListener;
  28. use App\Module\Game\Listeners\PetCreatedListener;
  29. use App\Module\Game\Listeners\PetStatusChangedListener;
  30. use App\Module\Game\Listeners\PetUpdateListener;
  31. use App\Module\GameItems\Events\ItemQuantityChanged;
  32. use App\Module\Pet\Events\PetCreatedEvent;
  33. use App\Module\Pet\Events\PetStatusChangedEvent;
  34. use App\Module\Pet\Events\PetUpdateEvent;
  35. use Illuminate\Support\ServiceProvider;
  36. use Illuminate\Support\Facades\Event;
  37. /**
  38. * 游戏模块服务提供者
  39. *
  40. * 负责注册游戏模块的事件监听器、命令和其他服务
  41. */
  42. class GameServiceProvider extends ServiceProvider
  43. {
  44. /**
  45. * 要注册的命令
  46. *
  47. * @var array
  48. */
  49. protected $commands = [
  50. TestItemTempCommand::class,
  51. ImportRewardGroupsCommand::class,
  52. CleanExpiredRewardLogsCommand::class,
  53. TestConsumeCommand::class,
  54. TestConditionCommand::class,
  55. ];
  56. protected $listeners = [
  57. // ...
  58. ];
  59. /**
  60. * 注册服务
  61. */
  62. public function register(): void
  63. {
  64. // 注册命令
  65. $this->commands($this->commands);
  66. }
  67. /**
  68. * 启动服务
  69. */
  70. public function boot(): void
  71. {
  72. // 注册事件监听器
  73. Event::listen(
  74. ItemQuantityChanged::class,
  75. ItemQuantityChangedListener::class
  76. );
  77. // 注册宠物事件监听器
  78. Event::listen(
  79. PetCreatedEvent::class,
  80. PetCreatedListener::class
  81. );
  82. Event::listen(
  83. PetStatusChangedEvent::class,
  84. PetStatusChangedListener::class
  85. );
  86. // 注册宠物更新事件监听器
  87. Event::listen(
  88. PetUpdateEvent::class,
  89. PetUpdateListener::class
  90. );
  91. // 注册奖励组系统事件监听器
  92. Event::listen(
  93. RewardGrantedEvent::class,
  94. LogRewardGrantedListener::class
  95. );
  96. // 注册奖励组系统事件监听器
  97. Event::listen(
  98. RewardGrantedEvent::class,
  99. NotifyRewardGrantedListener::class
  100. );
  101. // 注册土地事件监听器
  102. Event::listen(
  103. LandUpgradedEvent::class,
  104. LandUpgradedListener::class
  105. );
  106. // 注册作物种植事件监听器
  107. Event::listen(
  108. CropPlantedEvent::class,
  109. CropPlantedListener::class
  110. );
  111. // 注册作物生长阶段变更事件监听器
  112. Event::listen(
  113. CropGrowthStageChangedEvent::class,
  114. CropGrowthStageChangedListener::class
  115. );
  116. // 注册灾害清理事件监听器
  117. Event::listen(
  118. DisasterClearedEvent::class,
  119. DisasterClearedListener::class
  120. );
  121. // 注册房屋事件监听器
  122. Event::listen(
  123. HouseUpgradedEvent::class,
  124. HouseUpgradedListener::class
  125. );
  126. Event::listen(
  127. HouseDowngradedEvent::class,
  128. HouseDowngradedListener::class
  129. );
  130. // 注册资金事件监听器
  131. Event::listen(
  132. FundChangedEvent::class,
  133. FundChangedListener::class
  134. );
  135. }
  136. }