| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Console\Commands;
- use App\Module\AppGame\Handler\Public\PlayerDataHandler;
- use Illuminate\Console\Command;
- use Uraus\Kku\Request\RequestPublicPlayerData;
- use Uraus\Kku\Response;
- class TestPlayerDataHandler extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'test:player-data-handler {user_id=1}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '测试玩家数据Handler';
- /**
- * Execute the console command.
- */
- public function handle()
- {
- $userId = (int) $this->argument('user_id');
-
- $this->info("开始测试PlayerDataHandler,用户ID: {$userId}");
-
- // 创建测试请求
- $request = new RequestPublicPlayerData();
- $request->setUserId($userId);
- // 创建响应对象
- $response = new Response();
- // 创建Handler实例
- $handler = new PlayerDataHandler($response);
- // 模拟登录状态
- $handler->user_id = $userId;
- try {
- // 执行Handler
- $result = $handler->handle($request);
-
- $this->info("Handler执行成功!");
- $this->info("响应类型: " . get_class($result));
-
- // 检查用户信息
- if ($result->hasUserInfo()) {
- $userInfo = $result->getUserInfo();
- $this->info("=== 用户信息 ===");
- $this->info("用户ID: " . $userInfo->getUserD());
- $this->info("皮肤ID: " . $userInfo->getSkinId());
- $this->info("头像: " . $userInfo->getAvatar());
- $this->info("昵称: " . $userInfo->getNickName());
- } else {
- $this->warn("未获取到用户信息");
- }
-
- // 检查神像信息
- $godsInfo = $result->getGodsInfo();
- $this->info("=== 神像信息 ===");
- $this->info("神像数量: " . count($godsInfo));
- foreach ($godsInfo as $god) {
- $this->info("神像ID: " . $god->getId() . ", 状态: " . ($god->getStatus() ? '激活' : '未激活'));
- }
-
- // 检查土地信息
- $landInfo = $result->getLandInfo();
- $this->info("=== 土地信息 ===");
- $this->info("土地数量: " . count($landInfo));
- foreach ($landInfo as $land) {
- $this->info("土地ID: " . $land->getId() . ", 位置: " . $land->getIndex() . ", 等级: " . $land->getLevel() . ", 状态: " . $land->getStatus());
- if ($land->getSeedId() > 0) {
- $this->info(" - 种子ID: " . $land->getSeedId());
- $this->info(" - 果实ID: " . $land->getFruitId());
- $this->info(" - 植株ID: " . $land->getPlantId());
- $this->info(" - 种子状态: " . $land->getSeedStatus());
- $this->info(" - 种植时间: " . date('Y-m-d H:i:s', $land->getSeedPlantingTimes()));
- $this->info(" - 阶段开始时间: " . date('Y-m-d H:i:s', $land->getStageStartTimes()));
- $this->info(" - 阶段结束时间: " . date('Y-m-d H:i:s', $land->getStageNextTimes()));
- }
- }
- // 检查宠物信息
- if ($result->hasPetInfo()) {
- $petInfo = $result->getPetInfo();
- $this->info("=== 宠物信息 ===");
- $this->info("宠物种族ID: " . $petInfo->getTypeId());
- $this->info("宠物名称: " . $petInfo->getName());
- $this->info("宠物等级: " . $petInfo->getLevel());
- $this->info("宠物体力: " . $petInfo->getPower());
- } else {
- $this->info("=== 宠物信息 ===");
- $this->info("用户没有宠物");
- }
-
- $this->info("测试完成!");
-
- } catch (\Exception $e) {
- $this->error("Handler执行失败: " . $e->getMessage());
- $this->error("错误堆栈: " . $e->getTraceAsString());
- }
- }
- }
|