最后更新时间:2025年5月29日
物品分解系统允许玩家将不需要的物品分解为其他有用的材料或资源。系统采用规则驱动的设计,支持灵活的分解配置和复杂的分解逻辑。
| 字段名 | 类型 | 说明 | 功能 |
|---|---|---|---|
id |
int | 规则ID,主键 | 唯一标识分解规则 |
name |
varchar(255) | 规则名称 | 便于管理和识别的规则名称 |
code |
varchar(100) | 规则编码(唯一) | 程序中引用的唯一标识符 |
description |
text | 规则描述 | 详细说明规则的用途和效果 |
item_id |
int | 物品ID | 指定特定物品:当设置时,规则仅适用于该物品 |
category_id |
int | 分类ID | 指定物品分类:当item_id为空时,规则适用于该分类下的所有物品 |
consume_group_id |
int | 消耗组ID | 额外消耗:分解时需要额外消耗的资源(如分解工具、手续费等) |
reward_group_id |
int | 奖励组ID | 分解奖励:分解成功后获得的奖励(替代旧的分解结果表) |
condition_group_id |
int | 条件组ID | 使用条件:使用该分解规则需要满足的条件(如等级、技能等) |
min_rarity |
tinyint | 最小适用稀有度 | 稀有度范围下限:规则适用的最低稀有度等级 |
max_rarity |
tinyint | 最大适用稀有度 | 稀有度范围上限:规则适用的最高稀有度等级 |
priority |
int | 规则优先级 | 匹配优先级:多个规则匹配时,优先级高的规则生效 |
sort_order |
int | 排序权重 | 显示排序:在管理界面中的显示顺序 |
is_active |
tinyint | 是否激活 | 规则开关:控制规则是否生效 |
| 字段名 | 类型 | 说明 |
|---|---|---|
rule_id |
int | 分解规则ID |
result_item_id |
int | 结果物品ID |
min_quantity |
int | 最小数量 |
max_quantity |
int | 最大数量 |
base_chance |
decimal(5,2) | 基础获取概率 |
rarity_factor |
decimal(5,2) | 稀有度影响因子 |
quality_factor |
decimal(5,2) | 品质影响因子 |
功能:指定规则适用的特定物品
使用场景:
匹配优先级:最高(优先于分类规则和通用规则)
示例:
-- 为传说武器设置特殊分解规则
INSERT INTO item_dismantle_rules (name, item_id, reward_group_id, priority)
VALUES ('传说武器分解', 1001, 100, 100);
功能:定义分解成功后获得的奖励
使用场景:
优势:
示例:
-- 奖励组:分解铁剑获得铁锭
-- 在game_reward_groups表中配置奖励组
-- 在game_reward_items表中配置具体奖励项
功能:定义分解时需要额外消耗的资源
使用场景:
特点:
示例:
-- 消耗组:分解高级装备需要分解工具
-- 在game_consume_groups表中配置消耗组
-- 在game_consume_items表中配置具体消耗项
功能:定义使用分解规则需要满足的条件
使用场景:
特点:
功能:定义规则适用的稀有度范围
⚠️ 当前问题:
期望功能:
需要修复:
功能:控制多个规则匹配时的选择顺序
匹配逻辑:
使用场景:
private static function getDismantleRule(int $itemId): ?ItemDismantleRule
{
$item = Item::find($itemId);
if (!$item) return null;
// 1. 优先查找特定物品规则
$rule = ItemDismantleRule::where('item_id', $itemId)
->where('is_active', true)
->orderBy('priority', 'desc')
->first();
if ($rule) return $rule;
// 2. 查找分类规则
$rule = ItemDismantleRule::where('category_id', $item->category_id)
->where('is_active', true)
->orderBy('priority', 'desc')
->first();
return $rule;
}
private static function getDismantleRule(int $itemId): ?ItemDismantleRule
{
$item = Item::find($itemId);
if (!$item) return null;
$rarity = $item->rarity ?? 1; // 需要添加rarity字段
// 1. 特定物品规则(包含稀有度匹配)
$rule = ItemDismantleRule::where('item_id', $itemId)
->where('is_active', true)
->where('min_rarity', '<=', $rarity)
->where('max_rarity', '>=', $rarity)
->orderBy('priority', 'desc')
->first();
if ($rule) return $rule;
// 2. 分类规则(包含稀有度匹配)
$rule = ItemDismantleRule::where('category_id', $item->category_id)
->whereNull('item_id')
->where('is_active', true)
->where('min_rarity', '<=', $rarity)
->where('max_rarity', '>=', $rarity)
->orderBy('priority', 'desc')
->first();
// 3. 通用规则(稀有度匹配)
if (!$rule) {
$rule = ItemDismantleRule::whereNull('item_id')
->whereNull('category_id')
->where('is_active', true)
->where('min_rarity', '<=', $rarity)
->where('max_rarity', '>=', $rarity)
->orderBy('priority', 'desc')
->first();
}
return $rule;
}
稀有度字段缺失:
规则匹配不完整:
组系统集成不完整:
-- 创建木材分解规则
INSERT INTO item_dismantle_rules (
name, code, description,
category_id, reward_group_id,
min_rarity, max_rarity, priority, is_active
) VALUES (
'基础木材分解', 'basic_wood_dismantle', '分解基础木材获得木屑',
1, 10, 1, 3, 10, 1
);
-- 创建传说装备分解规则
INSERT INTO item_dismantle_rules (
name, code, description,
item_id, consume_group_id, reward_group_id, condition_group_id,
min_rarity, max_rarity, priority, is_active
) VALUES (
'传说装备分解', 'legendary_equipment_dismantle', '分解传说装备获得稀有材料',
1001, 5, 20, 3, 5, 5, 100, 1
);
✅ 规则匹配算法优化:
DismantleService::getDismantleRule()方法✅ 组系统集成:
⚠️ 物品稀有度字段:
rarity字段numeric_attributes获取稀有度是临时方案⚠️ 服务层方法缺失:
ConditionService::checkConditionGroup() 方法需要实现ConsumeService::checkConsumeGroup() 方法需要实现RewardService::generateRewards() 方法需要实现⚠️ 数据库结构更新:
-- 为物品表添加稀有度字段
ALTER TABLE `kku_item_items`
ADD COLUMN `rarity` tinyint DEFAULT 1 COMMENT '物品稀有度(1:普通, 2:优秀, 3:稀有, 4:史诗, 5:传说)'
AFTER `type`;
-- 添加索引
ALTER TABLE `kku_item_items`
ADD KEY `idx_rarity` (`rarity`);
// 在Item模型中添加rarity字段
protected $fillable = [
// ... 其他字段
'rarity',
];
protected $casts = [
// ... 其他字段
'rarity' => 'integer',
];
# 执行分解规则表结构更新
mysql -u username -p database_name < database/sql/update_item_dismantle_rules_for_groups.sql
物品分解系统设计合理,采用了灵活的规则驱动架构和现代的组系统。通过本次分析和修复:
系统整体架构优秀,只需要完善少数细节即可发挥完整功能。