| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Module\Game\Logics\Reward;
- use App\Module\Game\Dtos\RewardItemDto;
- use UCore\Exception\LogicException;
- class Item
- {
- /**
- * 处理奖励项数量(支持随机数量)
- */
- public static function processQuantity(RewardItemDto $item, int $multiplier = 1): RewardItemDto
- {
- $processedItem = clone $item;
- // 检查是否有数量范围设置
- if ($item->minQuantity > 0 && $item->maxQuantity > 0) {
- if($multiplier> 1){
- throw new LogicException('倍率下,不能随机!');
- }
- $minQty = max(1, $item->minQuantity);
- $maxQty = max($minQty, $item->maxQuantity);
- $processedItem->quantity = mt_rand($minQty, $maxQty);
- } else {
- $processedItem->quantity = max(1, $item->quantity) * $multiplier;
- }
- return $processedItem;
- }
- }
|