重构*_weight为*_weight

This commit is contained in:
2026-03-07 10:07:44 +08:00
parent 7e5585aee0
commit fe1ceeb4fb
9 changed files with 127 additions and 128 deletions

View File

@@ -19,7 +19,7 @@ class LotteryService
private int $playerId;
private ?int $configType0Id = null;
private ?int $configType1Id = null;
/** @var array{t1_wight?:int,t2_wight?:int,t3_wight?:int,t4_wight?:int,t5_wight?:int} */
/** @var array{t1_weight?:int,t2_weight?:int,t3_weight?:int,t4_weight?:int,t5_weight?:int} */
private array $playerWeights = [];
public function __construct(int $playerId)
@@ -62,11 +62,11 @@ class LotteryService
$s->configType0Id = $config0 ? (int) $config0->id : null;
$s->configType1Id = $config1 ? (int) $config1->id : null;
$s->playerWeights = [
't1_wight' => (int) ($player->t1_wight ?? 0),
't2_wight' => (int) ($player->t2_wight ?? 0),
't3_wight' => (int) ($player->t3_wight ?? 0),
't4_wight' => (int) ($player->t4_wight ?? 0),
't5_wight' => (int) ($player->t5_wight ?? 0),
't1_weight' => (int) ($player->t1_weight ?? 0),
't2_weight' => (int) ($player->t2_weight ?? 0),
't3_weight' => (int) ($player->t3_weight ?? 0),
't4_weight' => (int) ($player->t4_weight ?? 0),
't5_weight' => (int) ($player->t5_weight ?? 0),
];
$s->save();
return $s;
@@ -83,33 +83,33 @@ class LotteryService
Cache::set($key, json_encode($data), self::EXPIRE);
}
/** 根据奖池配置的 t1_wight..t5_wight 权重随机抽取档位 T1-T5 */
/** 根据奖池配置的 t1_weight..t5_weight 权重随机抽取档位 T1-T5 */
public static function drawTierByWeights(DiceLotteryConfig $config): string
{
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
$weights = [
(int) ($config->t1_wight ?? 0),
(int) ($config->t2_wight ?? 0),
(int) ($config->t3_wight ?? 0),
(int) ($config->t4_wight ?? 0),
(int) ($config->t5_wight ?? 0),
(int) ($config->t1_weight ?? 0),
(int) ($config->t2_weight ?? 0),
(int) ($config->t3_weight ?? 0),
(int) ($config->t4_weight ?? 0),
(int) ($config->t5_weight ?? 0),
];
return self::drawTierByWeightArray($tiers, $weights);
}
/**
* 根据玩家 t1_wightt5_wight 权重随机抽取中奖档位 T1-T5
* t1_wight=T1, t2_wight=T2, t3_wight=T3, t4_wight=T4, t5_wight=T5
* 根据玩家 t1_weightt5_weight 权重随机抽取中奖档位 T1-T5
* t1_weight=T1, t2_weight=T2, t3_weight=T3, t4_weight=T4, t5_weight=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),
(int) ($player->t1_weight ?? 0),
(int) ($player->t2_weight ?? 0),
(int) ($player->t3_weight ?? 0),
(int) ($player->t4_weight ?? 0),
(int) ($player->t5_weight ?? 0),
];
return self::drawTierByWeightArray($tiers, $weights);
}