FarmServiceProvider.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Module\Farm\Providers;
  3. use App\Module\Farm\Commands;
  4. use App\Module\AppGame\Events\LoginSuccessEvent;
  5. use App\Module\Farm\Events\CropGrowthStageChangedEvent;
  6. use App\Module\Farm\Events\CropHarvestedEvent;
  7. use App\Module\Farm\Events\HouseUpgradedEvent;
  8. use App\Module\Farm\Listeners\AddLandAfterHouseUpgradeListener;
  9. use App\Module\Farm\Listeners\CalculateHarvestOutputListener;
  10. use App\Module\Farm\Listeners\CheckHouseDowngradeListener;
  11. use App\Module\Farm\Listeners\GenerateDisasterListener;
  12. use App\Module\Farm\Listeners\LoginSuccessListener;
  13. use App\Module\Farm\Listeners\UpdateCropStatusListener;
  14. use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
  15. use Illuminate\Support\Facades\Event;
  16. /**
  17. * 农场模块服务提供者
  18. */
  19. class FarmServiceProvider extends ServiceProvider
  20. {
  21. /**
  22. * 事件与监听器映射
  23. *
  24. * @var array
  25. */
  26. protected $listen = [
  27. CropGrowthStageChangedEvent::class => [
  28. UpdateCropStatusListener::class,
  29. GenerateDisasterListener::class,
  30. ],
  31. HouseUpgradedEvent::class => [
  32. AddLandAfterHouseUpgradeListener::class,
  33. ],
  34. LoginSuccessEvent::class => [
  35. LoginSuccessListener::class,
  36. ],
  37. ];
  38. /**
  39. * 注册服务
  40. *
  41. * @return void
  42. */
  43. public function register()
  44. {
  45. // 注册命令
  46. $this->commands([
  47. Commands\UpdateCropGrowthCommand::class,
  48. Commands\GenerateDisastersCommand::class,
  49. Commands\CheckHouseDowngradeCommand::class,
  50. Commands\CleanExpiredLogsCommand::class,
  51. Commands\GenerateFarmHouseConfigJson::class,
  52. Commands\GenerateFarmShrineConfigJson::class,
  53. Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
  54. Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class,
  55. Commands\InitializeUserLandsCommand::class
  56. ]);
  57. }
  58. /**
  59. * 引导服务
  60. *
  61. * @return void
  62. */
  63. public function boot()
  64. {
  65. $events = $this->app['events'];
  66. foreach ($this->listen as $event => $listeners) {
  67. foreach ($listeners as $listener) {
  68. $events->listen($event, $listener);
  69. }
  70. }
  71. // 注册定时任务监听器
  72. // $this->app->booted(function () {
  73. // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
  74. //
  75. //
  76. // // 每小时随机生成灾害
  77. // $schedule->command('farm:generate-disasters')->hourly();
  78. //
  79. //
  80. // // 达人等级更新已移至Team模块
  81. //
  82. // // 每周一凌晨4点清理过期日志
  83. // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
  84. //
  85. // // 每天凌晨5点重建缓存
  86. // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
  87. // });
  88. }
  89. }