mirror of https://github.com/pragma-/pbot.git
Spinach: Random category and other minor improvements
This commit is contained in:
parent
8b2e61938b
commit
e47d704b8d
|
@ -596,8 +596,15 @@ sub spinach_cmd {
|
||||||
return "$nick: Choice out of range. Please choose a valid category. $self->{state_data}->{categories_text}";
|
return "$nick: Choice out of range. Please choose a valid category. $self->{state_data}->{categories_text}";
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{state_data}->{current_category} = $self->{state_data}->{category_options}->[$arguments];
|
if ($arguments == @{$self->{state_data}->{category_options}} - 1) {
|
||||||
return "/msg $self->{channel} $nick has chosen $self->{state_data}->{current_category}!";
|
$arguments = (@{$self->{state_data}->{category_options}} - 1) * rand;
|
||||||
|
$self->{state_data}->{current_category} = $self->{state_data}->{category_options}->[$arguments];
|
||||||
|
return "/msg $self->{channel} $nick has chosen RANDOM! Randomly choosing category: $self->{state_data}->{current_category}!";
|
||||||
|
} else {
|
||||||
|
$self->{state_data}->{current_category} = $self->{state_data}->{category_options}->[$arguments];
|
||||||
|
return "/msg $self->{channel} $nick has chosen $self->{state_data}->{current_category}!";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($self->{current_state} =~ /getlies$/) {
|
if ($self->{current_state} =~ /getlies$/) {
|
||||||
|
@ -674,7 +681,7 @@ sub spinach_cmd {
|
||||||
$arguments--;
|
$arguments--;
|
||||||
|
|
||||||
if ($arguments < 0 or $arguments >= @{$self->{state_data}->{current_choices}}) {
|
if ($arguments < 0 or $arguments >= @{$self->{state_data}->{current_choices}}) {
|
||||||
return "$nick: Selection out of range. Please select a valid truth: $self->{state_data}->{current_choices_text}";
|
return "$nick: Selection out of range. Please select a valid truth. $self->{state_data}->{current_choices_text}";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $changed = exists $player->{truth};
|
my $changed = exists $player->{truth};
|
||||||
|
@ -823,6 +830,7 @@ sub run_one_state {
|
||||||
if ($self->{previous_state} ne $self->{current_state}) {
|
if ($self->{previous_state} ne $self->{current_state}) {
|
||||||
$state_data->{newstate} = 1;
|
$state_data->{newstate} = 1;
|
||||||
$state_data->{ticks} = 1;
|
$state_data->{ticks} = 1;
|
||||||
|
$state_data->{ticks} += $state_data->{tick_drift} if exists $state_data->{tick_drift};
|
||||||
$state_data->{first_tock} = 1;
|
$state_data->{first_tock} = 1;
|
||||||
} else {
|
} else {
|
||||||
$state_data->{newstate} = 0;
|
$state_data->{newstate} = 0;
|
||||||
|
@ -1307,10 +1315,12 @@ sub choosecategory {
|
||||||
push @choices, $cat;
|
push @choices, $cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
last if @choices == 8;
|
last if @choices == 7;
|
||||||
last if ++$no_infinite_loops > 200;
|
last if ++$no_infinite_loops > 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push @choices, 'RANDOM';
|
||||||
|
|
||||||
$state->{categories_text} = '';
|
$state->{categories_text} = '';
|
||||||
my $i = 1;
|
my $i = 1;
|
||||||
my $comma = '';
|
my $comma = '';
|
||||||
|
@ -1341,7 +1351,7 @@ sub choosecategory {
|
||||||
|
|
||||||
if (exists $state->{random_category}) {
|
if (exists $state->{random_category}) {
|
||||||
delete $state->{random_category};
|
delete $state->{random_category};
|
||||||
my $category = $state->{category_options}->[rand @{$state->{category_options}}];
|
my $category = $state->{category_options}->[rand (@{$state->{category_options}} - 1)];
|
||||||
$self->send_message($self->{channel}, "$color{bold}Category: $category!$color{reset}");
|
$self->send_message($self->{channel}, "$color{bold}Category: $category!$color{reset}");
|
||||||
$state->{current_category} = $category;
|
$state->{current_category} = $category;
|
||||||
return 'next';
|
return 'next';
|
||||||
|
@ -1349,9 +1359,9 @@ sub choosecategory {
|
||||||
|
|
||||||
|
|
||||||
if (++$state->{counter} > $state->{max_count}) {
|
if (++$state->{counter} > $state->{max_count}) {
|
||||||
$state->{players}->[$state->{current_player}]->{missedinputs}++;
|
# $state->{players}->[$state->{current_player}]->{missedinputs}++;
|
||||||
my $name = $state->{players}->[$state->{current_player}]->{name};
|
my $name = $state->{players}->[$state->{current_player}]->{name};
|
||||||
my $category = $state->{category_options}->[rand @{$state->{category_options}}];
|
my $category = $state->{category_options}->[rand (@{$state->{category_options}} - 1)];
|
||||||
$self->send_message($self->{channel}, "$color{bold}$name took too long to choose. Randomly choosing: $category!$color{reset}");
|
$self->send_message($self->{channel}, "$color{bold}$name took too long to choose. Randomly choosing: $category!$color{reset}");
|
||||||
$state->{current_category} = $category;
|
$state->{current_category} = $category;
|
||||||
return 'next';
|
return 'next';
|
||||||
|
@ -1390,6 +1400,7 @@ sub getnewquestion {
|
||||||
delete $player->{deceived};
|
delete $player->{deceived};
|
||||||
delete $player->{skip};
|
delete $player->{skip};
|
||||||
}
|
}
|
||||||
|
$state->{current_choices_text} = "";
|
||||||
return 'next';
|
return 'next';
|
||||||
} else {
|
} else {
|
||||||
return 'wait';
|
return 'wait';
|
||||||
|
@ -1484,61 +1495,61 @@ sub findtruth {
|
||||||
|
|
||||||
return 'next' if not @notruth;
|
return 'next' if not @notruth;
|
||||||
|
|
||||||
if ($state->{ticks} % $tock == 0) {
|
if ($state->{init}) {
|
||||||
delete $state->{first_tock};
|
delete $state->{init};
|
||||||
if ($state->{init}) {
|
|
||||||
delete $state->{init};
|
|
||||||
|
|
||||||
my @choices;
|
my @choices;
|
||||||
my @suggestions = @{$state->{current_question}->{suggestions}};
|
my @suggestions = @{$state->{current_question}->{suggestions}};
|
||||||
my @lies;
|
my @lies;
|
||||||
|
|
||||||
foreach my $player (@{$state->{players}}) {
|
foreach my $player (@{$state->{players}}) {
|
||||||
if ($player->{lie}) {
|
if ($player->{lie}) {
|
||||||
if (not grep { $_ eq $player->{lie} } @lies) {
|
if (not grep { $_ eq $player->{lie} } @lies) {
|
||||||
push @lies, uc $player->{lie};
|
push @lies, uc $player->{lie};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
|
||||||
my $limit = @{$state->{players}} < 5 ? 5 : @{$state->{players}};
|
|
||||||
last if @choices >= $limit;
|
|
||||||
|
|
||||||
if (@lies) {
|
|
||||||
my $random = rand @lies;
|
|
||||||
push @choices, $lies[$random];
|
|
||||||
splice @lies, $random, 1;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@suggestions) {
|
|
||||||
my $random = rand @suggestions;
|
|
||||||
my $suggestion = uc $suggestions[$random];
|
|
||||||
push @choices, $suggestion if not grep { $_ eq $suggestion } @choices;
|
|
||||||
splice @suggestions, $random, 1;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
|
|
||||||
splice @choices, rand @choices, 0, uc $state->{current_question}->{answer};
|
|
||||||
$state->{correct_answer} = uc $state->{current_question}->{answer};
|
|
||||||
|
|
||||||
my $i = 0;
|
|
||||||
my $comma = '';
|
|
||||||
my $text = '';
|
|
||||||
foreach my $choice (@choices) {
|
|
||||||
++$i;
|
|
||||||
$text .= "$comma$i) $choice";
|
|
||||||
$comma = '; ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$state->{current_choices_text} = $text;
|
|
||||||
$state->{current_choices} = \@choices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
my $limit = @{$state->{players}} < 5 ? 5 : @{$state->{players}};
|
||||||
|
last if @choices >= $limit;
|
||||||
|
|
||||||
|
if (@lies) {
|
||||||
|
my $random = rand @lies;
|
||||||
|
push @choices, $lies[$random];
|
||||||
|
splice @lies, $random, 1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@suggestions) {
|
||||||
|
my $random = rand @suggestions;
|
||||||
|
my $suggestion = uc $suggestions[$random];
|
||||||
|
push @choices, $suggestion if not grep { $_ eq $suggestion } @choices;
|
||||||
|
splice @suggestions, $random, 1;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
splice @choices, rand @choices, 0, uc $state->{current_question}->{answer};
|
||||||
|
$state->{correct_answer} = uc $state->{current_question}->{answer};
|
||||||
|
|
||||||
|
my $i = 0;
|
||||||
|
my $comma = '';
|
||||||
|
my $text = '';
|
||||||
|
foreach my $choice (@choices) {
|
||||||
|
++$i;
|
||||||
|
$text .= "$comma$i) $choice";
|
||||||
|
$comma = '; ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$state->{current_choices_text} = $text;
|
||||||
|
$state->{current_choices} = \@choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($state->{ticks} % $tock == 0) {
|
||||||
|
delete $state->{first_tock};
|
||||||
if (++$state->{counter} > $state->{max_count}) {
|
if (++$state->{counter} > $state->{max_count}) {
|
||||||
my @missedinputs;
|
my @missedinputs;
|
||||||
foreach my $player (@{$state->{players}}) {
|
foreach my $player (@{$state->{players}}) {
|
||||||
|
@ -1627,8 +1638,16 @@ sub showlies {
|
||||||
$player->{deceived} = $lie;
|
$player->{deceived} = $lie;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'next' if $state->{current_lie_player} >= @{$state->{players}};
|
if ($state->{current_lie_player} >= @{$state->{players}}) {
|
||||||
return 'wait';
|
if (@liars) {
|
||||||
|
delete $state->{tick_drift};
|
||||||
|
} else {
|
||||||
|
$state->{tick_drift} = $tock - 1;
|
||||||
|
}
|
||||||
|
return 'next';
|
||||||
|
} else {
|
||||||
|
return 'wait';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'wait';
|
return 'wait';
|
||||||
|
|
Loading…
Reference in New Issue