| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Module\Pet\Models;
- use UCore\ModelCore;
- use App\Module\Pet\Casts\DisplayAttributesCast;
- use App\Module\Pet\Casts\NumericAttributesCast;
- /**
- * 宠物等级配置模型
- *
- * field start
- * @property int $id
- * @property int $pet_id 宠物 ID
- * @property int $level 等级
- * @property int $exp_required 升级所需经验值
- * @property int $stamina_max 最大体力值
- * @property int $stamina_recovery_rate 每分钟恢复体力值
- * @property object|array $unlock_skills 解锁的技能ID列表
- * @property object|array $display_attributes 等级显示属性配置
- * @property object|array $numeric_attributes 等级数值属性配置
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- * field end
- */
- class PetLevelConfig extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'pet_level_configs';
- // attrlist start
- protected $fillable = [
- 'id',
- 'pet_id',
- 'level',
- 'exp_required',
- 'stamina_max',
- 'stamina_recovery_rate',
- 'unlock_skills',
- 'display_attributes',
- 'numeric_attributes',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'level' => 'integer',
- 'exp_required' => 'integer',
- 'stamina_max' => 'integer',
- 'stamina_recovery_rate' => 'integer',
- 'unlock_skills' => 'json',
- 'display_attributes' => DisplayAttributesCast::class,
- 'numeric_attributes' => NumericAttributesCast::class,
- ];
- /**
- * 获取指定等级的配置
- *
- * @param int $level
- * @return self|null
- */
- public static function getByLevel(int $level): ?self
- {
- return self::where('level', $level)->first();
- }
- /**
- * 获取下一级配置
- *
- * @return self|null
- */
- public function getNextLevel(): ?self
- {
- return self::where('level', $this->level + 1)->first();
- }
- }
|