1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
12 | use DC::Macro; |
13 | use DC::Macro; |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
16 | |
17 | |
|
|
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
19 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
20 | |
|
|
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
23 | |
|
|
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
|
|
25 | |
17 | sub new { |
26 | sub new { |
18 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
19 | |
28 | |
20 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
21 | setup_req => { |
30 | setup_req => { |
22 | extmap => 1, |
31 | extmap => 1, |
23 | excmd => 1, |
|
|
24 | widget => 2, |
32 | widget => 2, |
25 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
26 | }, |
34 | }, |
27 | ); |
35 | ); |
28 | |
36 | |
29 | $self->{map_widget}->clr_commands; |
37 | $self->update_fx_want; |
30 | |
38 | |
31 | my @cmd_help = map { |
39 | my $exp_guard = $self->addme_guard; |
32 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
40 | my $skl_guard = $self->addme_guard; |
33 | or die "unparseable command help: $_->{kw}[0]"; |
41 | my $spl_guard = $self->addme_guard; |
|
|
42 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
43 | my ($exp, $skl, $spl) = @_; |
34 | |
44 | |
35 | my $cmd = $1; |
45 | $self->register_face_handler ($exp, sub { |
36 | my @args = split /\|/, $2; |
46 | my ($face) = @_; |
37 | @args = (".*") unless @args; |
|
|
38 | |
47 | |
39 | my (undef, @par) = DC::Pod::section_of $_; |
48 | undef $exp_guard; |
40 | my $text = DC::Pod::as_label @par; |
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
41 | |
52 | |
42 | $_ = $_ eq ".*" ? "" : " $_" |
53 | $self->register_face_handler ($skl, sub { |
43 | for @args; |
54 | my ($face) = @_; |
44 | |
55 | |
45 | map ["$cmd$_", $text], |
56 | undef $skl_guard; |
46 | sort { (length $a) <=> (length $b) } |
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
47 | @args |
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
48 | } sort { $a->{par} <=> $b->{par} } |
59 | }); |
49 | DC::Pod::find command => "*"; |
60 | |
|
|
61 | $self->register_face_handler ($spl, sub { |
|
|
62 | my ($face) = @_; |
|
|
63 | |
|
|
64 | undef $spl_guard; |
|
|
65 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
66 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
67 | }); |
|
|
68 | |
|
|
69 | () |
|
|
70 | }); |
|
|
71 | |
|
|
72 | $::COMPLETER->reset; |
50 | |
73 | |
51 | $self->{json_coder} |
74 | $self->{json_coder} |
52 | ->convert_blessed |
75 | ->convert_blessed |
53 | ->filter_json_single_key_object ("\fw" => sub { |
76 | ->filter_json_single_key_object ("\fw" => sub { |
54 | $self->{widget}{$_[0]} |
77 | $self->{widget}{$_[0]} |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
87 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
88 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
89 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
90 | for values %{delete $ws->{w} || {}}; |
68 | } |
91 | } |
|
|
92 | |
|
|
93 | delete $self->{items}; |
|
|
94 | $::INV->clear; |
|
|
95 | $::INVR->clear; |
|
|
96 | $::INVR_HB->clear; |
|
|
97 | $::FLOORBOX->clear; |
69 | }); |
98 | }); |
70 | |
99 | |
71 | $self->{map_widget}->add_command (@$_) |
|
|
72 | for @cmd_help; |
|
|
73 | |
|
|
74 | { |
100 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
101 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
76 | DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
77 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
102 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
103 | } |
79 | |
104 | |
80 | { |
105 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
106 | $self->{noface} = my $tex = $TEX_NOFACE; |
82 | DC::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
83 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
107 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
108 | } |
|
|
109 | |
|
|
110 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
111 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
112 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
113 | # |
|
|
114 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
115 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
116 | # $self->{texture}[$_]->unload; |
|
|
117 | # warn "expire texture $_\n";#d# |
|
|
118 | # } |
|
|
119 | # |
|
|
120 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
121 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
122 | # warn "count is $count\n";#d# |
|
|
123 | # }; |
85 | |
124 | |
86 | $self->{open_container} = 0; |
125 | $self->{open_container} = 0; |
87 | |
126 | |
88 | # per server |
127 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
128 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
90 | |
129 | |
91 | $self |
130 | $self |
92 | } |
131 | } |
|
|
132 | |
|
|
133 | #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# |
|
|
134 | #sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# |
93 | |
135 | |
94 | sub update_fx_want { |
136 | sub update_fx_want { |
95 | my ($self) = @_; |
137 | my ($self) = @_; |
96 | |
138 | |
97 | $self->send_exti_msg (fx_want => { |
139 | $self->send_exti_msg (fx_want => { |
… | |
… | |
102 | } |
144 | } |
103 | |
145 | |
104 | sub ext_capabilities { |
146 | sub ext_capabilities { |
105 | my ($self, %cap) = @_; |
147 | my ($self, %cap) = @_; |
106 | |
148 | |
107 | $self->update_fx_want; |
|
|
108 | |
|
|
109 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
110 | my ($exp_table) = @_; |
|
|
111 | |
|
|
112 | $self->register_face_handler ($exp_table, sub { |
|
|
113 | my ($face) = @_; |
|
|
114 | |
|
|
115 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
116 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
117 | }); |
|
|
118 | |
|
|
119 | () |
|
|
120 | }); |
|
|
121 | |
|
|
122 | if (my $ts = $cap{tileset}) { |
149 | if (my $ts = $cap{tileset}) { |
123 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
150 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
124 | $self->{tileset} = $default; |
151 | $self->{tileset} = $default; |
125 | $self->{tilesize} = $default->[3]; |
152 | $self->{tilesize} = $default->[3]; |
126 | $self->setup_req (tileset => $default->[0]); |
153 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
136 | sub ext_ambient_music { |
163 | sub ext_ambient_music { |
137 | my ($self, $songs) = @_; |
164 | my ($self, $songs) = @_; |
138 | &::audio_music_set_ambient ($songs); |
165 | &::audio_music_set_ambient ($songs); |
139 | } |
166 | } |
140 | |
167 | |
|
|
168 | sub ext_command_list { |
|
|
169 | my ($self, @faces) = @_; |
|
|
170 | |
|
|
171 | my $handler = $self->{command_facehandler} = {}; |
|
|
172 | my $commands = $::COMPLETER->{command_list} = {}; |
|
|
173 | |
|
|
174 | for my $idx (@faces) { |
|
|
175 | $handler->{$idx} = $self->register_face_handler ($idx, sub { |
|
|
176 | my ($face) = @_; |
|
|
177 | |
|
|
178 | $commands->{$idx} = |
|
|
179 | $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); |
|
|
180 | }); |
|
|
181 | } |
|
|
182 | } |
|
|
183 | |
141 | ############################################################################# |
184 | ############################################################################# |
142 | |
185 | |
143 | sub widget_associate { |
186 | sub widget_associate { |
144 | my ($self, $ws, $id, $widget) = @_; |
187 | my ($self, $ws, $id, $widget) = @_; |
145 | |
188 | |
… | |
… | |
194 | ); |
237 | ); |
195 | } |
238 | } |
196 | |
239 | |
197 | # widgetset create template |
240 | # widgetset create template |
198 | sub ext_ws_ct { |
241 | sub ext_ws_ct { |
199 | my ($self, $ws, $template, $cfg) = @_; |
242 | my ($self, $ws, $type, $template, $done_cb, $cfg) = @_; |
200 | |
243 | |
201 | $template = eval <<EOF; |
244 | $done_cb ||= sub { }; |
202 | [ |
|
|
203 | Toplevel => { |
|
|
204 | s_id => "toplevel", |
|
|
205 | title => "Character Creation", |
|
|
206 | x => "center", |
|
|
207 | y => "center", |
|
|
208 | z => 5, |
|
|
209 | s_cl => [VBox => {s_cl => [ |
|
|
210 | Label => { |
|
|
211 | text => "Character Creation", |
|
|
212 | fontsize => 1, |
|
|
213 | align => 0, |
|
|
214 | }, |
|
|
215 | Label => { |
|
|
216 | markup => "View or Edit your character attributes below, then press <b>Finish</b> to create your character", |
|
|
217 | fontsize => 0.8, |
|
|
218 | align => 0, |
|
|
219 | }, |
|
|
220 | Notebook => { |
|
|
221 | s_cl => [ |
|
|
222 | Label => { |
|
|
223 | text => "hulla-hoop" |
|
|
224 | }, |
|
|
225 | Entry => { |
|
|
226 | s_id => "entry", |
|
|
227 | }, |
|
|
228 | ], |
|
|
229 | }, |
|
|
230 | Button => { |
|
|
231 | s_id => "finish", |
|
|
232 | title => "Finish", |
|
|
233 | }, |
|
|
234 | ]}], |
|
|
235 | }, |
|
|
236 | ] |
|
|
237 | EOF |
|
|
238 | die if $@; |
|
|
239 | |
245 | |
240 | my $parse_list; $parse_list = sub { |
246 | my $parse_list; $parse_list = sub { |
241 | my ($list) = @_; |
247 | my ($list) = @_; |
242 | my @w; |
248 | my @w; |
243 | |
249 | |
… | |
… | |
260 | } |
266 | } |
261 | |
267 | |
262 | @w |
268 | @w |
263 | }; |
269 | }; |
264 | |
270 | |
|
|
271 | # either array reference, or face # |
|
|
272 | if ($type eq "inline") { |
|
|
273 | $done_cb->(); |
265 | $parse_list->($template); |
274 | $parse_list->($template); |
|
|
275 | } elsif ($type eq "face") { |
|
|
276 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
277 | my ($face) = @_; |
266 | |
278 | |
|
|
279 | undef $handler; |
|
|
280 | $done_cb->(); |
|
|
281 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
282 | }); |
|
|
283 | } else { |
|
|
284 | $done_cb->(0); |
|
|
285 | } |
267 | } |
286 | } |
268 | |
287 | |
269 | # widgetset associate |
288 | # widgetset associate |
270 | sub ext_ws_a { |
289 | sub ext_ws_a { |
271 | my ($self, %ass) = @_; |
290 | my ($self, %ass) = @_; |
… | |
… | |
274 | my %wkw = ( |
293 | my %wkw = ( |
275 | root => $DC::UI::ROOT, |
294 | root => $DC::UI::ROOT, |
276 | tooltip => $DC::UI::TOOLTIP, |
295 | tooltip => $DC::UI::TOOLTIP, |
277 | |
296 | |
278 | mapwidget => $::MAPWIDGET, |
297 | mapwidget => $::MAPWIDGET, |
|
|
298 | menubar => $::MENUBAR, |
|
|
299 | menupopup => $::MENUPOPUP, |
|
|
300 | pickup_enable => $::PICKUP_ENABLE, |
279 | buttonbar => $::BUTTONBAR, |
301 | buttonbar => $::BUTTONBAR, |
280 | metaserver => $::METASERVER, |
302 | metaserver => $::METASERVER, |
281 | buttonbar => $::BUTTONBAR, |
303 | buttonbar => $::BUTTONBAR, |
282 | login_button => $::LOGIN_BUTTON, |
304 | login_button => $::LOGIN_BUTTON, |
283 | quit_dialog => $::QUIT_DIALOG, |
305 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
299 | spell_list => $::SPELL_LIST, |
321 | spell_list => $::SPELL_LIST, |
300 | |
322 | |
301 | floorbox => $::FLOORBOX, |
323 | floorbox => $::FLOORBOX, |
302 | help_window => $::HELP_WINDOW, |
324 | help_window => $::HELP_WINDOW, |
303 | message_window => $::MESSAGE_WINDOW, |
325 | message_window => $::MESSAGE_WINDOW, |
|
|
326 | message_dist => $::MESSAGE_DIST, |
304 | statusbox => $::SDTATUSBOX, |
327 | statusbox => $::STATUSBOX, |
305 | |
328 | |
306 | inv => $::INV, |
329 | inv => $::INV, |
307 | invr => $::INVR, |
330 | invr => $::INVR, |
308 | invr_hb => $::INVR_HB, |
331 | invr_hb => $::INVR_HB, |
309 | ); |
332 | ); |
… | |
… | |
357 | |
380 | |
358 | # message window |
381 | # message window |
359 | sub ext_channel_info { |
382 | sub ext_channel_info { |
360 | my ($self, $info) = @_; |
383 | my ($self, $info) = @_; |
361 | $self->{channels}->{$info->{id}} = $info; |
384 | $self->{channels}->{$info->{id}} = $info; |
362 | $::MESSAGE_WINDOW->add_channel ($info); |
385 | $::MESSAGE_DIST->add_channel ($info); |
363 | } |
386 | } |
364 | |
387 | |
365 | ############################################################################# |
388 | ############################################################################# |
366 | |
389 | |
367 | sub logprint { |
390 | sub logprint { |
… | |
… | |
393 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
416 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
394 | : () |
417 | : () |
395 | } |
418 | } |
396 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
419 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
397 | |
420 | |
398 | join "", @diff |
421 | "\u$name: " . (join ", ", @diff) |
399 | } |
422 | } |
400 | |
423 | |
401 | # all stats that are chacked against changes |
424 | # all stats that are chacked against changes |
402 | my @statchange = ( |
425 | my @statchange = ( |
403 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
426 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
446 | |
469 | |
447 | if (my @diffs = |
470 | if (my @diffs = |
448 | ( |
471 | ( |
449 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
472 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
450 | map { |
473 | map { |
451 | $stats->{$_} && $prev->{$_} |
474 | $stats->{$_} && $prev->{$_} |
452 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
475 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
453 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
476 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
454 | ) |
477 | ) |
455 | ) { |
478 | ) { |
456 | my $msg = join " ", @diffs; |
479 | my $msg = join " ", @diffs; |
… | |
… | |
458 | } |
481 | } |
459 | |
482 | |
460 | if ( |
483 | if ( |
461 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
484 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
462 | ) { |
485 | ) { |
463 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
486 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
464 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
487 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
465 | } |
488 | } |
466 | |
489 | |
467 | $self->update_stats_window ($stats, $prev); |
490 | $self->update_stats_window ($stats, $prev); |
468 | |
491 | |
… | |
… | |
506 | |
529 | |
507 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
530 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
508 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
531 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
509 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
532 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
510 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
533 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
511 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
534 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
512 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
535 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
513 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
536 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
514 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
537 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
515 | my $title = $stats->{+CS_STAT_TITLE}; |
538 | my $title = $stats->{+CS_STAT_TITLE}; |
516 | $title =~ s/^Player: //; |
539 | $title =~ s/^Player: //; |
517 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
540 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
518 | |
541 | |
… | |
… | |
530 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
553 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
531 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
554 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
532 | |
555 | |
533 | $self->update_weight; |
556 | $self->update_weight; |
534 | |
557 | |
535 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
558 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
536 | for keys %RES_TBL; |
559 | for keys %RES_TBL; |
537 | |
560 | |
538 | my $sktbl = $::STATWIDS->{skill_tbl}; |
561 | my $sktbl = $::STATWIDS->{skill_tbl}; |
539 | my @skills = keys %{ $self->{skill_info} }; |
562 | my @skills = keys %{ $self->{skill_info} }; |
540 | |
563 | |
… | |
… | |
549 | $sktbl->clear; |
572 | $sktbl->clear; |
550 | |
573 | |
551 | my $sw = $self->{skillwid}{""} ||= [ |
574 | my $sw = $self->{skillwid}{""} ||= [ |
552 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
575 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
553 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
576 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
554 | 2, 0, (new DC::UI::Label text => "Progress", align => 0), |
577 | 2, 0, (new DC::UI::Label text => "Progress"), |
555 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1), |
578 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
556 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
579 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
557 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
580 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
558 | 6, 0, (new DC::UI::Label text => "Progress", align => 0), |
581 | 6, 0, (new DC::UI::Label text => "Progress"), |
559 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1), |
582 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
560 | ]; |
583 | ]; |
561 | |
584 | |
562 | my @add = @$sw; |
585 | my @add = @$sw; |
563 | |
586 | |
564 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
587 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
565 | |
588 | |
566 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
589 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
567 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
590 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
568 | |
591 | |
569 | my ($x, $y) = (0, 1); |
592 | my ($x, $y) = (0, 1); |
… | |
… | |
603 | |
626 | |
604 | # progress |
627 | # progress |
605 | (new DC::UI::ExperienceProgress), |
628 | (new DC::UI::ExperienceProgress), |
606 | |
629 | |
607 | # label |
630 | # label |
608 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, |
631 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
609 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
632 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
610 | ]; |
633 | ]; |
611 | |
634 | |
612 | push @add, |
635 | push @add, |
613 | $x * 4 + 0, $y, $sw->[0], |
636 | $x * 4 + 0, $y, $sw->[0], |
… | |
… | |
631 | my $sw = $self->{skillwid}{$idx}; |
654 | my $sw = $self->{skillwid}{$idx}; |
632 | $sw->[0]->set_text (::formsep ($val->[1])); |
655 | $sw->[0]->set_text (::formsep ($val->[1])); |
633 | $sw->[1]->set_text ($val->[0] * 1); |
656 | $sw->[1]->set_text ($val->[0] * 1); |
634 | $sw->[2]->set_value (@$val); |
657 | $sw->[2]->set_value (@$val); |
635 | |
658 | |
636 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
659 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
637 | $::GAUGES->{sklprg}->set_value (@$val); |
660 | $::GAUGES->{skillexp}->set_value (@$val); |
638 | } |
661 | } |
639 | } |
662 | } |
640 | |
663 | |
641 | sub user_send { |
664 | sub user_send { |
642 | my ($self, $command) = @_; |
665 | my ($self, $command) = @_; |
… | |
… | |
655 | } |
678 | } |
656 | |
679 | |
657 | sub map_scroll { |
680 | sub map_scroll { |
658 | my ($self, $dx, $dy) = @_; |
681 | my ($self, $dx, $dy) = @_; |
659 | |
682 | |
660 | $self->{map}->scroll ($dx, $dy); |
683 | $self->{map_widget}->scroll ($dx, $dy); |
661 | } |
684 | } |
662 | |
685 | |
663 | sub feed_map1a { |
686 | sub feed_map1a { |
664 | my ($self, $data) = @_; |
687 | my ($self, $data) = @_; |
665 | |
688 | |
666 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
689 | my $missing = $self->{map}->map1a_update ($data); |
667 | my $delay; |
690 | my $delay; |
668 | |
691 | |
669 | for my $tile (@$missing) { |
692 | for my $tile (@$missing) { |
670 | next if $self->{delay}{$tile}; |
693 | next if $self->{delay}{$tile}; |
671 | |
694 | |
672 | $delay = 1; |
695 | $delay = 1; |
673 | |
696 | |
674 | if (my $tex = $::CONN->{texture}[$tile]) { |
697 | if (my $tex = $self->{texture}[$tile]) { |
675 | $tex->upload; |
698 | $tex->upload; |
676 | } else { |
699 | } else { |
677 | $self->{delay}{$tile} = 1; |
700 | $self->{delay}{$tile} = 1; |
678 | |
701 | |
679 | # we assume the face is in-flight and will eventually come |
702 | # we assume the face is in-flight and will eventually arrive |
680 | push @{$self->{tile_cb}{$tile}}, sub { |
703 | push @{$self->{tile_cb}{$tile}}, sub { |
681 | delete $self->{delay}{$tile}; |
704 | delete $self->{delay}{$tile}; |
682 | $_[0]->upload; |
705 | $_[0]->upload; |
683 | }; |
706 | }; |
684 | } |
707 | } |
685 | } |
708 | } |
686 | |
709 | |
687 | if ($delay) { |
710 | if ($delay) { |
688 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
711 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
689 | EV::once undef, 0, 0.03, sub { |
712 | EV::once undef, 0, 0.03, sub { |
690 | $self->{map_widget}->update |
713 | $self->{map_widget}->update |
691 | if $self->{map_widget}; |
714 | if $self->{map_widget}; |
692 | }; |
715 | }; |
693 | } else { |
716 | } else { |
… | |
… | |
702 | } |
725 | } |
703 | |
726 | |
704 | sub flush_map { |
727 | sub flush_map { |
705 | my ($self) = @_; |
728 | my ($self) = @_; |
706 | |
729 | |
707 | my $map_info = delete $self->{map_info} |
730 | return unless $self->{map_info}; |
708 | or return; |
|
|
709 | |
731 | |
|
|
732 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
710 | my ($hash, $x, $y, $w, $h) = @$map_info; |
733 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
711 | |
734 | |
712 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
735 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
713 | $self->{map_cache_new}{$hash} = \$data; |
736 | |
|
|
737 | if ($data ne $$rdata) { |
|
|
738 | $map_info->[1] = \$data; |
|
|
739 | my $cdata = Compress::LZF::compress $data; |
714 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
740 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
741 | } |
|
|
742 | } |
715 | } |
743 | } |
716 | |
744 | |
717 | sub map_clear { |
745 | sub map_clear { |
718 | my ($self) = @_; |
746 | my ($self) = @_; |
719 | |
747 | |
720 | $self->flush_map; |
748 | $self->flush_map; |
|
|
749 | delete $self->{map_info}; |
721 | delete $self->{neigh_map}; |
750 | delete $self->{neigh_map}; |
722 | |
751 | |
723 | $self->{map}->clear; |
752 | $self->{map}->clear; |
724 | delete $self->{map_widget}{magicmap}; |
753 | delete $self->{map_widget}{magicmap}; |
725 | } |
754 | } |
… | |
… | |
746 | |
775 | |
747 | $self->bg_fetch; |
776 | $self->bg_fetch; |
748 | }; |
777 | }; |
749 | } |
778 | } |
750 | |
779 | |
751 | sub load_map($$$) { |
780 | sub load_map($$$$$$) { |
752 | my ($self, $hash, $x, $y) = @_; |
781 | my ($self, $hash, $x, $y, $w, $h) = @_; |
753 | |
782 | |
754 | my $gen = $self->{map_change_gen}; |
783 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
755 | |
784 | |
756 | my $cb = sub { |
785 | my $cb = sub { |
757 | return unless $gen == $self->{map_change_gen}; |
786 | $map_info->[1] = \$_[0]; |
758 | |
787 | |
759 | my ($data) = @_; |
|
|
760 | |
|
|
761 | if (defined $data) { |
|
|
762 | $self->{map_cache_new}{$hash} = \$data; |
|
|
763 | |
|
|
764 | my $data = Compress::LZF::decompress $data; |
|
|
765 | |
|
|
766 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
788 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
767 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
789 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
768 | $self->bg_fetch unless $inprogress; |
790 | $self->bg_fetch unless $inprogress; |
769 | } |
|
|
770 | }; |
791 | }; |
771 | |
792 | |
772 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
793 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
773 | $cb->($$rdata); |
794 | $cb->(${ $map_info->[1] }); |
774 | } else { |
795 | } else { |
|
|
796 | my $gen = $self->{map_change_gen}; |
|
|
797 | |
775 | DC::DB::get $self->{mapcache} => $hash, $cb; |
798 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
799 | return unless $gen == $self->{map_change_gen}; |
|
|
800 | return unless defined $_[0]; |
|
|
801 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
802 | }; |
776 | } |
803 | } |
777 | } |
804 | } |
778 | |
805 | |
779 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
806 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
780 | # (server resource,s latency, bandwidth), so this hack is warranted. |
807 | # (server resources, latency, bandwidth), so this hack is warranted. |
781 | # the right fix is to make real tiled maps with an overview file |
808 | # the right fix is to make real tiled maps with an overview file |
782 | sub send_mapinfo { |
809 | sub send_mapinfo { |
783 | my ($self, $data, $cb) = @_; |
810 | my ($self, $data, $cb) = @_; |
784 | |
811 | |
785 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
812 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
810 | } |
837 | } |
811 | |
838 | |
812 | # this method does a "flood fill" into every tile direction |
839 | # this method does a "flood fill" into every tile direction |
813 | # it assumes that tiles are arranged in a rectangular grid, |
840 | # it assumes that tiles are arranged in a rectangular grid, |
814 | # i.e. a map is the same as the left of the right map etc. |
841 | # i.e. a map is the same as the left of the right map etc. |
815 | # failure to comply are harmless and result in display errors |
842 | # failure to comply is harmless and results in display errors |
816 | # at worst. |
843 | # at worst. |
817 | sub flood_fill { |
844 | sub flood_fill { |
818 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
845 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
819 | |
846 | |
820 | # the server does not allow map paths > 6 |
847 | # the server does not allow map paths > 6 |
… | |
… | |
856 | return if $mode ne "spatial"; |
883 | return if $mode ne "spatial"; |
857 | |
884 | |
858 | $x += $self->{map}->ox; |
885 | $x += $self->{map}->ox; |
859 | $y += $self->{map}->oy; |
886 | $y += $self->{map}->oy; |
860 | |
887 | |
861 | $self->load_map ($hash, $x, $y) |
888 | $self->load_map ($hash, $x, $y, $w, $h) |
862 | unless $self->{neigh_map}{$hash}[5]++;#d# |
889 | unless $self->{neigh_map}{$hash}[5]++;#d# |
863 | |
890 | |
864 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
891 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
865 | |
892 | |
866 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
893 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
874 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
901 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
875 | |
902 | |
876 | $self->flush_map; |
903 | $self->flush_map; |
877 | |
904 | |
878 | ++$self->{map_change_gen}; |
905 | ++$self->{map_change_gen}; |
879 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
906 | $self->{map_cache_old} = delete $self->{map_cache}; |
880 | |
907 | |
881 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
908 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
882 | |
909 | |
883 | my $mapmapw = $self->{mapmap}->{w}; |
910 | my $mapmapw = $self->{mapmap}->{w}; |
884 | my $mapmaph = $self->{mapmap}->{h}; |
911 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
896 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
923 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
897 | |
924 | |
898 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
925 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
899 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
926 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
900 | |
927 | |
901 | $self->load_map ($hash, $x, $y); |
928 | $self->load_map ($hash, $x, $y, $w, $h); |
902 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
929 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
903 | } |
930 | } |
904 | |
931 | |
905 | sub face_find { |
932 | sub face_find { |
906 | my ($self, $facenum, $face, $cb) = @_; |
933 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
977 | |
1004 | |
978 | my $tex = $self->{texture}[$tile] ||= |
1005 | my $tex = $self->{texture}[$tile] ||= |
979 | new DC::Texture |
1006 | new DC::Texture |
980 | tile => $tile, |
1007 | tile => $tile, |
981 | image => $data, delete_image => 1, |
1008 | image => $data, delete_image => 1, |
982 | minify => 1, mipmap => 1; |
1009 | minify => 1; |
983 | |
1010 | |
984 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1011 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
985 | $_->($tex) for @$cbs; |
1012 | $_->($tex) for @$cbs; |
986 | } |
1013 | } |
987 | } |
1014 | } |
… | |
… | |
992 | my ($self, $num, $cb) = @_; |
1019 | my ($self, $num, $cb) = @_; |
993 | |
1020 | |
994 | push @{$self->{face_cb}{$num}}, $cb; |
1021 | push @{$self->{face_cb}{$num}}, $cb; |
995 | |
1022 | |
996 | defined wantarray |
1023 | defined wantarray |
997 | ? DC::guard { |
1024 | ? Guard::guard { |
998 | @{$self->{face_cb}{$num}} |
1025 | @{$self->{face_cb}{$num}} |
999 | = grep $_ != $cb, |
1026 | = grep $_ != $cb, |
1000 | @{$self->{face_cb}{$num}}; |
1027 | @{$self->{face_cb}{$num}}; |
1001 | } |
1028 | } |
1002 | : () |
1029 | : () |
… | |
… | |
1030 | my ($self, $flags, $prompt) = @_; |
1057 | my ($self, $flags, $prompt) = @_; |
1031 | |
1058 | |
1032 | $prompt = $LAST_QUERY unless length $prompt; |
1059 | $prompt = $LAST_QUERY unless length $prompt; |
1033 | $LAST_QUERY = $prompt; |
1060 | $LAST_QUERY = $prompt; |
1034 | |
1061 | |
1035 | $self->{query}-> ($self, $flags, $prompt); |
1062 | $self->{query}->($self, $flags, $prompt); |
1036 | } |
1063 | } |
1037 | |
1064 | |
1038 | sub sanitise_xml($) { |
1065 | sub sanitise_xml($) { |
1039 | local $_ = shift; |
1066 | local $_ = shift; |
1040 | |
1067 | |
… | |
… | |
1048 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1075 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1049 | |
1076 | |
1050 | # handle some elements |
1077 | # handle some elements |
1051 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1078 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1052 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1079 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1080 | |
|
|
1081 | s/\s+$//; |
1053 | |
1082 | |
1054 | $_ |
1083 | $_ |
1055 | } |
1084 | } |
1056 | |
1085 | |
1057 | our %NAME_TO_COLOR = ( |
1086 | our %NAME_TO_COLOR = ( |
… | |
… | |
1070 | tan => 12, |
1099 | tan => 12, |
1071 | ); |
1100 | ); |
1072 | |
1101 | |
1073 | our @CF_COLOR = ( |
1102 | our @CF_COLOR = ( |
1074 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1103 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1075 | [1.00, 1.00, 1.00], |
1104 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1076 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1105 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1077 | [1.00, 0.00, 0.00], |
1106 | [1.00, 0.00, 0.00], |
1078 | [1.00, 0.54, 0.00], |
1107 | [1.00, 0.54, 0.00], |
1079 | [0.11, 0.56, 1.00], |
1108 | [0.11, 0.56, 1.00], |
1080 | [0.93, 0.46, 0.00], |
1109 | [0.93, 0.46, 0.00], |
1081 | [0.18, 0.54, 0.34], |
1110 | [0.18, 0.54, 0.34], |
… | |
… | |
1100 | $self->logprint ("msg: ", $text); |
1129 | $self->logprint ("msg: ", $text); |
1101 | return if $color < 0; # negative color == ignore if not understood |
1130 | return if $color < 0; # negative color == ignore if not understood |
1102 | |
1131 | |
1103 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1132 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1104 | |
1133 | |
1105 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1106 | # no longer neecssary with TRT servers |
|
|
1107 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1108 | |
|
|
1109 | for (split /\n/, $text) { |
|
|
1110 | ::message ({ |
1134 | ::message ({ |
1111 | fg => $fg, |
1135 | fg => $fg, |
1112 | markup => $_, |
1136 | markup => $text, |
1113 | type => $type, |
1137 | type => $type, |
1114 | extra => [@extra], |
1138 | extra => [@extra], |
1115 | color_flags => $color, #d# ugly, kill |
1139 | color_flags => $color, #d# ugly, kill |
1116 | }); |
1140 | }); |
1117 | |
1141 | |
1118 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1142 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1119 | # actually, this is an ugly design. _we_ should control the channels, |
1143 | # # actually, this is an ugly design. _we_ should control the channels, |
1120 | # not some random other widget, as the channels are clearly protocol-specific. |
1144 | # # not some random other widget, as the channels are clearly protocol-specific. |
1121 | # then we could also react to flags such as CLEAR without resorting to |
1145 | # # then we could also react to flags such as CLEAR without resorting to |
1122 | # hacks such as color_flags, above. |
1146 | # # hacks such as color_flags, above. |
1123 | } |
|
|
1124 | |
1147 | |
1125 | $self->{statusbox}->add ($text, |
1148 | $self->{statusbox}->add ($text, |
1126 | group => $text, |
1149 | group => $text, |
1127 | fg => $fg, |
1150 | fg => $fg, |
1128 | timeout => $color >= 2 ? 180 : 10, |
1151 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1138 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
1161 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
1139 | $spell->{message} =~ s/\n+$//; |
1162 | $spell->{message} =~ s/\n+$//; |
1140 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1163 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1141 | |
1164 | |
1142 | $::SPELL_LIST->add_spell ($spell); |
1165 | $::SPELL_LIST->add_spell ($spell); |
1143 | |
1166 | delete $::COMPLETER->{command_list}{spells}; |
1144 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
|
|
1145 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
|
|
1146 | } |
1167 | } |
1147 | |
1168 | |
1148 | sub spell_delete { |
1169 | sub spell_delete { |
1149 | my ($self, $spell) = @_; |
1170 | my ($self, $spell) = @_; |
1150 | |
1171 | |
1151 | $::SPELL_LIST->remove_spell ($spell); |
1172 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1173 | delete $::COMPLETER->{command_list}{spells}; |
1152 | } |
1174 | } |
1153 | |
1175 | |
1154 | sub setup { |
1176 | sub setup { |
1155 | my ($self, $setup) = @_; |
1177 | my ($self, $setup) = @_; |
1156 | |
1178 | |
… | |
… | |
1163 | |
1185 | |
1164 | my %skill_help; |
1186 | my %skill_help; |
1165 | |
1187 | |
1166 | for my $node (DC::Pod::find skill_description => "*") { |
1188 | for my $node (DC::Pod::find skill_description => "*") { |
1167 | my (undef, @par) = DC::Pod::section_of $node; |
1189 | my (undef, @par) = DC::Pod::section_of $node; |
1168 | $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; |
1190 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1169 | }; |
1191 | }; |
1170 | |
1192 | |
1171 | for my $skill (values %{$self->{skill_info}}) { |
1193 | for my $skill (values %{$self->{skill_info}}) { |
1172 | $self->{map_widget}->add_command ("ready_skill $skill", |
1194 | $self->{map_widget}->add_command ("ready_skill $skill", |
1173 | (DC::asxml "Ready the skill '$skill'\n\n") |
1195 | (DC::asxml "Ready the skill '$skill'\n\n") |
… | |
… | |
1179 | } |
1201 | } |
1180 | |
1202 | |
1181 | sub eof { |
1203 | sub eof { |
1182 | my ($self) = @_; |
1204 | my ($self) = @_; |
1183 | |
1205 | |
1184 | $self->{map_widget}->clr_commands; |
1206 | $::COMPLETER->reset; |
1185 | |
1207 | |
1186 | ::stop_game (); |
1208 | ::stop_game (); |
1187 | } |
1209 | } |
1188 | |
1210 | |
1189 | sub update_floorbox { |
1211 | sub update_floorbox { |
… | |
… | |
1193 | $::FLOORBOX->clear; |
1215 | $::FLOORBOX->clear; |
1194 | |
1216 | |
1195 | my @add; |
1217 | my @add; |
1196 | |
1218 | |
1197 | my $row; |
1219 | my $row; |
1198 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1220 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1221 | next if $_->{tag} & 0x80000000; |
1199 | if ($row < 6) { |
1222 | if ($row < 6) { |
1200 | local $_->{face_widget}; # hack to force recreation of widget |
1223 | local $_->{face_widget}; # hack to force recreation of widget |
1201 | local $_->{desc_widget}; # hack to force recreation of widget |
1224 | local $_->{desc_widget}; # hack to force recreation of widget |
1202 | DC::Item::update_widgets $_; |
1225 | DC::Item::update_widgets $_; |
1203 | |
1226 | |
… | |
… | |
1230 | sub set_opencont { |
1253 | sub set_opencont { |
1231 | my ($conn, $tag, $name) = @_; |
1254 | my ($conn, $tag, $name) = @_; |
1232 | $conn->{open_container} = $tag; |
1255 | $conn->{open_container} = $tag; |
1233 | update_floorbox; |
1256 | update_floorbox; |
1234 | |
1257 | |
1235 | $::INVR_HB->clear (); |
1258 | $::INVR_HB->clear; |
1236 | $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); |
1259 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1237 | |
1260 | |
1238 | if ($tag != 0) { # Floor isn't closable, is it? |
1261 | if ($tag != 0) { # Floor isn't closable, is it? |
1239 | $::INVR_HB->add (new DC::UI::Button |
1262 | $::INVR_HB->add (new DC::UI::Button |
1240 | text => "Close container", |
1263 | text => "Close container", |
1241 | tooltip => "Close the currently open container (if one is open)", |
1264 | tooltip => "Close the currently open container (if one is open)", |
… | |
… | |
1296 | } |
1319 | } |
1297 | |
1320 | |
1298 | sub item_update { |
1321 | sub item_update { |
1299 | my ($self, $item) = @_; |
1322 | my ($self, $item) = @_; |
1300 | |
1323 | |
1301 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1324 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1302 | |
1325 | |
1303 | DC::Item::update_widgets $item; |
1326 | DC::Item::update_widgets $item; |
1304 | |
1327 | |
1305 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1328 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1306 | set_opencont ($::CONN, 0, "Floor"); |
1329 | set_opencont ($::CONN, 0, "Floor"); |
1307 | |
1330 | |
1308 | } elsif ($item->{flags} & F_OPEN) { |
1331 | } elsif ($item->{flags} & F_OPEN) { |
1309 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1332 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1325 | |
1348 | |
1326 | my $weight = .001 * $self->{player}{weight}; |
1349 | my $weight = .001 * $self->{player}{weight}; |
1327 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1350 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1328 | |
1351 | |
1329 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1352 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1330 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1353 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1331 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1354 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1332 | } |
1355 | } |
1333 | |
1356 | |
1334 | sub update_server_info { |
1357 | sub update_server_info { |
1335 | my ($self) = @_; |
1358 | my ($self) = @_; |
1336 | |
1359 | |
1337 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1360 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1338 | |
1361 | |
|
|
1362 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1363 | |
1339 | $::SERVER_INFO->set_markup ( |
1364 | $::SERVER_INFO->set_markup ( |
1340 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1365 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1341 | . "protocol version <tt>$self->{version}</tt>\n" |
1366 | . "protocol version <tt>$version</tt>\n" |
1342 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1343 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1344 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1345 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1367 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1346 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1347 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1348 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1368 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1349 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1369 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1350 | . "map size $self->{mapw}×$self->{maph}\n" |
1370 | . "map size $self->{mapw}×$self->{maph}\n" |
1351 | ); |
1371 | ); |
1352 | |
1372 | |
1353 | } |
1373 | } |
… | |
… | |
1374 | }); |
1394 | }); |
1375 | |
1395 | |
1376 | $self->update_server_info; |
1396 | $self->update_server_info; |
1377 | |
1397 | |
1378 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1398 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1379 | $self->send_command ("pickup $::CFG->{pickup}"); |
1399 | $self->send_pickup ($::CFG->{pickup}); |
1380 | } |
1400 | } |
1381 | |
1401 | |
1382 | sub lookat { |
1402 | sub lookat { |
1383 | my ($self, $x, $y) = @_; |
1403 | my ($self, $x, $y) = @_; |
1384 | |
1404 | |
… | |
… | |
1386 | $self->send_ext_req (lookat => $x, $y, sub { |
1406 | $self->send_ext_req (lookat => $x, $y, sub { |
1387 | my (%msg) = @_; |
1407 | my (%msg) = @_; |
1388 | |
1408 | |
1389 | if (exists $msg{npc_dialog}) { |
1409 | if (exists $msg{npc_dialog}) { |
1390 | # start npc chat dialog |
1410 | # start npc chat dialog |
1391 | $self->{npc_dialog} = new DC::NPCDialog:: |
1411 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1392 | token => $msg{npc_dialog}, |
1412 | token => $msg{npc_dialog}, |
1393 | title => "$msg{npc_dialog}[0] (NPC)", |
1413 | title => "$msg{npc_dialog}[0] (NPC)", |
1394 | conn => $self, |
1414 | conn => $self, |
1395 | ; |
1415 | ; |
1396 | } |
1416 | } |
… | |
… | |
1401 | } |
1421 | } |
1402 | |
1422 | |
1403 | sub destroy { |
1423 | sub destroy { |
1404 | my ($self) = @_; |
1424 | my ($self) = @_; |
1405 | |
1425 | |
1406 | (delete $self->{npc_dialog})->destroy |
1426 | $_->destroy |
1407 | if $self->{npc_dialog}; |
1427 | for values %{ $self->{w} }; |
1408 | |
1428 | |
1409 | $self->SUPER::destroy; |
1429 | $self->SUPER::destroy; |
1410 | |
1430 | |
1411 | %$self = (); |
1431 | %$self = (); |
1412 | } |
1432 | } |
… | |
… | |
1548 | } |
1568 | } |
1549 | |
1569 | |
1550 | sub send { |
1570 | sub send { |
1551 | my ($self, $msg) = @_; |
1571 | my ($self, $msg) = @_; |
1552 | |
1572 | |
1553 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1573 | $self->{textview}->add_paragraph ({ |
|
|
1574 | markup => |
|
|
1575 | "\n<span foreground='#ffff00'><b>" |
|
|
1576 | . (DC::asxml $msg) |
|
|
1577 | . "</b></span>" |
|
|
1578 | }); |
1554 | $self->{textview}->scroll_to_bottom; |
1579 | $self->{textview}->scroll_to_bottom; |
1555 | |
1580 | |
1556 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1581 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1557 | } |
1582 | } |
1558 | |
1583 | |
… | |
… | |
1561 | |
1586 | |
1562 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1587 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1563 | |
1588 | |
1564 | if ($self->{conn}) { |
1589 | if ($self->{conn}) { |
1565 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1590 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1566 | delete $self->{conn}{npc_dialog}; |
1591 | delete $self->{conn}{w}{npc_dialog}; |
1567 | $self->{conn}->disconnect_ext ($self->{id}); |
1592 | $self->{conn}->disconnect_ext ($self->{id}); |
1568 | } |
1593 | } |
1569 | |
1594 | |
1570 | $self->SUPER::destroy; |
1595 | $self->SUPER::destroy; |
1571 | } |
1596 | } |