任务时间: 2025年06月04日 10:14
任务类型: 功能开发
优先级: 中等
状态: ✅ 已完成
为新的宝箱系统实现保底机制,确保用户在多次开启宝箱后能够获得稀有奖励,提升用户体验和游戏公平性。
kku_game_reward_group_pity_countsuser_id: 用户IDreward_group_id: 奖励组IDreward_item_id: 奖励项IDcount: 当前计数pity_threshold: 保底阈值last_attempt_at: 最后尝试时间last_hit_at: 最后命中时间为 kku_game_reward_items 表添加保底相关字段:
pity_threshold: 保底阈值(0表示不启用保底)pity_weight_factor: 保底权重因子(递增概率的倍数)pity_enabled: 是否启用保底机制提供完整的保底机制功能:
核心方法:
getUserPityCounts(): 获取用户保底计数initializePityCounts(): 初始化保底计数applyPityAdjustments(): 应用保底权重调整updatePityCounts(): 更新保底计数checkPityTriggers(): 检查保底触发getPityStatus(): 获取保底状态信息resetAllPityCounts(): 重置保底计数cleanupOldPityCounts(): 清理过期记录保底机制特点:
grantRewardWithPity() 方法grantRewardWithPity() 逻辑// 基础权重调整公式
$adjustedWeight = $baseWeight * (1 + $progressRatio * $weightFactor)
// 保底触发时
if ($count >= $threshold) {
$adjustedWeight = 999999.0; // 确保必中
}
-- 创建保底计数表
CREATE TABLE `kku_game_reward_group_pity_counts` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` bigint unsigned NOT NULL COMMENT '用户ID',
`reward_group_id` int NOT NULL COMMENT '奖励组ID',
`reward_item_id` int NOT NULL COMMENT '奖励项ID',
`count` int NOT NULL DEFAULT '0' COMMENT '当前计数',
`pity_threshold` int NOT NULL DEFAULT '0' COMMENT '保底阈值',
`last_attempt_at` timestamp NULL DEFAULT NULL COMMENT '最后尝试时间',
`last_hit_at` timestamp NULL DEFAULT NULL COMMENT '最后命中时间',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_user_reward_item` (`user_id`,`reward_group_id`,`reward_item_id`),
-- 其他索引和外键约束...
);
-- 添加保底字段到奖励项表
ALTER TABLE `kku_game_reward_items`
ADD COLUMN `pity_threshold` int NOT NULL DEFAULT '0' COMMENT '保底阈值(0表示不启用保底)',
ADD COLUMN `pity_weight_factor` decimal(8,4) NOT NULL DEFAULT '1.0000' COMMENT '保底权重因子(递增概率的倍数)',
ADD COLUMN `pity_enabled` tinyint NOT NULL DEFAULT '0' COMMENT '是否启用保底机制';
// 发放奖励(启用保底机制)
$result = RewardService::grantRewardWithPity(
$userId,
$rewardGroupId,
'chest_open',
$chestId,
true // 启用保底
);
// 查看用户保底状态
$pityStatus = RewardService::getUserPityStatus($userId, $rewardGroupId);
// 重置用户保底计数
RewardService::resetUserPity($userId, $rewardGroupId);
成功实现了完整的宝箱保底机制系统,包括:
该系统为游戏提供了公平、透明的保底机制,提升了用户体验,同时保持了系统的稳定性和可扩展性。