|
|
@@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Log;
|
|
|
*/
|
|
|
class GeneratePetJsonCommand extends Command
|
|
|
{
|
|
|
+
|
|
|
/**
|
|
|
* 命令名称和签名
|
|
|
*
|
|
|
@@ -37,7 +38,7 @@ class GeneratePetJsonCommand extends Command
|
|
|
* @param bool $saveToFile 是否保存到文件
|
|
|
* @return array 生成的数据
|
|
|
*/
|
|
|
- public static function generateJson(bool $saveToFile = true)
|
|
|
+ public static function generateJson()
|
|
|
{
|
|
|
try {
|
|
|
// 生成宠物基础配置JSON
|
|
|
@@ -49,26 +50,21 @@ class GeneratePetJsonCommand extends Command
|
|
|
// 生成宠物技能配置JSON
|
|
|
$petSkillConfigData = self::generatePetSkillConfigJson();
|
|
|
|
|
|
- // 如果需要保存到文件
|
|
|
- if ($saveToFile) {
|
|
|
- self::saveJsonToFile('pet_config.json', $petConfigData);
|
|
|
- self::saveJsonToFile('pet_level_config.json', $petLevelConfigData);
|
|
|
- self::saveJsonToFile('pet_skill_config.json', $petSkillConfigData);
|
|
|
- }
|
|
|
|
|
|
// 返回所有配置数据
|
|
|
return [
|
|
|
- 'pet_config' => $petConfigData,
|
|
|
+ 'pet_config' => $petConfigData,
|
|
|
'pet_level_config' => $petLevelConfigData,
|
|
|
'pet_skill_config' => $petSkillConfigData,
|
|
|
- 'success' => true
|
|
|
+ 'success' => true,
|
|
|
+ 'generated_ts' => time()
|
|
|
];
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Generate pet JSON failed: ' . $e->getMessage());
|
|
|
|
|
|
return [
|
|
|
'success' => false,
|
|
|
- 'error' => $e->getMessage()
|
|
|
+ 'error' => $e->getMessage()
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
@@ -82,9 +78,9 @@ class GeneratePetJsonCommand extends Command
|
|
|
$petConfigs = PetConfig::all()
|
|
|
->map(function ($config) {
|
|
|
return [
|
|
|
- 'id' => $config->id,
|
|
|
- 'pet_type' => $config->pet_type,
|
|
|
- 'grade_probability' => $config->grade_probability,
|
|
|
+ 'id' => $config->id,
|
|
|
+ 'pet_type' => $config->pet_type,
|
|
|
+ 'grade_probability' => $config->grade_probability,
|
|
|
'display_attributes' => $config->display_attributes,
|
|
|
'numeric_attributes' => $config->numeric_attributes
|
|
|
];
|
|
|
@@ -94,7 +90,7 @@ class GeneratePetJsonCommand extends Command
|
|
|
// 准备完整数据,包含生成时间
|
|
|
return [
|
|
|
'generated_ts' => time(),
|
|
|
- 'pets' => $petConfigs
|
|
|
+ 'pets' => $petConfigs
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -108,9 +104,9 @@ class GeneratePetJsonCommand extends Command
|
|
|
->get()
|
|
|
->map(function ($config) {
|
|
|
return [
|
|
|
- 'level' => $config->level,
|
|
|
- 'exp_required' => $config->exp_required,
|
|
|
- 'skills' => $config->skills,
|
|
|
+ 'level' => $config->level,
|
|
|
+ 'exp_required' => $config->exp_required,
|
|
|
+ 'skills' => $config->skills,
|
|
|
'display_attributes' => $config->display_attributes,
|
|
|
'numeric_attributes' => $config->numeric_attributes
|
|
|
];
|
|
|
@@ -120,7 +116,7 @@ class GeneratePetJsonCommand extends Command
|
|
|
// 准备完整数据,包含生成时间
|
|
|
return [
|
|
|
'generated_ts' => time(),
|
|
|
- 'pet_levels' => $petLevelConfigs
|
|
|
+ 'pet_levels' => $petLevelConfigs
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -133,12 +129,12 @@ class GeneratePetJsonCommand extends Command
|
|
|
$petSkills = PetSkill::all()
|
|
|
->map(function ($skill) {
|
|
|
return [
|
|
|
- 'id' => $skill->id,
|
|
|
- 'skill_name' => $skill->skill_name,
|
|
|
+ 'id' => $skill->id,
|
|
|
+ 'skill_name' => $skill->skill_name,
|
|
|
'stamina_cost' => $skill->stamina_cost,
|
|
|
- 'cool_down' => $skill->cool_down,
|
|
|
- 'effect_desc' => $skill->effect_desc,
|
|
|
- 'min_level' => $skill->min_level
|
|
|
+ 'cool_down' => $skill->cool_down,
|
|
|
+ 'effect_desc' => $skill->effect_desc,
|
|
|
+ 'min_level' => $skill->min_level
|
|
|
];
|
|
|
})
|
|
|
->toArray();
|
|
|
@@ -146,38 +142,11 @@ class GeneratePetJsonCommand extends Command
|
|
|
// 准备完整数据,包含生成时间
|
|
|
return [
|
|
|
'generated_ts' => time(),
|
|
|
- 'pet_skills' => $petSkills
|
|
|
+ 'pet_skills' => $petSkills
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 将JSON数据保存到文件
|
|
|
- *
|
|
|
- * @param string $filename 文件名
|
|
|
- * @param array $data 要保存的数据
|
|
|
- * @return bool 是否保存成功
|
|
|
- */
|
|
|
- protected static function saveJsonToFile(string $filename, array $data): bool
|
|
|
- {
|
|
|
- try {
|
|
|
- // 确保目录存在
|
|
|
- $directory = 'public/json';
|
|
|
- if (!file_exists($directory)) {
|
|
|
- mkdir($directory, 0755, true);
|
|
|
- }
|
|
|
-
|
|
|
- // 将数据保存为JSON文件
|
|
|
- $jsonContent = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
|
- $filePath = $directory . '/' . $filename;
|
|
|
- file_put_contents($filePath, $jsonContent);
|
|
|
-
|
|
|
- Log::info('Pet JSON file saved to: ' . $filePath);
|
|
|
- return true;
|
|
|
- } catch (\Exception $e) {
|
|
|
- Log::error('Save pet JSON to file failed: ' . $e->getMessage());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 执行命令
|
|
|
@@ -195,9 +164,9 @@ class GeneratePetJsonCommand extends Command
|
|
|
$this->info('Pet configs: ' . count($result['pet_config']['pets']));
|
|
|
$this->info('Pet level configs: ' . count($result['pet_level_config']['pet_levels']));
|
|
|
$this->info('Pet skill configs: ' . count($result['pet_skill_config']['pet_skills']));
|
|
|
- $this->info('JSON files saved to public/json/ directory');
|
|
|
} else {
|
|
|
$this->error('Failed to generate pet configuration JSON files: ' . $result['error']);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|