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; |
… | |
… | |
11 | use DC::Pod; |
12 | use DC::Pod; |
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'; |
|
|
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# |
16 | |
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, |
… | |
… | |
27 | ); |
36 | ); |
28 | |
37 | |
29 | $self->{map_widget}->clr_commands; |
38 | $self->{map_widget}->clr_commands; |
30 | |
39 | |
31 | my @cmd_help = map { |
40 | my @cmd_help = map { |
32 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
41 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | or die "unparseable command help: $_->{kw}[0]"; |
42 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
34 | |
43 | |
35 | my $cmd = $1; |
44 | my $cmd = $1; |
36 | my @args = split /\|/, $2; |
45 | my @args = split /\|/, $2; |
37 | @args = (".*") unless @args; |
46 | @args = (".*") unless @args; |
38 | |
47 | |
… | |
… | |
43 | for @args; |
52 | for @args; |
44 | |
53 | |
45 | map ["$cmd$_", $text], |
54 | map ["$cmd$_", $text], |
46 | sort { (length $a) <=> (length $b) } |
55 | sort { (length $a) <=> (length $b) } |
47 | @args |
56 | @args |
48 | } sort { $a->{par} <=> $b->{par} } |
57 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
49 | DC::Pod::find command => "*"; |
58 | DC::Pod::find command => "*"; |
50 | |
59 | |
51 | $self->{json_coder} |
60 | $self->{json_coder} |
52 | ->convert_blessed |
61 | ->convert_blessed |
53 | ->filter_json_single_key_object ("\fw" => sub { |
62 | ->filter_json_single_key_object ("\fw" => sub { |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
73 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
74 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
75 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
76 | for values %{delete $ws->{w} || {}}; |
68 | } |
77 | } |
|
|
78 | |
|
|
79 | delete $self->{items}; |
|
|
80 | $::INV->clear; |
|
|
81 | $::INVR->clear; |
|
|
82 | $::INVR_HB->clear; |
|
|
83 | $::FLOORBOX->clear; |
69 | }); |
84 | }); |
70 | |
85 | |
71 | $self->{map_widget}->add_command (@$_) |
86 | $self->{map_widget}->add_command (@$_) |
72 | for @cmd_help; |
87 | for @cmd_help; |
73 | |
88 | |
74 | { |
89 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
90 | $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}}); |
91 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
92 | } |
79 | |
93 | |
80 | { |
94 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
95 | $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}}); |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
97 | } |
|
|
98 | |
|
|
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
102 | # |
|
|
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
105 | # $self->{texture}[$_]->unload; |
|
|
106 | # warn "expire texture $_\n";#d# |
|
|
107 | # } |
|
|
108 | # |
|
|
109 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
110 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
111 | # warn "count is $count\n";#d# |
|
|
112 | # }; |
85 | |
113 | |
86 | $self->{open_container} = 0; |
114 | $self->{open_container} = 0; |
87 | |
115 | |
88 | # per server |
116 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
117 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
225 | @w |
253 | @w |
226 | }; |
254 | }; |
227 | |
255 | |
228 | # either array reference, or face # |
256 | # either array reference, or face # |
229 | if ($type eq "inline") { |
257 | if ($type eq "inline") { |
|
|
258 | $done_cb->(); |
230 | $parse_list->($template); |
259 | $parse_list->($template); |
231 | $done_cb->(); |
|
|
232 | } elsif ($type eq "face") { |
260 | } elsif ($type eq "face") { |
233 | #... |
261 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
262 | my ($face) = @_; |
|
|
263 | |
|
|
264 | undef $handler; |
234 | $done_cb->(0); |
265 | $done_cb->(); |
|
|
266 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
267 | }); |
235 | } else { |
268 | } else { |
236 | $done_cb->(0); |
269 | $done_cb->(0); |
237 | } |
270 | } |
238 | } |
271 | } |
239 | |
272 | |
… | |
… | |
245 | my %wkw = ( |
278 | my %wkw = ( |
246 | root => $DC::UI::ROOT, |
279 | root => $DC::UI::ROOT, |
247 | tooltip => $DC::UI::TOOLTIP, |
280 | tooltip => $DC::UI::TOOLTIP, |
248 | |
281 | |
249 | mapwidget => $::MAPWIDGET, |
282 | mapwidget => $::MAPWIDGET, |
|
|
283 | menubar => $::MENUBAR, |
|
|
284 | menupopup => $::MENUPOPUP, |
|
|
285 | pickup_enable => $::PICKUP_ENABLE, |
250 | buttonbar => $::BUTTONBAR, |
286 | buttonbar => $::BUTTONBAR, |
251 | metaserver => $::METASERVER, |
287 | metaserver => $::METASERVER, |
252 | buttonbar => $::BUTTONBAR, |
288 | buttonbar => $::BUTTONBAR, |
253 | login_button => $::LOGIN_BUTTON, |
289 | login_button => $::LOGIN_BUTTON, |
254 | quit_dialog => $::QUIT_DIALOG, |
290 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
270 | spell_list => $::SPELL_LIST, |
306 | spell_list => $::SPELL_LIST, |
271 | |
307 | |
272 | floorbox => $::FLOORBOX, |
308 | floorbox => $::FLOORBOX, |
273 | help_window => $::HELP_WINDOW, |
309 | help_window => $::HELP_WINDOW, |
274 | message_window => $::MESSAGE_WINDOW, |
310 | message_window => $::MESSAGE_WINDOW, |
|
|
311 | message_dist => $::MESSAGE_DIST, |
275 | statusbox => $::SDTATUSBOX, |
312 | statusbox => $::STATUSBOX, |
276 | |
313 | |
277 | inv => $::INV, |
314 | inv => $::INV, |
278 | invr => $::INVR, |
315 | invr => $::INVR, |
279 | invr_hb => $::INVR_HB, |
316 | invr_hb => $::INVR_HB, |
280 | ); |
317 | ); |
… | |
… | |
328 | |
365 | |
329 | # message window |
366 | # message window |
330 | sub ext_channel_info { |
367 | sub ext_channel_info { |
331 | my ($self, $info) = @_; |
368 | my ($self, $info) = @_; |
332 | $self->{channels}->{$info->{id}} = $info; |
369 | $self->{channels}->{$info->{id}} = $info; |
333 | $::MESSAGE_WINDOW->add_channel ($info); |
370 | $::MESSAGE_DIST->add_channel ($info); |
334 | } |
371 | } |
335 | |
372 | |
336 | ############################################################################# |
373 | ############################################################################# |
337 | |
374 | |
338 | sub logprint { |
375 | sub logprint { |
… | |
… | |
364 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
401 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
365 | : () |
402 | : () |
366 | } |
403 | } |
367 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
404 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
368 | |
405 | |
369 | join "", @diff |
406 | "\u$name: " . (join ", ", @diff) |
370 | } |
407 | } |
371 | |
408 | |
372 | # all stats that are chacked against changes |
409 | # all stats that are chacked against changes |
373 | my @statchange = ( |
410 | my @statchange = ( |
374 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
411 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
429 | } |
466 | } |
430 | |
467 | |
431 | if ( |
468 | if ( |
432 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
469 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
433 | ) { |
470 | ) { |
434 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
471 | 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); |
472 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
436 | } |
473 | } |
437 | |
474 | |
438 | $self->update_stats_window ($stats, $prev); |
475 | $self->update_stats_window ($stats, $prev); |
439 | |
476 | |
… | |
… | |
477 | |
514 | |
478 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
515 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
479 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
516 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
480 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
517 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
481 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
518 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
482 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
519 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
483 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
520 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
484 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
521 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
485 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
522 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
486 | my $title = $stats->{+CS_STAT_TITLE}; |
523 | my $title = $stats->{+CS_STAT_TITLE}; |
487 | $title =~ s/^Player: //; |
524 | $title =~ s/^Player: //; |
488 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
525 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
489 | |
526 | |
… | |
… | |
501 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
538 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
502 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
539 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
503 | |
540 | |
504 | $self->update_weight; |
541 | $self->update_weight; |
505 | |
542 | |
506 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
543 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
507 | for keys %RES_TBL; |
544 | for keys %RES_TBL; |
508 | |
545 | |
509 | my $sktbl = $::STATWIDS->{skill_tbl}; |
546 | my $sktbl = $::STATWIDS->{skill_tbl}; |
510 | my @skills = keys %{ $self->{skill_info} }; |
547 | my @skills = keys %{ $self->{skill_info} }; |
511 | |
548 | |
… | |
… | |
520 | $sktbl->clear; |
557 | $sktbl->clear; |
521 | |
558 | |
522 | my $sw = $self->{skillwid}{""} ||= [ |
559 | my $sw = $self->{skillwid}{""} ||= [ |
523 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
560 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
524 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
561 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
525 | 2, 0, (new DC::UI::Label text => "Progress", align => 0), |
562 | 2, 0, (new DC::UI::Label text => "Progress"), |
526 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1), |
563 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
527 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
564 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
528 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
565 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
529 | 6, 0, (new DC::UI::Label text => "Progress", align => 0), |
566 | 6, 0, (new DC::UI::Label text => "Progress"), |
530 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1), |
567 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
531 | ]; |
568 | ]; |
532 | |
569 | |
533 | my @add = @$sw; |
570 | my @add = @$sw; |
534 | |
571 | |
535 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
572 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
536 | |
573 | |
537 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
574 | 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); |
575 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
539 | |
576 | |
540 | my ($x, $y) = (0, 1); |
577 | my ($x, $y) = (0, 1); |
… | |
… | |
574 | |
611 | |
575 | # progress |
612 | # progress |
576 | (new DC::UI::ExperienceProgress), |
613 | (new DC::UI::ExperienceProgress), |
577 | |
614 | |
578 | # label |
615 | # label |
579 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, |
616 | (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), |
617 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
581 | ]; |
618 | ]; |
582 | |
619 | |
583 | push @add, |
620 | push @add, |
584 | $x * 4 + 0, $y, $sw->[0], |
621 | $x * 4 + 0, $y, $sw->[0], |
… | |
… | |
602 | my $sw = $self->{skillwid}{$idx}; |
639 | my $sw = $self->{skillwid}{$idx}; |
603 | $sw->[0]->set_text (::formsep ($val->[1])); |
640 | $sw->[0]->set_text (::formsep ($val->[1])); |
604 | $sw->[1]->set_text ($val->[0] * 1); |
641 | $sw->[1]->set_text ($val->[0] * 1); |
605 | $sw->[2]->set_value (@$val); |
642 | $sw->[2]->set_value (@$val); |
606 | |
643 | |
607 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
644 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
608 | $::GAUGES->{sklprg}->set_value (@$val); |
645 | $::GAUGES->{skillexp}->set_value (@$val); |
609 | } |
646 | } |
610 | } |
647 | } |
611 | |
648 | |
612 | sub user_send { |
649 | sub user_send { |
613 | my ($self, $command) = @_; |
650 | my ($self, $command) = @_; |
… | |
… | |
626 | } |
663 | } |
627 | |
664 | |
628 | sub map_scroll { |
665 | sub map_scroll { |
629 | my ($self, $dx, $dy) = @_; |
666 | my ($self, $dx, $dy) = @_; |
630 | |
667 | |
631 | $self->{map}->scroll ($dx, $dy); |
668 | $self->{map_widget}->scroll ($dx, $dy); |
632 | } |
669 | } |
633 | |
670 | |
634 | sub feed_map1a { |
671 | sub feed_map1a { |
635 | my ($self, $data) = @_; |
672 | my ($self, $data) = @_; |
636 | |
673 | |
… | |
… | |
640 | for my $tile (@$missing) { |
677 | for my $tile (@$missing) { |
641 | next if $self->{delay}{$tile}; |
678 | next if $self->{delay}{$tile}; |
642 | |
679 | |
643 | $delay = 1; |
680 | $delay = 1; |
644 | |
681 | |
645 | if (my $tex = $::CONN->{texture}[$tile]) { |
682 | if (my $tex = $self->{texture}[$tile]) { |
646 | $tex->upload; |
683 | $tex->upload; |
647 | } else { |
684 | } else { |
648 | $self->{delay}{$tile} = 1; |
685 | $self->{delay}{$tile} = 1; |
649 | |
686 | |
650 | # we assume the face is in-flight and will eventually come |
687 | # we assume the face is in-flight and will eventually arrive |
651 | push @{$self->{tile_cb}{$tile}}, sub { |
688 | push @{$self->{tile_cb}{$tile}}, sub { |
652 | delete $self->{delay}{$tile}; |
689 | delete $self->{delay}{$tile}; |
653 | $_[0]->upload; |
690 | $_[0]->upload; |
654 | }; |
691 | }; |
655 | } |
692 | } |
656 | } |
693 | } |
657 | |
694 | |
658 | if ($delay) { |
695 | if ($delay) { |
659 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
696 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
660 | EV::once undef, 0, 0.03, sub { |
697 | EV::once undef, 0, 0.03, sub { |
661 | $self->{map_widget}->update |
698 | $self->{map_widget}->update |
662 | if $self->{map_widget}; |
699 | if $self->{map_widget}; |
663 | }; |
700 | }; |
664 | } else { |
701 | } else { |
… | |
… | |
673 | } |
710 | } |
674 | |
711 | |
675 | sub flush_map { |
712 | sub flush_map { |
676 | my ($self) = @_; |
713 | my ($self) = @_; |
677 | |
714 | |
678 | my $map_info = delete $self->{map_info} |
715 | return unless $self->{map_info}; |
679 | or return; |
|
|
680 | |
716 | |
|
|
717 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
681 | my ($hash, $x, $y, $w, $h) = @$map_info; |
718 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
682 | |
719 | |
683 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
720 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
684 | $self->{map_cache_new}{$hash} = \$data; |
721 | |
|
|
722 | if ($data ne $$rdata) { |
|
|
723 | $map_info->[1] = \$data; |
|
|
724 | my $cdata = Compress::LZF::compress $data; |
685 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
725 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
726 | } |
|
|
727 | } |
686 | } |
728 | } |
687 | |
729 | |
688 | sub map_clear { |
730 | sub map_clear { |
689 | my ($self) = @_; |
731 | my ($self) = @_; |
690 | |
732 | |
691 | $self->flush_map; |
733 | $self->flush_map; |
|
|
734 | delete $self->{map_info}; |
692 | delete $self->{neigh_map}; |
735 | delete $self->{neigh_map}; |
693 | |
736 | |
694 | $self->{map}->clear; |
737 | $self->{map}->clear; |
695 | delete $self->{map_widget}{magicmap}; |
738 | delete $self->{map_widget}{magicmap}; |
696 | } |
739 | } |
… | |
… | |
717 | |
760 | |
718 | $self->bg_fetch; |
761 | $self->bg_fetch; |
719 | }; |
762 | }; |
720 | } |
763 | } |
721 | |
764 | |
722 | sub load_map($$$) { |
765 | sub load_map($$$$$$) { |
723 | my ($self, $hash, $x, $y) = @_; |
766 | my ($self, $hash, $x, $y, $w, $h) = @_; |
724 | |
767 | |
725 | my $gen = $self->{map_change_gen}; |
768 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
726 | |
769 | |
727 | my $cb = sub { |
770 | my $cb = sub { |
728 | return unless $gen == $self->{map_change_gen}; |
771 | $map_info->[1] = \$_[0]; |
729 | |
772 | |
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} || [] }; |
773 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
738 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
774 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
739 | $self->bg_fetch unless $inprogress; |
775 | $self->bg_fetch unless $inprogress; |
740 | } |
|
|
741 | }; |
776 | }; |
742 | |
777 | |
743 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
778 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
744 | $cb->($$rdata); |
779 | $cb->(${ $map_info->[1] }); |
745 | } else { |
780 | } else { |
|
|
781 | my $gen = $self->{map_change_gen}; |
|
|
782 | |
746 | DC::DB::get $self->{mapcache} => $hash, $cb; |
783 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
784 | return unless $gen == $self->{map_change_gen}; |
|
|
785 | return unless defined $_[0]; |
|
|
786 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
787 | }; |
747 | } |
788 | } |
748 | } |
789 | } |
749 | |
790 | |
750 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
791 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
751 | # (server resource,s latency, bandwidth), so this hack is warranted. |
792 | # (server resources, latency, bandwidth), so this hack is warranted. |
752 | # the right fix is to make real tiled maps with an overview file |
793 | # the right fix is to make real tiled maps with an overview file |
753 | sub send_mapinfo { |
794 | sub send_mapinfo { |
754 | my ($self, $data, $cb) = @_; |
795 | my ($self, $data, $cb) = @_; |
755 | |
796 | |
756 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
797 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
781 | } |
822 | } |
782 | |
823 | |
783 | # this method does a "flood fill" into every tile direction |
824 | # this method does a "flood fill" into every tile direction |
784 | # it assumes that tiles are arranged in a rectangular grid, |
825 | # 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. |
826 | # 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 |
827 | # failure to comply is harmless and results in display errors |
787 | # at worst. |
828 | # at worst. |
788 | sub flood_fill { |
829 | sub flood_fill { |
789 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
830 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
790 | |
831 | |
791 | # the server does not allow map paths > 6 |
832 | # the server does not allow map paths > 6 |
… | |
… | |
827 | return if $mode ne "spatial"; |
868 | return if $mode ne "spatial"; |
828 | |
869 | |
829 | $x += $self->{map}->ox; |
870 | $x += $self->{map}->ox; |
830 | $y += $self->{map}->oy; |
871 | $y += $self->{map}->oy; |
831 | |
872 | |
832 | $self->load_map ($hash, $x, $y) |
873 | $self->load_map ($hash, $x, $y, $w, $h) |
833 | unless $self->{neigh_map}{$hash}[5]++;#d# |
874 | unless $self->{neigh_map}{$hash}[5]++;#d# |
834 | |
875 | |
835 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
876 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
836 | |
877 | |
837 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
878 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
845 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
886 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
846 | |
887 | |
847 | $self->flush_map; |
888 | $self->flush_map; |
848 | |
889 | |
849 | ++$self->{map_change_gen}; |
890 | ++$self->{map_change_gen}; |
850 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
891 | $self->{map_cache_old} = delete $self->{map_cache}; |
851 | |
892 | |
852 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
893 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
853 | |
894 | |
854 | my $mapmapw = $self->{mapmap}->{w}; |
895 | my $mapmapw = $self->{mapmap}->{w}; |
855 | my $mapmaph = $self->{mapmap}->{h}; |
896 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
867 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
908 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
868 | |
909 | |
869 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
910 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
870 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
911 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
871 | |
912 | |
872 | $self->load_map ($hash, $x, $y); |
913 | $self->load_map ($hash, $x, $y, $w, $h); |
873 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
914 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
874 | } |
915 | } |
875 | |
916 | |
876 | sub face_find { |
917 | sub face_find { |
877 | my ($self, $facenum, $face, $cb) = @_; |
918 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
948 | |
989 | |
949 | my $tex = $self->{texture}[$tile] ||= |
990 | my $tex = $self->{texture}[$tile] ||= |
950 | new DC::Texture |
991 | new DC::Texture |
951 | tile => $tile, |
992 | tile => $tile, |
952 | image => $data, delete_image => 1, |
993 | image => $data, delete_image => 1, |
953 | minify => 1, mipmap => 1; |
994 | minify => 1; |
954 | |
995 | |
955 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
996 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
956 | $_->($tex) for @$cbs; |
997 | $_->($tex) for @$cbs; |
957 | } |
998 | } |
958 | } |
999 | } |
… | |
… | |
963 | my ($self, $num, $cb) = @_; |
1004 | my ($self, $num, $cb) = @_; |
964 | |
1005 | |
965 | push @{$self->{face_cb}{$num}}, $cb; |
1006 | push @{$self->{face_cb}{$num}}, $cb; |
966 | |
1007 | |
967 | defined wantarray |
1008 | defined wantarray |
968 | ? DC::guard { |
1009 | ? Guard::guard { |
969 | @{$self->{face_cb}{$num}} |
1010 | @{$self->{face_cb}{$num}} |
970 | = grep $_ != $cb, |
1011 | = grep $_ != $cb, |
971 | @{$self->{face_cb}{$num}}; |
1012 | @{$self->{face_cb}{$num}}; |
972 | } |
1013 | } |
973 | : () |
1014 | : () |
… | |
… | |
1019 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1060 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1020 | |
1061 | |
1021 | # handle some elements |
1062 | # handle some elements |
1022 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1063 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1023 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1064 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1065 | |
|
|
1066 | s/\s+$//; |
1024 | |
1067 | |
1025 | $_ |
1068 | $_ |
1026 | } |
1069 | } |
1027 | |
1070 | |
1028 | our %NAME_TO_COLOR = ( |
1071 | our %NAME_TO_COLOR = ( |
… | |
… | |
1075 | |
1118 | |
1076 | ## try to create single paragraphs of multiple lines sent by the server |
1119 | ## try to create single paragraphs of multiple lines sent by the server |
1077 | # no longer neecssary with TRT servers |
1120 | # no longer neecssary with TRT servers |
1078 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1121 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1079 | |
1122 | |
1080 | for (split /\n/, $text) { |
|
|
1081 | ::message ({ |
1123 | ::message ({ |
1082 | fg => $fg, |
1124 | fg => $fg, |
1083 | markup => $_, |
1125 | markup => $text, |
1084 | type => $type, |
1126 | type => $type, |
1085 | extra => [@extra], |
1127 | extra => [@extra], |
1086 | color_flags => $color, #d# ugly, kill |
1128 | color_flags => $color, #d# ugly, kill |
1087 | }); |
1129 | }); |
1088 | |
1130 | |
1089 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1131 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1090 | # actually, this is an ugly design. _we_ should control the channels, |
1132 | # # actually, this is an ugly design. _we_ should control the channels, |
1091 | # not some random other widget, as the channels are clearly protocol-specific. |
1133 | # # 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 |
1134 | # # then we could also react to flags such as CLEAR without resorting to |
1093 | # hacks such as color_flags, above. |
1135 | # # hacks such as color_flags, above. |
1094 | } |
|
|
1095 | |
1136 | |
1096 | $self->{statusbox}->add ($text, |
1137 | $self->{statusbox}->add ($text, |
1097 | group => $text, |
1138 | group => $text, |
1098 | fg => $fg, |
1139 | fg => $fg, |
1099 | timeout => $color >= 2 ? 180 : 10, |
1140 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1134 | |
1175 | |
1135 | my %skill_help; |
1176 | my %skill_help; |
1136 | |
1177 | |
1137 | for my $node (DC::Pod::find skill_description => "*") { |
1178 | for my $node (DC::Pod::find skill_description => "*") { |
1138 | my (undef, @par) = DC::Pod::section_of $node; |
1179 | my (undef, @par) = DC::Pod::section_of $node; |
1139 | $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; |
1180 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1140 | }; |
1181 | }; |
1141 | |
1182 | |
1142 | for my $skill (values %{$self->{skill_info}}) { |
1183 | for my $skill (values %{$self->{skill_info}}) { |
1143 | $self->{map_widget}->add_command ("ready_skill $skill", |
1184 | $self->{map_widget}->add_command ("ready_skill $skill", |
1144 | (DC::asxml "Ready the skill '$skill'\n\n") |
1185 | (DC::asxml "Ready the skill '$skill'\n\n") |
… | |
… | |
1164 | $::FLOORBOX->clear; |
1205 | $::FLOORBOX->clear; |
1165 | |
1206 | |
1166 | my @add; |
1207 | my @add; |
1167 | |
1208 | |
1168 | my $row; |
1209 | my $row; |
1169 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1210 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1211 | next if $_->{tag} & 0x80000000; |
1170 | if ($row < 6) { |
1212 | if ($row < 6) { |
1171 | local $_->{face_widget}; # hack to force recreation of widget |
1213 | local $_->{face_widget}; # hack to force recreation of widget |
1172 | local $_->{desc_widget}; # hack to force recreation of widget |
1214 | local $_->{desc_widget}; # hack to force recreation of widget |
1173 | DC::Item::update_widgets $_; |
1215 | DC::Item::update_widgets $_; |
1174 | |
1216 | |
… | |
… | |
1201 | sub set_opencont { |
1243 | sub set_opencont { |
1202 | my ($conn, $tag, $name) = @_; |
1244 | my ($conn, $tag, $name) = @_; |
1203 | $conn->{open_container} = $tag; |
1245 | $conn->{open_container} = $tag; |
1204 | update_floorbox; |
1246 | update_floorbox; |
1205 | |
1247 | |
1206 | $::INVR_HB->clear (); |
1248 | $::INVR_HB->clear; |
1207 | $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); |
1249 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1208 | |
1250 | |
1209 | if ($tag != 0) { # Floor isn't closable, is it? |
1251 | if ($tag != 0) { # Floor isn't closable, is it? |
1210 | $::INVR_HB->add (new DC::UI::Button |
1252 | $::INVR_HB->add (new DC::UI::Button |
1211 | text => "Close container", |
1253 | text => "Close container", |
1212 | tooltip => "Close the currently open container (if one is open)", |
1254 | tooltip => "Close the currently open container (if one is open)", |
… | |
… | |
1267 | } |
1309 | } |
1268 | |
1310 | |
1269 | sub item_update { |
1311 | sub item_update { |
1270 | my ($self, $item) = @_; |
1312 | my ($self, $item) = @_; |
1271 | |
1313 | |
1272 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1314 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1273 | |
1315 | |
1274 | DC::Item::update_widgets $item; |
1316 | DC::Item::update_widgets $item; |
1275 | |
1317 | |
1276 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1318 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1277 | set_opencont ($::CONN, 0, "Floor"); |
1319 | set_opencont ($::CONN, 0, "Floor"); |
1278 | |
1320 | |
1279 | } elsif ($item->{flags} & F_OPEN) { |
1321 | } elsif ($item->{flags} & F_OPEN) { |
1280 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1322 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1296 | |
1338 | |
1297 | my $weight = .001 * $self->{player}{weight}; |
1339 | my $weight = .001 * $self->{player}{weight}; |
1298 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1340 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1299 | |
1341 | |
1300 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1342 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1301 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1343 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1302 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1344 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1303 | } |
1345 | } |
1304 | |
1346 | |
1305 | sub update_server_info { |
1347 | sub update_server_info { |
1306 | my ($self) = @_; |
1348 | my ($self) = @_; |
1307 | |
1349 | |
1308 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1350 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1309 | |
1351 | |
|
|
1352 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1353 | |
1310 | $::SERVER_INFO->set_markup ( |
1354 | $::SERVER_INFO->set_markup ( |
1311 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1355 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1312 | . "protocol version <tt>$self->{version}</tt>\n" |
1356 | . "protocol version <tt>$version</tt>\n" |
1313 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1357 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1314 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1358 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1315 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1359 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1316 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1360 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1317 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1361 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1318 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1362 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1319 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1363 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1320 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1364 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1321 | . "map size $self->{mapw}×$self->{maph}\n" |
1365 | . "map size $self->{mapw}×$self->{maph}\n" |
1322 | ); |
1366 | ); |
1323 | |
1367 | |
1324 | } |
1368 | } |
… | |
… | |
1345 | }); |
1389 | }); |
1346 | |
1390 | |
1347 | $self->update_server_info; |
1391 | $self->update_server_info; |
1348 | |
1392 | |
1349 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1393 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1350 | $self->send_command ("pickup $::CFG->{pickup}"); |
1394 | $self->send_pickup ($::CFG->{pickup}); |
1351 | } |
1395 | } |
1352 | |
1396 | |
1353 | sub lookat { |
1397 | sub lookat { |
1354 | my ($self, $x, $y) = @_; |
1398 | my ($self, $x, $y) = @_; |
1355 | |
1399 | |
… | |
… | |
1519 | } |
1563 | } |
1520 | |
1564 | |
1521 | sub send { |
1565 | sub send { |
1522 | my ($self, $msg) = @_; |
1566 | my ($self, $msg) = @_; |
1523 | |
1567 | |
1524 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1568 | $self->{textview}->add_paragraph ({ |
|
|
1569 | markup => |
|
|
1570 | "\n<span foreground='#ffff00'><b>" |
|
|
1571 | . (DC::asxml $msg) |
|
|
1572 | . "</b></span>" |
|
|
1573 | }); |
1525 | $self->{textview}->scroll_to_bottom; |
1574 | $self->{textview}->scroll_to_bottom; |
1526 | |
1575 | |
1527 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1576 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1528 | } |
1577 | } |
1529 | |
1578 | |