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 | |
|
|
37 | $self->update_fx_want; |
|
|
38 | |
|
|
39 | my $exp_guard = $self->addme_guard; |
|
|
40 | my $skl_guard = $self->addme_guard; |
|
|
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) = @_; |
|
|
44 | |
|
|
45 | $self->register_face_handler ($exp, sub { |
|
|
46 | my ($face) = @_; |
|
|
47 | |
|
|
48 | undef $exp_guard; |
|
|
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
|
|
52 | |
|
|
53 | $self->register_face_handler ($skl, sub { |
|
|
54 | my ($face) = @_; |
|
|
55 | |
|
|
56 | undef $skl_guard; |
|
|
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
|
|
59 | }); |
|
|
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 | |
29 | $self->{map_widget}->clr_commands; |
72 | $self->{map_widget}->clr_commands; |
30 | |
73 | |
31 | my @cmd_help = map { |
74 | my @cmd_help = map { |
32 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
75 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | or die "unparseable command help: $_->{kw}[0]"; |
76 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
34 | |
77 | |
35 | my $cmd = $1; |
78 | my $cmd = $1; |
36 | my @args = split /\|/, $2; |
79 | my @args = split /\|/, $2; |
37 | @args = (".*") unless @args; |
80 | @args = (".*") unless @args; |
38 | |
81 | |
… | |
… | |
43 | for @args; |
86 | for @args; |
44 | |
87 | |
45 | map ["$cmd$_", $text], |
88 | map ["$cmd$_", $text], |
46 | sort { (length $a) <=> (length $b) } |
89 | sort { (length $a) <=> (length $b) } |
47 | @args |
90 | @args |
48 | } sort { $a->{par} <=> $b->{par} } |
91 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
49 | DC::Pod::find command => "*"; |
92 | DC::Pod::find command => "*"; |
50 | |
93 | |
51 | $self->{json_coder} |
94 | $self->{json_coder} |
52 | ->convert_blessed |
95 | ->convert_blessed |
53 | ->filter_json_single_key_object ("\fw" => sub { |
96 | ->filter_json_single_key_object ("\fw" => sub { |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
107 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
108 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
109 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
110 | for values %{delete $ws->{w} || {}}; |
68 | } |
111 | } |
|
|
112 | |
|
|
113 | delete $self->{items}; |
|
|
114 | $::INV->clear; |
|
|
115 | $::INVR->clear; |
|
|
116 | $::INVR_HB->clear; |
|
|
117 | $::FLOORBOX->clear; |
69 | }); |
118 | }); |
70 | |
119 | |
71 | $self->{map_widget}->add_command (@$_) |
120 | $self->{map_widget}->add_command (@$_) |
72 | for @cmd_help; |
121 | for @cmd_help; |
73 | |
122 | |
74 | { |
123 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
124 | $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}}); |
125 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
126 | } |
79 | |
127 | |
80 | { |
128 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
129 | $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}}); |
130 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
131 | } |
|
|
132 | |
|
|
133 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
134 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
135 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
136 | # |
|
|
137 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
138 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
139 | # $self->{texture}[$_]->unload; |
|
|
140 | # warn "expire texture $_\n";#d# |
|
|
141 | # } |
|
|
142 | # |
|
|
143 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
144 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
145 | # warn "count is $count\n";#d# |
|
|
146 | # }; |
85 | |
147 | |
86 | $self->{open_container} = 0; |
148 | $self->{open_container} = 0; |
87 | |
149 | |
88 | # per server |
150 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
151 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
101 | }); |
163 | }); |
102 | } |
164 | } |
103 | |
165 | |
104 | sub ext_capabilities { |
166 | sub ext_capabilities { |
105 | my ($self, %cap) = @_; |
167 | my ($self, %cap) = @_; |
106 | |
|
|
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 | |
168 | |
122 | if (my $ts = $cap{tileset}) { |
169 | if (my $ts = $cap{tileset}) { |
123 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
170 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
124 | $self->{tileset} = $default; |
171 | $self->{tileset} = $default; |
125 | $self->{tilesize} = $default->[3]; |
172 | $self->{tilesize} = $default->[3]; |
… | |
… | |
225 | @w |
272 | @w |
226 | }; |
273 | }; |
227 | |
274 | |
228 | # either array reference, or face # |
275 | # either array reference, or face # |
229 | if ($type eq "inline") { |
276 | if ($type eq "inline") { |
|
|
277 | $done_cb->(); |
230 | $parse_list->($template); |
278 | $parse_list->($template); |
231 | $done_cb->(); |
|
|
232 | } elsif ($type eq "face") { |
279 | } elsif ($type eq "face") { |
233 | #... |
280 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
281 | my ($face) = @_; |
|
|
282 | |
|
|
283 | undef $handler; |
234 | $done_cb->(0); |
284 | $done_cb->(); |
|
|
285 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
286 | }); |
235 | } else { |
287 | } else { |
236 | $done_cb->(0); |
288 | $done_cb->(0); |
237 | } |
289 | } |
238 | } |
290 | } |
239 | |
291 | |
… | |
… | |
245 | my %wkw = ( |
297 | my %wkw = ( |
246 | root => $DC::UI::ROOT, |
298 | root => $DC::UI::ROOT, |
247 | tooltip => $DC::UI::TOOLTIP, |
299 | tooltip => $DC::UI::TOOLTIP, |
248 | |
300 | |
249 | mapwidget => $::MAPWIDGET, |
301 | mapwidget => $::MAPWIDGET, |
|
|
302 | menubar => $::MENUBAR, |
|
|
303 | menupopup => $::MENUPOPUP, |
|
|
304 | pickup_enable => $::PICKUP_ENABLE, |
250 | buttonbar => $::BUTTONBAR, |
305 | buttonbar => $::BUTTONBAR, |
251 | metaserver => $::METASERVER, |
306 | metaserver => $::METASERVER, |
252 | buttonbar => $::BUTTONBAR, |
307 | buttonbar => $::BUTTONBAR, |
253 | login_button => $::LOGIN_BUTTON, |
308 | login_button => $::LOGIN_BUTTON, |
254 | quit_dialog => $::QUIT_DIALOG, |
309 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
270 | spell_list => $::SPELL_LIST, |
325 | spell_list => $::SPELL_LIST, |
271 | |
326 | |
272 | floorbox => $::FLOORBOX, |
327 | floorbox => $::FLOORBOX, |
273 | help_window => $::HELP_WINDOW, |
328 | help_window => $::HELP_WINDOW, |
274 | message_window => $::MESSAGE_WINDOW, |
329 | message_window => $::MESSAGE_WINDOW, |
|
|
330 | message_dist => $::MESSAGE_DIST, |
275 | statusbox => $::SDTATUSBOX, |
331 | statusbox => $::STATUSBOX, |
276 | |
332 | |
277 | inv => $::INV, |
333 | inv => $::INV, |
278 | invr => $::INVR, |
334 | invr => $::INVR, |
279 | invr_hb => $::INVR_HB, |
335 | invr_hb => $::INVR_HB, |
280 | ); |
336 | ); |
… | |
… | |
328 | |
384 | |
329 | # message window |
385 | # message window |
330 | sub ext_channel_info { |
386 | sub ext_channel_info { |
331 | my ($self, $info) = @_; |
387 | my ($self, $info) = @_; |
332 | $self->{channels}->{$info->{id}} = $info; |
388 | $self->{channels}->{$info->{id}} = $info; |
333 | $::MESSAGE_WINDOW->add_channel ($info); |
389 | $::MESSAGE_DIST->add_channel ($info); |
334 | } |
390 | } |
335 | |
391 | |
336 | ############################################################################# |
392 | ############################################################################# |
337 | |
393 | |
338 | sub logprint { |
394 | sub logprint { |
… | |
… | |
364 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
420 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
365 | : () |
421 | : () |
366 | } |
422 | } |
367 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
423 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
368 | |
424 | |
369 | join "", @diff |
425 | "\u$name: " . (join ", ", @diff) |
370 | } |
426 | } |
371 | |
427 | |
372 | # all stats that are chacked against changes |
428 | # all stats that are chacked against changes |
373 | my @statchange = ( |
429 | my @statchange = ( |
374 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
430 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
417 | |
473 | |
418 | if (my @diffs = |
474 | if (my @diffs = |
419 | ( |
475 | ( |
420 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
476 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
421 | map { |
477 | map { |
422 | $stats->{$_} && $prev->{$_} |
478 | $stats->{$_} && $prev->{$_} |
423 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
479 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
424 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
480 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
425 | ) |
481 | ) |
426 | ) { |
482 | ) { |
427 | my $msg = join " ", @diffs; |
483 | my $msg = join " ", @diffs; |
… | |
… | |
429 | } |
485 | } |
430 | |
486 | |
431 | if ( |
487 | if ( |
432 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
488 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
433 | ) { |
489 | ) { |
434 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
490 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
435 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
491 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
436 | } |
492 | } |
437 | |
493 | |
438 | $self->update_stats_window ($stats, $prev); |
494 | $self->update_stats_window ($stats, $prev); |
439 | |
495 | |
… | |
… | |
477 | |
533 | |
478 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
534 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
479 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
535 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
480 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
536 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
481 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
537 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
482 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
538 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
483 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
539 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
484 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
540 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
485 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
541 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
486 | my $title = $stats->{+CS_STAT_TITLE}; |
542 | my $title = $stats->{+CS_STAT_TITLE}; |
487 | $title =~ s/^Player: //; |
543 | $title =~ s/^Player: //; |
488 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
544 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
489 | |
545 | |
… | |
… | |
501 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
557 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
502 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
558 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
503 | |
559 | |
504 | $self->update_weight; |
560 | $self->update_weight; |
505 | |
561 | |
506 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
562 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
507 | for keys %RES_TBL; |
563 | for keys %RES_TBL; |
508 | |
564 | |
509 | my $sktbl = $::STATWIDS->{skill_tbl}; |
565 | my $sktbl = $::STATWIDS->{skill_tbl}; |
510 | my @skills = keys %{ $self->{skill_info} }; |
566 | my @skills = keys %{ $self->{skill_info} }; |
511 | |
567 | |
… | |
… | |
520 | $sktbl->clear; |
576 | $sktbl->clear; |
521 | |
577 | |
522 | my $sw = $self->{skillwid}{""} ||= [ |
578 | my $sw = $self->{skillwid}{""} ||= [ |
523 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
579 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
524 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
580 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
525 | 2, 0, (new DC::UI::Label text => "Progress", align => 0), |
581 | 2, 0, (new DC::UI::Label text => "Progress"), |
526 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1), |
582 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
527 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
583 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
528 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
584 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
529 | 6, 0, (new DC::UI::Label text => "Progress", align => 0), |
585 | 6, 0, (new DC::UI::Label text => "Progress"), |
530 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1), |
586 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
531 | ]; |
587 | ]; |
532 | |
588 | |
533 | my @add = @$sw; |
589 | my @add = @$sw; |
534 | |
590 | |
535 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
591 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
536 | |
592 | |
537 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
593 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
538 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
594 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
539 | |
595 | |
540 | my ($x, $y) = (0, 1); |
596 | my ($x, $y) = (0, 1); |
… | |
… | |
574 | |
630 | |
575 | # progress |
631 | # progress |
576 | (new DC::UI::ExperienceProgress), |
632 | (new DC::UI::ExperienceProgress), |
577 | |
633 | |
578 | # label |
634 | # label |
579 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, |
635 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
580 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
636 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
581 | ]; |
637 | ]; |
582 | |
638 | |
583 | push @add, |
639 | push @add, |
584 | $x * 4 + 0, $y, $sw->[0], |
640 | $x * 4 + 0, $y, $sw->[0], |
… | |
… | |
602 | my $sw = $self->{skillwid}{$idx}; |
658 | my $sw = $self->{skillwid}{$idx}; |
603 | $sw->[0]->set_text (::formsep ($val->[1])); |
659 | $sw->[0]->set_text (::formsep ($val->[1])); |
604 | $sw->[1]->set_text ($val->[0] * 1); |
660 | $sw->[1]->set_text ($val->[0] * 1); |
605 | $sw->[2]->set_value (@$val); |
661 | $sw->[2]->set_value (@$val); |
606 | |
662 | |
607 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
663 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
608 | $::GAUGES->{sklprg}->set_value (@$val); |
664 | $::GAUGES->{skillexp}->set_value (@$val); |
609 | } |
665 | } |
610 | } |
666 | } |
611 | |
667 | |
612 | sub user_send { |
668 | sub user_send { |
613 | my ($self, $command) = @_; |
669 | my ($self, $command) = @_; |
… | |
… | |
626 | } |
682 | } |
627 | |
683 | |
628 | sub map_scroll { |
684 | sub map_scroll { |
629 | my ($self, $dx, $dy) = @_; |
685 | my ($self, $dx, $dy) = @_; |
630 | |
686 | |
631 | $self->{map}->scroll ($dx, $dy); |
687 | $self->{map_widget}->scroll ($dx, $dy); |
632 | } |
688 | } |
633 | |
689 | |
634 | sub feed_map1a { |
690 | sub feed_map1a { |
635 | my ($self, $data) = @_; |
691 | my ($self, $data) = @_; |
636 | |
692 | |
637 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
693 | my $missing = $self->{map}->map1a_update ($data); |
638 | my $delay; |
694 | my $delay; |
639 | |
695 | |
640 | for my $tile (@$missing) { |
696 | for my $tile (@$missing) { |
641 | next if $self->{delay}{$tile}; |
697 | next if $self->{delay}{$tile}; |
642 | |
698 | |
643 | $delay = 1; |
699 | $delay = 1; |
644 | |
700 | |
645 | if (my $tex = $::CONN->{texture}[$tile]) { |
701 | if (my $tex = $self->{texture}[$tile]) { |
646 | $tex->upload; |
702 | $tex->upload; |
647 | } else { |
703 | } else { |
648 | $self->{delay}{$tile} = 1; |
704 | $self->{delay}{$tile} = 1; |
649 | |
705 | |
650 | # we assume the face is in-flight and will eventually come |
706 | # we assume the face is in-flight and will eventually arrive |
651 | push @{$self->{tile_cb}{$tile}}, sub { |
707 | push @{$self->{tile_cb}{$tile}}, sub { |
652 | delete $self->{delay}{$tile}; |
708 | delete $self->{delay}{$tile}; |
653 | $_[0]->upload; |
709 | $_[0]->upload; |
654 | }; |
710 | }; |
655 | } |
711 | } |
656 | } |
712 | } |
657 | |
713 | |
658 | if ($delay) { |
714 | if ($delay) { |
659 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
715 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
660 | EV::once undef, 0, 0.03, sub { |
716 | EV::once undef, 0, 0.03, sub { |
661 | $self->{map_widget}->update |
717 | $self->{map_widget}->update |
662 | if $self->{map_widget}; |
718 | if $self->{map_widget}; |
663 | }; |
719 | }; |
664 | } else { |
720 | } else { |
… | |
… | |
673 | } |
729 | } |
674 | |
730 | |
675 | sub flush_map { |
731 | sub flush_map { |
676 | my ($self) = @_; |
732 | my ($self) = @_; |
677 | |
733 | |
678 | my $map_info = delete $self->{map_info} |
734 | return unless $self->{map_info}; |
679 | or return; |
|
|
680 | |
735 | |
|
|
736 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
681 | my ($hash, $x, $y, $w, $h) = @$map_info; |
737 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
682 | |
738 | |
683 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
739 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
684 | $self->{map_cache_new}{$hash} = \$data; |
740 | |
|
|
741 | if ($data ne $$rdata) { |
|
|
742 | $map_info->[1] = \$data; |
|
|
743 | my $cdata = Compress::LZF::compress $data; |
685 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
744 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
745 | } |
|
|
746 | } |
686 | } |
747 | } |
687 | |
748 | |
688 | sub map_clear { |
749 | sub map_clear { |
689 | my ($self) = @_; |
750 | my ($self) = @_; |
690 | |
751 | |
691 | $self->flush_map; |
752 | $self->flush_map; |
|
|
753 | delete $self->{map_info}; |
692 | delete $self->{neigh_map}; |
754 | delete $self->{neigh_map}; |
693 | |
755 | |
694 | $self->{map}->clear; |
756 | $self->{map}->clear; |
695 | delete $self->{map_widget}{magicmap}; |
757 | delete $self->{map_widget}{magicmap}; |
696 | } |
758 | } |
… | |
… | |
717 | |
779 | |
718 | $self->bg_fetch; |
780 | $self->bg_fetch; |
719 | }; |
781 | }; |
720 | } |
782 | } |
721 | |
783 | |
722 | sub load_map($$$) { |
784 | sub load_map($$$$$$) { |
723 | my ($self, $hash, $x, $y) = @_; |
785 | my ($self, $hash, $x, $y, $w, $h) = @_; |
724 | |
786 | |
725 | my $gen = $self->{map_change_gen}; |
787 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
726 | |
788 | |
727 | my $cb = sub { |
789 | my $cb = sub { |
728 | return unless $gen == $self->{map_change_gen}; |
790 | $map_info->[1] = \$_[0]; |
729 | |
791 | |
730 | my ($data) = @_; |
|
|
731 | |
|
|
732 | if (defined $data) { |
|
|
733 | $self->{map_cache_new}{$hash} = \$data; |
|
|
734 | |
|
|
735 | my $data = Compress::LZF::decompress $data; |
|
|
736 | |
|
|
737 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
792 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
738 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
793 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
739 | $self->bg_fetch unless $inprogress; |
794 | $self->bg_fetch unless $inprogress; |
740 | } |
|
|
741 | }; |
795 | }; |
742 | |
796 | |
743 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
797 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
744 | $cb->($$rdata); |
798 | $cb->(${ $map_info->[1] }); |
745 | } else { |
799 | } else { |
|
|
800 | my $gen = $self->{map_change_gen}; |
|
|
801 | |
746 | DC::DB::get $self->{mapcache} => $hash, $cb; |
802 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
803 | return unless $gen == $self->{map_change_gen}; |
|
|
804 | return unless defined $_[0]; |
|
|
805 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
806 | }; |
747 | } |
807 | } |
748 | } |
808 | } |
749 | |
809 | |
750 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
810 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
751 | # (server resource,s latency, bandwidth), so this hack is warranted. |
811 | # (server resources, latency, bandwidth), so this hack is warranted. |
752 | # the right fix is to make real tiled maps with an overview file |
812 | # the right fix is to make real tiled maps with an overview file |
753 | sub send_mapinfo { |
813 | sub send_mapinfo { |
754 | my ($self, $data, $cb) = @_; |
814 | my ($self, $data, $cb) = @_; |
755 | |
815 | |
756 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
816 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
781 | } |
841 | } |
782 | |
842 | |
783 | # this method does a "flood fill" into every tile direction |
843 | # this method does a "flood fill" into every tile direction |
784 | # it assumes that tiles are arranged in a rectangular grid, |
844 | # it assumes that tiles are arranged in a rectangular grid, |
785 | # i.e. a map is the same as the left of the right map etc. |
845 | # i.e. a map is the same as the left of the right map etc. |
786 | # failure to comply are harmless and result in display errors |
846 | # failure to comply is harmless and results in display errors |
787 | # at worst. |
847 | # at worst. |
788 | sub flood_fill { |
848 | sub flood_fill { |
789 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
849 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
790 | |
850 | |
791 | # the server does not allow map paths > 6 |
851 | # the server does not allow map paths > 6 |
… | |
… | |
827 | return if $mode ne "spatial"; |
887 | return if $mode ne "spatial"; |
828 | |
888 | |
829 | $x += $self->{map}->ox; |
889 | $x += $self->{map}->ox; |
830 | $y += $self->{map}->oy; |
890 | $y += $self->{map}->oy; |
831 | |
891 | |
832 | $self->load_map ($hash, $x, $y) |
892 | $self->load_map ($hash, $x, $y, $w, $h) |
833 | unless $self->{neigh_map}{$hash}[5]++;#d# |
893 | unless $self->{neigh_map}{$hash}[5]++;#d# |
834 | |
894 | |
835 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
895 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
836 | |
896 | |
837 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
897 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
845 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
905 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
846 | |
906 | |
847 | $self->flush_map; |
907 | $self->flush_map; |
848 | |
908 | |
849 | ++$self->{map_change_gen}; |
909 | ++$self->{map_change_gen}; |
850 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
910 | $self->{map_cache_old} = delete $self->{map_cache}; |
851 | |
911 | |
852 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
912 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
853 | |
913 | |
854 | my $mapmapw = $self->{mapmap}->{w}; |
914 | my $mapmapw = $self->{mapmap}->{w}; |
855 | my $mapmaph = $self->{mapmap}->{h}; |
915 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
867 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
927 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
868 | |
928 | |
869 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
929 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
870 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
930 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
871 | |
931 | |
872 | $self->load_map ($hash, $x, $y); |
932 | $self->load_map ($hash, $x, $y, $w, $h); |
873 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
933 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
874 | } |
934 | } |
875 | |
935 | |
876 | sub face_find { |
936 | sub face_find { |
877 | my ($self, $facenum, $face, $cb) = @_; |
937 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
948 | |
1008 | |
949 | my $tex = $self->{texture}[$tile] ||= |
1009 | my $tex = $self->{texture}[$tile] ||= |
950 | new DC::Texture |
1010 | new DC::Texture |
951 | tile => $tile, |
1011 | tile => $tile, |
952 | image => $data, delete_image => 1, |
1012 | image => $data, delete_image => 1, |
953 | minify => 1, mipmap => 1; |
1013 | minify => 1; |
954 | |
1014 | |
955 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1015 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
956 | $_->($tex) for @$cbs; |
1016 | $_->($tex) for @$cbs; |
957 | } |
1017 | } |
958 | } |
1018 | } |
… | |
… | |
963 | my ($self, $num, $cb) = @_; |
1023 | my ($self, $num, $cb) = @_; |
964 | |
1024 | |
965 | push @{$self->{face_cb}{$num}}, $cb; |
1025 | push @{$self->{face_cb}{$num}}, $cb; |
966 | |
1026 | |
967 | defined wantarray |
1027 | defined wantarray |
968 | ? DC::guard { |
1028 | ? Guard::guard { |
969 | @{$self->{face_cb}{$num}} |
1029 | @{$self->{face_cb}{$num}} |
970 | = grep $_ != $cb, |
1030 | = grep $_ != $cb, |
971 | @{$self->{face_cb}{$num}}; |
1031 | @{$self->{face_cb}{$num}}; |
972 | } |
1032 | } |
973 | : () |
1033 | : () |
… | |
… | |
1001 | my ($self, $flags, $prompt) = @_; |
1061 | my ($self, $flags, $prompt) = @_; |
1002 | |
1062 | |
1003 | $prompt = $LAST_QUERY unless length $prompt; |
1063 | $prompt = $LAST_QUERY unless length $prompt; |
1004 | $LAST_QUERY = $prompt; |
1064 | $LAST_QUERY = $prompt; |
1005 | |
1065 | |
1006 | $self->{query}-> ($self, $flags, $prompt); |
1066 | $self->{query}->($self, $flags, $prompt); |
1007 | } |
1067 | } |
1008 | |
1068 | |
1009 | sub sanitise_xml($) { |
1069 | sub sanitise_xml($) { |
1010 | local $_ = shift; |
1070 | local $_ = shift; |
1011 | |
1071 | |
… | |
… | |
1019 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1079 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1020 | |
1080 | |
1021 | # handle some elements |
1081 | # handle some elements |
1022 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1082 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1023 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1083 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1084 | |
|
|
1085 | s/\s+$//; |
1024 | |
1086 | |
1025 | $_ |
1087 | $_ |
1026 | } |
1088 | } |
1027 | |
1089 | |
1028 | our %NAME_TO_COLOR = ( |
1090 | our %NAME_TO_COLOR = ( |
… | |
… | |
1041 | tan => 12, |
1103 | tan => 12, |
1042 | ); |
1104 | ); |
1043 | |
1105 | |
1044 | our @CF_COLOR = ( |
1106 | our @CF_COLOR = ( |
1045 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1107 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1046 | [1.00, 1.00, 1.00], |
1108 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1047 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1109 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1048 | [1.00, 0.00, 0.00], |
1110 | [1.00, 0.00, 0.00], |
1049 | [1.00, 0.54, 0.00], |
1111 | [1.00, 0.54, 0.00], |
1050 | [0.11, 0.56, 1.00], |
1112 | [0.11, 0.56, 1.00], |
1051 | [0.93, 0.46, 0.00], |
1113 | [0.93, 0.46, 0.00], |
1052 | [0.18, 0.54, 0.34], |
1114 | [0.18, 0.54, 0.34], |
… | |
… | |
1071 | $self->logprint ("msg: ", $text); |
1133 | $self->logprint ("msg: ", $text); |
1072 | return if $color < 0; # negative color == ignore if not understood |
1134 | return if $color < 0; # negative color == ignore if not understood |
1073 | |
1135 | |
1074 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1136 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1075 | |
1137 | |
1076 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1077 | # no longer neecssary with TRT servers |
|
|
1078 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1079 | |
|
|
1080 | for (split /\n/, $text) { |
|
|
1081 | ::message ({ |
1138 | ::message ({ |
1082 | fg => $fg, |
1139 | fg => $fg, |
1083 | markup => $_, |
1140 | markup => $text, |
1084 | type => $type, |
1141 | type => $type, |
1085 | extra => [@extra], |
1142 | extra => [@extra], |
1086 | color_flags => $color, #d# ugly, kill |
1143 | color_flags => $color, #d# ugly, kill |
1087 | }); |
1144 | }); |
1088 | |
1145 | |
1089 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1146 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1090 | # actually, this is an ugly design. _we_ should control the channels, |
1147 | # # actually, this is an ugly design. _we_ should control the channels, |
1091 | # not some random other widget, as the channels are clearly protocol-specific. |
1148 | # # not some random other widget, as the channels are clearly protocol-specific. |
1092 | # then we could also react to flags such as CLEAR without resorting to |
1149 | # # then we could also react to flags such as CLEAR without resorting to |
1093 | # hacks such as color_flags, above. |
1150 | # # hacks such as color_flags, above. |
1094 | } |
|
|
1095 | |
1151 | |
1096 | $self->{statusbox}->add ($text, |
1152 | $self->{statusbox}->add ($text, |
1097 | group => $text, |
1153 | group => $text, |
1098 | fg => $fg, |
1154 | fg => $fg, |
1099 | timeout => $color >= 2 ? 180 : 10, |
1155 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1134 | |
1190 | |
1135 | my %skill_help; |
1191 | my %skill_help; |
1136 | |
1192 | |
1137 | for my $node (DC::Pod::find skill_description => "*") { |
1193 | for my $node (DC::Pod::find skill_description => "*") { |
1138 | my (undef, @par) = DC::Pod::section_of $node; |
1194 | my (undef, @par) = DC::Pod::section_of $node; |
1139 | $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; |
1195 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1140 | }; |
1196 | }; |
1141 | |
1197 | |
1142 | for my $skill (values %{$self->{skill_info}}) { |
1198 | for my $skill (values %{$self->{skill_info}}) { |
1143 | $self->{map_widget}->add_command ("ready_skill $skill", |
1199 | $self->{map_widget}->add_command ("ready_skill $skill", |
1144 | (DC::asxml "Ready the skill '$skill'\n\n") |
1200 | (DC::asxml "Ready the skill '$skill'\n\n") |
… | |
… | |
1164 | $::FLOORBOX->clear; |
1220 | $::FLOORBOX->clear; |
1165 | |
1221 | |
1166 | my @add; |
1222 | my @add; |
1167 | |
1223 | |
1168 | my $row; |
1224 | my $row; |
1169 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1225 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1226 | next if $_->{tag} & 0x80000000; |
1170 | if ($row < 6) { |
1227 | if ($row < 6) { |
1171 | local $_->{face_widget}; # hack to force recreation of widget |
1228 | local $_->{face_widget}; # hack to force recreation of widget |
1172 | local $_->{desc_widget}; # hack to force recreation of widget |
1229 | local $_->{desc_widget}; # hack to force recreation of widget |
1173 | DC::Item::update_widgets $_; |
1230 | DC::Item::update_widgets $_; |
1174 | |
1231 | |
… | |
… | |
1201 | sub set_opencont { |
1258 | sub set_opencont { |
1202 | my ($conn, $tag, $name) = @_; |
1259 | my ($conn, $tag, $name) = @_; |
1203 | $conn->{open_container} = $tag; |
1260 | $conn->{open_container} = $tag; |
1204 | update_floorbox; |
1261 | update_floorbox; |
1205 | |
1262 | |
1206 | $::INVR_HB->clear (); |
1263 | $::INVR_HB->clear; |
1207 | $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); |
1264 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1208 | |
1265 | |
1209 | if ($tag != 0) { # Floor isn't closable, is it? |
1266 | if ($tag != 0) { # Floor isn't closable, is it? |
1210 | $::INVR_HB->add (new DC::UI::Button |
1267 | $::INVR_HB->add (new DC::UI::Button |
1211 | text => "Close container", |
1268 | text => "Close container", |
1212 | tooltip => "Close the currently open container (if one is open)", |
1269 | tooltip => "Close the currently open container (if one is open)", |
… | |
… | |
1267 | } |
1324 | } |
1268 | |
1325 | |
1269 | sub item_update { |
1326 | sub item_update { |
1270 | my ($self, $item) = @_; |
1327 | my ($self, $item) = @_; |
1271 | |
1328 | |
1272 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1329 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1273 | |
1330 | |
1274 | DC::Item::update_widgets $item; |
1331 | DC::Item::update_widgets $item; |
1275 | |
1332 | |
1276 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1333 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1277 | set_opencont ($::CONN, 0, "Floor"); |
1334 | set_opencont ($::CONN, 0, "Floor"); |
1278 | |
1335 | |
1279 | } elsif ($item->{flags} & F_OPEN) { |
1336 | } elsif ($item->{flags} & F_OPEN) { |
1280 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1337 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1296 | |
1353 | |
1297 | my $weight = .001 * $self->{player}{weight}; |
1354 | my $weight = .001 * $self->{player}{weight}; |
1298 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1355 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1299 | |
1356 | |
1300 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1357 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1301 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1358 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1302 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1359 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1303 | } |
1360 | } |
1304 | |
1361 | |
1305 | sub update_server_info { |
1362 | sub update_server_info { |
1306 | my ($self) = @_; |
1363 | my ($self) = @_; |
1307 | |
1364 | |
1308 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1365 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1309 | |
1366 | |
|
|
1367 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1368 | |
1310 | $::SERVER_INFO->set_markup ( |
1369 | $::SERVER_INFO->set_markup ( |
1311 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1370 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1312 | . "protocol version <tt>$self->{version}</tt>\n" |
1371 | . "protocol version <tt>$version</tt>\n" |
1313 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1314 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1315 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1316 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1372 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1317 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1318 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1319 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1373 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1320 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1374 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1321 | . "map size $self->{mapw}×$self->{maph}\n" |
1375 | . "map size $self->{mapw}×$self->{maph}\n" |
1322 | ); |
1376 | ); |
1323 | |
1377 | |
1324 | } |
1378 | } |
… | |
… | |
1345 | }); |
1399 | }); |
1346 | |
1400 | |
1347 | $self->update_server_info; |
1401 | $self->update_server_info; |
1348 | |
1402 | |
1349 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1403 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1350 | $self->send_command ("pickup $::CFG->{pickup}"); |
1404 | $self->send_pickup ($::CFG->{pickup}); |
1351 | } |
1405 | } |
1352 | |
1406 | |
1353 | sub lookat { |
1407 | sub lookat { |
1354 | my ($self, $x, $y) = @_; |
1408 | my ($self, $x, $y) = @_; |
1355 | |
1409 | |
… | |
… | |
1357 | $self->send_ext_req (lookat => $x, $y, sub { |
1411 | $self->send_ext_req (lookat => $x, $y, sub { |
1358 | my (%msg) = @_; |
1412 | my (%msg) = @_; |
1359 | |
1413 | |
1360 | if (exists $msg{npc_dialog}) { |
1414 | if (exists $msg{npc_dialog}) { |
1361 | # start npc chat dialog |
1415 | # start npc chat dialog |
1362 | $self->{npc_dialog} = new DC::NPCDialog:: |
1416 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1363 | token => $msg{npc_dialog}, |
1417 | token => $msg{npc_dialog}, |
1364 | title => "$msg{npc_dialog}[0] (NPC)", |
1418 | title => "$msg{npc_dialog}[0] (NPC)", |
1365 | conn => $self, |
1419 | conn => $self, |
1366 | ; |
1420 | ; |
1367 | } |
1421 | } |
… | |
… | |
1372 | } |
1426 | } |
1373 | |
1427 | |
1374 | sub destroy { |
1428 | sub destroy { |
1375 | my ($self) = @_; |
1429 | my ($self) = @_; |
1376 | |
1430 | |
1377 | (delete $self->{npc_dialog})->destroy |
1431 | $_->destroy |
1378 | if $self->{npc_dialog}; |
1432 | for values %{ $self->{w} }; |
1379 | |
1433 | |
1380 | $self->SUPER::destroy; |
1434 | $self->SUPER::destroy; |
1381 | |
1435 | |
1382 | %$self = (); |
1436 | %$self = (); |
1383 | } |
1437 | } |
… | |
… | |
1519 | } |
1573 | } |
1520 | |
1574 | |
1521 | sub send { |
1575 | sub send { |
1522 | my ($self, $msg) = @_; |
1576 | my ($self, $msg) = @_; |
1523 | |
1577 | |
1524 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1578 | $self->{textview}->add_paragraph ({ |
|
|
1579 | markup => |
|
|
1580 | "\n<span foreground='#ffff00'><b>" |
|
|
1581 | . (DC::asxml $msg) |
|
|
1582 | . "</b></span>" |
|
|
1583 | }); |
1525 | $self->{textview}->scroll_to_bottom; |
1584 | $self->{textview}->scroll_to_bottom; |
1526 | |
1585 | |
1527 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1586 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1528 | } |
1587 | } |
1529 | |
1588 | |
… | |
… | |
1532 | |
1591 | |
1533 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1592 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1534 | |
1593 | |
1535 | if ($self->{conn}) { |
1594 | if ($self->{conn}) { |
1536 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1595 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1537 | delete $self->{conn}{npc_dialog}; |
1596 | delete $self->{conn}{w}{npc_dialog}; |
1538 | $self->{conn}->disconnect_ext ($self->{id}); |
1597 | $self->{conn}->disconnect_ext ($self->{id}); |
1539 | } |
1598 | } |
1540 | |
1599 | |
1541 | $self->SUPER::destroy; |
1600 | $self->SUPER::destroy; |
1542 | } |
1601 | } |