3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-04 18:38:47 +02:00

Spinach: Immediately stop game when last player exits

This commit is contained in:
Pragmatic Software 2019-05-07 03:26:40 -07:00
parent a75c4b4a65
commit a0359c27dd

View File

@ -484,7 +484,13 @@ sub spinach_cmd {
if ($self->{state_data}->{current_player} >= @{$self->{state_data}->{players}}) {
$self->{state_data}->{current_player} = @{$self->{state_data}->{players}} - 1
}
return "/msg $self->{channel} $nick has left the game!";
if (not @{$self->{state_data}->{players}}) {
$self->{current_state} = 'nogame';
return "/msg $self->{channel} $nick has left the game! All players have left. The game has been stopped.";
} else {
return "/msg $self->{channel} $nick has left the game!";
}
} else {
return "$nick: But you are not even playing the game.";
}
@ -961,7 +967,6 @@ sub player_left {
for (my $i = 0; $i < @{$self->{state_data}->{players}}; $i++) {
if ($self->{state_data}->{players}->[$i]->{id} == $id) {
splice @{$self->{state_data}->{players}}, $i--, 1;
$self->send_message($self->{channel}, "$nick has left the game!");
$removed = 1;
}
}
@ -970,7 +975,7 @@ sub player_left {
if ($self->{state_data}->{current_player} >= @{$self->{state_data}->{players}}) {
$self->{state_data}->{current_player} = @{$self->{state_data}->{players}} - 1
}
return "/msg $self->{channel} $nick has left the game!";
$self->send_message($self->{channel}, "$nick has left the game!");
}
}