1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
|
|
5 | |
|
|
6 | use Guard (); |
5 | |
7 | |
6 | use Deliantra::Protocol::Constants; |
8 | use Deliantra::Protocol::Constants; |
7 | |
9 | |
8 | use DC; |
10 | use DC; |
9 | use DC::DB; |
11 | use DC::DB; |
… | |
… | |
11 | use DC::Pod; |
13 | use DC::Pod; |
12 | use DC::Macro; |
14 | use DC::Macro; |
13 | use DC::Item; |
15 | use DC::Item; |
14 | |
16 | |
15 | use base 'Deliantra::Protocol::Base'; |
17 | use base 'Deliantra::Protocol::Base'; |
|
|
18 | |
|
|
19 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
20 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
21 | |
|
|
22 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
23 | "noface.png", minify => 1, mipmap => 1; |
|
|
24 | |
|
|
25 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
26 | "hidden.png", minify => 1, mipmap => 1; |
|
|
27 | |
|
|
28 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
29 | |
17 | sub new { |
30 | sub new { |
18 | my ($class, %arg) = @_; |
31 | my ($class, %arg) = @_; |
19 | |
32 | |
20 | my $self = $class->SUPER::new (%arg, |
33 | my $self = $class->SUPER::new (%arg, |
… | |
… | |
67 | for values %{delete $ws->{w} || {}}; |
80 | for values %{delete $ws->{w} || {}}; |
68 | } |
81 | } |
69 | |
82 | |
70 | delete $self->{items}; |
83 | delete $self->{items}; |
71 | $::INV->clear; |
84 | $::INV->clear; |
|
|
85 | $::INVR->clear; |
72 | $::INVR_HB->clear; |
86 | $::INVR_HB->clear; |
73 | $::FLOORBOX->clear; |
87 | $::FLOORBOX->clear; |
74 | }); |
88 | }); |
75 | |
89 | |
76 | $self->{map_widget}->add_command (@$_) |
90 | $self->{map_widget}->add_command (@$_) |
77 | for @cmd_help; |
91 | for @cmd_help; |
78 | |
92 | |
79 | { |
93 | { |
80 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
94 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
81 | DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
82 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
95 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
83 | } |
96 | } |
84 | |
97 | |
85 | { |
98 | { |
86 | $self->{noface} = my $tex = new_from_file DC::Texture |
99 | $self->{noface} = my $tex = $TEX_NOFACE; |
87 | DC::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
88 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
100 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
101 | } |
|
|
102 | |
|
|
103 | { |
|
|
104 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
105 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
106 | } |
|
|
107 | |
|
|
108 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
109 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
110 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
111 | # |
|
|
112 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
113 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
114 | # $self->{texture}[$_]->unload; |
|
|
115 | # warn "expire texture $_\n";#d# |
|
|
116 | # } |
|
|
117 | # |
|
|
118 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
119 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
120 | # warn "count is $count\n";#d# |
|
|
121 | # }; |
90 | |
122 | |
91 | $self->{open_container} = 0; |
123 | $self->{open_container} = 0; |
92 | |
124 | |
93 | # per server |
125 | # per server |
94 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
126 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
255 | my %wkw = ( |
287 | my %wkw = ( |
256 | root => $DC::UI::ROOT, |
288 | root => $DC::UI::ROOT, |
257 | tooltip => $DC::UI::TOOLTIP, |
289 | tooltip => $DC::UI::TOOLTIP, |
258 | |
290 | |
259 | mapwidget => $::MAPWIDGET, |
291 | mapwidget => $::MAPWIDGET, |
|
|
292 | menubar => $::MENUBAR, |
|
|
293 | menupopup => $::MENUPOPUP, |
|
|
294 | pickup_enable => $::PICKUP_ENABLE, |
260 | buttonbar => $::BUTTONBAR, |
295 | buttonbar => $::BUTTONBAR, |
261 | metaserver => $::METASERVER, |
296 | metaserver => $::METASERVER, |
262 | buttonbar => $::BUTTONBAR, |
297 | buttonbar => $::BUTTONBAR, |
263 | login_button => $::LOGIN_BUTTON, |
298 | login_button => $::LOGIN_BUTTON, |
264 | quit_dialog => $::QUIT_DIALOG, |
299 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
281 | |
316 | |
282 | floorbox => $::FLOORBOX, |
317 | floorbox => $::FLOORBOX, |
283 | help_window => $::HELP_WINDOW, |
318 | help_window => $::HELP_WINDOW, |
284 | message_window => $::MESSAGE_WINDOW, |
319 | message_window => $::MESSAGE_WINDOW, |
285 | message_dist => $::MESSAGE_DIST, |
320 | message_dist => $::MESSAGE_DIST, |
286 | statusbox => $::SDTATUSBOX, |
321 | statusbox => $::STATUSBOX, |
287 | |
322 | |
288 | inv => $::INV, |
323 | inv => $::INV, |
289 | invr => $::INVR, |
324 | invr => $::INVR, |
290 | invr_hb => $::INVR_HB, |
325 | invr_hb => $::INVR_HB, |
291 | ); |
326 | ); |
… | |
… | |
488 | |
523 | |
489 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
524 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
490 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
525 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
491 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
526 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
492 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
527 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
493 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
528 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
494 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
529 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
495 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
530 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
496 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
531 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
497 | my $title = $stats->{+CS_STAT_TITLE}; |
532 | my $title = $stats->{+CS_STAT_TITLE}; |
498 | $title =~ s/^Player: //; |
533 | $title =~ s/^Player: //; |
499 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
534 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
500 | |
535 | |
… | |
… | |
541 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
576 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
542 | ]; |
577 | ]; |
543 | |
578 | |
544 | my @add = @$sw; |
579 | my @add = @$sw; |
545 | |
580 | |
546 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
581 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
547 | |
582 | |
548 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
583 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
549 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
584 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
550 | |
585 | |
551 | my ($x, $y) = (0, 1); |
586 | my ($x, $y) = (0, 1); |
… | |
… | |
613 | my $sw = $self->{skillwid}{$idx}; |
648 | my $sw = $self->{skillwid}{$idx}; |
614 | $sw->[0]->set_text (::formsep ($val->[1])); |
649 | $sw->[0]->set_text (::formsep ($val->[1])); |
615 | $sw->[1]->set_text ($val->[0] * 1); |
650 | $sw->[1]->set_text ($val->[0] * 1); |
616 | $sw->[2]->set_value (@$val); |
651 | $sw->[2]->set_value (@$val); |
617 | |
652 | |
618 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
653 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
619 | $::GAUGES->{sklprg}->set_value (@$val); |
654 | $::GAUGES->{skillexp}->set_value (@$val); |
620 | } |
655 | } |
621 | } |
656 | } |
622 | |
657 | |
623 | sub user_send { |
658 | sub user_send { |
624 | my ($self, $command) = @_; |
659 | my ($self, $command) = @_; |
… | |
… | |
651 | for my $tile (@$missing) { |
686 | for my $tile (@$missing) { |
652 | next if $self->{delay}{$tile}; |
687 | next if $self->{delay}{$tile}; |
653 | |
688 | |
654 | $delay = 1; |
689 | $delay = 1; |
655 | |
690 | |
656 | if (my $tex = $::CONN->{texture}[$tile]) { |
691 | if (my $tex = $self->{texture}[$tile]) { |
657 | $tex->upload; |
692 | $tex->upload; |
658 | } else { |
693 | } else { |
659 | $self->{delay}{$tile} = 1; |
694 | $self->{delay}{$tile} = 1; |
660 | |
695 | |
661 | # we assume the face is in-flight and will eventually come |
696 | # we assume the face is in-flight and will eventually arrive |
662 | push @{$self->{tile_cb}{$tile}}, sub { |
697 | push @{$self->{tile_cb}{$tile}}, sub { |
663 | delete $self->{delay}{$tile}; |
698 | delete $self->{delay}{$tile}; |
664 | $_[0]->upload; |
699 | $_[0]->upload; |
665 | }; |
700 | }; |
666 | } |
701 | } |
667 | } |
702 | } |
668 | |
703 | |
669 | if ($delay) { |
704 | if ($delay) { |
670 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
705 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
671 | EV::once undef, 0, 0.03, sub { |
706 | EV::once undef, 0, 0.03, sub { |
672 | $self->{map_widget}->update |
707 | $self->{map_widget}->update |
673 | if $self->{map_widget}; |
708 | if $self->{map_widget}; |
674 | }; |
709 | }; |
675 | } else { |
710 | } else { |
… | |
… | |
978 | my ($self, $num, $cb) = @_; |
1013 | my ($self, $num, $cb) = @_; |
979 | |
1014 | |
980 | push @{$self->{face_cb}{$num}}, $cb; |
1015 | push @{$self->{face_cb}{$num}}, $cb; |
981 | |
1016 | |
982 | defined wantarray |
1017 | defined wantarray |
983 | ? DC::guard { |
1018 | ? Guard::guard { |
984 | @{$self->{face_cb}{$num}} |
1019 | @{$self->{face_cb}{$num}} |
985 | = grep $_ != $cb, |
1020 | = grep $_ != $cb, |
986 | @{$self->{face_cb}{$num}}; |
1021 | @{$self->{face_cb}{$num}}; |
987 | } |
1022 | } |
988 | : () |
1023 | : () |
… | |
… | |
1092 | |
1127 | |
1093 | ## try to create single paragraphs of multiple lines sent by the server |
1128 | ## try to create single paragraphs of multiple lines sent by the server |
1094 | # no longer neecssary with TRT servers |
1129 | # no longer neecssary with TRT servers |
1095 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1130 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1096 | |
1131 | |
1097 | for (split /\n/, $text) { |
|
|
1098 | ::message ({ |
1132 | ::message ({ |
1099 | fg => $fg, |
1133 | fg => $fg, |
1100 | markup => $_, |
1134 | markup => $text, |
1101 | type => $type, |
1135 | type => $type, |
1102 | extra => [@extra], |
1136 | extra => [@extra], |
1103 | color_flags => $color, #d# ugly, kill |
1137 | color_flags => $color, #d# ugly, kill |
1104 | }); |
1138 | }); |
1105 | |
1139 | |
1106 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1140 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1107 | # actually, this is an ugly design. _we_ should control the channels, |
1141 | # # actually, this is an ugly design. _we_ should control the channels, |
1108 | # not some random other widget, as the channels are clearly protocol-specific. |
1142 | # # not some random other widget, as the channels are clearly protocol-specific. |
1109 | # then we could also react to flags such as CLEAR without resorting to |
1143 | # # then we could also react to flags such as CLEAR without resorting to |
1110 | # hacks such as color_flags, above. |
1144 | # # hacks such as color_flags, above. |
1111 | } |
|
|
1112 | |
1145 | |
1113 | $self->{statusbox}->add ($text, |
1146 | $self->{statusbox}->add ($text, |
1114 | group => $text, |
1147 | group => $text, |
1115 | fg => $fg, |
1148 | fg => $fg, |
1116 | timeout => $color >= 2 ? 180 : 10, |
1149 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1363 | }); |
1396 | }); |
1364 | |
1397 | |
1365 | $self->update_server_info; |
1398 | $self->update_server_info; |
1366 | |
1399 | |
1367 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1400 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1368 | $self->send_command ("pickup $::CFG->{pickup}"); |
1401 | $self->send_pickup ($::CFG->{pickup}); |
1369 | |
1402 | |
1370 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
1403 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
1371 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1404 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1372 | } |
1405 | } |
1373 | |
1406 | |
… | |
… | |
1540 | } |
1573 | } |
1541 | |
1574 | |
1542 | sub send { |
1575 | sub send { |
1543 | my ($self, $msg) = @_; |
1576 | my ($self, $msg) = @_; |
1544 | |
1577 | |
1545 | $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 | }); |
1546 | $self->{textview}->scroll_to_bottom; |
1584 | $self->{textview}->scroll_to_bottom; |
1547 | |
1585 | |
1548 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1586 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1549 | } |
1587 | } |
1550 | |
1588 | |