PetLevelConfig.php 2.1 KB

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