argument('stealer_id'); $targetId = (int) $this->argument('target_id'); $landId = (int) $this->argument('land_id'); $petId = (int) $this->argument('pet_id'); $this->info("开始测试偷菜功能"); $this->info("偷菜者ID: {$stealerId}"); $this->info("被偷者ID: {$targetId}"); $this->info("土地ID: {$landId}"); $this->info("宠物ID: {$petId}"); $this->line(''); try { // 获取作物ID $crop = FarmCrop::where('land_id', $landId)->first(); if (!$crop) { $this->error("土地上没有作物"); return 1; } $plantId = $crop->id; $this->info("作物ID: {$plantId}"); $this->line(''); // 1. 显示偷菜前的状态 $this->showPreStealStatus($stealerId, $targetId, $landId); // 2. 检查是否可以偷菜 $canStealResult = PetStealService::canSteal($stealerId, $targetId, $landId); $this->info("偷菜检查结果:"); $this->line(" 可以偷菜: " . ($canStealResult['can_steal'] ? '是' : '否')); if (!$canStealResult['can_steal']) { $this->line(" 原因: " . $canStealResult['reason']); return 1; } $this->line(''); // 3. 执行偷菜 $this->info("执行偷菜操作..."); $result = PetStealService::stealCrop($stealerId, $targetId, $plantId, $petId); // 4. 显示偷菜结果 $this->showStealResult($result); // 5. 显示偷菜后的状态 $this->showPostStealStatus($stealerId, $targetId, $landId); $this->info("偷菜测试完成!"); return 0; } catch (\Exception $e) { $this->error("偷菜测试失败: " . $e->getMessage()); return 1; } } /** * 显示偷菜前的状态 * * @param int $stealerId 偷菜者ID * @param int $targetId 被偷者ID * @param int $landId 土地ID */ private function showPreStealStatus(int $stealerId, int $targetId, int $landId): void { $this->info("偷菜前状态:"); // 偷菜者宠物状态 $stealerPet = PetUser::where('user_id', $stealerId)->first(); if ($stealerPet) { $this->line(" 偷菜者宠物: 等级{$stealerPet->level}, 体力{$stealerPet->stamina}, 状态{$stealerPet->status->name}"); } else { $this->line(" 偷菜者宠物: 无"); } // 被偷者宠物状态 $targetPet = PetUser::where('user_id', $targetId)->first(); if ($targetPet) { $this->line(" 被偷者宠物: 等级{$targetPet->level}, 体力{$targetPet->stamina}, 状态{$targetPet->status->name}"); } else { $this->line(" 被偷者宠物: 无"); } // 土地和作物状态 $land = FarmLand::find($landId); if ($land) { $crop = FarmCrop::where('land_id', $landId)->first(); if ($crop) { $this->line(" 作物状态: {$crop->growth_stage->name}, 可摘取数量: {$crop->pickable_amount}"); } else { $this->line(" 作物状态: 无作物"); } } else { $this->line(" 土地状态: 土地不存在"); } // 偷菜次数 $stealInfo = PetStealService::getStealInfo($landId); $this->line(" 已被偷次数: {$stealInfo['successful_steal_count']}/5"); $this->line(''); } /** * 显示偷菜结果 * * @param \App\Module\Pet\Dtos\StealResultDto $result 偷菜结果 */ private function showStealResult($result): void { $this->info("偷菜结果:"); $this->line(" 偷菜成功: " . ($result->success ? '是' : '否')); $this->line(" 被防御: " . ($result->defended ? '是' : '否')); $this->line(" 偷取数量: {$result->stealAmount}"); $this->line(" 偷菜者体力消耗: {$result->stealerStaminaCost}"); $this->line(" 被偷者体力消耗: {$result->targetStaminaCost}"); if ($result->itemId) { $this->line(" 获得物品ID: {$result->itemId}"); } if ($result->failReason) { $this->line(" 失败原因: {$result->failReason}"); } $this->line(" 偷菜日志ID: {$result->stealLogId}"); $this->line(''); } /** * 显示偷菜后的状态 * * @param int $stealerId 偷菜者ID * @param int $targetId 被偷者ID * @param int $landId 土地ID */ private function showPostStealStatus(int $stealerId, int $targetId, int $landId): void { $this->info("偷菜后状态:"); // 偷菜者宠物状态 $stealerPet = PetUser::where('user_id', $stealerId)->first(); if ($stealerPet) { $this->line(" 偷菜者宠物: 等级{$stealerPet->level}, 体力{$stealerPet->stamina}, 状态{$stealerPet->status->name}"); } // 被偷者宠物状态 $targetPet = PetUser::where('user_id', $targetId)->first(); if ($targetPet) { $this->line(" 被偷者宠物: 等级{$targetPet->level}, 体力{$targetPet->stamina}, 状态{$targetPet->status->name}"); } // 作物状态 $crop = FarmCrop::where('land_id', $landId)->first(); if ($crop) { $this->line(" 作物状态: {$crop->growth_stage->name}, 可摘取数量: {$crop->pickable_amount}"); } // 偷菜次数 $stealInfo = PetStealService::getStealInfo($landId); $this->line(" 已被偷次数: {$stealInfo['successful_steal_count']}/5"); // 偷菜统计 $stealerStats = PetStealService::getStealStats($stealerId); $targetStats = PetStealService::getStealStats($targetId); $this->line(" 偷菜者今日偷菜次数: {$stealerStats['today']['steal_count']}"); $this->line(" 被偷者今日被偷次数: {$targetStats['today']['being_stolen_count']}"); $this->line(''); } }