| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Module\GameItems\Providers;
- use App\Module\GameItems\Events\ItemQuantityChanged;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Support\ServiceProvider;
- /**
- * 物品模块服务提供者
- *
- * 负责注册物品模块的服务、命令、事件监听器等
- * 此类是物品模块与Laravel框架集成的核心
- */
- class GameItemsServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- *
- * 在此方法中注册物品模块的服务容器绑定
- * 此方法在应用启动早期被调用,适合注册服务但不适合使用任何服务
- *
- * @return void
- */
- public function register()
- {
- }
- /**
- * 引导服务
- *
- * 在所有服务提供者被注册后调用,可以使用已注册的服务
- * 负责注册命令、事件监听器等
- *
- * @return void
- */
- public function boot()
- {
- if ($this->app->runningInConsole()) {
- $this->commands([
- \App\Module\GameItems\Commands\GenerateItemsJsonCommand::class, // 生成物品JSON数据命令
- \App\Module\GameItems\Commands\GenerateRecipeJsonCommand::class, // 生成 合成配方 JSON数据命令
- \App\Module\GameItems\Commands\GenerateChestJsonCommand::class, // 生成宝箱JSON数据命令
- \App\Module\GameItems\Console\Commands\UpdateChestDatabaseCommand::class, // 更新宝箱数据库结构命令
- \App\Module\GameItems\Console\Commands\MigrateChestToGroupSystemCommand::class, // 宝箱系统迁移命令
- ]);
- }
- // 注册事件监听器
- $this->registerEventListeners();
- }
- /**
- * 注册事件监听器
- *
- * 注册物品模块的所有事件监听器
- * 包括物品获取、消耗、数量变更等事件的监听器
- *
- * @return void
- */
- protected function registerEventListeners()
- {
- // 物品数量变更事件监听器示例
- // 取消注释以启用此监听器
- // Event::listen(ItemQuantityChanged::class, function (ItemQuantityChanged $event) {
- // // 在这里处理物品数量变更事件
- // // 可以用于更新任务进度、触发成就、记录日志等
- // \Log::info('物品数量变更', [
- // 'user_id' => $event->userId,
- // 'item_id' => $event->itemId,
- // 'old_quantity' => $event->oldQuantity,
- // 'new_quantity' => $event->newQuantity,
- // 'change_amount' => $event->changeAmount,
- // ]);
- // });
- }
- }
|