GameServiceProvider.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\Events\RewardGrantedEvent;
  13. // 这些事件类需要在 Farm 模块中定义
  14. // 如果 Farm 模块中尚未定义这些事件类,请先在 Farm 模块中创建它们
  15. use App\Module\Farm\Events\CropGrowthStageChangedEvent;
  16. use App\Module\Farm\Events\CropPlantedEvent;
  17. use App\Module\Farm\Events\DisasterClearedEvent;
  18. use App\Module\Farm\Events\BuffActivatedEvent;
  19. use App\Module\Farm\Events\HouseDowngradedEvent;
  20. use App\Module\Farm\Events\HouseUpgradedEvent;
  21. use App\Module\Farm\Events\LandStatusChangedEvent;
  22. use App\Module\Farm\Events\LandUpgradedEvent;
  23. use App\Module\Fund\Events\FundChangedEvent;
  24. use App\Module\Game\Listeners\BuffActivatedListener;
  25. use App\Module\Game\Listeners\CropGrowthStageChangedListener;
  26. use App\Module\Game\Listeners\CropPlantedListener;
  27. use App\Module\Game\Listeners\DisasterClearedListener;
  28. use App\Module\Game\Listeners\FundChangedListener;
  29. use App\Module\Game\Listeners\HouseDowngradedListener;
  30. use App\Module\Game\Listeners\HouseUpgradedListener;
  31. use App\Module\Game\Listeners\ItemQuantityChangedListener;
  32. use App\Module\Game\Listeners\LandStatusChangedListener;
  33. use App\Module\Game\Listeners\LandUpgradedListener;
  34. use App\Module\Game\Listeners\LogRewardGrantedListener;
  35. use App\Module\Game\Listeners\NotifyRewardGrantedListener;
  36. use App\Module\Game\Listeners\PetCreatedListener;
  37. use App\Module\Game\Listeners\PetSkillUsedListener;
  38. use App\Module\Game\Listeners\PetStatusChangedListener;
  39. use App\Module\Game\Listeners\PetUpdateListener;
  40. use App\Module\GameItems\Events\ItemQuantityChanged;
  41. use App\Module\Pet\Events\PetCreatedEvent;
  42. use App\Module\Pet\Events\PetSkillUsedEvent;
  43. use App\Module\Pet\Events\PetStatusChangedEvent;
  44. use App\Module\Pet\Events\PetUpdateEvent;
  45. use Illuminate\Support\ServiceProvider;
  46. use Illuminate\Support\Facades\Event;
  47. /**
  48. * 游戏模块服务提供者
  49. *
  50. * 负责注册游戏模块的事件监听器、命令和其他服务
  51. */
  52. class GameServiceProvider extends ServiceProvider
  53. {
  54. /**
  55. * 要注册的命令
  56. *
  57. * @var array
  58. */
  59. protected $commands = [
  60. TestItemTempCommand::class,
  61. ImportRewardGroupsCommand::class,
  62. CleanExpiredRewardLogsCommand::class,
  63. CleanExpiredUserLogsCommand::class,
  64. CollectUserLogsCommand::class,
  65. TestConsumeCommand::class,
  66. TestConditionCommand::class,
  67. TestRewardDeductCollectorCommand::class,
  68. TestGodRewardCommand::class,
  69. ];
  70. protected $listeners = [
  71. // ...
  72. ];
  73. /**
  74. * 注册服务
  75. */
  76. public function register(): void
  77. {
  78. // 注册命令
  79. $this->commands($this->commands);
  80. }
  81. /**
  82. * 启动服务
  83. */
  84. public function boot(): void
  85. {
  86. // 注册事件监听器
  87. Event::listen(
  88. ItemQuantityChanged::class,
  89. ItemQuantityChangedListener::class
  90. );
  91. // 注册宠物事件监听器
  92. Event::listen(
  93. PetCreatedEvent::class,
  94. PetCreatedListener::class
  95. );
  96. Event::listen(
  97. PetStatusChangedEvent::class,
  98. PetStatusChangedListener::class
  99. );
  100. // 注册宠物更新事件监听器
  101. Event::listen(
  102. PetUpdateEvent::class,
  103. PetUpdateListener::class
  104. );
  105. // 注册宠物技能使用事件监听器
  106. Event::listen(
  107. PetSkillUsedEvent::class,
  108. PetSkillUsedListener::class
  109. );
  110. // 注册奖励组系统事件监听器
  111. Event::listen(
  112. RewardGrantedEvent::class,
  113. LogRewardGrantedListener::class
  114. );
  115. // 注册奖励组系统事件监听器
  116. Event::listen(
  117. RewardGrantedEvent::class,
  118. NotifyRewardGrantedListener::class
  119. );
  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. }