| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Module\Farm\Models;
- use UCore\ModelCore;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 神秘种子土地影响配置模型
- *
- * @property int $id
- * @property int $seed_id 种子ID
- * @property int $land_type_id 土地类型ID
- * @property int $output_item_id 产出物品ID
- * @property float $probability_modifier 概率修正值
- * @property float|null $probability_override 概率覆盖值
- * @property bool $is_active 是否启用
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- *
- * @property-read FarmSeed $seed 关联的种子
- * @property-read FarmLandType $landType 关联的土地类型
- */
- class FarmMysterySeeLandEffect extends ModelCore
- {
- protected $table = 'farm_mystery_seed_land_effects';
- // attrlist start
- protected $fillable = [
- 'id',
- 'seed_id',
- 'land_type_id',
- 'output_item_id',
- 'probability_modifier',
- 'probability_override',
- 'is_active',
- ];
- // attrlist end
- protected $casts = [
- 'probability_modifier' => 'decimal:4',
- 'probability_override' => 'decimal:4',
- 'is_active' => 'boolean'
- ];
- /**
- * 关联种子
- */
- public function seed(): BelongsTo
- {
- return $this->belongsTo(FarmSeed::class, 'seed_id');
- }
- /**
- * 关联土地类型
- */
- public function landType(): BelongsTo
- {
- return $this->belongsTo(FarmLandType::class, 'land_type_id');
- }
- /**
- * 获取调整类型
- *
- * @return string
- */
- public function getAdjustmentTypeAttribute(): string
- {
- return $this->probability_override !== null ? 'override' : 'modifier';
- }
- /**
- * 获取最终概率值
- *
- * @param float $baseProbability 基础概率
- * @return float
- */
- public function getFinalProbability(float $baseProbability): float
- {
- if ($this->probability_override !== null) {
- // 使用覆盖值
- return $this->probability_override;
- } else {
- // 使用修正值
- return $baseProbability + $this->probability_modifier;
- }
- }
- /**
- * 作用域:启用的配置
- */
- public function scopeActive($query)
- {
- return $query->where('is_active', true);
- }
- /**
- * 作用域:指定种子的配置
- */
- public function scopeForSeed($query, int $seedId)
- {
- return $query->where('seed_id', $seedId);
- }
- /**
- * 作用域:指定土地类型的配置
- */
- public function scopeForLandType($query, int $landTypeId)
- {
- return $query->where('land_type_id', $landTypeId);
- }
- }
|