Forráskód Böngészése

修复宠物技能使用数据临时存储错误:创建PetGrade枚举并修复PetDtoFactory属性访问问题

notfff 7 hónapja
szülő
commit
cb640c420d

+ 16 - 0
app/Module/Pet/Enums/PetGrade.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Module\Pet\Enums;
+
+/**
+ * 宠物品阶枚举
+ *
+ * 定义宠物可能的品阶值,用于表示宠物的品质等级
+ */
+enum PetGrade: int
+{
+    case FIRST = 1;     // 一品
+    case SECOND = 2;    // 二品
+    case THIRD = 3;     // 三品
+    case FOURTH = 4;    // 四品
+}

+ 7 - 5
app/Module/Pet/Factories/PetDtoFactory.php

@@ -28,7 +28,7 @@ class PetDtoFactory
         // 创建宠物DTO
         $petDto = new PetDataDto();
         $petDto->id = $pet->id;
-        $petDto->type_id = $pet->type_id ?? 0; // 如果模型中没有type_id字段,默认为0
+        $petDto->typeId = $pet->type_id ?? 0; // 如果模型中没有type_id字段,默认为0
         $petDto->name = $pet->name;
         $petDto->level = $pet->level;
         $petDto->exp = $pet->experience;
@@ -47,15 +47,17 @@ class PetDtoFactory
             $fightingCapacity = $petLogic->calculatePower($pet->id);
         }
 
-        $petDto->fighting_capacity = $fightingCapacity;
+        $petDto->fightingCapacity = $fightingCapacity;
         $petDto->score = $fightingCapacity; // 暂时使用战力作为评分
 
         // 设置品阶和状态
-        $petDto->grade = $pet->grade->value;
+        // grade字段在数据库中是integer,直接使用
+        $petDto->grade = $pet->grade;
+        // status字段被转换为PetStatus枚举,需要获取value
         $petDto->status = $pet->status->value;
 
         // 获取宠物生活技能
-        $petDto->life_skills = self::createPetLifeSkillDtos($pet);
+        $petDto->lifeSkills = self::createPetLifeSkillDtos($pet);
 
         return $petDto;
     }
@@ -117,7 +119,7 @@ class PetDtoFactory
             }
 
             $skillDto = new PetLifeSkillDto();
-            $skillDto->skill_id = $skill->id;
+            $skillDto->skillId = $skill->id;
             $skillDto->canuse = $canUse;
             $skillDto->curnum = $cooldownRemaining;
             $skillDto->maxnum = $skill->cool_down;