GameServiceProvider.php 5.7 KB

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