'integer',
'category_id' => 'integer',
'consume_group_id' => 'integer',
'reward_group_id' => 'integer',
'condition_group_id' => 'integer',
'min_rarity' => 'integer',
'max_rarity' => 'integer',
'priority' => 'integer',
'sort_order' => 'integer',
'is_active' => 'boolean',
];
/**
* 获取关联的物品(如果有)
*
* @return BelongsTo
*/
public function item(): BelongsTo
{
return $this->belongsTo(Item::class, 'item_id');
}
/**
* 获取关联的分类(如果有)
*
* @return BelongsTo
*/
public function category(): BelongsTo
{
return $this->belongsTo(ItemCategory::class, 'category_id');
}
/**
* 获取消耗组
*
* @return BelongsTo
*/
public function consumeGroup(): BelongsTo
{
return $this->belongsTo(\App\Module\Game\Models\GameConsumeGroup::class, 'consume_group_id');
}
/**
* 获取奖励组
*
* @return BelongsTo
*/
public function rewardGroup(): BelongsTo
{
return $this->belongsTo(\App\Module\Game\Models\GameRewardGroup::class, 'reward_group_id');
}
/**
* 获取条件组
*
* @return BelongsTo
*/
public function conditionGroup(): BelongsTo
{
return $this->belongsTo(\App\Module\Game\Models\GameConditionGroup::class, 'condition_group_id');
}
/**
* 获取分解日志
*
* @return HasMany
*/
public function dismantleLogs(): HasMany
{
return $this->hasMany(ItemDismantleLog::class, 'rule_id');
}
/**
* 计算分解返还的金币
*
* @param int $itemPrice 物品价格
* @return int
*/
public function calculateCoinReturn(int $itemPrice): int
{
if ($this->coin_return_rate <= 0) {
return 0;
}
return (int)($itemPrice * $this->coin_return_rate);
}
/**
* 格式化消耗组详情用于显示
*
* @return string
*/
public function formatConsumeDetails(): string
{
if (!$this->consumeGroup) {
return '无消耗组';
}
return $this->consumeGroup->formatConsumeDetails();
}
/**
* 格式化奖励组详情用于显示
*
* @return string
*/
public function formatRewardDetails(): string
{
if (!$this->rewardGroup) {
return '无奖励组';
}
return $this->rewardGroup->formatRewardDetails();
}
/**
* 格式化条件组详情用于显示
*
* @return string
*/
public function formatConditionDetails(): string
{
if (!$this->conditionGroup) {
return '无条件组';
}
return $this->conditionGroup->formatConditionDetails();
}
/**
* 检查用户是否可以使用该分解规则
*
* @param int $userId 用户ID
* @param int $itemId 物品ID
* @param int $quantity 分解数量
* @return array 检查结果
*/
public function canDismantleByUser(int $userId, int $itemId, int $quantity = 1): array
{
// 检查规则是否激活
if (!$this->is_active) {
return [
'can_dismantle' => false,
'reason' => '分解规则未激活',
];
}
// 检查条件组(如果设置了条件组)
if ($this->condition_group_id && $this->conditionGroup) {
// TODO: 实现ConditionService::checkConditionGroup方法
// $conditionService = app(\App\Module\Game\Services\ConditionService::class);
// $conditionResult = $conditionService->checkConditionGroup($userId, $this->condition_group_id);
//
// if (!$conditionResult['is_satisfied']) {
// return [
// 'can_dismantle' => false,
// 'reason' => '条件不满足',
// 'condition_details' => $conditionResult['details'],
// ];
// }
}
// 检查消耗组(如果设置了消耗组,用于额外消耗,如分解工具等)
if ($this->consume_group_id && $this->consumeGroup) {
// TODO: 实现ConsumeService::checkConsumeGroup方法
// $consumeService = app(\App\Module\Game\Services\ConsumeService::class);
// $consumeResult = $consumeService->checkConsumeGroup($userId, $this->consume_group_id);
//
// if (!$consumeResult['can_consume']) {
// return [
// 'can_dismantle' => false,
// 'reason' => '分解工具或材料不足',
// 'consume_details' => $consumeResult['details'],
// ];
// }
}
return [
'can_dismantle' => true,
];
}
/**
* 获取分解结果(使用奖励组)
*
* @return array
*/
public function getDismantleResults(): array
{
// 如果设置了奖励组,使用奖励组系统
if ($this->reward_group_id && $this->rewardGroup) {
// TODO: 实现RewardService::generateRewards方法
// $rewardService = app(\App\Module\Game\Services\RewardService::class);
// return $rewardService->generateRewards($this->reward_group_id);
// 临时返回空数组,等待RewardService实现
return [];
}
// 旧的分解结果表已废弃,返回空数组
// 所有分解奖励应该通过奖励组系统配置
return [];
}
}