Selaa lähdekoodia

feat(Pet): 添加宠物技能到期时间并优化升级逻辑

- 在 PetLifeSkillDto 和 protobuf 中添加技能到期时间字段
- 优化宠物升级逻辑,处理解锁技能的旧配置问题
- 修改物品数量验证错误提示,增加物品 ID- 更新生成时间戳
notfff 7 kuukautta sitten
vanhempi
commit
5039bed1bf

+ 2 - 0
app/Module/AppGame/Proto/PetDataDto.php

@@ -43,6 +43,8 @@ class PetDataDto
 //                $petLifeSkill->setCanuse($skill->canuse ?? false); // 不再处理
                 $petLifeSkill->setCurnum($skill->curnum ?? 0);
                 $petLifeSkill->setMaxnum($skill->maxnum ?? 0);
+                $petLifeSkill->setEndTimes($skill->end_times ?? 0);
+
                 $lifeSkills[] = $petLifeSkill;
             }
             $dataPet->setLifeSkills($lifeSkills);

+ 1 - 1
app/Module/GameItems/Validators/ItemQuantityValidator.php

@@ -77,7 +77,7 @@ class ItemQuantityValidator extends Validator
                 // 只验证普通物品数量
                 $normalQuantity = ItemQuantity::getUserItemQuantity($userId, $itemId);
                 if ($normalQuantity < $quantity) {
-                    $this->addError("普通物品数量不足,需要{$quantity}个,但只有{$normalQuantity}个");
+                    $this->addError("普通物品 $itemId 数量不足,需要{$quantity}个,但只有{$normalQuantity}个");
                     return false;
                 }
                 return true;

+ 8 - 0
app/Module/Pet/Dtos/PetLifeSkillDto.php

@@ -35,4 +35,12 @@ class PetLifeSkillDto extends BaseDto
      * @var int
      */
     public int $maxnum = 0;
+
+    /**
+     * 结束时间
+     *
+     * @var int $end_times
+     */
+    public int $end_times = 0;
+
 }

+ 8 - 2
app/Module/Pet/Factories/PetDtoFactory.php

@@ -94,11 +94,16 @@ class PetDtoFactory
 
         $skillDtos = [];
         foreach ($availableSkills as $skill) {
+            $skillDto = new PetLifeSkillDto();
+
             $curnum = 0; // 当前剩余时间(激活技能的剩余时间)
             $maxnum = 0; // 最大时间(激活技能的持续时间)
 
             // 检查是否有激活的技能
             if (isset($activeSkills[$skill->id])) {
+                /**
+                 * @var \App\Module\Pet\Models\PetActiveSkill $activeSkill
+                 */
                 $activeSkill = $activeSkills[$skill->id];
                 $now = now();
 
@@ -108,17 +113,18 @@ class PetDtoFactory
                     $curnum = $remainingSeconds; // 剩余激活时间
                     $maxnum = $skill->duration_time; // 技能持续时间
                 }
+                $skillDto->end_times = $activeSkill->end_time->getTimestamp();
+
             }
 
 
 
 
-            $skillDto = new PetLifeSkillDto();
             $skillDto->skillId = $skill->id;
 //            $skillDto->canuse = $canUse; // 不再处理
             $skillDto->curnum = $curnum; // 激活技能的剩余时间
             $skillDto->maxnum = $maxnum; // 激活技能的持续时间
-
+//            $
             $skillDtos[] = $skillDto;
         }
 

+ 16 - 2
app/Module/Pet/Logic/PetLogic.php

@@ -22,6 +22,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use UCore\Dto\Res;
 use UCore\Exception\LogicException;
