… | |
… | |
42 | aio_rename "$cf::LOCALDIR/highscore~", "$cf::LOCALDIR/highscore" |
42 | aio_rename "$cf::LOCALDIR/highscore~", "$cf::LOCALDIR/highscore" |
43 | and return; |
43 | and return; |
44 | |
44 | |
45 | aio_pathsync "$cf::LOCALDIR"; |
45 | aio_pathsync "$cf::LOCALDIR"; |
46 | |
46 | |
47 | warn "saved highscore file.\n"; |
47 | cf::trace "saved highscore file.\n"; |
48 | |
48 | |
49 | 1 |
49 | 1 |
50 | } |
50 | } |
51 | |
51 | |
52 | our $HEADER = " |place | name | experience | killer | HP |mana |grace|\n"; |
52 | our $HEADER = " | rank | name | experience | reason | HP |mana |grace|\n"; |
53 | our $SEP = " +------+-------------|--------------------|----------------------+-----+-----+-----+\n"; |
53 | our $SEP = " +------+--------------------|--------------|----------------------+-----+-----+-----+\n"; |
54 | our $FORMAT = " | %4s | %-11.11s | %18s | %-20.20s | %3s | %3s | %3s |\n"; |
54 | our $FORMAT = " | %4s | %-18.18s | %12s | %-20.20s | %3s | %3s | %3s |\n"; |
55 | |
55 | |
56 | our $SCORE_CHANNEL = { |
56 | our $SCORE_CHANNEL = { |
57 | id => "highscore", |
57 | id => "highscore", |
58 | title => "Highscore", |
58 | title => "Highscore", |
59 | tooltip => "Your highscore ranking.", |
59 | tooltip => "Your highscore ranking.", |
… | |
… | |
62 | sub fmt($$) { |
62 | sub fmt($$) { |
63 | my ($pos, $score) = @_; |
63 | my ($pos, $score) = @_; |
64 | |
64 | |
65 | my ($name, $title, $exp, $killer, $map, $hp, $sp, $grace) = @$score; |
65 | my ($name, $title, $exp, $killer, $map, $hp, $sp, $grace) = @$score; |
66 | |
66 | |
67 | sprintf $FORMAT, $pos // "-", $name, $exp, $killer, $hp, $sp, $grace |
67 | sprintf $FORMAT, defined $pos ? $pos + 1 : "-", $name, $exp, $killer, $hp, $sp, $grace |
68 | } |
68 | } |
69 | |
69 | |
70 | sub check($) { |
70 | sub check($) { |
71 | my ($ob) = @_; |
71 | my ($ob) = @_; |
72 | |
72 | |
… | |
… | |
78 | $ob->map ? $ob->map->name || $ob->map->path : "", |
78 | $ob->map ? $ob->map->name || $ob->map->path : "", |
79 | $ob->stats->maxhp, |
79 | $ob->stats->maxhp, |
80 | $ob->stats->maxsp, |
80 | $ob->stats->maxsp, |
81 | $ob->stats->maxgrace, |
81 | $ob->stats->maxgrace, |
82 | $ob->uuid, |
82 | $ob->uuid, |
83 | int EV::now, |
83 | int AE::now, |
84 | ]; |
84 | ]; |
85 | |
85 | |
86 | cf::async { |
86 | cf::async { |
87 | my $guard = cf::lock_acquire "highscore:check"; |
87 | my $guard = cf::lock_acquire "highscore:check"; |
88 | |
88 | |
… | |
… | |
148 | . (fmt -1 + (scalar @$hiscore), $hiscore->[-1]) |
148 | . (fmt -1 + (scalar @$hiscore), $hiscore->[-1]) |
149 | . (fmt undef, $score) |
149 | . (fmt undef, $score) |
150 | . $SEP; |
150 | . $SEP; |
151 | } |
151 | } |
152 | |
152 | |
153 | warn $msg;#d# remove once working stable |
153 | cf::info $msg;#d# remove once working stable |
154 | |
154 | |
155 | $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR); |
155 | $ob->send_msg ($SCORE_CHANNEL => $msg, cf::NDI_CLEAR); |
156 | |
156 | |
157 | if ($save) { |
157 | if ($save) { |
158 | save_hiscore $hiscore |
158 | save_hiscore $hiscore |
159 | or die "unable to write highscore file: $!"; |
159 | or die "unable to write highscore file: $!"; |
160 | } |
160 | } |
161 | }; |
161 | }; |
162 | } |
162 | } |
163 | |
163 | |
164 | |
|
|