Advertisement
KeplerBR

[Plugin 4fun] Caça-Palavras

May 26th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 19.73 KB | None | 0 0
  1. # Plugin para jogar Caça Palavras no Ragnarok
  2. # by KeplerBR
  3.  
  4. package forca;
  5.     use strict;
  6.     use warnings;
  7.     use Plugins;
  8.     use Globals;
  9.     use Skill;
  10.     use Misc qw(look center);
  11.     use Log qw(message);
  12.     use Commands;
  13.     use DBI;
  14.  
  15.     # Register Plugin and Hooks
  16.     Plugins::register("wordFinder", "Jogo de Caça Palavras no Ragnarok!", \&on_unload);
  17.         my $hooks = Plugins::addHooks(
  18.             ['start3', \&start],
  19.             ['packet/received_sync', \&informPublic],
  20.             ['packet_privMsg', \&informPM],
  21.             ['packet/map_loaded', \&startGame],
  22.             #['packet_pubMsg', \&analyzeResponse],
  23.         );
  24.  
  25.     my $commandHangmanGame = Commands::register(
  26.         ["inform", "Informa o placar e sobre o atual jogo de caça palavras", \&commandInform]
  27.     );
  28.  
  29. # Variáveis globais
  30. my (@currentsWords, @totalWordListSkill, @wordListSkill, @wordListMonster, @totalWordListMonster, @totalWordListItem, @wordListItem, @scenery, @placePosition, @placeX, @placeY,
  31.     $wordsFound, $totalWords, $tip, $remainingTime, %scoreboard, %nickListTime);
  32. my @alphabet = ('a' .. 'z'); my $row = 6; my $column = 9; my $inform = 0;
  33. my $datadir = $Plugins::current_plugin_folder;
  34.  
  35. # Database info
  36. my $hostname= "127.0.0.1";
  37. my $port = 3306;
  38. my $user = "ragnarok";
  39. my $password = "ragnarok";
  40. my $database = "ragna4fun";
  41. my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port;mysql_enable_utf8=1";
  42. my $dbh = DBI->connect($dsn, $user, $password); # Connect to the database
  43.  
  44.     ################################
  45.     #On Unload code
  46.     sub on_unload {
  47.         Plugins::delHooks($hooks);
  48.         Commands::unregister($commandHangmanGame);
  49.     }
  50.  
  51.     ################################
  52.     # Carregar lista de palavras e placar
  53.     sub start {
  54.         # Carregar palavras
  55.         &loadWordList;
  56.  
  57.         # Carregar placar
  58.         my $sth = $dbh->prepare("SELECT * FROM $config{table}");
  59.         $sth->execute();
  60.         while (my $ref = $sth->fetchrow_hashref()) {
  61.             $scoreboard{$ref->{nick}} = $ref->{points};
  62.         }
  63.         $sth->finish();
  64.     }
  65.  
  66.     ################################
  67.     # Iniciar partida de Jogo da Forca
  68.     sub startGame {
  69.         return if (@scenery);
  70.  
  71.         srand;
  72.         look(3, 2);
  73.         $wordsFound = 0;
  74.  
  75.         # Pegar as palavras aleatorialmente
  76.         if (scalar(@wordListItem) + scalar(@wordListSkill) + scalar(@wordListMonster) < 6) {
  77.             @wordListSkill = @totalWordListSkill;
  78.             @wordListItem = @totalWordListItem;
  79.             @wordListMonster = @totalWordListMonster;
  80.         }
  81.        
  82.         # TODO: Deixar essa parte mais legível
  83.         $totalWords = int(rand(5));
  84.         my $rand; my $countItem = 0; my $countMonster = 0; my $countSkill = 0;
  85.         for (my $i = 0; $i <= $totalWords; $i++) {
  86.             my $type = int(rand(3));
  87.             if ($type == 2 && @wordListSkill) {
  88.                 $rand = int(rand scalar(@wordListSkill));
  89.                 $currentsWords[$i] = $wordListSkill[$rand];
  90.                 delete $wordListSkill[$rand];
  91.                 if ($currentsWords[$i]) {
  92.                     $countSkill++;
  93.                 } else {
  94.                     $i--
  95.                 }
  96.             } elsif ($type == 1 && @wordListMonster) {
  97.                 $rand = int(rand scalar(@wordListMonster));
  98.                 $currentsWords[$i] = $wordListMonster[$rand];
  99.                 delete $wordListMonster[$rand];
  100.                 if ($currentsWords[$i]) {
  101.                     $countMonster++;
  102.                 } else {
  103.                     $i--
  104.                 }
  105.             } elsif (@wordListItem) {
  106.                 $rand = int(rand scalar(@wordListItem));
  107.                 $currentsWords[$i] = $wordListItem[$rand];
  108.                 delete $wordListItem[$rand];
  109.                 if ($currentsWords[$i]) {
  110.                     $countItem++;
  111.                 } else {
  112.                     $i--
  113.                 }
  114.             }
  115.         }
  116.        
  117.         # Gerer dica
  118.         message "countItem: $countItem | countSkill: $countSkill | countMonter: $countMonster\n";
  119.         $tip = 'Há ';
  120.         if ($countItem > 1) {
  121.             $tip .= "$countItem itens";
  122.             if ($countSkill && $countMonster) {
  123.                 $tip .= ', ';
  124.             } elsif ($countSkill || $countMonster) {
  125.                 $tip .= ' e ';
  126.             }
  127.         } elsif ($countItem == 1) {
  128.             $tip .= '1 item';
  129.             if ($countSkill && $countMonster) {
  130.                 $tip .= ', ';
  131.             } elsif ($countSkill || $countMonster) {
  132.                 $tip .= ' e ';
  133.             }
  134.         }
  135.         if ($countSkill > 1) {
  136.             $tip .= "$countSkill skills ";
  137.             $tip .= 'e ' if ($countMonster);
  138.         } elsif ($countSkill == 1) {
  139.             $tip .= '1 skill ';
  140.             $tip .= 'e ' if ($countMonster);
  141.         }
  142.         if ($countMonster > 1) {
  143.             $tip .= "$countMonster monstros ";
  144.         } elsif ($countMonster == 1) {
  145.             $tip .= "1 monstro ";
  146.         }
  147.        
  148.         # Criar cenário do caça palavras
  149.             for (my $i = 0; $i <= $totalWords; $i++) {
  150.                 positionWord:
  151.                 #  Randomizar os lugares das palavras
  152.                 $placePosition[$i] = int(rand(2)) - 1; # 1 -> Em pé |:| 0 -> Deitado
  153.                 my ($coordinatesPossibleX, $coordinatesPossibleY);
  154.                 if ($placePosition[$i]) {
  155.                     $coordinatesPossibleX = $column - length($currentsWords[$i]);
  156.                     $coordinatesPossibleY = $row;
  157.                 } else {
  158.                     $coordinatesPossibleX = $row - length($currentsWords[$i]);
  159.                     $coordinatesPossibleY = $column;
  160.                 }
  161.                 $placeX[$i] = int(rand($coordinatesPossibleX)); $placeY[$i] = int(rand($coordinatesPossibleY));
  162.                
  163.                 # Verificar se uma palavra não se sobressaindo de outra sem que a letra da interceção seja igual            
  164.                 if ($i) { # Não precisa analisar caso só tenha no cenário uma única palavra
  165.                     for (my $i2 = 0; $i2 <= length($currentsWords[$i]); $i2++) {
  166.                         if ($placePosition[$i]) {
  167.                             # Em pé
  168.                             goto positionWord if ($scenery[$placeX[$i]][$placeY[$i] + $i2] &&
  169.                                 $scenery[$placeX[$i]][$placeY[$i] + $i2] ne substr($currentsWords[$i], $i2, 1));
  170.                         } else {
  171.                             # Deitado
  172.                             goto positionWord if ($scenery[$placeX[$i] + $i2][$placeY[$i]] &&
  173.                                 $scenery[$placeX[$i] + $i2][$placeY[$i]] ne substr($currentsWords[$i], $i2, 1));
  174.                         }
  175.                     }
  176.                 }
  177.                
  178.                 # Colocar a palavra no cenário
  179.                 for (my $i2 = 0; $i2 <= length($currentsWords[$i]); $i2++) {
  180.                     if ($placePosition[$i]) {
  181.                         # Em pé
  182.                         $scenery[$placeX[$i]][$placeY[$i] + $i2] = substr($currentsWords[$i], $i2, 1);
  183.                     } else {
  184.                         # Deitado
  185.                         $scenery[$placeX[$i] + $i2][$placeY[$i]] = substr($currentsWords[$i], $i2, 1);
  186.                     }
  187.                 }
  188.             }
  189.            
  190.             # Os espaços que sobraram serão preenchidos com letras aleatórias
  191.             for (my $X = 0; $X < $row; $X++) {
  192.                 for (my $Y = 0; $Y < $column; $Y++) {
  193.                     chooseRandomLetter:
  194.                     $scenery[$X][$Y] = $alphabet[rand( scalar @alphabet)] if (!$scenery[$X][$Y]);
  195.                    
  196.                     # Verificar se irá gerar um falso positivo
  197.                     # my $analysisLine = '';
  198.                     # for (my $analysisX = 0; $analysisX < $X; $analysisX++) {
  199.                         # $analysisLine .= $scenery[$analysisX][$Y];
  200.                     # }
  201.                    
  202.                     # my $analysisColumn = '';
  203.                     # for (my $analysisY = 0; $analysisY < $Y; $analysisY++) {
  204.                         # $analysisColumn .= $scenery[$X][$analysisY];
  205.                     # }
  206.                    
  207.                     # message "ALIASE...\n";
  208.                     # while (<@totalWordListSkill>) {
  209.                         # next if ($_ ~~ @currentsWords);
  210.                         # if (((length($analysisLine) >= length($_)) && $_ =~ /$analysisLine/) || ((length($analysisColumn) >= length($_)) && $_ =~ /$analysisColumn/)) {
  211.                             # message "[REPETIDA SKILL] $_ - $analysisLine - $analysisColumn\n";
  212.                             # goto chooseRandomLetter;
  213.                         # }
  214.                         # #goto chooseRandomLetter if ($_ =~ /$analysisLine/ || $_ =~ /analysisColumn/);
  215.                     # }
  216.                    
  217.                     # while (<@totalWordListItem>) {
  218.                         # next if ($_ ~~ @currentsWords);
  219.                         # if (((length($analysisLine) >= length($_)) && $_ =~ /$analysisLine/) || ((length($analysisColumn) >= length($_)) && $_ =~ /$analysisColumn/)) {
  220.                             # message "[REPETIDA ITEM] $_ - $analysisLine - $analysisColumn\n";
  221.                             # goto chooseRandomLetter;
  222.                         # }
  223.                         # #goto chooseRandomLetter if ($_ =~ /$analysisLine/ || $_ =~ /$analysisColumn/);
  224.                     # }
  225.                 }
  226.             }
  227.        
  228.         # Tempo da partida
  229.         $remainingTime = time + ($totalWords + 1) * 20 + 300;
  230.        
  231.         $taskManager->add(Task::Timeout->new(
  232.                 name => 'pluginPalavrasTempoLimite',
  233.                 function => sub {
  234.                         Commands::run("c Tempo da partida encerrado! As palavras eram: @currentsWords");
  235.                         @scenery = ();  @currentsWords = (); $inform = 0;
  236.                         Plugins::delHook('packet_pubMsg', $hooks);
  237.                         sleep 2; # MUDAR PARA TASK DEPOIS!
  238.                         &startGame;
  239.                     },
  240.                 seconds => $remainingTime - time,
  241.         ));
  242.        
  243.         # Enviar mensagens informando sobre a partida
  244.         message "Palavras: @currentsWords\n", "list";
  245.         &sendScenario;
  246.         Commands::run("e heh") if $config{sendEmoticon};
  247.         $hooks = Plugins::addHooks(
  248.             ['packet_pubMsg', \&analyzeResponse],
  249.         );
  250.        
  251.         $inform = 0;
  252.     }
  253.  
  254.     ################################
  255.     # Verificar mensagem pública
  256.     sub analyzeResponse {
  257.         my $hookname = shift;
  258.         my $args = shift;
  259.  
  260.         # Recolhendo variáveis...
  261.         my $nickPlayer = $args->{pubMsgUser};
  262.         my $chatMessage = lc($args->{Msg});
  263.         my $initialLetter = substr($chatMessage, 0, 1);
  264.  
  265.         return if (length($chatMessage) == 1);
  266.         for (my $i = 0; $i < length($chatMessage); $i++) {
  267.             return unless (substr($chatMessage, $i, 1) ~~ @alphabet);
  268.         }
  269.         $inform = 0; # Evitar flood
  270.        
  271.         # Palavras-chaves de comandos
  272.         if ($chatMessage eq "jogo") {
  273.             &sendScenario;
  274.             return;
  275.         }
  276.  
  277.         # Verificar respostas
  278.         my $answer = -1;
  279.         for (my $i = 0; $i <= $totalWords; $i++) {
  280.             if (lc($currentsWords[$i]) eq lc($chatMessage)) {
  281.                 if ($currentsWords[$i] =~ /[A-Z]+/) {
  282.                     Commands::run("c A palavra '$chatMessage' já foi encontrada no caça-palavras!");
  283.                     Commands::run("e ??") if $config{sendEmoticon};
  284.                     return;
  285.                 } else {
  286.                     $answer = $i;
  287.                     last;
  288.                 }
  289.             }
  290.         }
  291.        
  292.         if ($answer == -1) {
  293.             # Errou
  294.  
  295.             Commands::run("c No Caça Palavras não tem '$chatMessage'!");
  296.             Commands::run("e ??") if $config{sendEmoticon};
  297.             return;
  298.         } else {
  299.             # Acertou
  300.             $wordsFound++;
  301.  
  302.             # Dando pontos
  303.             my $pointsEarned = 5; # TODO: Precisa mesmo dessa variável??
  304.             &saveScores($nickPlayer, $pointsEarned);
  305.        
  306.             # Atualizando cenário
  307.             for (my $i = 0; $i < length($currentsWords[$answer]); $i++) {
  308.                 if ($placePosition[$answer]) {
  309.                     # Em pé
  310.                     $scenery[$placeX[$answer]][$placeY[$answer] + $i] = uc($scenery[$placeX[$answer]][$placeY[$answer] + $i]);
  311.                 } else {
  312.                     # Deitado
  313.                     $scenery[$placeX[$answer] + $i][$placeY[$answer]] = uc($scenery[$placeX[$answer] + $i][$placeY[$answer]]);
  314.                 }
  315.                 $currentsWords[$answer] = uc($currentsWords[$answer]);
  316.             }
  317.            
  318.             # Informar
  319.             if ($wordsFound != $totalWords + 1) {
  320.                 Commands::run("c $nickPlayer, parabéns! Acertou uma palavra! +$pointsEarned pontos! Você tem $scoreboard{$nickPlayer} pontos!");
  321.                 $remainingTime += 15;
  322.                 &sendScenario;
  323.             } else {
  324.                 &sendScenario;
  325.                 # Iniciar nova partida, caso todas as palavras tenham sido encontradas
  326.                 Commands::run("c $nickPlayer, parabéns! Caça Palavras concluído! +$pointsEarned! Você tem $scoreboard{$nickPlayer} pontos!");
  327.                
  328.                 Plugins::delHook('packet_pubMsg', $hooks);
  329.                 @scenery = ();  @currentsWords = (); $inform = 0;
  330.                 $taskManager->add(Task::Timeout->new(
  331.                         name => 'pluginPalavrasRecomeçarPart1',
  332.                         function => sub {&startGame;},
  333.                         seconds => 5,
  334.                 ));
  335.             }
  336.            
  337.             # Finalizar
  338.             Commands::run("e e11") if $config{sendEmoticon};
  339.             return 1;
  340.         }
  341.     }
  342.  
  343.     ################################
  344.     # Misc: Salvar pontos dos players
  345.     sub saveScores {
  346.         my ($nickPlayer, $pointsEarned) = @_;
  347.  
  348.         if (exists $scoreboard{$nickPlayer}) {
  349.             # Atualizar placar
  350.             $scoreboard{$nickPlayer} += $pointsEarned;
  351.            
  352.             my $sth = $dbh->prepare("UPDATE $config{table} SET points = ? WHERE nick = ?")
  353.                 or die "Couldn't prepare statement";
  354.             $sth->execute($scoreboard{$nickPlayer}, $nickPlayer)
  355.                 or die "Couldn't execute the query";
  356.             $sth->finish;
  357.         } else {
  358.             # Adicionar player
  359.             $scoreboard{$nickPlayer} = $pointsEarned;
  360.            
  361.             my $sth = $dbh->prepare("INSERT into $config{table}(nick, points) values(?,?)")
  362.                 or die "Couldn't prepare statement";
  363.             $sth->execute($nickPlayer, $scoreboard{$nickPlayer})
  364.                 or die "Couldn't execute the query";
  365.             $sth->finish;
  366.         }
  367.     }
  368.    
  369.     ################################
  370.     # Misc: Carregar lista de palavras
  371.     sub loadWordList {
  372.         my $limit;
  373.         ($row > $column) ? $limit = $column : $limit = $row;
  374.        
  375.         open my $fileListSkill,"<" . $datadir . '\listSkill.txt' or die $!;
  376.             while (<$fileListSkill>) {
  377.                 my $jump = 0;
  378.                 my $word = lc($_);
  379.                 $word =~ s/\R//g;
  380.                 next if (length($word) >= $limit);
  381.                
  382.                 for (my $i = 0; $i < length($word); $i++) {
  383.                     unless (substr($word, $i, 1) ~~ @alphabet) {
  384.                         $jump = 1;
  385.                         last;
  386.                     }
  387.                 }
  388.                 push (@totalWordListSkill, $word) if (!$jump);
  389.             }
  390.         close $fileListSkill;
  391.  
  392.         open my $fileListMonster,"<" . $datadir . '\listMonster.txt' or die $!;
  393.             while (<$fileListMonster>) {
  394.                 my $jump = 0;
  395.                 my $word = lc($_);
  396.                 $word =~ s/\R//g;
  397.                 next if (length($word) >= $limit);
  398.                
  399.                 for (my $i = 0; $i < length($word); $i++) {
  400.                     unless (substr($word, $i, 1) ~~ @alphabet) {
  401.                         $jump = 1;
  402.                         last;
  403.                     }
  404.                 }
  405.                 push (@totalWordListMonster, $word) if (!$jump);
  406.             }
  407.         close $fileListMonster;
  408.        
  409.         for (keys %items_lut) {
  410.             my $jump = 0;
  411.             my $word = lc($items_lut{$_});
  412.             next if (length($word) >= $limit);
  413.            
  414.             for (my $i = 0; $i < length($word); $i++) {
  415.                 unless (substr($word, $i, 1) ~~ @alphabet) {
  416.                     $jump = 1;
  417.                     last;
  418.                 }
  419.             }
  420.             push (@totalWordListItem, $word) if (!$jump);
  421.         }
  422.        
  423.         @wordListSkill = @totalWordListSkill;
  424.         @wordListMonster = @totalWordListMonster;
  425.         @wordListItem = @totalWordListItem;
  426.     }
  427.  
  428.     ################################
  429.     # Misc: Enviar cenário
  430.     sub sendScenario {
  431.         my $messageRemainingTime = $remainingTime - time;
  432.        
  433.         Commands::run("c § ################################ Caça Palavras:");
  434.         if (($totalWords + 1 - $wordsFound) > 1) {
  435.             Commands::run("c § #### Essa partida irá durar mais $messageRemainingTime segundos!");
  436.             Commands::run("c § #### Faltam " . scalar($totalWords + 1 - $wordsFound) . " palavras! $tip");
  437.         } elsif (($totalWords + 1 - $wordsFound) == 1) {
  438.            
  439.             Commands::run("c § #### Essa partida irá durar mais $messageRemainingTime segundos!\"");
  440.             Commands::run("c § #### Caça Palavras: Falta " . scalar($totalWords + 1 - $wordsFound) . " palavra! $tip");
  441.         } else {
  442.             Commands::run("c § #### Concluído enquanto restava mais $messageRemainingTime segundos!! Parabéns!!!");
  443.         }
  444.        
  445.         my %spacing = (
  446.             'a' => '  ',
  447.             'b' => '  ',
  448.             'c' => '  ',
  449.             'd' => '  ',
  450.             'e' => '  ',
  451.             'f' => '   ',
  452.             'g' => '  ',
  453.             'h' => '  ',
  454.             'i' => '   ',
  455.             'j' => '   ',
  456.             'k' => '  ',
  457.             'l' => '   ',
  458.             'm' => ' ',
  459.             'n' => '  ',
  460.             'o' => '  ',
  461.             'p' => '  ',
  462.             'q' => '  ',
  463.             'r' => '   ',
  464.             's' => '  ',
  465.             't' => '   ',
  466.             'u' => '  ',
  467.             'v' => '  ',
  468.             'x' => '  ',
  469.             'w' => '  ',
  470.             'y' => '  ',
  471.             'z' => '  ',
  472.             'A' => '  ',
  473.             'B' => '  ',
  474.             'C' => '  ',
  475.             'D' => '  ',
  476.             'E' => '  ',
  477.             'F' => '  ',
  478.             'G' => '  ',
  479.             'H' => '  ',
  480.             'I' => '   ',
  481.             'J' => '  ',
  482.             'K' => '  ',
  483.             'L' => '  ',
  484.             'M' => '  ',
  485.             'N' => '  ',
  486.             'O' => ' ',
  487.             'P' => '  ',
  488.             'Q' => '  ',
  489.             'R' => '  ',
  490.             'S' => '  ',
  491.             'T' => '  ',
  492.             'U' => '  ',
  493.             'V' => '  ',
  494.             'X' => '  ',
  495.             'W' => ' ',
  496.             'Y' => '  ',
  497.             'Z' => '  ',
  498.         );
  499.        
  500.         for (my $X = 0; $X < $row; $X++) {
  501.             my $message = '';
  502.             for (my $Y = 0; $Y < $column; $Y++) {
  503.                 $message .= $scenery[$X][$Y] . $spacing{$scenery[$X][$Y]} . '|';
  504.             }
  505.             Commands::run("c $message");
  506.         }
  507.     }
  508.        
  509.     ################################
  510.     # Informar que esta tendo Jogo da Forca
  511.     sub informPublic {
  512.         $inform++;
  513.         if ($inform == 4) { # Evitar flood
  514.             Commands::run("c Jogue Caça Palavras do Ragnarok! Cada acerto vale 5 ponto!");
  515.             Commands::run("c Para ver o placar e como participar, basta me enviar PM!");
  516.             &sendScenario;
  517.             $inform = 0;
  518.         }
  519.     }
  520.    
  521.     ################################
  522.     # Ao receber uma PM, irá da umas infos
  523.     sub informPM {
  524.         my $hookname = shift;
  525.         my $args = shift;
  526.         my $nick = $args->{privMsgUser};
  527.         my $message = $args->{privMsg};
  528.        
  529.         # Anti-Spam
  530.         if ((time - $nickListTime{$nick}) < 10) {
  531.             Commands::run("pm \"$nick\" Desculpe-me, você mandou PM a pouco tempo! Tente daqui a 10s!");
  532.             return;
  533.         }
  534.         $nickListTime{$nick} = time;
  535.  
  536.         # Analisando PM
  537.         if ($message =~ /placar completo/i) {
  538.             my $i = 0;
  539.             for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  540.                 $i++;
  541.                 last if (!$_);
  542.                 Commands::run("pm \"$nick\" * $i° - $_ - $scoreboard{$_} pontos");
  543.                 last if ($i == 100);
  544.             }
  545.         } elsif ($message =~ /comentário:/i || $message =~ /comentario:/i) {
  546.             # Anti-flood
  547.             my $sth = $dbh->prepare("SELECT * FROM palavras_comment WHERE nick = ?")
  548.                 or die "Couldn't prepare statement";
  549.             $sth->execute($nick)
  550.                 or die "Couldn't execute the query";
  551.             $sth->finish;
  552.            
  553.             if ($sth->rows < 2) {
  554.                 $message =~ s/comentário://i;
  555.                 my $sth = $dbh->prepare("INSERT into palavras_comment(server, nick, comment) value(?,?,?)")
  556.                     or die "Couldn't prepare statement";
  557.                 $sth->execute($config{master}, $nick, $message)
  558.                     or die "Couldn't execute the query";
  559.                 $sth->finish;
  560.                
  561.                 Commands::run("pm \"$nick\" Obrigado, $nick! Seu comentário foi enviado com sucesso! Irei lê-lo depois.");
  562.             } else {
  563.                 Commands::run("pm \"$nick\" Desculpe, $nick, mas não é possível enviar mais que 2 comentários por personagem...");
  564.             }
  565.         } elsif ($scoreboard{$message}) {
  566.             my $i = 0;
  567.             for (sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  568.                 $i++;
  569.                 last if ($_ eq $message);
  570.             }
  571.             Commands::run("pm \"$nick\" $message tem $scoreboard{$message} pontos e esta em $i° lugar!");
  572.         } else {
  573.             Commands::run("pm \"$nick\" Para participar do Caça Palavras, basta você buscar e dizer a(s) palavras escondidas!");
  574.             Commands::run("pm \"$nick\" ENVIE A MENSAGEM PELO CHAT PÚBLICO, não por PM!! Envie pelo chat pública!!");
  575.             Commands::run("pm \"$nick\" Cada partida tem um tempo para terminar! Cada acerto aumenta em +15s o tempo");
  576.             Commands::run("pm \"$nick\" -------------------");
  577.             Commands::run("pm \"$nick\" Dica: Envie, pelo chat público (NÃO por PM):");
  578.             Commands::run("pm \"$nick\" * 'jogo' -> para exibir o cenário onde estão as palavras que devem ser achadas");
  579.             Commands::run("pm \"$nick\" -------------------");
  580.             Commands::run("pm \"$nick\" Placar dos 15 primeiros lugares:");
  581.  
  582.             my $i = 0;
  583.             for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  584.                 $i++;
  585.                 last if (!$_);
  586.                 Commands::run("pm \"$nick\" * $i° - $_ - $scoreboard{$_} pontos");
  587.                 last if ($i == 15);
  588.             }
  589.            
  590.             Commands::run("pm \"$nick\" Total de jogadores: " . scalar (keys %scoreboard));
  591.             Commands::run("pm \"$nick\" -------------------");
  592.             Commands::run("pm \"$nick\" Se quiser me enviar um comentário, mande PM com o texto e escrito 'Comentário:'");
  593.             Commands::run("pm \"$nick\" Exemplo: 'Comentário: O jogo caça palavras é muito legal =)'");
  594.             Commands::run("pm \"$nick\" -------------------");
  595.             Commands::run("pm \"$nick\" Para visualizar a pontuação específica de um jogador, envie, por PM, o nick dele");
  596.             Commands::run("pm \"$nick\" Para visualizar os 100 primeiros lugares, envie, por PM, 'placar completo'!");
  597.         }
  598.     }
  599.  
  600.     ################################
  601.     # Função do comando "inform"
  602.     sub commandInform {
  603.         my $message;
  604.  
  605.         $message = center('Placar atual', 50, '-') . "\n";
  606.        
  607.         my $i = 0;
  608.         for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  609.             $i++;
  610.             $message .= "* $i° - $_ - $scoreboard{$_} pontos\n";
  611.             last if ($i == 50);
  612.         }
  613.  
  614.         $message .= "Total: " . scalar (keys %scoreboard) . "\n";
  615.  
  616.         $message .= center('Informações do Caça Palavras', 50, '-') . "\n";
  617.         $message .= "Dica: $tip\n";
  618.         $message .= "Palavras escondidas: @currentsWords\n";
  619.         my $messageRemainingTime = $remainingTime - time;
  620.         $message .= "Tempo restante: $messageRemainingTime\n";
  621.         $message .= "Cenário: \n";
  622.        
  623.         for (my $X = 0; $X < $row; $X++) {
  624.             my $messageScenery = '';
  625.             for (my $Y = 0; $Y < $column; $Y++) {
  626.                 $messageScenery .= $scenery[$X][$Y] . ' ';
  627.             }
  628.             $message .= $messageScenery . "\n";
  629.         }
  630.  
  631.         message $message, "list";
  632.     }
  633.  
  634. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement