/util/audio.pl

https://github.com/ekosz/bingehack · Perl · 207 lines · 188 code · 14 blank · 5 comment · 28 complexity · f5ae0ac5e1814772f6ee85451d07cee9 MD5 · raw file

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my $tts = "festival --pipe";
  5. my $board = "./rx";
  6. my %players = ();
  7. open(my $BOARD, "$board |") or die "Couldn't open board executable.\n";
  8. my $team_ant=0;
  9. my $i = 0;
  10. while (<$BOARD>){
  11. #chomp $line;
  12. my $line = $_;
  13. #print "Got: $line\n";
  14. my @player_import = split(",", $line);
  15. my ($name, $race, $gender, $alignment, $class, $hp, $hpmax, $ulevel, $ac, $num_prayers, $num_wishes, $num_deaths, $num_moves, $dlevel, $msg) = @player_import;
  16. if($name =~ m/port34/){
  17. $name='port__';
  18. $player_import[0]=$name;
  19. }
  20. if(exists($players{ $name } )){
  21. # check to see if something important changed
  22. say_if_important(player_hasher(@player_import));
  23. $players{ $name } = player_hasher(@player_import);
  24. }
  25. else{
  26. my %player_stats = %{player_hasher(@player_import)};
  27. $players{ $name } = \%player_stats;
  28. my $long_class = class_expander($class,$gender);
  29. play_text("$name the $long_class has entered $msg!\n");
  30. }
  31. $i++;
  32. if($i==10000){
  33. print "Restarting backend.\n";
  34. # close($BOARD);
  35. open($BOARD, "$board |") or die "Couldn't open board executable.\n";
  36. $i=0;
  37. }
  38. }
  39. sub say_if_important{
  40. my $ptr = shift;
  41. my %new_player_stats = %{$ptr};
  42. my $name = $new_player_stats{ 'name' };
  43. my %old_player_stats = %{$players{ $name }};
  44. my $old_gender = $old_player_stats{'gender'};
  45. my $new_gender = $new_player_stats{'gender'};
  46. my $long_old_gender = gender_possessive($old_gender);
  47. my $long_new_gender = gender_possessive($new_gender);
  48. my $old_gender_pronoun = gender_pronoun($old_gender);
  49. my $new_gender_pronoun = gender_pronoun($new_gender);
  50. my $old_msg = $old_player_stats{'msg'};
  51. my $new_msg = $new_player_stats{'msg'};
  52. my $new_long_class = class_expander($new_player_stats{'class'},$new_player_stats{'gender'});
  53. unless($old_gender eq $new_gender ){
  54. play_text("$name decided to bat for the other team. $old_gender_pronoun is now a $new_gender_pronoun.");
  55. }
  56. unless($old_player_stats{ 'num_prayers' } eq $new_player_stats{ 'num_prayers' } ){
  57. play_text("$name got down on $long_new_gender knees and prayed to $long_new_gender god.");
  58. }
  59. if($old_player_stats{ 'num_wishes' } lt $new_player_stats{ 'num_wishes' }){
  60. play_text("$name pretends that airplanes in the night sky are like shooting stars. $new_gender_pronoun made a wish!");
  61. }
  62. if($old_player_stats{ 'num_deaths' } lt $new_player_stats{ 'num_deaths'}){
  63. play_text("$name has died.");
  64. }
  65. unless(($old_player_stats{ 'ulevel' } eq $new_player_stats{ 'ulevel' }) and $new_player_stats{'ulevel'} > 5 ){
  66. if($old_player_stats{ 'ulevel' } gt $new_player_stats{ 'ulevel' }){
  67. play_text("Poor $name. $new_gender_pronoun just lost a level!");
  68. }
  69. elsif($new_player_stats{'ulevel'} > 5){ #First 5 are basically just audio spam and not worthy of mention.
  70. play_text("Congratulations to $name $new_gender_pronoun just hit level $new_player_stats{'ulevel'}.");
  71. }
  72. }
  73. unless($old_msg eq $new_msg){
  74. if($new_msg =~ m/quit/){
  75. play_text("$name the $new_long_class rage-quit.");
  76. }
  77. elsif($new_msg =~ m/escaped/){
  78. play_text("$name the $new_long_class escaped the dungeon!");
  79. }
  80. elsif($new_msg =~ m/Sokoban/){
  81. play_text("$name the $new_long_class has entered $new_msg");
  82. }
  83. elsif($new_msg =~ m/^killed/){
  84. if($new_msg =~ m/ ant /i ){
  85. $team_ant++;
  86. play_text("Go team ant! This has been kill number $team_ant for team ant.");
  87. }
  88. play_text("$name the $new_long_class was $new_msg\n");
  89. }
  90. else{
  91. play_text("$name the $new_long_class has entered the $new_msg");
  92. }
  93. }
  94. }
  95. sub gender_pronoun{
  96. if(shift =~ m/^male/){
  97. return "he";
  98. }
  99. else{
  100. return "she";
  101. }
  102. }
  103. sub gender_possessive{
  104. return gender_pronoun(shift)? "his" : "her";
  105. }
  106. sub class_expander{
  107. my $class = shift;
  108. $class =~ tr/[A-Z]/[a-z]/;
  109. my $gender = shift;
  110. if($class =~ m/^arc/){
  111. return "archeologist";
  112. }
  113. if($class =~ m/^bar/){
  114. return "barbarian";
  115. }
  116. if($class =~ m/^cav/){
  117. if($gender eq "m"){
  118. return "caveman";
  119. }
  120. if($gender eq "f"){
  121. return "cavewoman";
  122. }
  123. }
  124. if($class =~ m/^hea/){
  125. return "healer";
  126. }
  127. if($class =~ m/^kni/){
  128. return "knight";
  129. }
  130. if($class =~ m/^mon/){
  131. return "monk";
  132. }
  133. if($class =~ m/^pri/){
  134. if($gender eq "m"){
  135. return "priest";
  136. }
  137. if($gender eq "f"){
  138. return "priestess";
  139. }
  140. }
  141. if($class =~ m/^ran/){
  142. return "ranger";
  143. }
  144. if($class =~ m/^rog/){
  145. return "rogue";
  146. }
  147. if($class =~ m/^sam/){
  148. return "samurai";
  149. }
  150. if($class =~ m/^tou/){
  151. return "tourist";
  152. }
  153. if($class =~ m/^val/){
  154. return "valkyrie";
  155. }
  156. if($class =~ m/^wiz/){
  157. return "wizard";
  158. }
  159. return "UNKNOWN CLASS";
  160. }
  161. sub starts_with_vowel{
  162. my $str = shift;
  163. if($str =~ m/^{aeiou}/){
  164. return 1;
  165. }
  166. return 0;
  167. }
  168. sub player_hasher{
  169. my @player_stats = @_;
  170. my %player_hash;
  171. my ($name, $race, $gender, $alignment, $class, $hp, $hpmax, $ulevel, $ac, $num_prayers, $num_wishes, $num_deaths, $num_moves, $dlevel, $msg) = @player_stats;
  172. $player_hash{ 'name' } = $name;
  173. $player_hash{ 'race' } = $race;
  174. $player_hash{ 'gender' } = $gender;
  175. $player_hash{ 'alignment' } = $alignment;
  176. $player_hash{ 'class' } = $class;
  177. $player_hash{ 'hp' } = $hp;
  178. $player_hash{ 'hpmax' } = $hpmax;
  179. $player_hash{ 'ulevel' } = $ulevel;
  180. $player_hash{ 'ac' } = $ac;
  181. $player_hash{ 'num_prayers' } = $num_prayers;
  182. $player_hash{ 'num_wishes' } = $num_wishes;
  183. $player_hash{ 'num_deaths' } = $num_deaths;
  184. $player_hash{ 'num_moves' } = $num_moves;
  185. $player_hash{ 'dlevel' } = $dlevel;
  186. $player_hash{ 'msg' } = $msg;
  187. return \%player_hash;
  188. }
  189. sub play_text{
  190. my $text = shift;
  191. print "Saying: $text\n";
  192. `echo "$text" | festival --tts`;
  193. }