'integer', 'max_quantity' => 'integer', 'chance' => 'float', ]; /** * 获取关联的分解规则 * * @return BelongsTo */ public function rule(): BelongsTo { return $this->belongsTo(ItemDismantleRule::class, 'rule_id'); } /** * 获取关联的结果物品 * * @return BelongsTo */ public function resultItem(): BelongsTo { return $this->belongsTo(ItemItem::class, 'result_item_id'); } /** * 获取随机数量 * * @return int */ public function getRandomQuantity(): int { if ($this->min_quantity == $this->max_quantity) { return $this->min_quantity; } return mt_rand($this->min_quantity, $this->max_quantity); } /** * 检查是否命中概率 * * @return bool */ public function isChanceHit(): bool { if ($this->chance >= 1.0) { return true; } return mt_rand(1, 10000) <= $this->chance * 10000; } }