FarmServiceProvider.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\FixCropFinalOutputCommand::class,
  49. Commands\GenerateDisastersCommand::class,
  50. Commands\CheckHouseDowngradeCommand::class,
  51. Commands\CleanExpiredLogsCommand::class,
  52. Commands\GenerateFarmHouseConfigJson::class,
  53. Commands\GenerateFarmShrineConfigJson::class,
  54. Commands\GenerateFarmLandConfigJson::class,
  55. Commands\GenerateFarmSeedConfigJson::class,
  56. Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
  57. Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class,
  58. Commands\InitializeUserLandsCommand::class
  59. ]);
  60. }
  61. /**
  62. * 引导服务
  63. *
  64. * @return void
  65. */
  66. public function boot()
  67. {
  68. $events = $this->app['events'];
  69. foreach ($this->listen as $event => $listeners) {
  70. foreach ($listeners as $listener) {
  71. $events->listen($event, $listener);
  72. }
  73. }
  74. // 注册定时任务监听器
  75. // $this->app->booted(function () {
  76. // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
  77. //
  78. //
  79. // // 每小时随机生成灾害
  80. // $schedule->command('farm:generate-disasters')->hourly();
  81. //
  82. //
  83. // // 达人等级更新已移至Team模块
  84. //
  85. // // 每周一凌晨4点清理过期日志
  86. // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
  87. //
  88. // // 每天凌晨5点重建缓存
  89. // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
  90. // });
  91. }
  92. }