Your Name 8 mesi fa
parent
commit
fbf06f65e9

+ 0 - 59
app/Module/GameItems/Casts/DisplayAttributesCast.php

@@ -16,64 +16,5 @@ class DisplayAttributesCast extends \UCore\Model\CastsAttributes
     public string $img = ' ';
 
 
-    /**
-     * 将给定的值转换为存储格式
-     *
-     * @param Model $model
-     * @param string $key
-     * @param mixed $value
-     * @param array $attributes
-     * @return string|null
-     */
-    public function set($model, string $key, $value, array $attributes)
-    {
-        if (is_null($value)) {
-            return json_encode([], JSON_UNESCAPED_UNICODE);
-        }
-
-        if (is_array($value)) {
-            // 确保所有值都是字符串类型
-            $sanitized = [];
-            foreach ($value as $k => $v) {
-                $sanitized[$k] = (string)$v;
-            }
-
-            return json_encode($sanitized, JSON_UNESCAPED_UNICODE);
-        }
-
-        if (is_string($value) && $this->isJson($value)) {
-            // 如果已经是JSON字符串,确保解码后的值都是字符串类型
-            $decoded = json_decode($value, true);
-            if (is_array($decoded)) {
-                $sanitized = [];
-                foreach ($decoded as $k => $v) {
-                    $sanitized[$k] = (string)$v;
-                }
-
-                return json_encode($sanitized, JSON_UNESCAPED_UNICODE);
-            }
-
-            return $value;
-        }
-
-        return json_encode([], JSON_UNESCAPED_UNICODE);
-    }
-
-    /**
-     * 判断字符串是否为有效的JSON
-     *
-     * @param string $value
-     * @return bool
-     */
-    protected function isJson($value)
-    {
-        if (!is_string($value)) {
-            return false;
-        }
-
-        json_decode($value);
-
-        return json_last_error() === JSON_ERROR_NONE;
-    }
 
 }

+ 2 - 15
app/Module/Pet/AdminControllers/Helper/FormHelperTrait.php

@@ -23,19 +23,6 @@ trait FormHelperTrait
             ->model($table->getModel(), $table->getModelSelectId(), $table->getModelViewName()); // 设置编辑数据显示
     }
 
-    /**
-     * 宠物属性JSON编辑器
-     * 
-     * @param $field
-     * @param $label
-     * @return \Dcat\Admin\Form\Field\Embeds
-     */
-    public function embedsCats($field, $label = null)
-    {
-        return $this->form->embeds($field, $label, function ($form) {
-            $form->text('key1', '属性1')->default('');
-            $form->text('key2', '属性2')->default('');
-            $form->text('key3', '属性3')->default('');
-        });
-    }
+
+
 }

+ 9 - 10
app/Module/Pet/AdminControllers/PetSkillController.php

@@ -41,7 +41,9 @@ class PetSkillController extends AdminController
             $grid->column('id', 'ID')->sortable();
             $grid->column('skill_name', '技能名称');
             $grid->column('stamina_cost', '体力消耗')->sortable();
+            $grid->column('duration_time', ' 持续时间(秒)')->sortable();
             $grid->column('cool_down', '冷却时间(秒)')->sortable();
+
             $grid->column('effect_desc', '效果描述');
             $grid->column('min_level', '最低等级要求')->sortable();
             $grid->column('created_at', '创建时间');
