优化一键测试权重
This commit is contained in:
@@ -430,11 +430,13 @@ class PlayStartLogic
|
||||
|
||||
/**
|
||||
* 模拟一局抽奖(不写库、不扣玩家),用于权重测试写入 dice_play_record_test
|
||||
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig $config 奖池配置
|
||||
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig|null $config 奖池配置,自定义档位时可为 null
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @param int $lotteryType 0=付费 1=免费
|
||||
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
|
||||
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier(用于统计档位概率)
|
||||
*/
|
||||
public function simulateOnePlay($config, int $direction): array
|
||||
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, ?array $customTierWeights = null): array
|
||||
{
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
@@ -442,7 +444,14 @@ class PlayStartLogic
|
||||
$chosen = null;
|
||||
$tier = null;
|
||||
for ($tierAttempt = 0; $tierAttempt < $maxTierRetry; $tierAttempt++) {
|
||||
$tier = LotteryService::drawTierByWeights($config);
|
||||
if ($customTierWeights !== null && $customTierWeights !== []) {
|
||||
$tier = LotteryService::drawTierByWeightsFromArray($customTierWeights);
|
||||
} else {
|
||||
if ($config === null) {
|
||||
throw new \RuntimeException('模拟抽奖:未提供奖池配置或自定义档位权重');
|
||||
}
|
||||
$tier = LotteryService::drawTierByWeights($config);
|
||||
}
|
||||
$tierRewards = $byTierDirection[$tier][$direction] ?? [];
|
||||
if (empty($tierRewards)) {
|
||||
continue;
|
||||
@@ -495,15 +504,15 @@ class PlayStartLogic
|
||||
}
|
||||
|
||||
$winCoin = $superWinCoin + $rewardWinCoin;
|
||||
$configId = (int) $config->id;
|
||||
$configId = $config !== null ? (int) $config->id : 0;
|
||||
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
|
||||
$configName = (string) ($config->name ?? '');
|
||||
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
|
||||
|
||||
return [
|
||||
'player_id' => 0,
|
||||
'admin_id' => 0,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => self::LOTTERY_TYPE_PAID,
|
||||
'lottery_type' => $lotteryType,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
|
||||
Reference in New Issue
Block a user