Skip to content

Commit

Permalink
Merge 1f783b0 into 55c31a2
Browse files Browse the repository at this point in the history
  • Loading branch information
stromblom committed Aug 5, 2019
2 parents 55c31a2 + 1f783b0 commit 81fc843
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Services/PackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,34 @@ public function createPack(Dominion $dominion, string $packName, string $packPas
*/
public function getPack(Round $round, string $packName, string $packPassword, Race $race): Pack
{
$otherRaceId = null;
if(((int)$round->players_per_race !== 0)) {
if ($race->name == 'Spirit') {
// count spud as same race
$otherRaceId = Race::where('name', 'Undead')->first()->id;
} elseif ($race->name == 'Undead') {
// count spud as same race
$otherRaceId = Race::where('name', 'Spirit')->first()->id;
} elseif ($race->name == 'Nomad') {
// count huno as same race
$otherRaceId = Race::where('name', 'Human')->first()->id;
} elseif ($race->name == 'Human') {
// count huno as same race
$otherRaceId = Race::where('name', 'Nomad')->first()->id;
}
}

$pack = Pack::where([
'round_id' => $round->id,
'name' => $packName,
'password' => $packPassword,
])->withCount([
'dominions',
'dominions as players_with_race' => function (Builder $query) use ($race) {
'dominions as players_with_race' => function (Builder $query) use ($race, $otherRaceId) {
$query->where('race_id', $race->id);
if($otherRaceId) {
$query->orWhere('race_id', $otherRaceId);
}
}
])->first();

Expand Down

0 comments on commit 81fc843

Please sign in to comment.