| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Module\Farm\Providers;
- use App\Module\Farm\Commands;
- use App\Module\AppGame\Events\LoginSuccessEvent;
- use App\Module\Farm\Events\CropGrowthStageChangedEvent;
- use App\Module\Farm\Events\CropHarvestedEvent;
- use App\Module\Farm\Events\HouseUpgradedEvent;
- use App\Module\Farm\Listeners\AddLandAfterHouseUpgradeListener;
- use App\Module\Farm\Listeners\CalculateHarvestOutputListener;
- use App\Module\Farm\Listeners\CheckHouseDowngradeListener;
- use App\Module\Farm\Listeners\GenerateDisasterListener;
- use App\Module\Farm\Listeners\LoginSuccessListener;
- use App\Module\Farm\Listeners\UpdateCropStatusListener;
- use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
- use Illuminate\Support\Facades\Event;
- /**
- * 农场模块服务提供者
- */
- class FarmServiceProvider extends ServiceProvider
- {
- /**
- * 事件与监听器映射
- *
- * @var array
- */
- protected $listen = [
- CropGrowthStageChangedEvent::class => [
- UpdateCropStatusListener::class,
- GenerateDisasterListener::class,
- ],
- HouseUpgradedEvent::class => [
- AddLandAfterHouseUpgradeListener::class,
- ],
- LoginSuccessEvent::class => [
- LoginSuccessListener::class,
- ],
- ];
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册命令
- $this->commands([
- Commands\UpdateCropGrowthCommand::class,
- Commands\GenerateDisastersCommand::class,
- Commands\CheckHouseDowngradeCommand::class,
- Commands\CleanExpiredLogsCommand::class,
- Commands\GenerateFarmHouseConfigJson::class,
- Commands\GenerateFarmShrineConfigJson::class,
- Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
- Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class,
- Commands\InitializeUserLandsCommand::class
- ]);
- }
- /**
- * 引导服务
- *
- * @return void
- */
- public function boot()
- {
- $events = $this->app['events'];
- foreach ($this->listen as $event => $listeners) {
- foreach ($listeners as $listener) {
- $events->listen($event, $listener);
- }
- }
- // 注册定时任务监听器
- // $this->app->booted(function () {
- // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
- //
- //
- // // 每小时随机生成灾害
- // $schedule->command('farm:generate-disasters')->hourly();
- //
- //
- // // 达人等级更新已移至Team模块
- //
- // // 每周一凌晨4点清理过期日志
- // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
- //
- // // 每天凌晨5点重建缓存
- // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
- // });
- }
- }
|