PetLevelConfig.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Module\Pet\Models;
  3. use UCore\ModelCore;
  4. use App\Module\Pet\Casts\DisplayAttributesCast;
  5. use App\Module\Pet\Casts\NumericAttributesCast;
  6. /**
  7. * 宠物等级配置模型
  8. *
  9. * field start
  10. * @property int $id
  11. * @property int $level 等级
  12. * @property int $exp_required 升级所需经验值
  13. * @property int $stamina_max 最大体力值
  14. * @property int $stamina_recovery_rate 每分钟恢复体力值
  15. * @property object|array $unlock_skills 解锁的技能ID列表
  16. * @property object|array $display_attributes 等级显示属性配置
  17. * @property object|array $numeric_attributes 等级数值属性配置
  18. * @property \Carbon\Carbon $created_at
  19. * @property \Carbon\Carbon $updated_at
  20. * field end
  21. */
  22. class PetLevelConfig extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'pet_level_configs';
  30. // attrlist start
  31. protected $fillable = [
  32. 'id',
  33. 'level',
  34. 'exp_required',
  35. 'stamina_max',
  36. 'stamina_recovery_rate',
  37. 'unlock_skills',
  38. 'display_attributes',
  39. 'numeric_attributes',
  40. ];
  41. // attrlist end
  42. /**
  43. * 应该被转换为原生类型的属性
  44. *
  45. * @var array
  46. */
  47. protected $casts = [
  48. 'level' => 'integer',
  49. 'exp_required' => 'integer',
  50. 'stamina_max' => 'integer',
  51. 'stamina_recovery_rate' => 'integer',
  52. 'unlock_skills' => 'json',
  53. 'display_attributes' => DisplayAttributesCast::class,
  54. 'numeric_attributes' => NumericAttributesCast::class,
  55. ];
  56. /**
  57. * 获取指定等级的配置
  58. *
  59. * @param int $level
  60. * @return self|null
  61. */
  62. public static function getByLevel(int $level): ?self
  63. {
  64. return self::where('level', $level)->first();
  65. }
  66. /**
  67. * 获取下一级配置
  68. *
  69. * @return self|null
  70. */
  71. public function getNextLevel(): ?self
  72. {
  73. return self::where('level', $this->level + 1)->first();
  74. }
  75. }