1 | #! perl # depends=irc |
1 | #! perl # depends=irc |
|
|
2 | |
|
|
3 | # statistics-package |
2 | |
4 | |
3 | use Fcntl; |
5 | use Fcntl; |
4 | use Coro::AIO; |
6 | use Coro::AIO; |
5 | |
7 | |
6 | our $UPDATE_LOGINS = EV::idle sub { |
8 | our $UPDATE_LOGINS = EV::idle sub { |
… | |
… | |
97 | my ($pl, $path) = @_; |
99 | my ($pl, $path) = @_; |
98 | $pl->ob->set_ob_key_value (schmorplog_last_save => time); |
100 | $pl->ob->set_ob_key_value (schmorplog_last_save => time); |
99 | }, |
101 | }, |
100 | ); |
102 | ); |
101 | |
103 | |
|
|
104 | cf::register_script_function "statistician::talk" => sub { |
|
|
105 | my ($who, $msg, $npc) = @_; |
|
|
106 | |
|
|
107 | my ($cmd, $args) = split /\s+/, $msg, 2; |
|
|
108 | |
|
|
109 | $args ||= $who->name; |
|
|
110 | |
|
|
111 | if ($cmd eq "deaths") { |
|
|
112 | cf::async { |
|
|
113 | my $pl = cf::player::find $args |
|
|
114 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
|
|
115 | |
|
|
116 | my $s = $pl->ob->{stats_death} |
|
|
117 | or return $who->reply ($npc, "$args didn't die even once."); |
|
|
118 | |
|
|
119 | my $rep = "$args died a total of " . $pl->ob->get_ob_key_value ("schmorplog_death_count") . " times, among them:\n\n\n\n"; |
|
|
120 | |
|
|
121 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
|
|
122 | $rep .= "$s->{$_} time(s) due to $_.\n\n"; |
|
|
123 | } |
|
|
124 | |
|
|
125 | $who->reply ($npc, $rep); |
|
|
126 | }; |
|
|
127 | } elsif ($cmd eq "kills") { |
|
|
128 | cf::async { |
|
|
129 | my $pl = cf::player::find $args |
|
|
130 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
|
|
131 | |
|
|
132 | my $s = $pl->ob->{stats_kill} |
|
|
133 | or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far."); |
|
|
134 | |
|
|
135 | my $rep = sprintf "\n\nC<%6s> %s\n\n", "Kills", "Name"; |
|
|
136 | for (sort { $s->{$a} <=> $s->{$b} } keys %$s) { |
|
|
137 | $rep .= sprintf "C<%6s> %s\n\n", $s->{$_}, $_; |
|
|
138 | } |
|
|
139 | |
|
|
140 | $who->reply ($npc, $rep); |
|
|
141 | }; |
|
|
142 | } elsif ($cmd eq "hi") { |
|
|
143 | $who->reply ($npc, "Hello!\n\n" |
|
|
144 | . "I am a statistician, I keep statistics about all people here.\n\n" |
|
|
145 | . "To know how often somebody died, ask C<deaths> I<playername>\n\n" |
|
|
146 | . "To know how many kills somebody scored, ask C<kills> I<playername>"); |
|
|
147 | } else { |
|
|
148 | $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); |
|
|
149 | } |
|
|
150 | |
|
|
151 | $cmd = lc $cmd; |
|
|
152 | }; |
|
|
153 | |