+use UCore\Helper\Logger;
 use Uraus\Kku\Common\DataPetSimple;
 
 /**
@@ -154,6 +155,7 @@ class PetLogic
         $change = false;
         // 记录旧等级
         $oldLevel = $pet->level;
+        $nextLevelConfigOld = null;
         foreach (range(1, 20) as $level) {
 
             // 获取当前等级配置
@@ -165,6 +167,7 @@ class PetLogic
             // 获取下一级配置
             $nextLevelConfig = PetLevelConfig::where('level', $pet->level + 1)->first();
             if (!$nextLevelConfig) {
+
                 break;
             }
             if($pet->experience < $nextLevelConfig->exp_required){
@@ -182,6 +185,8 @@ class PetLogic
                 $pet->max_experience = 0;
             }
             $change = true;
+            $nextLevelConfigOld = $nextLevelConfig;
+
 
         }
         if ($change) {
@@ -191,9 +196,18 @@ class PetLogic
 
             // 获取新解锁的技能
             $unlockedSkills = [];
-            if ($nextLevelConfig->unlock_skills) {
-                $unlockedSkills = json_decode($nextLevelConfig->unlock_skills, true);
+
+            if($nextLevelConfig){
+                if ($nextLevelConfig->unlock_skills) {
+                    $unlockedSkills = json_decode($nextLevelConfig->unlock_skills, true);
+                }
             }
+            if($nextLevelConfigOld){
+                if ($nextLevelConfigOld->unlock_skills) {
+                    $unlockedSkills = json_decode($nextLevelConfigOld->unlock_skills, true);
+                }
+            }
+
 
             // 触发宠物升级事件
             event(new PetLevelUpEvent(

+ 1 - 1
config/proto_route.php

@@ -90,7 +90,7 @@ return array (
       7 => 'query_data',
     ),
   ),
-  'generated_at' => '+08:00 2025-06-07 16:21:50',
+  'generated_at' => '+08:00 2025-06-07 18:28:35',
   'conventions' => 
   array (
     'handler_namespace' => 'App\\Module\\AppGame\\Handler',

+ 5 - 4
protophp/GPBMetadata/Proto/Game.php

@@ -16,7 +16,7 @@ class Game
         }
         $pool->internalAddGeneratedFile(
             '
-Ÿ
+Ÿ
 proto/game.proto	uraus.kku"„4
 Request
 request_unid (	;
@@ -477,7 +477,7 @@ last_times (
 APPLYING	
 AGREE
 
-REFUSE"ã-
+REFUSE"ö-
 Common)
 KeyValue
 kname (	
@@ -642,12 +642,13 @@ DataHourse
 skill_id (
 canuse (
 curnum (
-maxnum (P
+maxnum (c
 PetLifeSkill
 skill_id (
 canuse (
 curnum (
-maxnum (2
+maxnum (
+	end_times (2
 StreamerMessage
 message (	
 remain (‰

+ 34 - 0
protophp/Uraus/Kku/Common/PetLifeSkill.php

@@ -39,6 +39,12 @@ class PetLifeSkill extends \Google\Protobuf\Internal\Message
      * Generated from protobuf field <code>int64 maxnum = 4;</code>
      */
     protected $maxnum = 0;
+    /**
+     * 技能到期 时间戳
+     *
+     * Generated from protobuf field <code>int64 end_times = 5;</code>
+     */
+    protected $end_times = 0;
 
     /**
      * Constructor.
@@ -54,6 +60,8 @@ class PetLifeSkill extends \Google\Protobuf\Internal\Message
      *          剩余时间
      *     @type int|string $maxnum
      *          技能最大时间
+     *     @type int|string $end_times
+     *           技能到期 时间戳
      * }
      */
     public function __construct($data = NULL) {
@@ -165,6 +173,32 @@ class PetLifeSkill extends \Google\Protobuf\Internal\Message
         return $this;
     }
 
+    /**
+     * 技能到期 时间戳
+     *
+     * Generated from protobuf field <code>int64 end_times = 5;</code>
+     * @return int|string
+     */
+    public function getEndTimes()
+    {
+        return $this->end_times;
+    }
+
+    /**
+     * 技能到期 时间戳
+     *
+     * Generated from protobuf field <code>int64 end_times = 5;</code>
+     * @param int|string $var
+     * @return $this
+     */
+    public function setEndTimes($var)
+    {
+        GPBUtil::checkInt64($var);
+        $this->end_times = $var;
+
+        return $this;
+    }
+
 }
 
 // Adding a class alias for backwards compatibility with the previous class name.