GameServiceProvider.php 5.6 KB

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