app/Models/Card.php: in getBySettings() implement support to include X number of jackpot cards in the result.
This commit is contained in:
parent
0a80dbeb5e
commit
020645dbca
2 changed files with 37 additions and 6 deletions
|
|
@ -78,17 +78,30 @@ class Card extends Model
|
|||
/**
|
||||
* Get cards depending on settings.
|
||||
*/
|
||||
public static function getBySettings(GameSettings $settings, ?int $max = null)
|
||||
public static function getBySettings(GameSettings $settings, ?int $max = null, int $num_jackpot = 0)
|
||||
{
|
||||
$query = self::settingsQuery($settings)
|
||||
->inRandomOrder();
|
||||
->where('jackpot', '=', 0);
|
||||
|
||||
if ($max !== null) {
|
||||
$query->limit($max);
|
||||
$jitems = \collect([]);
|
||||
if ($num_jackpot > 0) {
|
||||
$jitems = self::settingsQuery($settings)
|
||||
->where('jackpot', '!=', 0)
|
||||
->limit($num_jackpot)
|
||||
->get();
|
||||
}
|
||||
|
||||
return $query->get()
|
||||
->makeHidden(['character', 'class', 'deleted_at']);
|
||||
if ($max !== null) {
|
||||
$query->limit($max - count($jitems));
|
||||
}
|
||||
|
||||
if (count($jitems) > 0) {
|
||||
$items = $query->get()->merge($jitems)->shuffle();
|
||||
} else {
|
||||
$items = $query->inRandomOrder()->get();
|
||||
}
|
||||
|
||||
return $items->makeHidden(['character', 'class', 'deleted_at']);
|
||||
}
|
||||
|
||||
protected static function settingsQuery(GameSettings $settings): Builder
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue