… | |
… | |
7 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
8 | |
8 | |
9 | use DC; |
9 | use DC; |
10 | use DC::DB; |
10 | use DC::DB; |
11 | use DC::UI; |
11 | use DC::UI; |
12 | use DC::Pod; |
|
|
13 | use DC::Macro; |
12 | use DC::Macro; |
14 | use DC::Item; |
13 | use DC::Item; |
15 | |
14 | |
16 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
17 | |
16 | |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
19 | "dialogue.png", minify => 1, mipmap => 1; |
18 | "dialogue.png", minify => 1, mipmap => 1; |
20 | |
19 | |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
21 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
23 | |
22 | |
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
23 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
… | |
… | |
27 | my ($class, %arg) = @_; |
26 | my ($class, %arg) = @_; |
28 | |
27 | |
29 | my $self = $class->SUPER::new (%arg, |
28 | my $self = $class->SUPER::new (%arg, |
30 | setup_req => { |
29 | setup_req => { |
31 | extmap => 1, |
30 | extmap => 1, |
32 | excmd => 1, |
|
|
33 | widget => 2, |
31 | widget => 2, |
34 | %{$arg{setup_req} || {}}, |
32 | %{$arg{setup_req} || {}}, |
35 | }, |
33 | }, |
36 | ); |
34 | ); |
37 | |
35 | |
38 | $self->{map_widget}->clr_commands; |
36 | $self->update_fx_want; |
39 | |
37 | |
40 | my @cmd_help = map { |
38 | my $exp_guard = $self->addme_guard; |
41 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
39 | my $skl_guard = $self->addme_guard; |
42 | 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) = @_; |
43 | |
43 | |
44 | my $cmd = $1; |
44 | $self->register_face_handler ($exp, sub { |
45 | my @args = split /\|/, $2; |
45 | my ($face) = @_; |
46 | @args = (".*") unless @args; |
|
|
47 | |
46 | |
48 | my (undef, @par) = DC::Pod::section_of $_; |
47 | undef $exp_guard; |
49 | 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 | }); |
50 | |
51 | |
51 | $_ = $_ eq ".*" ? "" : " $_" |
52 | $self->register_face_handler ($skl, sub { |
52 | for @args; |
53 | my ($face) = @_; |
53 | |
54 | |
54 | map ["$cmd$_", $text], |
55 | undef $skl_guard; |
55 | sort { (length $a) <=> (length $b) } |
56 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
56 | @args |
57 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
57 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
58 | }); |
58 | 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; |
59 | |
72 | |
60 | $self->{json_coder} |
73 | $self->{json_coder} |
61 | ->convert_blessed |
74 | ->convert_blessed |
62 | ->filter_json_single_key_object ("\fw" => sub { |
75 | ->filter_json_single_key_object ("\fw" => sub { |
63 | $self->{widget}{$_[0]} |
76 | $self->{widget}{$_[0]} |
… | |
… | |
81 | $::INVR->clear; |
94 | $::INVR->clear; |
82 | $::INVR_HB->clear; |
95 | $::INVR_HB->clear; |
83 | $::FLOORBOX->clear; |
96 | $::FLOORBOX->clear; |
84 | }); |
97 | }); |
85 | |
98 | |
86 | $self->{map_widget}->add_command (@$_) |
|
|
87 | for @cmd_help; |
|
|
88 | |
|
|
89 | { |
99 | { |
90 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
100 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
91 | $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}}); |
92 | } |
102 | } |
93 | |
103 | |
… | |
… | |
95 | $self->{noface} = my $tex = $TEX_NOFACE; |
105 | $self->{noface} = my $tex = $TEX_NOFACE; |
96 | $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}}); |
97 | } |
107 | } |
98 | |
108 | |
99 | # $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 |
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
110 | # $self->{expire_w} = AE::timer 1, 1, sub { |
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
102 | # |
112 | # |
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
105 | # $self->{texture}[$_]->unload; |
115 | # $self->{texture}[$_]->unload; |
… | |
… | |
117 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
118 | |
128 | |
119 | $self |
129 | $self |
120 | } |
130 | } |
121 | |
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 | |
122 | sub update_fx_want { |
135 | sub update_fx_want { |
123 | my ($self) = @_; |
136 | my ($self) = @_; |
124 | |
137 | |
125 | $self->send_exti_msg (fx_want => { |
138 | $self->send_exti_msg (fx_want => { |
126 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
139 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
… | |
… | |
130 | } |
143 | } |
131 | |
144 | |
132 | sub ext_capabilities { |
145 | sub ext_capabilities { |
133 | my ($self, %cap) = @_; |
146 | my ($self, %cap) = @_; |
134 | |
147 | |
135 | $self->update_fx_want; |
|
|
136 | |
|
|
137 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
138 | my ($exp_table) = @_; |
|
|
139 | |
|
|
140 | $self->register_face_handler ($exp_table, sub { |
|
|
141 | my ($face) = @_; |
|
|
142 | |
|
|
143 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
144 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
145 | }); |
|
|
146 | |
|
|
147 | () |
|
|
148 | }); |
|
|
149 | |
|
|
150 | if (my $ts = $cap{tileset}) { |
148 | if (my $ts = $cap{tileset}) { |
151 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
149 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
152 | $self->{tileset} = $default; |
150 | $self->{tileset} = $default; |
153 | $self->{tilesize} = $default->[3]; |
151 | $self->{tilesize} = $default->[3]; |
154 | $self->setup_req (tileset => $default->[0]); |
152 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
162 | } |
160 | } |
163 | |
161 | |
164 | sub ext_ambient_music { |
162 | sub ext_ambient_music { |
165 | my ($self, $songs) = @_; |
163 | my ($self, $songs) = @_; |
166 | &::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 | } |
167 | } |
181 | } |
168 | |
182 | |
169 | ############################################################################# |
183 | ############################################################################# |
170 | |
184 | |
171 | sub widget_associate { |
185 | sub widget_associate { |
… | |
… | |
454 | |
468 | |
455 | if (my @diffs = |
469 | if (my @diffs = |
456 | ( |
470 | ( |
457 | ($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" : ()), |
458 | map { |
472 | map { |
459 | $stats->{$_} && $prev->{$_} |
473 | $stats->{$_} && $prev->{$_} |
460 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
474 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
461 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
475 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
462 | ) |
476 | ) |
463 | ) { |
477 | ) { |
464 | my $msg = join " ", @diffs; |
478 | my $msg = join " ", @diffs; |
… | |
… | |
612 | # progress |
626 | # progress |
613 | (new DC::UI::ExperienceProgress), |
627 | (new DC::UI::ExperienceProgress), |
614 | |
628 | |
615 | # label |
629 | # label |
616 | (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, |
617 | 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"), |
618 | ]; |
632 | ]; |
619 | |
633 | |
620 | push @add, |
634 | push @add, |
621 | $x * 4 + 0, $y, $sw->[0], |
635 | $x * 4 + 0, $y, $sw->[0], |
622 | $x * 4 + 1, $y, $sw->[1], |
636 | $x * 4 + 1, $y, $sw->[1], |
… | |
… | |
669 | } |
683 | } |
670 | |
684 | |
671 | sub feed_map1a { |
685 | sub feed_map1a { |
672 | my ($self, $data) = @_; |
686 | my ($self, $data) = @_; |
673 | |
687 | |
674 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
688 | my $missing = $self->{map}->map1a_update ($data); |
675 | my $delay; |
689 | my $delay; |
676 | |
690 | |
677 | for my $tile (@$missing) { |
691 | for my $tile (@$missing) { |
678 | next if $self->{delay}{$tile}; |
692 | next if $self->{delay}{$tile}; |
679 | |
693 | |
… | |
… | |
1042 | my ($self, $flags, $prompt) = @_; |
1056 | my ($self, $flags, $prompt) = @_; |
1043 | |
1057 | |
1044 | $prompt = $LAST_QUERY unless length $prompt; |
1058 | $prompt = $LAST_QUERY unless length $prompt; |
1045 | $LAST_QUERY = $prompt; |
1059 | $LAST_QUERY = $prompt; |
1046 | |
1060 | |
1047 | $self->{query}-> ($self, $flags, $prompt); |
1061 | $self->{query}->($self, $flags, $prompt); |
1048 | } |
|
|
1049 | |
|
|
1050 | sub sanitise_xml($) { |
|
|
1051 | local $_ = shift; |
|
|
1052 | |
|
|
1053 | # we now weed out all tags we do not support |
|
|
1054 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
1055 | }{ |
|
|
1056 | "<" |
|
|
1057 | }gex; |
|
|
1058 | |
|
|
1059 | # now all entities |
|
|
1060 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
1061 | |
|
|
1062 | # handle some elements |
|
|
1063 | 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+$//; |
|
|
1067 | |
|
|
1068 | $_ |
|
|
1069 | } |
1062 | } |
1070 | |
1063 | |
1071 | our %NAME_TO_COLOR = ( |
1064 | our %NAME_TO_COLOR = ( |
1072 | black => 0, |
1065 | black => 0, |
1073 | white => 1, |
1066 | white => 1, |
… | |
… | |
1084 | tan => 12, |
1077 | tan => 12, |
1085 | ); |
1078 | ); |
1086 | |
1079 | |
1087 | our @CF_COLOR = ( |
1080 | our @CF_COLOR = ( |
1088 | [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], |
1089 | [1.00, 1.00, 1.00], |
1082 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1090 | [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], |
1091 | [1.00, 0.00, 0.00], |
1084 | [1.00, 0.00, 0.00], |
1092 | [1.00, 0.54, 0.00], |
1085 | [1.00, 0.54, 0.00], |
1093 | [0.11, 0.56, 1.00], |
1086 | [0.11, 0.56, 1.00], |
1094 | [0.93, 0.46, 0.00], |
1087 | [0.93, 0.46, 0.00], |
1095 | [0.18, 0.54, 0.34], |
1088 | [0.18, 0.54, 0.34], |
… | |
… | |
1101 | ); |
1094 | ); |
1102 | |
1095 | |
1103 | sub msg { |
1096 | sub msg { |
1104 | my ($self, $color, $type, $text, @extra) = @_; |
1097 | my ($self, $color, $type, $text, @extra) = @_; |
1105 | |
1098 | |
1106 | $text = sanitise_xml $text; |
1099 | $text = DC::sanitise_cfxml $text; |
1107 | |
1100 | |
1108 | if (my $cb = $self->{cb_msg}{$type}) { |
1101 | if (my $cb = $self->{cb_msg}{$type}) { |
1109 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1102 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1110 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1103 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1111 | $type =~ s/-/_/g; |
1104 | $type =~ s/-/_/g; |
… | |
… | |
1114 | $self->logprint ("msg: ", $text); |
1107 | $self->logprint ("msg: ", $text); |
1115 | return if $color < 0; # negative color == ignore if not understood |
1108 | return if $color < 0; # negative color == ignore if not understood |
1116 | |
1109 | |
1117 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1110 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1118 | |
1111 | |
1119 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1120 | # no longer neecssary with TRT servers |
|
|
1121 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1122 | |
|
|
1123 | ::message ({ |
1112 | ::message ({ |
1124 | fg => $fg, |
1113 | fg => $fg, |
1125 | markup => $text, |
1114 | markup => $text, |
1126 | type => $type, |
1115 | type => $type, |
1127 | extra => [@extra], |
1116 | extra => [@extra], |
… | |
… | |
1144 | } |
1133 | } |
1145 | |
1134 | |
1146 | sub spell_add { |
1135 | sub spell_add { |
1147 | my ($self, $spell) = @_; |
1136 | my ($self, $spell) = @_; |
1148 | |
1137 | |
1149 | # try to create single paragraphs out of the multiple lines sent by the server |
|
|
1150 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1151 | $spell->{message} =~ s/\n+$//; |
|
|
1152 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
1153 | |
|
|
1154 | $::SPELL_LIST->add_spell ($spell); |
1138 | $::SPELL_LIST->add_spell ($spell); |
1155 | |
1139 | delete $::COMPLETER->{command_list}{spells}; |
1156 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
|
|
1157 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
|
|
1158 | } |
1140 | } |
1159 | |
1141 | |
1160 | sub spell_delete { |
1142 | sub spell_delete { |
1161 | my ($self, $spell) = @_; |
1143 | my ($self, $spell) = @_; |
1162 | |
1144 | |
1163 | $::SPELL_LIST->remove_spell ($spell); |
1145 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1146 | delete $::COMPLETER->{command_list}{spells}; |
1164 | } |
1147 | } |
1165 | |
1148 | |
1166 | sub setup { |
1149 | sub setup { |
1167 | my ($self, $setup) = @_; |
1150 | my ($self, $setup) = @_; |
1168 | |
1151 | |
1169 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1152 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1170 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1153 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1171 | } |
1154 | } |
1172 | |
1155 | |
1173 | sub addme_success { |
|
|
1174 | my ($self) = @_; |
|
|
1175 | |
|
|
1176 | my %skill_help; |
|
|
1177 | |
|
|
1178 | for my $node (DC::Pod::find skill_description => "*") { |
|
|
1179 | my (undef, @par) = DC::Pod::section_of $node; |
|
|
1180 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
|
|
1181 | }; |
|
|
1182 | |
|
|
1183 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1184 | $self->{map_widget}->add_command ("ready_skill $skill", |
|
|
1185 | (DC::asxml "Ready the skill '$skill'\n\n") |
|
|
1186 | . $skill_help{$skill}); |
|
|
1187 | $self->{map_widget}->add_command ("use_skill $skill", |
|
|
1188 | (DC::asxml "Immediately use the skill '$skill'\n\n") |
|
|
1189 | . $skill_help{$skill}); |
|
|
1190 | } |
|
|
1191 | } |
|
|
1192 | |
|
|
1193 | sub eof { |
1156 | sub eof { |
1194 | my ($self) = @_; |
1157 | my ($self) = @_; |
1195 | |
1158 | |
1196 | $self->{map_widget}->clr_commands; |
1159 | $::COMPLETER->reset; |
1197 | |
1160 | |
1198 | ::stop_game (); |
1161 | ::stop_game (); |
1199 | } |
1162 | } |
1200 | |
1163 | |
1201 | sub update_floorbox { |
1164 | sub update_floorbox { |
… | |
… | |
1352 | my $version = JSON::XS->new->encode ($self->{s_version}); |
1315 | my $version = JSON::XS->new->encode ($self->{s_version}); |
1353 | |
1316 | |
1354 | $::SERVER_INFO->set_markup ( |
1317 | $::SERVER_INFO->set_markup ( |
1355 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1318 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1356 | . "protocol version <tt>$version</tt>\n" |
1319 | . "protocol version <tt>$version</tt>\n" |
1357 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1358 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1359 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1360 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1320 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1361 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1362 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1363 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1321 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1364 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1322 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1365 | . "map size $self->{mapw}×$self->{maph}\n" |
1323 | . "map size $self->{mapw}×$self->{maph}\n" |
1366 | ); |
1324 | ); |
1367 | |
1325 | |
… | |
… | |
1401 | $self->send_ext_req (lookat => $x, $y, sub { |
1359 | $self->send_ext_req (lookat => $x, $y, sub { |
1402 | my (%msg) = @_; |
1360 | my (%msg) = @_; |
1403 | |
1361 | |
1404 | if (exists $msg{npc_dialog}) { |
1362 | if (exists $msg{npc_dialog}) { |
1405 | # start npc chat dialog |
1363 | # start npc chat dialog |
1406 | $self->{npc_dialog} = new DC::NPCDialog:: |
1364 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1407 | token => $msg{npc_dialog}, |
1365 | token => $msg{npc_dialog}, |
1408 | title => "$msg{npc_dialog}[0] (NPC)", |
1366 | title => "$msg{npc_dialog}[0] (NPC)", |
1409 | conn => $self, |
1367 | conn => $self, |
1410 | ; |
1368 | ; |
1411 | } |
1369 | } |
… | |
… | |
1416 | } |
1374 | } |
1417 | |
1375 | |
1418 | sub destroy { |
1376 | sub destroy { |
1419 | my ($self) = @_; |
1377 | my ($self) = @_; |
1420 | |
1378 | |
1421 | (delete $self->{npc_dialog})->destroy |
1379 | $_->destroy |
1422 | if $self->{npc_dialog}; |
1380 | for values %{ $self->{w} }; |
1423 | |
1381 | |
1424 | $self->SUPER::destroy; |
1382 | $self->SUPER::destroy; |
1425 | |
1383 | |
1426 | %$self = (); |
1384 | %$self = (); |
1427 | } |
1385 | } |
… | |
… | |
1527 | |
1485 | |
1528 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1486 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1529 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1487 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1530 | |
1488 | |
1531 | if (exists $info{msg}) { |
1489 | if (exists $info{msg}) { |
1532 | my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; |
1490 | my $text = "\n" . DC::sanitise_cfxml $info{msg}; |
1533 | 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} }; |
1534 | my @link; |
1492 | my @link; |
1535 | $text =~ s{ |
1493 | $text =~ s{ |
1536 | ($match) |
1494 | ($match) |
1537 | }{ |
1495 | }{ |
… | |
… | |
1581 | |
1539 | |
1582 | #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 |
1583 | |
1541 | |
1584 | if ($self->{conn}) { |
1542 | if ($self->{conn}) { |
1585 | $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}; |
1586 | delete $self->{conn}{npc_dialog}; |
1544 | delete $self->{conn}{w}{npc_dialog}; |
1587 | $self->{conn}->disconnect_ext ($self->{id}); |
1545 | $self->{conn}->disconnect_ext ($self->{id}); |
1588 | } |
1546 | } |
1589 | |
1547 | |
1590 | $self->SUPER::destroy; |
1548 | $self->SUPER::destroy; |
1591 | } |
1549 | } |