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; |
10 | use DC::UI; |
11 | use DC::UI; |
11 | use DC::Pod; |
|
|
12 | use DC::Macro; |
12 | use DC::Macro; |
13 | use DC::Item; |
13 | use DC::Item; |
14 | |
14 | |
15 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
16 | |
16 | |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | "dialogue.png", minify => 1, mipmap => 1; |
18 | "dialogue.png", minify => 1, mipmap => 1; |
19 | |
19 | |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | "noface.png", minify => 1, mipmap => 1; |
21 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
22 | |
|
|
23 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
24 | "hidden.png", minify => 1, mipmap => 1; |
|
|
25 | |
22 | |
26 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
23 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
27 | |
24 | |
28 | sub new { |
25 | sub new { |
29 | my ($class, %arg) = @_; |
26 | my ($class, %arg) = @_; |
30 | |
27 | |
31 | my $self = $class->SUPER::new (%arg, |
28 | my $self = $class->SUPER::new (%arg, |
32 | setup_req => { |
29 | setup_req => { |
33 | extmap => 1, |
30 | extmap => 1, |
34 | excmd => 1, |
|
|
35 | widget => 2, |
31 | widget => 2, |
36 | %{$arg{setup_req} || {}}, |
32 | %{$arg{setup_req} || {}}, |
37 | }, |
33 | }, |
38 | ); |
34 | ); |
39 | |
35 | |
40 | $self->{map_widget}->clr_commands; |
36 | $self->update_fx_want; |
41 | |
37 | |
42 | my @cmd_help = map { |
38 | my $exp_guard = $self->addme_guard; |
43 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
39 | my $skl_guard = $self->addme_guard; |
44 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
40 | my $spl_guard = $self->addme_guard; |
|
|
41 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
42 | my ($exp, $skl, $spl) = @_; |
45 | |
43 | |
46 | my $cmd = $1; |
44 | $self->register_face_handler ($exp, sub { |
47 | my @args = split /\|/, $2; |
45 | my ($face) = @_; |
48 | @args = (".*") unless @args; |
|
|
49 | |
46 | |
50 | my (undef, @par) = DC::Pod::section_of $_; |
47 | undef $exp_guard; |
51 | my $text = DC::Pod::as_label @par; |
48 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
49 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
50 | }); |
52 | |
51 | |
53 | $_ = $_ eq ".*" ? "" : " $_" |
52 | $self->register_face_handler ($skl, sub { |
54 | for @args; |
53 | my ($face) = @_; |
55 | |
54 | |
56 | map ["$cmd$_", $text], |
55 | undef $skl_guard; |
57 | sort { (length $a) <=> (length $b) } |
56 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
58 | @args |
57 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
59 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
58 | }); |
60 | DC::Pod::find command => "*"; |
59 | |
|
|
60 | $self->register_face_handler ($spl, sub { |
|
|
61 | my ($face) = @_; |
|
|
62 | |
|
|
63 | undef $spl_guard; |
|
|
64 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
65 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
66 | }); |
|
|
67 | |
|
|
68 | () |
|
|
69 | }); |
|
|
70 | |
|
|
71 | $::COMPLETER->reset; |
61 | |
72 | |
62 | $self->{json_coder} |
73 | $self->{json_coder} |
63 | ->convert_blessed |
74 | ->convert_blessed |
64 | ->filter_json_single_key_object ("\fw" => sub { |
75 | ->filter_json_single_key_object ("\fw" => sub { |
65 | $self->{widget}{$_[0]} |
76 | $self->{widget}{$_[0]} |
… | |
… | |
83 | $::INVR->clear; |
94 | $::INVR->clear; |
84 | $::INVR_HB->clear; |
95 | $::INVR_HB->clear; |
85 | $::FLOORBOX->clear; |
96 | $::FLOORBOX->clear; |
86 | }); |
97 | }); |
87 | |
98 | |
88 | $self->{map_widget}->add_command (@$_) |
|
|
89 | for @cmd_help; |
|
|
90 | |
|
|
91 | { |
99 | { |
92 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
100 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
93 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
101 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
94 | } |
102 | } |
95 | |
103 | |
96 | { |
104 | { |
97 | $self->{noface} = my $tex = $TEX_NOFACE; |
105 | $self->{noface} = my $tex = $TEX_NOFACE; |
98 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
106 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
99 | } |
107 | } |
100 | |
108 | |
101 | { |
|
|
102 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
103 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
104 | } |
|
|
105 | |
|
|
106 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
109 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
107 | # $self->{expire_w} = EV::timer 1, 1, sub { |
110 | # $self->{expire_w} = AE::timer 1, 1, sub { |
108 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
109 | # |
112 | # |
110 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
111 | # warn DC::SvREFCNT $self->{texture}[$_]; |
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
112 | # $self->{texture}[$_]->unload; |
115 | # $self->{texture}[$_]->unload; |
… | |
… | |
124 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
125 | |
128 | |
126 | $self |
129 | $self |
127 | } |
130 | } |
128 | |
131 | |
|
|
132 | #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# |
|
|
133 | #sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# |
|
|
134 | |
129 | sub update_fx_want { |
135 | sub update_fx_want { |
130 | my ($self) = @_; |
136 | my ($self) = @_; |
131 | |
137 | |
132 | $self->send_exti_msg (fx_want => { |
138 | $self->send_exti_msg (fx_want => { |
133 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
139 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
… | |
… | |
137 | } |
143 | } |
138 | |
144 | |
139 | sub ext_capabilities { |
145 | sub ext_capabilities { |
140 | my ($self, %cap) = @_; |
146 | my ($self, %cap) = @_; |
141 | |
147 | |
142 | $self->update_fx_want; |
|
|
143 | |
|
|
144 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
145 | my ($exp_table) = @_; |
|
|
146 | |
|
|
147 | $self->register_face_handler ($exp_table, sub { |
|
|
148 | my ($face) = @_; |
|
|
149 | |
|
|
150 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
151 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
152 | }); |
|
|
153 | |
|
|
154 | () |
|
|
155 | }); |
|
|
156 | |
|
|
157 | if (my $ts = $cap{tileset}) { |
148 | if (my $ts = $cap{tileset}) { |
158 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
149 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
159 | $self->{tileset} = $default; |
150 | $self->{tileset} = $default; |
160 | $self->{tilesize} = $default->[3]; |
151 | $self->{tilesize} = $default->[3]; |
161 | $self->setup_req (tileset => $default->[0]); |
152 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
169 | } |
160 | } |
170 | |
161 | |
171 | sub ext_ambient_music { |
162 | sub ext_ambient_music { |
172 | my ($self, $songs) = @_; |
163 | my ($self, $songs) = @_; |
173 | &::audio_music_set_ambient ($songs); |
164 | &::audio_music_set_ambient ($songs); |
|
|
165 | } |
|
|
166 | |
|
|
167 | sub ext_command_list { |
|
|
168 | my ($self, @faces) = @_; |
|
|
169 | |
|
|
170 | my $handler = $self->{command_facehandler} = {}; |
|
|
171 | my $commands = $::COMPLETER->{command_list} = {}; |
|
|
172 | |
|
|
173 | for my $idx (@faces) { |
|
|
174 | $handler->{$idx} = $self->register_face_handler ($idx, sub { |
|
|
175 | my ($face) = @_; |
|
|
176 | |
|
|
177 | $commands->{$idx} = |
|
|
178 | $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); |
|
|
179 | }); |
|
|
180 | } |
174 | } |
181 | } |
175 | |
182 | |
176 | ############################################################################# |
183 | ############################################################################# |
177 | |
184 | |
178 | sub widget_associate { |
185 | sub widget_associate { |
… | |
… | |
285 | my %wkw = ( |
292 | my %wkw = ( |
286 | root => $DC::UI::ROOT, |
293 | root => $DC::UI::ROOT, |
287 | tooltip => $DC::UI::TOOLTIP, |
294 | tooltip => $DC::UI::TOOLTIP, |
288 | |
295 | |
289 | mapwidget => $::MAPWIDGET, |
296 | mapwidget => $::MAPWIDGET, |
|
|
297 | menubar => $::MENUBAR, |
|
|
298 | menupopup => $::MENUPOPUP, |
|
|
299 | pickup_enable => $::PICKUP_ENABLE, |
290 | buttonbar => $::BUTTONBAR, |
300 | buttonbar => $::BUTTONBAR, |
291 | metaserver => $::METASERVER, |
301 | metaserver => $::METASERVER, |
292 | buttonbar => $::BUTTONBAR, |
302 | buttonbar => $::BUTTONBAR, |
293 | login_button => $::LOGIN_BUTTON, |
303 | login_button => $::LOGIN_BUTTON, |
294 | quit_dialog => $::QUIT_DIALOG, |
304 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
311 | |
321 | |
312 | floorbox => $::FLOORBOX, |
322 | floorbox => $::FLOORBOX, |
313 | help_window => $::HELP_WINDOW, |
323 | help_window => $::HELP_WINDOW, |
314 | message_window => $::MESSAGE_WINDOW, |
324 | message_window => $::MESSAGE_WINDOW, |
315 | message_dist => $::MESSAGE_DIST, |
325 | message_dist => $::MESSAGE_DIST, |
316 | statusbox => $::SDTATUSBOX, |
326 | statusbox => $::STATUSBOX, |
317 | |
327 | |
318 | inv => $::INV, |
328 | inv => $::INV, |
319 | invr => $::INVR, |
329 | invr => $::INVR, |
320 | invr_hb => $::INVR_HB, |
330 | invr_hb => $::INVR_HB, |
321 | ); |
331 | ); |
… | |
… | |
405 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
415 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
406 | : () |
416 | : () |
407 | } |
417 | } |
408 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
418 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
409 | |
419 | |
410 | join "", @diff |
420 | "\u$name: " . (join ", ", @diff) |
411 | } |
421 | } |
412 | |
422 | |
413 | # all stats that are chacked against changes |
423 | # all stats that are chacked against changes |
414 | my @statchange = ( |
424 | my @statchange = ( |
415 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
425 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
458 | |
468 | |
459 | if (my @diffs = |
469 | if (my @diffs = |
460 | ( |
470 | ( |
461 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
471 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
462 | map { |
472 | map { |
463 | $stats->{$_} && $prev->{$_} |
473 | $stats->{$_} && $prev->{$_} |
464 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
474 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
465 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
475 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
466 | ) |
476 | ) |
467 | ) { |
477 | ) { |
468 | my $msg = join " ", @diffs; |
478 | my $msg = join " ", @diffs; |
… | |
… | |
470 | } |
480 | } |
471 | |
481 | |
472 | if ( |
482 | if ( |
473 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
483 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
474 | ) { |
484 | ) { |
475 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
485 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
476 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
486 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
477 | } |
487 | } |
478 | |
488 | |
479 | $self->update_stats_window ($stats, $prev); |
489 | $self->update_stats_window ($stats, $prev); |
480 | |
490 | |
… | |
… | |
518 | |
528 | |
519 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
529 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
520 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
530 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
521 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
531 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
522 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
532 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
523 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
533 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
524 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
534 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
525 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
535 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
526 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
536 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
527 | my $title = $stats->{+CS_STAT_TITLE}; |
537 | my $title = $stats->{+CS_STAT_TITLE}; |
528 | $title =~ s/^Player: //; |
538 | $title =~ s/^Player: //; |
529 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
539 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
530 | |
540 | |
… | |
… | |
542 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
552 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
543 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
553 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
544 | |
554 | |
545 | $self->update_weight; |
555 | $self->update_weight; |
546 | |
556 | |
547 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
557 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
548 | for keys %RES_TBL; |
558 | for keys %RES_TBL; |
549 | |
559 | |
550 | my $sktbl = $::STATWIDS->{skill_tbl}; |
560 | my $sktbl = $::STATWIDS->{skill_tbl}; |
551 | my @skills = keys %{ $self->{skill_info} }; |
561 | my @skills = keys %{ $self->{skill_info} }; |
552 | |
562 | |
… | |
… | |
616 | # progress |
626 | # progress |
617 | (new DC::UI::ExperienceProgress), |
627 | (new DC::UI::ExperienceProgress), |
618 | |
628 | |
619 | # label |
629 | # label |
620 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
630 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
621 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
631 | can_events => 1, can_hover => 1, tooltip => "#(skill/$name)$TOOLTIP_ALL"), |
622 | ]; |
632 | ]; |
623 | |
633 | |
624 | push @add, |
634 | push @add, |
625 | $x * 4 + 0, $y, $sw->[0], |
635 | $x * 4 + 0, $y, $sw->[0], |
626 | $x * 4 + 1, $y, $sw->[1], |
636 | $x * 4 + 1, $y, $sw->[1], |
… | |
… | |
643 | my $sw = $self->{skillwid}{$idx}; |
653 | my $sw = $self->{skillwid}{$idx}; |
644 | $sw->[0]->set_text (::formsep ($val->[1])); |
654 | $sw->[0]->set_text (::formsep ($val->[1])); |
645 | $sw->[1]->set_text ($val->[0] * 1); |
655 | $sw->[1]->set_text ($val->[0] * 1); |
646 | $sw->[2]->set_value (@$val); |
656 | $sw->[2]->set_value (@$val); |
647 | |
657 | |
648 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
658 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
649 | $::GAUGES->{sklprg}->set_value (@$val); |
659 | $::GAUGES->{skillexp}->set_value (@$val); |
650 | } |
660 | } |
651 | } |
661 | } |
652 | |
662 | |
653 | sub user_send { |
663 | sub user_send { |
654 | my ($self, $command) = @_; |
664 | my ($self, $command) = @_; |
… | |
… | |
673 | } |
683 | } |
674 | |
684 | |
675 | sub feed_map1a { |
685 | sub feed_map1a { |
676 | my ($self, $data) = @_; |
686 | my ($self, $data) = @_; |
677 | |
687 | |
678 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
688 | my $missing = $self->{map}->map1a_update ($data); |
679 | my $delay; |
689 | my $delay; |
680 | |
690 | |
681 | for my $tile (@$missing) { |
691 | for my $tile (@$missing) { |
682 | next if $self->{delay}{$tile}; |
692 | next if $self->{delay}{$tile}; |
683 | |
693 | |
… | |
… | |
993 | |
1003 | |
994 | my $tex = $self->{texture}[$tile] ||= |
1004 | my $tex = $self->{texture}[$tile] ||= |
995 | new DC::Texture |
1005 | new DC::Texture |
996 | tile => $tile, |
1006 | tile => $tile, |
997 | image => $data, delete_image => 1, |
1007 | image => $data, delete_image => 1, |
998 | minify => 1, mipmap => 1; |
1008 | minify => 1; |
999 | |
1009 | |
1000 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1010 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1001 | $_->($tex) for @$cbs; |
1011 | $_->($tex) for @$cbs; |
1002 | } |
1012 | } |
1003 | } |
1013 | } |
… | |
… | |
1008 | my ($self, $num, $cb) = @_; |
1018 | my ($self, $num, $cb) = @_; |
1009 | |
1019 | |
1010 | push @{$self->{face_cb}{$num}}, $cb; |
1020 | push @{$self->{face_cb}{$num}}, $cb; |
1011 | |
1021 | |
1012 | defined wantarray |
1022 | defined wantarray |
1013 | ? DC::guard { |
1023 | ? Guard::guard { |
1014 | @{$self->{face_cb}{$num}} |
1024 | @{$self->{face_cb}{$num}} |
1015 | = grep $_ != $cb, |
1025 | = grep $_ != $cb, |
1016 | @{$self->{face_cb}{$num}}; |
1026 | @{$self->{face_cb}{$num}}; |
1017 | } |
1027 | } |
1018 | : () |
1028 | : () |
… | |
… | |
1046 | my ($self, $flags, $prompt) = @_; |
1056 | my ($self, $flags, $prompt) = @_; |
1047 | |
1057 | |
1048 | $prompt = $LAST_QUERY unless length $prompt; |
1058 | $prompt = $LAST_QUERY unless length $prompt; |
1049 | $LAST_QUERY = $prompt; |
1059 | $LAST_QUERY = $prompt; |
1050 | |
1060 | |
1051 | $self->{query}-> ($self, $flags, $prompt); |
1061 | $self->{query}->($self, $flags, $prompt); |
1052 | } |
|
|
1053 | |
|
|
1054 | sub sanitise_xml($) { |
|
|
1055 | local $_ = shift; |
|
|
1056 | |
|
|
1057 | # we now weed out all tags we do not support |
|
|
1058 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
1059 | }{ |
|
|
1060 | "<" |
|
|
1061 | }gex; |
|
|
1062 | |
|
|
1063 | # now all entities |
|
|
1064 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
1065 | |
|
|
1066 | # handle some elements |
|
|
1067 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
1068 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1069 | |
|
|
1070 | s/\s+$//; |
|
|
1071 | |
|
|
1072 | $_ |
|
|
1073 | } |
1062 | } |
1074 | |
1063 | |
1075 | our %NAME_TO_COLOR = ( |
1064 | our %NAME_TO_COLOR = ( |
1076 | black => 0, |
1065 | black => 0, |
1077 | white => 1, |
1066 | white => 1, |
… | |
… | |
1088 | tan => 12, |
1077 | tan => 12, |
1089 | ); |
1078 | ); |
1090 | |
1079 | |
1091 | our @CF_COLOR = ( |
1080 | our @CF_COLOR = ( |
1092 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1081 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1093 | [1.00, 1.00, 1.00], |
1082 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1094 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1083 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1095 | [1.00, 0.00, 0.00], |
1084 | [1.00, 0.00, 0.00], |
1096 | [1.00, 0.54, 0.00], |
1085 | [1.00, 0.54, 0.00], |
1097 | [0.11, 0.56, 1.00], |
1086 | [0.11, 0.56, 1.00], |
1098 | [0.93, 0.46, 0.00], |
1087 | [0.93, 0.46, 0.00], |
1099 | [0.18, 0.54, 0.34], |
1088 | [0.18, 0.54, 0.34], |
… | |
… | |
1105 | ); |
1094 | ); |
1106 | |
1095 | |
1107 | sub msg { |
1096 | sub msg { |
1108 | my ($self, $color, $type, $text, @extra) = @_; |
1097 | my ($self, $color, $type, $text, @extra) = @_; |
1109 | |
1098 | |
1110 | $text = sanitise_xml $text; |
1099 | $text = DC::sanitise_cfxml $text; |
1111 | |
1100 | |
1112 | if (my $cb = $self->{cb_msg}{$type}) { |
1101 | if (my $cb = $self->{cb_msg}{$type}) { |
1113 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1102 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1114 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1103 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1115 | $type =~ s/-/_/g; |
1104 | $type =~ s/-/_/g; |
… | |
… | |
1118 | $self->logprint ("msg: ", $text); |
1107 | $self->logprint ("msg: ", $text); |
1119 | return if $color < 0; # negative color == ignore if not understood |
1108 | return if $color < 0; # negative color == ignore if not understood |
1120 | |
1109 | |
1121 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1110 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1122 | |
1111 | |
1123 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1124 | # no longer neecssary with TRT servers |
|
|
1125 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1126 | |
|
|
1127 | ::message ({ |
1112 | ::message ({ |
1128 | fg => $fg, |
1113 | fg => $fg, |
1129 | markup => $text, |
1114 | markup => $text, |
1130 | type => $type, |
1115 | type => $type, |
1131 | extra => [@extra], |
1116 | extra => [@extra], |
… | |
… | |
1148 | } |
1133 | } |
1149 | |
1134 | |
1150 | sub spell_add { |
1135 | sub spell_add { |
1151 | my ($self, $spell) = @_; |
1136 | my ($self, $spell) = @_; |
1152 | |
1137 | |
1153 | # try to create single paragraphs out of the multiple lines sent by the server |
|
|
1154 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1155 | $spell->{message} =~ s/\n+$//; |
|
|
1156 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
1157 | |
|
|
1158 | $::SPELL_LIST->add_spell ($spell); |
1138 | $::SPELL_LIST->add_spell ($spell); |
1159 | |
1139 | delete $::COMPLETER->{command_list}{spells}; |
1160 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
|
|
1161 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
|
|
1162 | } |
1140 | } |
1163 | |
1141 | |
1164 | sub spell_delete { |
1142 | sub spell_delete { |
1165 | my ($self, $spell) = @_; |
1143 | my ($self, $spell) = @_; |
1166 | |
1144 | |
1167 | $::SPELL_LIST->remove_spell ($spell); |
1145 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1146 | delete $::COMPLETER->{command_list}{spells}; |
1168 | } |
1147 | } |
1169 | |
1148 | |
1170 | sub setup { |
1149 | sub setup { |
1171 | my ($self, $setup) = @_; |
1150 | my ($self, $setup) = @_; |
1172 | |
1151 | |
1173 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1152 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1174 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1153 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1175 | } |
1154 | } |
1176 | |
1155 | |
1177 | sub addme_success { |
|
|
1178 | my ($self) = @_; |
|
|
1179 | |
|
|
1180 | my %skill_help; |
|
|
1181 | |
|
|
1182 | for my $node (DC::Pod::find skill_description => "*") { |
|
|
1183 | my (undef, @par) = DC::Pod::section_of $node; |
|
|
1184 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
|
|
1185 | }; |
|
|
1186 | |
|
|
1187 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1188 | $self->{map_widget}->add_command ("ready_skill $skill", |
|
|
1189 | (DC::asxml "Ready the skill '$skill'\n\n") |
|
|
1190 | . $skill_help{$skill}); |
|
|
1191 | $self->{map_widget}->add_command ("use_skill $skill", |
|
|
1192 | (DC::asxml "Immediately use the skill '$skill'\n\n") |
|
|
1193 | . $skill_help{$skill}); |
|
|
1194 | } |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | sub eof { |
1156 | sub eof { |
1198 | my ($self) = @_; |
1157 | my ($self) = @_; |
1199 | |
1158 | |
1200 | $self->{map_widget}->clr_commands; |
1159 | $::COMPLETER->reset; |
1201 | |
1160 | |
1202 | ::stop_game (); |
1161 | ::stop_game (); |
1203 | } |
1162 | } |
1204 | |
1163 | |
1205 | sub update_floorbox { |
1164 | sub update_floorbox { |
… | |
… | |
1351 | sub update_server_info { |
1310 | sub update_server_info { |
1352 | my ($self) = @_; |
1311 | my ($self) = @_; |
1353 | |
1312 | |
1354 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1313 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1355 | |
1314 | |
|
|
1315 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1316 | |
1356 | $::SERVER_INFO->set_markup ( |
1317 | $::SERVER_INFO->set_markup ( |
1357 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1318 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1358 | . "protocol version <tt>$self->{version}</tt>\n" |
1319 | . "protocol version <tt>$version</tt>\n" |
1359 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1360 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1361 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1362 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1320 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1363 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1364 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1365 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1321 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1366 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1322 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1367 | . "map size $self->{mapw}×$self->{maph}\n" |
1323 | . "map size $self->{mapw}×$self->{maph}\n" |
1368 | ); |
1324 | ); |
1369 | |
1325 | |
… | |
… | |
1391 | }); |
1347 | }); |
1392 | |
1348 | |
1393 | $self->update_server_info; |
1349 | $self->update_server_info; |
1394 | |
1350 | |
1395 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1351 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1396 | $self->send_command ("pickup $::CFG->{pickup}"); |
1352 | $self->send_pickup ($::CFG->{pickup}); |
1397 | |
|
|
1398 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1399 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1400 | } |
1353 | } |
1401 | |
1354 | |
1402 | sub lookat { |
1355 | sub lookat { |
1403 | my ($self, $x, $y) = @_; |
1356 | my ($self, $x, $y) = @_; |
1404 | |
1357 | |
… | |
… | |
1406 | $self->send_ext_req (lookat => $x, $y, sub { |
1359 | $self->send_ext_req (lookat => $x, $y, sub { |
1407 | my (%msg) = @_; |
1360 | my (%msg) = @_; |
1408 | |
1361 | |
1409 | if (exists $msg{npc_dialog}) { |
1362 | if (exists $msg{npc_dialog}) { |
1410 | # start npc chat dialog |
1363 | # start npc chat dialog |
1411 | $self->{npc_dialog} = new DC::NPCDialog:: |
1364 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1412 | token => $msg{npc_dialog}, |
1365 | token => $msg{npc_dialog}, |
1413 | title => "$msg{npc_dialog}[0] (NPC)", |
1366 | title => "$msg{npc_dialog}[0] (NPC)", |
1414 | conn => $self, |
1367 | conn => $self, |
1415 | ; |
1368 | ; |
1416 | } |
1369 | } |
… | |
… | |
1421 | } |
1374 | } |
1422 | |
1375 | |
1423 | sub destroy { |
1376 | sub destroy { |
1424 | my ($self) = @_; |
1377 | my ($self) = @_; |
1425 | |
1378 | |
1426 | (delete $self->{npc_dialog})->destroy |
1379 | $_->destroy |
1427 | if $self->{npc_dialog}; |
1380 | for values %{ $self->{w} }; |
1428 | |
1381 | |
1429 | $self->SUPER::destroy; |
1382 | $self->SUPER::destroy; |
1430 | |
1383 | |
1431 | %$self = (); |
1384 | %$self = (); |
1432 | } |
1385 | } |
… | |
… | |
1532 | |
1485 | |
1533 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1486 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1534 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1487 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1535 | |
1488 | |
1536 | if (exists $info{msg}) { |
1489 | if (exists $info{msg}) { |
1537 | my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; |
1490 | my $text = "\n" . DC::sanitise_cfxml $info{msg}; |
1538 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1491 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1539 | my @link; |
1492 | my @link; |
1540 | $text =~ s{ |
1493 | $text =~ s{ |
1541 | ($match) |
1494 | ($match) |
1542 | }{ |
1495 | }{ |
… | |
… | |
1586 | |
1539 | |
1587 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1540 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1588 | |
1541 | |
1589 | if ($self->{conn}) { |
1542 | if ($self->{conn}) { |
1590 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1543 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1591 | delete $self->{conn}{npc_dialog}; |
1544 | delete $self->{conn}{w}{npc_dialog}; |
1592 | $self->{conn}->disconnect_ext ($self->{id}); |
1545 | $self->{conn}->disconnect_ext ($self->{id}); |
1593 | } |
1546 | } |
1594 | |
1547 | |
1595 | $self->SUPER::destroy; |
1548 | $self->SUPER::destroy; |
1596 | } |
1549 | } |