从新设计抽奖逻辑
This commit is contained in:
@@ -94,6 +94,29 @@ class LotteryService
|
||||
(int) ($config->t4_wight ?? 0),
|
||||
(int) ($config->t5_wight ?? 0),
|
||||
];
|
||||
return self::drawTierByWeightArray($tiers, $weights);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据玩家 t1_wight~t5_wight 权重随机抽取中奖档位 T1-T5
|
||||
* t1_wight=T1, t2_wight=T2, t3_wight=T3, t4_wight=T4, t5_wight=T5
|
||||
*/
|
||||
public static function drawTierByPlayerWeights(DicePlayer $player): string
|
||||
{
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$weights = [
|
||||
(int) ($player->t1_wight ?? 0),
|
||||
(int) ($player->t2_wight ?? 0),
|
||||
(int) ($player->t3_wight ?? 0),
|
||||
(int) ($player->t4_wight ?? 0),
|
||||
(int) ($player->t5_wight ?? 0),
|
||||
];
|
||||
return self::drawTierByWeightArray($tiers, $weights);
|
||||
}
|
||||
|
||||
/** 按档位权重数组抽取 T1-T5 */
|
||||
private static function drawTierByWeightArray(array $tiers, array $weights): string
|
||||
{
|
||||
$total = array_sum($weights);
|
||||
if ($total <= 0) {
|
||||
return $tiers[array_rand($tiers)];
|
||||
|
||||
Reference in New Issue
Block a user