@@ -74,12 +76,13 @@ class PetSkillController extends AdminController
      */
     protected function detail($id)
     {
-        return Show::make($id, new PetSkillRepository(['usageLogs']), function (Show $show) {
+        return Show::make($id, new PetSkillRepository(), function (Show $show) {
             $helper = new ShowHelper($show, $this);
             $helper->field('id', 'ID');
             $show->field('skill_name', '技能名称');
             $show->field('stamina_cost', '体力消耗');
             $show->field('cool_down', '冷却时间(秒)');
+            $show->field('duration_time', '持续时间(秒)');
             $show->field('effect_desc', '效果描述');
             $show->field('min_level', '最低等级要求');
             $show->field('created_at', '创建时间');
@@ -88,15 +91,6 @@ class PetSkillController extends AdminController
             // 禁用删除按钮
             $show->disableDeleteButton();
 
-            // 显示技能使用记录
-            $show->usageLogs('技能使用记录', function ($usageLogs) {
-                $usageLogs->resource('/admin/pet-skill-logs');
-                $usageLogs->id('ID');
-                $usageLogs->pet()->name('宠物名称');
-                $usageLogs->used_at('使用时间');
-                $usageLogs->effect_result('效果结果')->json();
-            });
-
             return $show;
         });
     }
@@ -125,6 +119,11 @@ class PetSkillController extends AdminController
                 ->min(0)
                 ->required()
                 ->help('技能使用后的冷却时间,单位:秒');
+            $form->number('duration_time', '持续时间(秒)')
+                ->default(3600)
+                ->min(0)
+                ->required()
+                ->help('技能使用后的持续时间,单位:秒');
 
             $form->textarea('effect_desc', '效果描述')
                 ->help('技能效果的详细描述');

+ 5 - 45
app/Module/Pet/Casts/DisplayAttributesCast.php

@@ -2,52 +2,12 @@
 
 namespace App\Module\Pet\Casts;
 
-use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
-use Illuminate\Database\Eloquent\Model;
 
-class DisplayAttributesCast implements CastsAttributes
+use UCore\Model\CastsAttributes;
+
+class DisplayAttributesCast extends CastsAttributes
 {
-    /**
-     * 将取出的数据转换为对应的类型
-     *
-     * @param  Model  $model
-     * @param  string  $key
-     * @param  mixed  $value
-     * @param  array  $attributes
-     * @return mixed
-     */
-    public function get($model, string $key, $value, array $attributes)
-    {
-        if (empty($value)) {
-            return (object) [];
-        }
-        
-        return json_decode($value);
-    }
 
-    /**
-     * 转换成将要存储到数据库中的值
-     *
-     * @param  Model  $model
-     * @param  string  $key
-     * @param  mixed  $value
-     * @param  array  $attributes
-     * @return mixed
-     */
-    public function set($model, string $key, $value, array $attributes)
-    {
-        if (empty($value)) {
-            return null;
-        }
-        
-        if (is_array($value)) {
-            return json_encode($value);
-        }
-        
-        if (is_object($value)) {
-            return json_encode($value);
-        }
-        
-        return $value;
-    }
+
+
 }

+ 47 - 0
app/Module/Pet/Casts/GradeProbability.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Module\Pet\Casts;
+
+use UCore\Model\CastsAttributes;
+
+class GradeProbability extends CastsAttributes
+{
+
+    /**
+     * 品阶1
+     *
+     * @var float $grade1
+     */
+    public float $grade1 = 10;
+
+    /**
+     * 品阶2
+     *
+     * @var float $grade1
+     */
+    public float $grade2 = 10;
+
+
+    /**
+     * 品阶3
+     *
+     * @var float $grade1
+     */
+    public float $grade3 = 10;
+
+
+    /**
+     * 品阶4
+     *
+     * @var float $grade1
+     */
+    public float $grade4 = 10;
+
+    /**
+     * 品阶5
+     *
+     * @var float $grade1
+     */
+    public float $grade5 = 10;
+
+}

+ 6 - 43
app/Module/Pet/Casts/NumericAttributesCast.php

@@ -2,52 +2,15 @@
 
 namespace App\Module\Pet\Casts;
 
-use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
-use Illuminate\Database\Eloquent\Model;
 
-class NumericAttributesCast implements CastsAttributes
+class NumericAttributesCast extends \UCore\Model\CastsAttributes
 {
-    /**
-     * 将取出的数据转换为对应的类型
-     *
-     * @param  Model  $model
-     * @param  string  $key
-     * @param  mixed  $value
-     * @param  array  $attributes
-     * @return mixed
-     */
-    public function get($model, string $key, $value, array $attributes)
-    {
-        if (empty($value)) {
-            return (object) [];
-        }
-        
-        return json_decode($value);
-    }
+
 
     /**
-     * 转换成将要存储到数据库中的值
-     *
-     * @param  Model  $model
-     * @param  string  $key
-     * @param  mixed  $value
-     * @param  array  $attributes
-     * @return mixed
+     * 每恢复1点体力需要几分钟
+     * @var int $stamina_recovery
      */
-    public function set($model, string $key, $value, array $attributes)
-    {
-        if (empty($value)) {
-            return null;
-        }
-        
-        if (is_array($value)) {
-            return json_encode($value);
-        }
-        
-        if (is_object($value)) {
-            return json_encode($value);
-        }
-        
-        return $value;
-    }
+    public int $stamina_recovery= 0;
+
 }

+ 9 - 31
app/Module/Pet/Models/PetBattleLog.php

@@ -8,15 +8,15 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 /**
  * 宠物战斗记录模型
  *
- * field start 
- * @property   int  $id  
- * @property   int  $pet_id  
+ * field start
+ * @property   int  $id
+ * @property   int  $pet_id
  * @property   int  $battle_type  战斗类型:1偷菜,2守护,3争霸赛
  * @property   int  $opponent_id  对手ID(可为空)
  * @property   int  $result  战斗结果:0失败,1胜利
  * @property   object|array  $reward  战斗奖励
- * @property   string  $battle_time  
- * @property   \Carbon\Carbon  $created_at  
+ * @property   string  $battle_time
+ * @property   \Carbon\Carbon  $created_at
  * field end
  */
 class PetBattleLog extends ModelCore
@@ -41,7 +41,7 @@ class PetBattleLog extends ModelCore
      */
     protected $table = 'pet_battle_logs';
 
-    // attrlist start 
+    // attrlist start
     protected $fillable = [
         'id',
         'pet_id',
@@ -96,33 +96,11 @@ class PetBattleLog extends ModelCore
         if (!$this->opponent_id) {
             return null;
         }
-        
+
         return $this->belongsTo(Pet::class, 'opponent_id');
     }
 
-    /**
-     * 检查战斗是否胜利
-     *
-     * @return bool
-     */
-    public function isVictory(): bool
-    {
-        return $this->result === self::RESULT_SUCCESS;
-    }
 
-    /**
-     * 获取战斗类型名称
-     *
-     * @return string
-     */
-    public function getBattleTypeName(): string
-    {
-        $types = [
-            self::BATTLE_TYPE_HARVEST => '偷菜',
-            self::BATTLE_TYPE_GUARD => '守护',
-            self::BATTLE_TYPE_ROYALE => '争霸赛',
-        ];
-        
-        return $types[$this->battle_type] ?? '未知';
-    }
+
+
 }

+ 13 - 19
app/Module/Pet/Models/PetConfig.php

@@ -2,6 +2,7 @@
 
 namespace App\Module\Pet\Models;
 
+use App\Module\Pet\Casts\GradeProbability;
 use UCore\ModelCore;
 use App\Module\Pet\Casts\DisplayAttributesCast;
 use App\Module\Pet\Casts\NumericAttributesCast;
@@ -9,21 +10,20 @@ use App\Module\Pet\Casts\NumericAttributesCast;
 /**
  * 宠物配置模型
  *
- * field start 
- * @property   int  $id  
- * @property   string  $pet_type  宠物类型
- * @property   object|array  $grade_probability  品阶概率配置
- * @property   object|array  $feed_effect  喂养效果配置
- * @property   int  $max_level  最大等级
- * @property   int  $stamina_recovery  体力恢复值/分钟
- * @property   object|array  $display_attributes  显示属性配置
- * @property   object|array  $numeric_attributes  数值属性配置
- * @property   \Carbon\Carbon  $created_at  
- * @property   \Carbon\Carbon  $updated_at  
+ * field start
+ *
+ * @property   int $id
+ * @property   string $pet_type  宠物类型
+ * @property   object|array $grade_probability  品阶概率配置
+ * @property   object|array $display_attributes  显示属性配置
+ * @property   object|array $numeric_attributes  数值属性配置
+ * @property   \Carbon\Carbon $created_at
+ * @property   \Carbon\Carbon $updated_at
  * field end
  */
 class PetConfig extends ModelCore
 {
+
     /**
      * 与模型关联的表名
      *
@@ -31,14 +31,11 @@ class PetConfig extends ModelCore
      */
     protected $table = 'pet_configs';
 
-    // attrlist start 
+    // attrlist start
     protected $fillable = [
         'id',
         'pet_type',
         'grade_probability',
-        'feed_effect',
-        'max_level',
-        'stamina_recovery',
         'display_attributes',
         'numeric_attributes',
     ];
@@ -50,10 +47,7 @@ class PetConfig extends ModelCore
      * @var array
      */
     protected $casts = [
-        'grade_probability' => 'json',
-        'feed_effect' => 'json',
-        'max_level' => 'integer',
-        'stamina_recovery' => 'integer',
+        'grade_probability'  => GradeProbability::class,
         'display_attributes' => DisplayAttributesCast::class,
         'numeric_attributes' => NumericAttributesCast::class,
     ];

+ 2 - 0
app/Module/Pet/Models/PetSkill.php

@@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
  * @property   string  $skill_name  技能名称
  * @property   int  $stamina_cost  体力消耗
  * @property   int  $cool_down  冷却时间(秒)
+ * @property   int  $duration_time  持续时间(秒)
  * @property   string  $effect_desc  效果描述
  * @property   int  $min_level  最低等级要求
  * @property   \Carbon\Carbon  $created_at  
@@ -40,6 +41,7 @@ class PetSkill extends ModelCore
         'skill_name',
         'stamina_cost',
         'cool_down',
+        'duration_time',
         'effect_desc',
         'min_level',
     ];