TestPlayerDataHandler.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\AppGame\Handler\Public\PlayerDataHandler;
  4. use Illuminate\Console\Command;
  5. use Uraus\Kku\Request\RequestPublicPlayerData;
  6. use Uraus\Kku\Response;
  7. class TestPlayerDataHandler extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'test:player-data-handler {user_id=1}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '测试玩家数据Handler';
  21. /**
  22. * Execute the console command.
  23. */
  24. public function handle()
  25. {
  26. $userId = (int) $this->argument('user_id');
  27. $this->info("开始测试PlayerDataHandler,用户ID: {$userId}");
  28. // 创建测试请求
  29. $request = new RequestPublicPlayerData();
  30. $request->setUserId($userId);
  31. // 创建响应对象
  32. $response = new Response();
  33. // 创建Handler实例
  34. $handler = new PlayerDataHandler($response);
  35. // 模拟登录状态
  36. $handler->user_id = $userId;
  37. try {
  38. // 执行Handler
  39. $result = $handler->handle($request);
  40. $this->info("Handler执行成功!");
  41. $this->info("响应类型: " . get_class($result));
  42. // 检查用户信息
  43. if ($result->hasUserInfo()) {
  44. $userInfo = $result->getUserInfo();
  45. $this->info("=== 用户信息 ===");
  46. $this->info("用户ID: " . $userInfo->getUserD());
  47. $this->info("皮肤ID: " . $userInfo->getSkinId());
  48. $this->info("头像: " . $userInfo->getAvatar());
  49. $this->info("昵称: " . $userInfo->getNickName());
  50. } else {
  51. $this->warn("未获取到用户信息");
  52. }
  53. // 检查神像信息
  54. $godsInfo = $result->getGodsInfo();
  55. $this->info("=== 神像信息 ===");
  56. $this->info("神像数量: " . count($godsInfo));
  57. foreach ($godsInfo as $god) {
  58. $this->info("神像ID: " . $god->getId() . ", 状态: " . ($god->getStatus() ? '激活' : '未激活'));
  59. }
  60. // 检查土地信息
  61. $landInfo = $result->getLandInfo();
  62. $this->info("=== 土地信息 ===");
  63. $this->info("土地数量: " . count($landInfo));
  64. foreach ($landInfo as $land) {
  65. $this->info("土地ID: " . $land->getId() . ", 位置: " . $land->getIndex() . ", 等级: " . $land->getLevel() . ", 状态: " . $land->getStatus());
  66. if ($land->getSeedId() > 0) {
  67. $this->info(" - 种子ID: " . $land->getSeedId());
  68. $this->info(" - 果实ID: " . $land->getFruitId());
  69. $this->info(" - 植株ID: " . $land->getPlantId());
  70. $this->info(" - 种子状态: " . $land->getSeedStatus());
  71. $this->info(" - 种植时间: " . date('Y-m-d H:i:s', $land->getSeedPlantingTimes()));
  72. $this->info(" - 阶段开始时间: " . date('Y-m-d H:i:s', $land->getStageStartTimes()));
  73. $this->info(" - 阶段结束时间: " . date('Y-m-d H:i:s', $land->getStageNextTimes()));
  74. }
  75. }
  76. // 检查宠物信息
  77. if ($result->hasPetInfo()) {
  78. $petInfo = $result->getPetInfo();
  79. $this->info("=== 宠物信息 ===");
  80. $this->info("宠物种族ID: " . $petInfo->getTypeId());
  81. $this->info("宠物名称: " . $petInfo->getName());
  82. $this->info("宠物等级: " . $petInfo->getLevel());
  83. $this->info("宠物体力: " . $petInfo->getPower());
  84. } else {
  85. $this->info("=== 宠物信息 ===");
  86. $this->info("用户没有宠物");
  87. }
  88. $this->info("测试完成!");
  89. } catch (\Exception $e) {
  90. $this->error("Handler执行失败: " . $e->getMessage());
  91. $this->error("错误堆栈: " . $e->getTraceAsString());
  92. }
  93. }
  94. }