Skip to content

Commit

Permalink
Fixing Frederiksberg rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevalentin committed May 29, 2018
1 parent dd74527 commit cdb54e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/LiarsDiceBotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,15 @@ public function endRound(BotMan $bot)

// Checking for Frederiksberg
$frederiksberg_hit = false;
$frederiksberg_winner_id = null;
if($this->game->frederiksberg_enabled && $this->end_round_hits == $dice_amount_to_look_for) {
Log::info("[INFO] Frederiksberg was enabled & hit!");
$frederiksberg_hit = true;
if($loser_id == $this->user->id) {
$frederiksberg_winner_id = $last_call->participant_id;
}else{
$frederiksberg_winner_id = $this->user->id;
}
}

$current_call = new Call;
Expand All @@ -474,7 +480,7 @@ public function endRound(BotMan $bot)
$current_call->loser_id = $loser_id;
$current_call->save();

$this->initRound($bot, $this->current_round_participants, null, $this->current_round_rolls->first()->round + 1, $frederiksberg_hit, $loser_id);
$this->initRound($bot, $this->current_round_participants, null, $this->current_round_rolls->first()->round + 1, $frederiksberg_hit, $loser_id, $frederiksberg_winner_id);

if($this->game->state == 'concluded') {
return;
Expand Down Expand Up @@ -617,7 +623,7 @@ public function say(BotMan $bot)
}
}

private function initRound(BotMan $bot, $participants, $no_of_dice, $round, $frederiksberg_hit = null, $loser_id = null) {
private function initRound(BotMan $bot, $participants, $no_of_dice, $round, $frederiksberg_hit = null, $loser_id = null, $frederiksberg_winner_id = null) {
foreach ($participants AS $participant) {
$player = User::find($participant->participant_id);
if($round > 0) {
Expand Down Expand Up @@ -660,7 +666,7 @@ private function initRound(BotMan $bot, $participants, $no_of_dice, $round, $fre
if($loser_id == $participant->participant_id) {
$dice_to_roll = $current_dice_count;
}else{
if($this->game->frederiksberg_enabled && $frederiksberg_hit) {
if($this->game->frederiksberg_enabled && $frederiksberg_hit && $frederiksberg_winner_id != $participant->participant_id) {
$dice_to_roll = $current_dice_count;
}else{
$dice_to_roll = $current_dice_count - 1;
Expand Down

0 comments on commit cdb54e9

Please sign in to comment.