Advertisement
KeplerBR

[Plugin 4fun] Jogo da Forca

Feb 24th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 19.37 KB | None | 0 0
  1. # Plugin para jogar Jogo da Forca 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("forca", "Jogo da Forca 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 da forca", \&commandInform]
  27.     );
  28.  
  29. # Variáveis globais
  30. my ($currentTip, $currentWord, @currentWordHidden, @lettersUsed, @wordListUsed);
  31. my $type = 2;
  32. my $inform = 0;
  33. my $delayPlacar = 0;
  34. my $datadir = $Plugins::current_plugin_folder;
  35. my (%scoreboard, %listSkills, %listSkillsHandle, %listItems, %listMonster, %nickListTime);
  36. my @alphabet = ('a' .. 'z', 'á', 'é', 'í', 'ó', 'ú', 'â', 'ê', 'î', 'ô', 'û', 'à', 'è', 'ì', 'ò', 'ù', 'ã', 'õ', 'ç');
  37.  
  38. # Database info
  39. my $hostname= "127.0.0.1";
  40. my $port = 3306;
  41. my $user = "ragnarok";
  42. my $password = "ragnarok";
  43. my $database = "ragna4fun";
  44. my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port;mysql_enable_utf8=1";
  45. my $dbh = DBI->connect($dsn, $user, $password); # Connect to the database
  46.  
  47.     ################################
  48.     #On Unload code
  49.     sub on_unload {
  50.         Plugins::delHooks($hooks);
  51.         Commands::unregister($commandHangmanGame);
  52.     }
  53.  
  54.     ################################
  55.     # Carregar lista de palavras e placar
  56.     sub start {
  57.         # Carregar palavras
  58.         %listSkills = reverse %Skill::StaticInfo::names;
  59.         %listSkillsHandle = reverse %Skill::StaticInfo::handles;
  60.        
  61.         for (keys %items_lut) {
  62.             $items_lut{$_} = lc($items_lut{$_});
  63.         }
  64.         %listItems = reverse %items_lut;
  65.        
  66.         open my $fileListMonster,"<" . $datadir . '\listMonsterSpecial.txt' or die $!;
  67.             while (<$fileListMonster>) {
  68.                 my $line = $_;
  69.                 $line =~ s/\R//g;
  70.                 $line =~ /(.*)\t(\d*)\t(.*)\t(.*)\t(\d*)\t(\d*)\t(\d*)\t(\d*)/;
  71.                 $listMonster{$1}{name} = $1;    $listMonster{$1}{lvl} = $2;     $listMonster{$1}{size} = $3;
  72.                 $listMonster{$1}{race} = $4;    $listMonster{$1}{drop1} = $5;   $listMonster{$1}{drop2} = $6;
  73.                 $listMonster{$1}{drop3} = $7;   $listMonster{$1}{drop4} = $8;
  74.             }
  75.         close $fileListMonster;
  76.        
  77.         # Carregar placar      
  78.         my $sth = $dbh->prepare("SELECT * FROM $config{table}");
  79.         $sth->execute();
  80.         while (my $ref = $sth->fetchrow_hashref()) {
  81.             $scoreboard{$ref->{nick}} = $ref->{points};
  82.         }
  83.         $sth->finish();
  84.     }
  85.  
  86.     ################################
  87.     # Iniciar partida de Jogo da Forca
  88.     sub startGame {
  89.         look(3, 2);
  90.        
  91.         # Anti-bug
  92.         return 0 if ($currentWord);
  93.         return 0 if ($taskManager->countTasksByName('pluginForcaRecomeçarPart2'));
  94.  
  95.         # Pegar uma palavra aleatóriamente
  96.         my $attempts = 0;
  97.         chooseWord:
  98.             $type++;
  99.             $type = 0 if ($type > 2);
  100.  
  101.             if ($type == 2) {
  102.                 $currentWord = lc($items_lut{(keys %items_lut)[rand keys %items_lut]});
  103.             } elsif ($type == 1) {
  104.                 $currentWord = lc($listSkills{(keys %listSkills)[rand keys %listSkills]});
  105.             } else {
  106.                 $currentWord = $listMonster{(keys %listMonster)[rand keys %listMonster]}{name};
  107.             }
  108.             $attempts++;
  109.             # Caso tenha repetido o loop muitas vezes, é provável que já usou todas as palavras possíveis
  110.             @wordListUsed = () if ($attempts > 100);
  111.         message "$currentWord\n";
  112.         goto chooseWord if ($currentWord ~~ @wordListUsed); # Palavra repetida
  113.             push (@wordListUsed, $currentWord);
  114.  
  115.             # Gerar palavra oculta
  116.             @currentWordHidden = ();
  117.             for (my $i = 0; $i < length($currentWord); $i++) {
  118.                 my $key = substr($currentWord, $i, 1);
  119.                 if ($key ~~ @alphabet) {
  120.                     (substr($currentWord, $i + 1, 1) ~~ @alphabet) ?
  121.                         push (@currentWordHidden, '_ ') :
  122.                         push (@currentWordHidden, '_');
  123.                 } else {
  124.                     ($key eq ' ') ?
  125.                         push (@currentWordHidden, '  ') :
  126.                         push (@currentWordHidden, $key);
  127.                 }
  128.             }
  129.             my $count = 0;
  130.             for (my $i = 0; $i <= @currentWordHidden; $i++) {
  131.                 $count += length($currentWordHidden[$i]);
  132.             }
  133.         goto chooseWord if ($count + 60 > $config{message_length_max}); # Evitar palavras muito grande que possam quebrar as mensagens em duas
  134.  
  135.         # Gerar a dica
  136.         $currentTip = '';
  137.         if ($type == 2) {
  138.             my $descItem = $itemsDesc_lut{$listItems{$currentWord}} || 0;
  139.             if ($descItem) {
  140.             message "-> $currentWord\n\n$descItem\n", "list";
  141.             my @num = (0..5);
  142.                 while (!$currentTip) {
  143.                     my $typeTip = $num[(rand @num)];
  144.                     if ($typeTip == 0) {
  145.                         $descItem =~ /Tipo: (.+)/i;
  146.                        
  147.                         $currentTip = "Item do tipo '$1'" if ($1);
  148.                     } elsif ($typeTip == 1) {
  149.                         $descItem =~ /Equipa em: (.+)/i;
  150.                        
  151.                         $currentTip = "Item que equipa em '$1'" if ($1);
  152.                     } elsif ($typeTip == 2) {
  153.                         $descItem =~ /Classes que utilizam: (.+?)\./;
  154.  
  155.                         $currentTip = "Item que podem equipar '$1'"  if (length($1) < 70 && $1);
  156.                     } elsif ($typeTip == 3) {
  157.                         $descItem =~ /(.+?)\./i;
  158.  
  159.                         $currentTip = $1 if ($1 && length($1) + length($currentWord) < $config{message_length_max} && !($1 =~ /$currentWord/i));
  160.                     } elsif ($typeTip == 4) {
  161.                         $descItem =~ /Nível da Arma: (.+?)/i;
  162.                        
  163.                         $currentTip = "Equipamento de nível '$1'" if ($1);
  164.                     } else {
  165.                         $descItem =~ /Nível necess?rio: (.+?)/i;
  166.                        
  167.                         $currentTip = "Equipamento que requer nível '$1'" if ($1);
  168.                     }
  169.  
  170.                     # Apagar valor do $num que foi usado
  171.                     @num = grep($_ != $typeTip, @num);
  172.  
  173.                     if (!@num) {
  174.                         $descItem =~ /Peso: (.+)/i;
  175.                        
  176.                         if ($1) {
  177.                             $currentTip = "Item que pesa '$1'" if ($1);
  178.                         } else {
  179.                             $currentTip = 'Um item!'
  180.                         }
  181.                     }
  182.                 }
  183.             } else {
  184.                 $currentTip = 'Um item';
  185.             }
  186.         } elsif ($type == 1) {
  187.             my $descSkill = $skillsDesc_lut{$listSkillsHandle{$Skill::StaticInfo::names{$currentWord}}} || 0;
  188.             if ($descSkill) {
  189.             message "-> $currentWord\n\n$descSkill\n", "list";
  190.             my @num = (0..2);
  191.                 while (!$currentTip) {
  192.                     my $typeTip = $num[(rand @num)];
  193.                     if ($typeTip == 0) {
  194.                         $descSkill =~ /(?:Tipo|Forma de Habilidade)\s*:\s* (.+)/i;
  195.                        
  196.                         $currentTip = "Habilidade do tipo '$1'" if ($1);
  197.                     } elsif ($typeTip == 1) {
  198.                         $descSkill =~ /Alvo\s*:\s* (.+)/i;
  199.                        
  200.                         $currentTip = "Habilidade que o alvo é '$1'" if ($1);
  201.                     } else {
  202.                         $descSkill =~ /(?:Resultado|Descrição|Content|Conteúdo)\s*:\s* (.+)(?:\.|)/i;
  203.  
  204.                         $currentTip = $1 if ($1 && length($1) + length($currentWord) < $config{message_length_max});
  205.                     }
  206.  
  207.                     # Apagar valor do $num que foi usado usado
  208.                     @num = grep($_ != $typeTip, @num);
  209.  
  210.                     $currentTip = 'Uma habilidade!' if (!@num);
  211.                 }
  212.             } else {
  213.                 $currentTip = 'Uma habilidade';
  214.             }
  215.         } else {
  216.             message "->$currentWord\n\n$listMonster{$currentWord}{lvl} $listMonster{$currentWord}{size} $listMonster{$currentWord}{race}\n", "list";
  217.             my $typeTip = int(rand(4)) - 1;
  218.                
  219.             if ($typeTip == 3) {
  220.                 $currentTip = "Monstro de nível '$listMonster{$currentWord}{lvl}'";
  221.             } elsif ($typeTip == 2) {
  222.                 $currentTip = "Monstro de tamanho '$listMonster{$currentWord}{size}'";
  223.             } elsif ($typeTip == 1) {
  224.                 $currentTip = "Monstro da raça '$listMonster{$currentWord}{race}'";
  225.             } else {
  226.                 my $randDrop = 0;
  227.                 $randDrop++ if ($items_lut{$listMonster{$currentWord}{drop1}});
  228.                 $randDrop++ if ($items_lut{$listMonster{$currentWord}{drop2}});
  229.                 $randDrop++ if ($items_lut{$listMonster{$currentWord}{drop3}});
  230.                 $randDrop++ if ($items_lut{$listMonster{$currentWord}{drop4}});
  231.                 message "randDrop: $randDrop\n";
  232.                 $randDrop = int(rand($randDrop));
  233.                
  234.                 if ($randDrop == 1) {
  235.                     $currentTip = "Monstro que dropa '" . $items_lut{$listMonster{$currentWord}{drop1}} . "'";
  236.                 } elsif ($randDrop == 2) {
  237.                     $currentTip = "Monstro que dropa '" . $items_lut{$listMonster{$currentWord}{drop2}} . "'";
  238.                 } elsif ($randDrop == 3) {
  239.                     $currentTip = "Monstro que dropa '" . $items_lut{$listMonster{$currentWord}{drop3}} . "'";
  240.                 } elsif ($randDrop == 4) {
  241.                     $currentTip = "Monstro que dropa '" . $items_lut{$listMonster{$currentWord}{drop4}} . "'";
  242.                 } else {
  243.                     $currentTip = "Monstro de nível '$listMonster{$currentWord}{lvl}'";
  244.                 }
  245.             }
  246.         }
  247.        
  248.         # Enviar mensagens informando
  249.         Commands::run("c Dica: $currentTip!");
  250.         Commands::run("e heh") if $config{sendEmoticon};
  251.         $taskManager->add(Task::Timeout->new(
  252.             name => 'pluginForcaRecomeçarPart2',
  253.             inGame => 1,
  254.             function => sub {
  255.                 Commands::run("c Palavra atual: @currentWordHidden");
  256.                 @lettersUsed = ();
  257.                 $hooks = Plugins::addHooks(
  258.                         ['packet_pubMsg', \&analyzeResponse],
  259.                     );
  260.                 },
  261.             seconds => 2,
  262.         ));
  263.         $inform = 0;
  264.     }
  265.  
  266.     ################################
  267.     # Verificar mensagem pública
  268.     sub analyzeResponse {
  269.         my $hookname = shift;
  270.         my $args = shift;
  271.  
  272.         return 0 if (!$currentWord);
  273.        
  274.         # Recolhendo variáveis...
  275.         my $nickPlayer = $args->{pubMsgUser};
  276.         my $chatMessage = lc($args->{Msg});
  277.         my $initialLetter = substr($chatMessage, 0, 1);
  278.  
  279.         return 0 if !($initialLetter ~~ @alphabet);
  280.  
  281.         # Palavras-chaves de comandos
  282.         if ($chatMessage eq "dica") {
  283.             Commands::run("c Dica: $currentTip!");
  284.             return 0;
  285.         } elsif ($chatMessage eq "palavra") {
  286.             Commands::run("c Palavra: @currentWordHidden");
  287.             return 0;
  288.         }
  289.  
  290.         # Verificar respostas
  291.         if (length($chatMessage) != 1 &&
  292.             ((length($chatMessage) + 2) < length($currentWord)) ||
  293.             (length($currentWord) < (length($chatMessage) - 2))) {
  294.             # Ignorar mensagens com tamanho muito diferente da palavra secreta
  295.  
  296.             return 0;
  297.         } elsif (length($chatMessage) > 1 && $chatMessage ne $currentWord) {
  298.             # Errou a palavra
  299.  
  300.             if (27 + length($chatMessage) + length($currentTip) >= $config{message_length_max}) {
  301.                 Commands::run("c A palavra não é '$chatMessage'!");
  302.             } else {
  303.                 Commands::run("c A palavra não é '$chatMessage'! Dica: $currentTip");
  304.             }
  305.             Commands::run("e ??") if $config{sendEmoticon};
  306.             return 0;
  307.         } elsif ($chatMessage eq $currentWord) {
  308.             # Acertou palavra inteira
  309.            
  310.             # Calcular pontos ganhos e amarzena-lo
  311.             my $hiddenLetters = 0;
  312.             for (@currentWordHidden) {
  313.                 $hiddenLetters++ if ($_ eq '_ ' || $_ eq '_');
  314.             }
  315.  
  316.             my $pointsEarned = 5 + int($hiddenLetters/2);
  317.             &saveScores($nickPlayer, $pointsEarned);
  318.        
  319.             # Informar
  320.             Commands::run("c $nickPlayer, parabéns! Acertou a palavra! +$pointsEarned pontos! Você tem $scoreboard{$nickPlayer} pontos!");
  321.             Commands::run("e e11") if $config{sendEmoticon};
  322.            
  323.             # Iniciar nova partida
  324.             undef $currentWord;
  325.             Plugins::delHook('packet_pubMsg', $hooks);
  326.             unless ($taskManager->countTasksByName('pluginForcaRecomeçarPart1')) {
  327.                 $taskManager->add(Task::Timeout->new(
  328.                         name => 'pluginForcaRecomeçarPart1',
  329.                         inGame => 1,
  330.                         function => sub {&startGame;},
  331.                         seconds => 5,
  332.                 ));
  333.             }
  334.            
  335.             $inform = 0;
  336.             return 1;
  337.         }
  338.  
  339.         # Verificar se esta repetindo letra
  340.  
  341.         my $contidion = $initialLetter;
  342.         $contidion = "/|ã|á|à|â|a|/" if ($initialLetter eq 'a');    $contidion = "/|é|è|ê|e|/" if ($initialLetter eq 'e');
  343.         $contidion = "/|í|ì|î|i|/" if ($initialLetter eq 'i');       $contidion = "/|õ|ó|ò|ô|o|/" if ($initialLetter eq 'o');
  344.         $contidion = "/|ú|ù|u|/" if ($initialLetter eq 'u');
  345.        
  346.         my $i = 0;
  347.         my $repeatingLetter = 0;
  348.         for (@lettersUsed) {
  349.             if ($contidion =~ $lettersUsed[$i]) {
  350.             $repeatingLetter = 1;
  351.             last;
  352.             }
  353.             $i++;
  354.         }
  355.  
  356.         if ($repeatingLetter) {
  357.             # Esta repetindo letra
  358.            
  359.             exists $scoreboard{$nickPlayer} ?
  360.                 Commands::run("c $nickPlayer, '$initialLetter' já foi usado! (Você tem $scoreboard{$nickPlayer} ponto(s))") :
  361.                 Commands::run("c $nickPlayer, '$initialLetter' já foi usado! (Para ver o placar, basta me mandar PM!)");
  362.             Commands::run("e !") if $config{sendEmoticon};
  363.        
  364.             $inform = 0;
  365.             return 0;
  366.         } else {
  367.             # Não esta repetindo letra
  368.            
  369.             push (@lettersUsed, $initialLetter);
  370.         }
  371.  
  372.         # Verificar se acertou alguma letra
  373.         my $pointsEarned = 0;
  374.         for (my $i = 0; $i < length($currentWord); $i++) {
  375.             my $letter = substr($currentWord, $i, 1);
  376.  
  377.             if ($letter ~~ @alphabet) {
  378.                 if ($contidion =~ $letter) {
  379.                     $pointsEarned++;
  380.                     $currentWordHidden[$i] = substr($currentWord, $i, 1);
  381.                 }
  382.             }
  383.         }
  384.        
  385.         if ($pointsEarned) {
  386.             # Acertou uma letra ou mais
  387.            
  388.             # Salvar pontos ganhos
  389.             &saveScores($nickPlayer, $pointsEarned);
  390.  
  391.             # Verificar se completou a palavra
  392.             my $incompleteWord = 0;
  393.             for (@currentWordHidden) {
  394.                 $incompleteWord = 1 if ($_ eq '_ ' || $_ eq '_');
  395.             }
  396.  
  397.             if ($incompleteWord) {
  398.                 Commands::run("c Certo, $nickPlayer! +$pointsEarned! Palavra esta: @currentWordHidden");
  399.                 Commands::run("e ok") if $config{sendEmoticon};
  400.             } else {
  401.                 Commands::run("c Certo, $nickPlayer! +$pointsEarned! Palavra concluída: @currentWordHidden");
  402.                 Commands::run("e ok") if $config{sendEmoticon};
  403.                
  404.                 # Iniciar nova partida
  405.                 undef $currentWord;
  406.                 Plugins::delHook('packet_pubMsg', $hooks);
  407.                 unless ($taskManager->countTasksByName('pluginForcaRecomeçarPart1')) {
  408.                     $taskManager->add(Task::Timeout->new(
  409.                         name => 'pluginForcaRecomeçarPart1',
  410.                         inGame => 1,
  411.                         function => sub {&startGame;},
  412.                         seconds => 5,
  413.                     ));
  414.                 }
  415.             }
  416.         } else {
  417.             # Não acertou
  418.             exists $scoreboard{$nickPlayer} ?
  419.                 Commands::run("c $nickPlayer, '$initialLetter' não consta no nome! (Você tem $scoreboard{$nickPlayer} ponto(s))") :
  420.                 Commands::run("c $nickPlayer, '$initialLetter' não consta no nome! (Para ver o placar, basta me mandar PM!)");
  421.             Commands::run("e ??") if $config{sendEmoticon};
  422.         }
  423.        
  424.         # Finalizar
  425.         $inform = 0; # Evitar flood
  426.     }
  427.  
  428.     ################################
  429.     # Salvar pontos dos players
  430.     sub saveScores {
  431.         my ($nickPlayer, $pointsEarned) = @_;
  432.  
  433.         if (exists $scoreboard{$nickPlayer}) {
  434.             # Atualizar placar
  435.             $scoreboard{$nickPlayer} += $pointsEarned;
  436.            
  437.             my $sth = $dbh->prepare("UPDATE $config{table} SET points = ? WHERE nick = ?")
  438.                 or die "Couldn't prepare statement";
  439.             $sth->execute($scoreboard{$nickPlayer}, $nickPlayer)
  440.                 or die "Couldn't execute the query";
  441.             $sth->finish;
  442.         } else {
  443.             # Adicionar player
  444.             $scoreboard{$nickPlayer} = $pointsEarned;
  445.            
  446.             my $sth = $dbh->prepare("INSERT into $config{table}(nick, points) values(?,?)")
  447.                 or die "Couldn't prepare statement";
  448.             $sth->execute($nickPlayer, $scoreboard{$nickPlayer})
  449.                 or die "Couldn't execute the query";
  450.             $sth->finish;
  451.         }
  452.     }
  453.  
  454.     ################################
  455.     # Informar que esta tendo Jogo da Forca
  456.     sub informPublic {
  457.         $inform++;
  458.         if ($inform == 3) { # Evitar flood
  459.             my $count = 0;
  460.             for (my $i = 0; $i <= @currentWordHidden; $i++) {
  461.                 $count += length($currentWordHidden[$i]);
  462.             }
  463.  
  464.             Commands::run("c Jogue Jogo da Forca! Cada letra vale 1 ponto; acertar a palavra valem 5 ou mais!");
  465.             Commands::run("c Para ver o placar e como participar, basta me enviar PM!");
  466.             if (length($currentTip) + $count + 22 > $config{message_length_max}) {
  467.                 Commands::run("c Dica: $currentTip!");
  468.                 Commands::run("c Palavra atual: @currentWordHidden");
  469.             } else {
  470.                 Commands::run("c Dica: $currentTip! Palavra atual: @currentWordHidden");
  471.             }
  472.             $inform = 0;
  473.         }
  474.     }
  475.    
  476.     ################################
  477.     # Ao receber uma PM, irá da umas infos
  478.     sub informPM {
  479.         my $hookname = shift;
  480.         my $args = shift;
  481.         my $nick = $args->{privMsgUser};
  482.         my $message = $args->{privMsg};
  483.        
  484.         # Anti-Spam
  485.         if ((time - $nickListTime{$nick}) < 10) {
  486.             Commands::run("pm \"$nick\" Desculpe-me, você mandou PM a pouco tempo! Tente daqui a 10s!");
  487.             return;
  488.         }
  489.         $nickListTime{$nick} = time;
  490.  
  491.         # Analisando PM
  492.         if ($message =~ /placar completo/i) {
  493.             my $i = 0;
  494.             for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  495.                 $i++;
  496.                 Commands::run("pm \"$nick\" * $i° - $_ - $scoreboard{$_} pontos");
  497.                 last if ($i == 100);
  498.             }
  499.         } elsif ($message =~ /comentário:/i || $message =~ /comentario:/i) {
  500.             # Anti-flood
  501.             my $sth = $dbh->prepare("SELECT * FROM forca_comment WHERE nick = ?")
  502.                 or die "Couldn't prepare statement";
  503.             $sth->execute($nick)
  504.                 or die "Couldn't execute the query";
  505.             $sth->finish;
  506.            
  507.             if ($sth->rows < 2) {
  508.                 $message =~ s/comentário://i;
  509.                 my $sth = $dbh->prepare("INSERT into forca_comment(server, nick, comment) value(?,?,?)")
  510.                     or die "Couldn't prepare statement";
  511.                 $sth->execute($config{master}, $nick, $message)
  512.                     or die "Couldn't execute the query";
  513.                 $sth->finish;
  514.                
  515.                 Commands::run("pm \"$nick\" Obrigado, $nick! Seu comentário foi enviado com sucesso! Irei lê-lo depois.");
  516.             } else {
  517.                 Commands::run("pm \"$nick\" Desculpe, $nick, mas não é possivel enviar mais que 2 comentários por personagem...");
  518.             }
  519.         } elsif ($scoreboard{$message}) {
  520.             my $i = 0;
  521.             for (sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  522.                 $i++;
  523.                 last if ($_ eq $message);
  524.             }
  525.             Commands::run("pm \"$nick\" $message tem $scoreboard{$message} pontos e esta em $i° lugar!");
  526.         } else {
  527.             Commands::run("pm \"$nick\" Para participar do Jogo da Forca, basta você descobrir a palavra enviando a letra (apenas a letra) ou palavra que acredita que seja!");
  528.             Commands::run("pm \"$nick\" ENVIE A MENSAGEM PELO CHAT PÚBLICO, não por PM! Pelo chat pública!!");
  529.             Commands::run("pm \"$nick\" Quanto mais incompleta estiver a palavra, mais pontos ganha ao acerta-la!");
  530.             Commands::run("pm \"$nick\" -------------------");
  531.             Commands::run("pm \"$nick\" Dica: Envie, pelo chat público (NÃO por PM):");
  532.             Commands::run("pm \"$nick\" * 'dica' -> para exibir a dica da palavra atual");
  533.             Commands::run("pm \"$nick\" * 'palavra' -> para exibir o estado atual da palavra");
  534.             Commands::run("pm \"$nick\" -------------------");
  535.             Commands::run("pm \"$nick\" Placar dos 15 primeiros lugares:");
  536.  
  537.             my $i = 0;
  538.             for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  539.                 $i++;
  540.                 Commands::run("pm \"$nick\" * $i° - $_ - $scoreboard{$_} pontos");
  541.                 last if ($i == 15);
  542.             }
  543.            
  544.             Commands::run("pm \"$nick\" Total de jogadores: " . scalar (keys %scoreboard));
  545.             Commands::run("pm \"$nick\" -------------------");
  546.             Commands::run("pm \"$nick\" Se quiser me enviar um comentário, mande PM com o texto e escrito 'Comentário:'");
  547.             Commands::run("pm \"$nick\" Exemplo: 'Comentário: O jogo da forca é muito legal =)'");
  548.             Commands::run("pm \"$nick\" -------------------");
  549.             Commands::run("pm \"$nick\" Para visualizar a pontuação específica de um jogador, envie, por PM, o nick dele");
  550.             Commands::run("pm \"$nick\" Para visualizar os 100 primeiros lugares, envie, por PM, 'placar completo'!");
  551.         }
  552.     }
  553.  
  554.     ################################
  555.     # Função do comando "inform"
  556.     sub commandInform {
  557.         my $message;
  558.  
  559.         $message = center('Placar atual', 50, '-') . "\n";
  560.        
  561.         my $i = 0;
  562.         for ( sort {$scoreboard{$b} <=> $scoreboard{$a}} keys %scoreboard) {
  563.             $i++;
  564.             $message .= "* $i° - $_ - $scoreboard{$_} pontos\n";
  565.             last if ($i == 50);
  566.         }
  567.  
  568.         $message .= "Total: " . scalar (keys %scoreboard) . "\n";
  569.  
  570.         $message .= center('Informações do Jogo da Forca atual', 50, '-') . "\n";
  571.         $message .= "Palavra atual: $currentWord\n";
  572.         $message .= "Estado atual: @currentWordHidden\n";
  573.         $message .= "Letras já usadas: @lettersUsed\n";
  574.         $message .= "Dica atual: $currentTip\n";
  575.  
  576.         message $message, "list";
  577.     }
  578.  
  579. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement