1 | package CFPlus::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
|
|
5 | use Guard (); |
|
|
6 | |
6 | use Crossfire::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use CFPlus; |
9 | use DC; |
9 | use CFPlus::DB; |
10 | use DC::DB; |
10 | use CFPlus::UI; |
11 | use DC::UI; |
11 | use CFPlus::Pod; |
12 | use DC::Pod; |
12 | use CFPlus::Macro; |
13 | use DC::Macro; |
13 | use CFPlus::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use Crossfire::Protocol::Base 0.95; |
|
|
16 | |
|
|
17 | use base 'Crossfire::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# |
18 | |
25 | |
19 | sub new { |
26 | sub new { |
20 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
21 | |
28 | |
22 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
30 | setup_req => { |
24 | extmap => 1, |
31 | extmap => 1, |
25 | excmd => 1, |
|
|
26 | xwidget1 => 1,#d# |
32 | widget => 2, |
27 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
28 | }, |
34 | }, |
29 | ); |
35 | ); |
30 | |
36 | |
|
|
37 | $self->update_fx_want; |
|
|
38 | |
|
|
39 | my $exp_guard = $self->addme_guard; |
|
|
40 | my $skl_guard = $self->addme_guard; |
|
|
41 | my $spl_guard = $self->addme_guard; |
|
|
42 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
43 | my ($exp, $skl, $spl) = @_; |
|
|
44 | |
|
|
45 | $self->register_face_handler ($exp, sub { |
|
|
46 | my ($face) = @_; |
|
|
47 | |
|
|
48 | undef $exp_guard; |
|
|
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
|
|
52 | |
|
|
53 | $self->register_face_handler ($skl, sub { |
|
|
54 | my ($face) = @_; |
|
|
55 | |
|
|
56 | undef $skl_guard; |
|
|
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
|
|
59 | }); |
|
|
60 | |
|
|
61 | $self->register_face_handler ($spl, sub { |
|
|
62 | my ($face) = @_; |
|
|
63 | |
|
|
64 | undef $spl_guard; |
|
|
65 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
66 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
67 | }); |
|
|
68 | |
|
|
69 | () |
|
|
70 | }); |
|
|
71 | |
31 | $self->{map_widget}->clr_commands; |
72 | $self->{map_widget}->clr_commands; |
32 | |
73 | |
33 | my @cmd_help = map { |
74 | my @cmd_help = map { |
34 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
75 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
35 | or die "unparseable command help: $_->{kw}[0]"; |
76 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
36 | |
77 | |
37 | my $cmd = $1; |
78 | my $cmd = $1; |
38 | my @args = split /\|/, $2; |
79 | my @args = split /\|/, $2; |
39 | @args = (".*") unless @args; |
80 | @args = (".*") unless @args; |
40 | |
81 | |
41 | my (undef, @par) = CFPlus::Pod::section_of $_; |
82 | my (undef, @par) = DC::Pod::section_of $_; |
42 | my $text = CFPlus::Pod::as_label @par; |
83 | my $text = DC::Pod::as_label @par; |
43 | |
84 | |
44 | $_ = $_ eq ".*" ? "" : " $_" |
85 | $_ = $_ eq ".*" ? "" : " $_" |
45 | for @args; |
86 | for @args; |
46 | |
87 | |
47 | map ["$cmd$_", $text], |
88 | map ["$cmd$_", $text], |
48 | sort { (length $a) <=> (length $b) } |
89 | sort { (length $a) <=> (length $b) } |
49 | @args |
90 | @args |
50 | } sort { $a->{par} <=> $b->{par} } |
91 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
51 | CFPlus::Pod::find command => "*"; |
92 | DC::Pod::find command => "*"; |
52 | |
|
|
53 | $self->connect_ext (ambient_music => sub { |
|
|
54 | my ($songs) = @_; |
|
|
55 | &::audio_music_set_ambient ($songs); |
|
|
56 | }); |
|
|
57 | |
|
|
58 | $self->connect_ext (capabilities => sub { |
|
|
59 | my (%cap) = @_; |
|
|
60 | |
|
|
61 | #$self->send ("setup sound 0"); # we use a different protocol |
|
|
62 | $self->update_fx_want; |
|
|
63 | |
|
|
64 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
65 | my ($exp_table) = @_; |
|
|
66 | |
|
|
67 | $self->register_face_handler ($exp_table, sub { |
|
|
68 | my ($face) = @_; |
|
|
69 | |
|
|
70 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
71 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
72 | }); |
|
|
73 | |
|
|
74 | () |
|
|
75 | }); |
|
|
76 | |
|
|
77 | if (my $ts = $cap{tileset}) { |
|
|
78 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
|
|
79 | $self->{tileset} = $default; |
|
|
80 | $self->{tilesize} = $default->[3]; |
|
|
81 | $self->setup_req (tileset => $default->[0]); |
|
|
82 | |
|
|
83 | my $w = int $self->{mapw} * 32 / $self->{tilesize}; |
|
|
84 | my $h = int $self->{maph} * 32 / $self->{tilesize}; |
|
|
85 | |
|
|
86 | $self->setup_req (mapsize => "${w}x${h}"); |
|
|
87 | } |
|
|
88 | } |
|
|
89 | }); |
|
|
90 | |
93 | |
91 | $self->{json_coder} |
94 | $self->{json_coder} |
92 | ->convert_blessed |
95 | ->convert_blessed |
93 | ->filter_json_single_key_object (__w_ => sub { |
96 | ->filter_json_single_key_object ("\fw" => sub { |
94 | $self->{widget}{$_[0]} |
97 | $self->{widget}{$_[0]} |
|
|
98 | }) |
|
|
99 | ->filter_json_single_key_object ("\fc" => sub { |
|
|
100 | my ($id) = @_; |
|
|
101 | sub { |
|
|
102 | $self->send_exti_msg (w_e => $id, @_); |
|
|
103 | } |
95 | }); |
104 | }); |
96 | |
|
|
97 | # widgetset new |
|
|
98 | $self->connect_ext (ws_n => sub { |
|
|
99 | my ($id) = @_; |
|
|
100 | |
|
|
101 | $self->{widgetset}{$id} = { |
|
|
102 | w => {}, |
|
|
103 | }; |
|
|
104 | }); |
|
|
105 | |
|
|
106 | # widgetset destroy |
|
|
107 | $self->connect_ext (ws_d => sub { |
|
|
108 | my ($id) = @_; |
|
|
109 | |
|
|
110 | my $ws = delete $self->{widgetset}{$id} |
|
|
111 | or return; |
|
|
112 | |
|
|
113 | $_->destroy |
|
|
114 | for values %{$ws->{w}}; |
|
|
115 | }); |
|
|
116 | |
|
|
117 | # widgetset create |
|
|
118 | $self->connect_ext (ws_c => sub { |
|
|
119 | my ($ws, $id, $class, $args) = @_; |
|
|
120 | |
|
|
121 | for my $ev (grep /^on_/, keys %$args) { |
|
|
122 | my $rid = $args->{$ev}; |
|
|
123 | $args->{$ev} = sub { |
|
|
124 | my $id = shift->{s_id}; |
|
|
125 | $self->send_exti_msg (w_e => $id, $rid, @_); |
|
|
126 | |
|
|
127 | 1 |
|
|
128 | }; |
|
|
129 | } |
|
|
130 | |
|
|
131 | $self->widget_associate ( |
|
|
132 | $ws, $id => scalar eval { |
|
|
133 | local $SIG{__DIE__}; |
|
|
134 | "CFPlus::UI::$class"->new (%$args) |
|
|
135 | } |
|
|
136 | ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; |
|
|
137 | }); |
|
|
138 | |
|
|
139 | # widgetset associate |
|
|
140 | $self->connect_ext (ws_a => sub { |
|
|
141 | my (%ass) = @_; |
|
|
142 | |
|
|
143 | # everything that has a name, wether conceivably useful or not |
|
|
144 | my %wkw = ( |
|
|
145 | root => $CFPlus::UI::ROOT, |
|
|
146 | tooltip => $CFPlus::UI::TOOLTIP, |
|
|
147 | |
|
|
148 | mapwidget => $::MAPWIDGET, |
|
|
149 | buttonbar => $::BUTTONBAR, |
|
|
150 | metaserver => $::METASERVER, |
|
|
151 | buttonbar => $::BUTTONBAR, |
|
|
152 | login_button => $::LOGIN_BUTTON, |
|
|
153 | quit_dialog => $::QUIT_DIALOG, |
|
|
154 | host_entry => $::HOST_ENTRY, |
|
|
155 | metaserver => $::METASERVER, |
|
|
156 | server_info => $::SERVER_INFO, |
|
|
157 | |
|
|
158 | setup_dialog => $::SETUP_DIALOG, |
|
|
159 | setup_notebook => $::SETUP_NOTEBOOK, |
|
|
160 | setup_server => $::SETUP_SERVER, |
|
|
161 | setup_keyboard => $::SETUP_KEYBOARD, |
|
|
162 | |
|
|
163 | pl_notebook => $::PL_NOTEBOOK, |
|
|
164 | pl_window => $::PL_WINDOW, |
|
|
165 | inventory_page => $::INVENTORY_PAGE, |
|
|
166 | stats_page => $::STATS_PAGE, |
|
|
167 | skill_page => $::SKILL_PAGE, |
|
|
168 | spell_page => $::SPELL_PAGE, |
|
|
169 | spell_list => $::SPELL_LIST, |
|
|
170 | |
|
|
171 | floorbox => $::FLOORBOX, |
|
|
172 | help_window => $::HELP_WINDOW, |
|
|
173 | message_window => $::MESSAGE_WINDOW, |
|
|
174 | statusbox => $::SDTATUSBOX, |
|
|
175 | |
|
|
176 | inv => $::INV, |
|
|
177 | invr => $::INVR, |
|
|
178 | invr_hb => $::INVR_HB, |
|
|
179 | ); |
|
|
180 | |
|
|
181 | while (my ($id, $name) = each %ass) { |
|
|
182 | $self->widget_associate (undef, $id => $wkw{$name}) |
|
|
183 | or warn "server failed to associate non-existent well-known widget $name\n"; |
|
|
184 | } |
|
|
185 | }); |
|
|
186 | |
|
|
187 | # widget call |
|
|
188 | $self->connect_ext (w_c => sub { |
|
|
189 | my ($id, $rid, $method, @args) = @_; |
|
|
190 | |
|
|
191 | my $w = $self->{widget}{$id} |
|
|
192 | or return; |
|
|
193 | |
|
|
194 | if ($rid) { |
|
|
195 | $self->send_exti_msg (w_r => $rid, $w->$method (@args)); |
|
|
196 | } else { |
|
|
197 | $w->$method (@args); |
|
|
198 | } |
|
|
199 | }); |
|
|
200 | |
|
|
201 | # widget set |
|
|
202 | $self->connect_ext (w_s => sub { |
|
|
203 | my ($id, $attr) = @_; |
|
|
204 | |
|
|
205 | my $w = $self->{widget}{$id} |
|
|
206 | or return; |
|
|
207 | |
|
|
208 | for (my $i = 0; $i < $#$attr; $i += 2) { |
|
|
209 | my ($member, $value) = @$attr[$i, $i+1]; |
|
|
210 | if (defined $value) { |
|
|
211 | $w->{$member} = $value; |
|
|
212 | } else { |
|
|
213 | delete $w->{$member}; |
|
|
214 | } |
|
|
215 | $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible}; |
|
|
216 | } |
|
|
217 | }); |
|
|
218 | |
|
|
219 | # widget get |
|
|
220 | $self->connect_ext (w_g => sub { |
|
|
221 | my ($id, $rid, $attr) = @_; |
|
|
222 | |
|
|
223 | my $w = $self->{widget}{$id} |
|
|
224 | or return; |
|
|
225 | |
|
|
226 | $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]); |
|
|
227 | }); |
|
|
228 | |
|
|
229 | # message window |
|
|
230 | $self->connect_ext (channel_info => sub { |
|
|
231 | my ($info) = @_; |
|
|
232 | $self->{channels}->{$info->{id}} = $info; |
|
|
233 | $::MESSAGE_WINDOW->add_channel ($info); |
|
|
234 | }); |
|
|
235 | |
105 | |
236 | # destroy widgets on logout |
106 | # destroy widgets on logout |
237 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
107 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
238 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
108 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
239 | $_->destroy |
109 | $_->destroy |
240 | for values %{delete $ws->{w} || {}}; |
110 | for values %{delete $ws->{w} || {}}; |
241 | } |
111 | } |
|
|
112 | |
|
|
113 | delete $self->{items}; |
|
|
114 | $::INV->clear; |
|
|
115 | $::INVR->clear; |
|
|
116 | $::INVR_HB->clear; |
|
|
117 | $::FLOORBOX->clear; |
242 | }); |
118 | }); |
243 | |
119 | |
244 | $self->{map_widget}->add_command (@$_) |
120 | $self->{map_widget}->add_command (@$_) |
245 | for @cmd_help; |
121 | for @cmd_help; |
246 | |
122 | |
247 | { |
123 | { |
248 | $self->{dialogue} = my $tex = new_from_file CFPlus::Texture |
124 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
249 | CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
250 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
125 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
251 | } |
126 | } |
252 | |
127 | |
253 | { |
128 | { |
254 | $self->{noface} = my $tex = new_from_file CFPlus::Texture |
129 | $self->{noface} = my $tex = $TEX_NOFACE; |
255 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
256 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
130 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
257 | } |
131 | } |
|
|
132 | |
|
|
133 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
134 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
135 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
136 | # |
|
|
137 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
138 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
139 | # $self->{texture}[$_]->unload; |
|
|
140 | # warn "expire texture $_\n";#d# |
|
|
141 | # } |
|
|
142 | # |
|
|
143 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
144 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
145 | # warn "count is $count\n";#d# |
|
|
146 | # }; |
258 | |
147 | |
259 | $self->{open_container} = 0; |
148 | $self->{open_container} = 0; |
260 | |
149 | |
261 | # per server |
150 | # per server |
262 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
151 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
263 | |
152 | |
264 | $self |
153 | $self |
265 | } |
|
|
266 | |
|
|
267 | sub widget_associate { |
|
|
268 | my ($self, $ws, $id, $widget) = @_; |
|
|
269 | |
|
|
270 | if ($widget) { |
|
|
271 | $widget->{s_id} = $id; |
|
|
272 | $self->{widget}{$id} = $widget; |
|
|
273 | |
|
|
274 | if ($ws) { |
|
|
275 | $widget->{s_ws} = $ws; |
|
|
276 | $self->{widgetset}{$ws}{w}{$id} = $widget; |
|
|
277 | } |
|
|
278 | |
|
|
279 | $widget->connect (on_destroy => sub { |
|
|
280 | my ($widget) = @_; |
|
|
281 | |
|
|
282 | delete $self->{widget}{$widget->{s_id}}; |
|
|
283 | delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} |
|
|
284 | if exists $widget->{s_ws}; |
|
|
285 | }); |
|
|
286 | |
|
|
287 | 1 |
|
|
288 | } else { |
|
|
289 | $self->send_exti_msg (w_e => $id, undef); |
|
|
290 | |
|
|
291 | 0 |
|
|
292 | } |
|
|
293 | } |
154 | } |
294 | |
155 | |
295 | sub update_fx_want { |
156 | sub update_fx_want { |
296 | my ($self) = @_; |
157 | my ($self) = @_; |
297 | |
158 | |
… | |
… | |
300 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
161 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
301 | 6 => 1, # FT_RSRC |
162 | 6 => 1, # FT_RSRC |
302 | }); |
163 | }); |
303 | } |
164 | } |
304 | |
165 | |
|
|
166 | sub ext_capabilities { |
|
|
167 | my ($self, %cap) = @_; |
|
|
168 | |
|
|
169 | if (my $ts = $cap{tileset}) { |
|
|
170 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
|
|
171 | $self->{tileset} = $default; |
|
|
172 | $self->{tilesize} = $default->[3]; |
|
|
173 | $self->setup_req (tileset => $default->[0]); |
|
|
174 | |
|
|
175 | my $w = int $self->{mapw} * 32 / $self->{tilesize}; |
|
|
176 | my $h = int $self->{maph} * 32 / $self->{tilesize}; |
|
|
177 | |
|
|
178 | $self->setup_req (mapsize => "${w}x${h}"); |
|
|
179 | } |
|
|
180 | } |
|
|
181 | } |
|
|
182 | |
|
|
183 | sub ext_ambient_music { |
|
|
184 | my ($self, $songs) = @_; |
|
|
185 | &::audio_music_set_ambient ($songs); |
|
|
186 | } |
|
|
187 | |
|
|
188 | ############################################################################# |
|
|
189 | |
|
|
190 | sub widget_associate { |
|
|
191 | my ($self, $ws, $id, $widget) = @_; |
|
|
192 | |
|
|
193 | $widget ||= new DC::UI::Bin; |
|
|
194 | |
|
|
195 | $widget->{s_id} = $id; |
|
|
196 | $self->{widget}{$id} = $widget; |
|
|
197 | |
|
|
198 | if ($ws) { |
|
|
199 | $widget->{s_ws} = $ws; |
|
|
200 | $self->{widgetset}{$ws}{w}{$id} = $widget; |
|
|
201 | } |
|
|
202 | |
|
|
203 | $widget->connect (on_destroy => sub { |
|
|
204 | my ($widget) = @_; |
|
|
205 | |
|
|
206 | delete $self->{widget}{$widget->{s_id}}; |
|
|
207 | delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} |
|
|
208 | if exists $widget->{s_ws}; |
|
|
209 | }); |
|
|
210 | } |
|
|
211 | |
|
|
212 | # widgetset new |
|
|
213 | sub ext_ws_n { |
|
|
214 | my ($self, $id) = @_; |
|
|
215 | |
|
|
216 | $self->{widgetset}{$id} = { |
|
|
217 | w => {}, |
|
|
218 | }; |
|
|
219 | } |
|
|
220 | |
|
|
221 | # widgetset destroy |
|
|
222 | sub ext_ws_d { |
|
|
223 | my ($self, $id) = @_; |
|
|
224 | |
|
|
225 | my $ws = delete $self->{widgetset}{$id} |
|
|
226 | or return; |
|
|
227 | |
|
|
228 | $_->destroy |
|
|
229 | for values %{$ws->{w}}; |
|
|
230 | } |
|
|
231 | |
|
|
232 | # widgetset create |
|
|
233 | sub ext_ws_c { |
|
|
234 | my ($self, $ws, $id, $class, $args) = @_; |
|
|
235 | |
|
|
236 | $self->widget_associate ( |
|
|
237 | $ws, $id => scalar eval { |
|
|
238 | local $SIG{__DIE__}; |
|
|
239 | "DC::UI::$class"->new (%$args) |
|
|
240 | } |
|
|
241 | ); |
|
|
242 | } |
|
|
243 | |
|
|
244 | # widgetset create template |
|
|
245 | sub ext_ws_ct { |
|
|
246 | my ($self, $ws, $type, $template, $done_cb, $cfg) = @_; |
|
|
247 | |
|
|
248 | $done_cb ||= sub { }; |
|
|
249 | |
|
|
250 | my $parse_list; $parse_list = sub { |
|
|
251 | my ($list) = @_; |
|
|
252 | my @w; |
|
|
253 | |
|
|
254 | while (@$list) { |
|
|
255 | my ($class, $args) = splice @$list, 0, 2; |
|
|
256 | my $name = delete $args->{s_id}; |
|
|
257 | my $cl = delete $args->{s_cl}; |
|
|
258 | my $cfg = delete $cfg->{$name}; |
|
|
259 | my $id = delete $cfg->{id}; |
|
|
260 | my $w = eval { "DC::UI::$class"->new (%$args, %{ $cfg || {} }) } |
|
|
261 | or next; |
|
|
262 | |
|
|
263 | $self->widget_associate ($ws, $id, $w) |
|
|
264 | if $id; |
|
|
265 | |
|
|
266 | $w->add ($parse_list->($cl)) |
|
|
267 | if $cl; |
|
|
268 | |
|
|
269 | push @w, $w; |
|
|
270 | } |
|
|
271 | |
|
|
272 | @w |
|
|
273 | }; |
|
|
274 | |
|
|
275 | # either array reference, or face # |
|
|
276 | if ($type eq "inline") { |
|
|
277 | $done_cb->(); |
|
|
278 | $parse_list->($template); |
|
|
279 | } elsif ($type eq "face") { |
|
|
280 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
281 | my ($face) = @_; |
|
|
282 | |
|
|
283 | undef $handler; |
|
|
284 | $done_cb->(); |
|
|
285 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
286 | }); |
|
|
287 | } else { |
|
|
288 | $done_cb->(0); |
|
|
289 | } |
|
|
290 | } |
|
|
291 | |
|
|
292 | # widgetset associate |
|
|
293 | sub ext_ws_a { |
|
|
294 | my ($self, %ass) = @_; |
|
|
295 | |
|
|
296 | # everything that has a name, wether conceivably useful or not |
|
|
297 | my %wkw = ( |
|
|
298 | root => $DC::UI::ROOT, |
|
|
299 | tooltip => $DC::UI::TOOLTIP, |
|
|
300 | |
|
|
301 | mapwidget => $::MAPWIDGET, |
|
|
302 | menubar => $::MENUBAR, |
|
|
303 | menupopup => $::MENUPOPUP, |
|
|
304 | pickup_enable => $::PICKUP_ENABLE, |
|
|
305 | buttonbar => $::BUTTONBAR, |
|
|
306 | metaserver => $::METASERVER, |
|
|
307 | buttonbar => $::BUTTONBAR, |
|
|
308 | login_button => $::LOGIN_BUTTON, |
|
|
309 | quit_dialog => $::QUIT_DIALOG, |
|
|
310 | host_entry => $::HOST_ENTRY, |
|
|
311 | metaserver => $::METASERVER, |
|
|
312 | server_info => $::SERVER_INFO, |
|
|
313 | |
|
|
314 | setup_dialog => $::SETUP_DIALOG, |
|
|
315 | setup_notebook => $::SETUP_NOTEBOOK, |
|
|
316 | setup_server => $::SETUP_SERVER, |
|
|
317 | setup_keyboard => $::SETUP_KEYBOARD, |
|
|
318 | |
|
|
319 | pl_notebook => $::PL_NOTEBOOK, |
|
|
320 | pl_window => $::PL_WINDOW, |
|
|
321 | inventory_page => $::INVENTORY_PAGE, |
|
|
322 | stats_page => $::STATS_PAGE, |
|
|
323 | skill_page => $::SKILL_PAGE, |
|
|
324 | spell_page => $::SPELL_PAGE, |
|
|
325 | spell_list => $::SPELL_LIST, |
|
|
326 | |
|
|
327 | floorbox => $::FLOORBOX, |
|
|
328 | help_window => $::HELP_WINDOW, |
|
|
329 | message_window => $::MESSAGE_WINDOW, |
|
|
330 | message_dist => $::MESSAGE_DIST, |
|
|
331 | statusbox => $::STATUSBOX, |
|
|
332 | |
|
|
333 | inv => $::INV, |
|
|
334 | invr => $::INVR, |
|
|
335 | invr_hb => $::INVR_HB, |
|
|
336 | ); |
|
|
337 | |
|
|
338 | while (my ($id, $name) = each %ass) { |
|
|
339 | $self->widget_associate (undef, $id => $wkw{$name}); |
|
|
340 | } |
|
|
341 | } |
|
|
342 | |
|
|
343 | # widget call |
|
|
344 | sub ext_w_c { |
|
|
345 | my ($self, $id, $rcb, $method, @args) = @_; |
|
|
346 | |
|
|
347 | my $w = $self->{widget}{$id} |
|
|
348 | or return; |
|
|
349 | |
|
|
350 | if ($rcb) { |
|
|
351 | $rcb->($w->$method (@args)); |
|
|
352 | } else { |
|
|
353 | $w->$method (@args); |
|
|
354 | } |
|
|
355 | } |
|
|
356 | |
|
|
357 | # widget set |
|
|
358 | sub ext_w_s { |
|
|
359 | my ($self, $id, $attr) = @_; |
|
|
360 | |
|
|
361 | my $w = $self->{widget}{$id} |
|
|
362 | or return; |
|
|
363 | |
|
|
364 | for (my $i = 0; $i < $#$attr; $i += 2) { |
|
|
365 | my ($member, $value) = @$attr[$i, $i+1]; |
|
|
366 | if (defined $value) { |
|
|
367 | $w->{$member} = $value; |
|
|
368 | } else { |
|
|
369 | delete $w->{$member}; |
|
|
370 | } |
|
|
371 | $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible}; |
|
|
372 | } |
|
|
373 | } |
|
|
374 | |
|
|
375 | # widget get |
|
|
376 | sub ext_w_g { |
|
|
377 | my ($self, $id, $rid, @attr) = @_; |
|
|
378 | |
|
|
379 | my $w = $self->{widget}{$id} |
|
|
380 | or return; |
|
|
381 | |
|
|
382 | $self->send_exti_msg (w_e => $rid, map $w->{$_}, @attr); |
|
|
383 | } |
|
|
384 | |
|
|
385 | # message window |
|
|
386 | sub ext_channel_info { |
|
|
387 | my ($self, $info) = @_; |
|
|
388 | $self->{channels}->{$info->{id}} = $info; |
|
|
389 | $::MESSAGE_DIST->add_channel ($info); |
|
|
390 | } |
|
|
391 | |
|
|
392 | ############################################################################# |
|
|
393 | |
305 | sub logprint { |
394 | sub logprint { |
306 | my ($self, @a) = @_; |
395 | my ($self, @a) = @_; |
307 | |
396 | |
308 | CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; |
397 | DC::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { }; |
309 | } |
398 | } |
310 | |
399 | |
311 | sub _stat_numdiff { |
400 | sub _stat_numdiff { |
312 | my ($self, $name, $old, $new) = @_; |
401 | my ($self, $name, $old, $new) = @_; |
313 | |
402 | |
… | |
… | |
331 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
420 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
332 | : () |
421 | : () |
333 | } |
422 | } |
334 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
423 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
335 | |
424 | |
336 | join "", @diff |
425 | "\u$name: " . (join ", ", @diff) |
337 | } |
426 | } |
338 | |
427 | |
339 | # all stats that are chacked against changes |
428 | # all stats that are chacked against changes |
340 | my @statchange = ( |
429 | my @statchange = ( |
341 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
430 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
384 | |
473 | |
385 | if (my @diffs = |
474 | if (my @diffs = |
386 | ( |
475 | ( |
387 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
476 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
388 | map { |
477 | map { |
389 | $stats->{$_} && $prev->{$_} |
478 | $stats->{$_} && $prev->{$_} |
390 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
479 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
391 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
480 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
392 | ) |
481 | ) |
393 | ) { |
482 | ) { |
394 | my $msg = join " ", @diffs; |
483 | my $msg = join " ", @diffs; |
… | |
… | |
396 | } |
485 | } |
397 | |
486 | |
398 | if ( |
487 | if ( |
399 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
488 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
400 | ) { |
489 | ) { |
401 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
490 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
402 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 10); |
491 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
403 | } |
492 | } |
404 | |
493 | |
405 | $self->update_stats_window ($stats, $prev); |
494 | $self->update_stats_window ($stats, $prev); |
406 | |
495 | |
407 | $self->{prev_stats} = { %$stats }; |
496 | $self->{prev_stats} = { %$stats }; |
… | |
… | |
444 | |
533 | |
445 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
534 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
446 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
535 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
447 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
536 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
448 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
537 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
449 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
538 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
450 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
539 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
451 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
540 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
452 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
541 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
453 | my $title = $stats->{+CS_STAT_TITLE}; |
542 | my $title = $stats->{+CS_STAT_TITLE}; |
454 | $title =~ s/^Player: //; |
543 | $title =~ s/^Player: //; |
455 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
544 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
456 | |
545 | |
… | |
… | |
468 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
557 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
469 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
558 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
470 | |
559 | |
471 | $self->update_weight; |
560 | $self->update_weight; |
472 | |
561 | |
473 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
562 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
474 | for keys %RES_TBL; |
563 | for keys %RES_TBL; |
475 | |
564 | |
476 | my $sktbl = $::STATWIDS->{skill_tbl}; |
565 | my $sktbl = $::STATWIDS->{skill_tbl}; |
477 | my @skills = keys %{ $self->{skill_info} }; |
566 | my @skills = keys %{ $self->{skill_info} }; |
478 | |
567 | |
479 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
568 | my @order = sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
|
|
569 | map [$_, $self->{skill_info}{$_}], |
|
|
570 | grep exists $stats->{$_}, |
|
|
571 | @skills; |
|
|
572 | |
|
|
573 | if ($self->{stat_order} ne join ",", map $_->[0], @order) { |
|
|
574 | $self->{stat_order} = join ",", map $_->[0], @order; |
|
|
575 | |
480 | $sktbl->clear; |
576 | $sktbl->clear; |
481 | |
577 | |
482 | my @add; |
578 | my $sw = $self->{skillwid}{""} ||= [ |
483 | |
|
|
484 | push @add, |
|
|
485 | 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), |
579 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
486 | 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), |
580 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
487 | 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), |
581 | 2, 0, (new DC::UI::Label text => "Progress"), |
488 | 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), |
582 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
489 | 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), |
583 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
490 | 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), |
584 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
491 | 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), |
585 | 6, 0, (new DC::UI::Label text => "Progress"), |
492 | 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), |
586 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
493 | ; |
587 | ]; |
494 | |
588 | |
|
|
589 | my @add = @$sw; |
|
|
590 | |
495 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
591 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
496 | |
592 | |
497 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
593 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
498 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
594 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
499 | |
595 | |
500 | my ($x, $y) = (0, 1); |
596 | my ($x, $y) = (0, 1); |
501 | for ( |
597 | for (@order) { |
502 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
|
|
503 | map [$_, $self->{skill_info}{$_}], |
|
|
504 | grep exists $stats->{$_}, |
|
|
505 | @skills |
|
|
506 | ) { |
|
|
507 | my ($idx, $name) = @$_; |
598 | my ($idx, $name) = @$_; |
508 | |
599 | |
509 | my $spell_cb = sub { |
600 | my $spell_cb = sub { |
510 | my ($widget, $ev) = @_; |
601 | my ($widget, $ev) = @_; |
511 | |
602 | |
512 | if ($ev->{button} == 1) { |
603 | if ($ev->{button} == 1) { |
513 | $::CONN->user_send ("ready_skill $name"); |
604 | $::CONN->user_send ("ready_skill $name"); |
514 | } elsif ($ev->{button} == 2) { |
605 | } elsif ($ev->{button} == 2) { |
515 | $::CONN->user_send ("use_skill $name"); |
606 | $::CONN->user_send ("use_skill $name"); |
516 | } elsif ($ev->{button} == 3) { |
607 | } elsif ($ev->{button} == 3) { |
517 | my $shortname = CFPlus::shorten $name, 14; |
608 | my $shortname = DC::shorten $name, 14; |
518 | (new CFPlus::UI::Menu |
609 | (new DC::UI::Menu |
519 | items => [ |
610 | items => [ |
520 | ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }], |
611 | ["bind <i>ready_skill $shortname</i> to a key" => sub { DC::Macro::quick_macro ["ready_skill $name"] }], |
521 | ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }], |
612 | ["bind <i>use_skill $shortname</i> to a key" => sub { DC::Macro::quick_macro ["use_skill $name"] }], |
522 | ], |
613 | ], |
523 | )->popup ($ev); |
614 | )->popup ($ev); |
524 | } else { |
615 | } else { |
525 | return 0; |
616 | return 0; |
526 | } |
617 | } |
527 | |
618 | |
528 | 1 |
619 | 1 |
529 | }; |
620 | }; |
530 | |
621 | |
|
|
622 | my $sw = $self->{skillwid}{$idx} ||= [ |
|
|
623 | # exp |
|
|
624 | (new DC::UI::Label |
|
|
625 | align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), |
|
|
626 | |
|
|
627 | # level |
|
|
628 | (new DC::UI::Label |
|
|
629 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), |
|
|
630 | |
|
|
631 | # progress |
|
|
632 | (new DC::UI::ExperienceProgress), |
|
|
633 | |
|
|
634 | # label |
|
|
635 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
|
|
636 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
|
|
637 | ]; |
|
|
638 | |
531 | push @add, |
639 | push @add, |
532 | $x * 4 + 0, $y, ($self->{stat_widget_exp}{$idx} ||= new CFPlus::UI::Label |
640 | $x * 4 + 0, $y, $sw->[0], |
533 | align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), |
641 | $x * 4 + 1, $y, $sw->[1], |
534 | $x * 4 + 1, $y, ($self->{stat_widget_lvl}{$idx} ||= new CFPlus::UI::Label |
642 | $x * 4 + 2, $y, $sw->[2], |
535 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), |
643 | $x * 4 + 3, $y, $sw->[3], |
536 | $x * 4 + 2, $y, ($self->{stat_widget_prg}{$idx} ||= new CFPlus::UI::ExperienceProgress), |
|
|
537 | $x * 4 + 3, $y, ($self->{stat_widget_lbl}{$idx} ||= new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, |
|
|
538 | can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
|
|
539 | ; |
644 | ; |
540 | |
645 | |
541 | $x++ and ($x, $y) = (0, $y + 1); |
646 | $x++ and ($x, $y) = (0, $y + 1); |
542 | } |
647 | } |
543 | |
648 | |
544 | $sktbl->add_at (@add); |
649 | $sktbl->add_at (@add); |
545 | } |
650 | } |
546 | |
651 | |
547 | for (grep exists $stats->{$_}, @skills) { |
652 | for (@order) { |
548 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
653 | my ($idx, $name) = @$_; |
549 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
654 | my $val = $stats->{$idx}; |
550 | $self->{stat_widget_prg}{$_}->set_value (@{$stats->{$_}}); |
|
|
551 | } |
|
|
552 | } |
|
|
553 | |
655 | |
554 | sub macro_send { |
656 | next if $prev->{$idx}[1] eq $val->[1]; |
555 | my ($self, $macro) = @_; |
|
|
556 | |
657 | |
557 | for my $cmd (@{ $macro->{action} }) { |
658 | my $sw = $self->{skillwid}{$idx}; |
558 | $self->send_command ($cmd); |
659 | $sw->[0]->set_text (::formsep ($val->[1])); |
|
|
660 | $sw->[1]->set_text ($val->[0] * 1); |
|
|
661 | $sw->[2]->set_value (@$val); |
|
|
662 | |
|
|
663 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
|
|
664 | $::GAUGES->{skillexp}->set_value (@$val); |
559 | } |
665 | } |
560 | } |
666 | } |
561 | |
667 | |
562 | sub user_send { |
668 | sub user_send { |
563 | my ($self, $command) = @_; |
669 | my ($self, $command) = @_; |
… | |
… | |
565 | $self->{record}->($command) |
671 | $self->{record}->($command) |
566 | if $self->{record}; |
672 | if $self->{record}; |
567 | |
673 | |
568 | $self->logprint ("send: ", $command); |
674 | $self->logprint ("send: ", $command); |
569 | $self->send_command ($command); |
675 | $self->send_command ($command); |
570 | ::status ($command); |
|
|
571 | } |
676 | } |
572 | |
677 | |
573 | sub record { |
678 | sub record { |
574 | my ($self, $cb) = @_; |
679 | my ($self, $cb) = @_; |
575 | |
680 | |
… | |
… | |
577 | } |
682 | } |
578 | |
683 | |
579 | sub map_scroll { |
684 | sub map_scroll { |
580 | my ($self, $dx, $dy) = @_; |
685 | my ($self, $dx, $dy) = @_; |
581 | |
686 | |
582 | $self->{map}->scroll ($dx, $dy); |
687 | $self->{map_widget}->scroll ($dx, $dy); |
583 | } |
688 | } |
584 | |
689 | |
585 | sub feed_map1a { |
690 | sub feed_map1a { |
586 | my ($self, $data) = @_; |
691 | my ($self, $data) = @_; |
587 | |
692 | |
588 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
693 | my $missing = $self->{map}->map1a_update ($data); |
589 | my $delay; |
694 | my $delay; |
590 | |
695 | |
591 | for my $tile (@$missing) { |
696 | for my $tile (@$missing) { |
592 | next if $self->{delay}{$tile}; |
697 | next if $self->{delay}{$tile}; |
593 | |
698 | |
594 | $delay = 1; |
699 | $delay = 1; |
595 | |
700 | |
596 | if (my $tex = $::CONN->{texture}[$tile]) { |
701 | if (my $tex = $self->{texture}[$tile]) { |
597 | $tex->upload; |
702 | $tex->upload; |
598 | } else { |
703 | } else { |
599 | $self->{delay}{$tile} = 1; |
704 | $self->{delay}{$tile} = 1; |
600 | |
705 | |
601 | # we assume the face is in-flight and will eventually come |
706 | # we assume the face is in-flight and will eventually arrive |
602 | push @{$self->{tile_cb}{$tile}}, sub { |
707 | push @{$self->{tile_cb}{$tile}}, sub { |
603 | delete $self->{delay}{$tile}; |
708 | delete $self->{delay}{$tile}; |
604 | $_[0]->upload; |
709 | $_[0]->upload; |
605 | }; |
710 | }; |
606 | } |
711 | } |
607 | } |
712 | } |
608 | |
713 | |
609 | if ($delay) { |
714 | if ($delay) { |
610 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
715 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
611 | Event->timer (after => 0.03, cb => sub { |
716 | EV::once undef, 0, 0.03, sub { |
612 | $_[0]->w->cancel; |
|
|
613 | $self->{map_widget}->update; |
717 | $self->{map_widget}->update |
|
|
718 | if $self->{map_widget}; |
614 | }); |
719 | }; |
615 | } else { |
720 | } else { |
616 | $self->{map_widget}->update; |
721 | $self->{map_widget}->update; |
617 | } |
722 | } |
618 | } |
723 | } |
619 | |
724 | |
… | |
… | |
624 | } |
729 | } |
625 | |
730 | |
626 | sub flush_map { |
731 | sub flush_map { |
627 | my ($self) = @_; |
732 | my ($self) = @_; |
628 | |
733 | |
629 | my $map_info = delete $self->{map_info} |
734 | return unless $self->{map_info}; |
630 | or return; |
|
|
631 | |
735 | |
|
|
736 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
632 | my ($hash, $x, $y, $w, $h) = @$map_info; |
737 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
633 | |
738 | |
634 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
739 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
635 | $self->{map_cache_new}{$hash} = \$data; |
740 | |
|
|
741 | if ($data ne $$rdata) { |
|
|
742 | $map_info->[1] = \$data; |
|
|
743 | my $cdata = Compress::LZF::compress $data; |
636 | CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; |
744 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
745 | } |
|
|
746 | } |
637 | } |
747 | } |
638 | |
748 | |
639 | sub map_clear { |
749 | sub map_clear { |
640 | my ($self) = @_; |
750 | my ($self) = @_; |
641 | |
751 | |
642 | $self->flush_map; |
752 | $self->flush_map; |
|
|
753 | delete $self->{map_info}; |
643 | delete $self->{neigh_map}; |
754 | delete $self->{neigh_map}; |
644 | |
755 | |
645 | $self->{map}->clear; |
756 | $self->{map}->clear; |
646 | delete $self->{map_widget}{magicmap}; |
757 | delete $self->{map_widget}{magicmap}; |
647 | } |
758 | } |
… | |
… | |
654 | do { |
765 | do { |
655 | $tile = pop @{$self->{bg_fetch}} |
766 | $tile = pop @{$self->{bg_fetch}} |
656 | or return; |
767 | or return; |
657 | } while $self->{texture}[$tile]; |
768 | } while $self->{texture}[$tile]; |
658 | |
769 | |
659 | CFPlus::DB::get tilecache => $tile, sub { |
770 | DC::DB::get tilecache => $tile, sub { |
660 | my ($data) = @_; |
771 | my ($data) = @_; |
661 | |
772 | |
662 | return unless $self->{map}; # stop when destroyed |
773 | return unless $self->{map}; # stop when destroyed |
663 | |
774 | |
664 | if (defined $data) { |
775 | if (defined $data) { |
… | |
… | |
668 | |
779 | |
669 | $self->bg_fetch; |
780 | $self->bg_fetch; |
670 | }; |
781 | }; |
671 | } |
782 | } |
672 | |
783 | |
673 | sub load_map($$$) { |
784 | sub load_map($$$$$$) { |
674 | my ($self, $hash, $x, $y) = @_; |
785 | my ($self, $hash, $x, $y, $w, $h) = @_; |
675 | |
786 | |
676 | my $gen = $self->{map_change_gen}; |
787 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
677 | |
788 | |
678 | my $cb = sub { |
789 | my $cb = sub { |
679 | return unless $gen == $self->{map_change_gen}; |
790 | $map_info->[1] = \$_[0]; |
680 | |
791 | |
681 | my ($data) = @_; |
|
|
682 | |
|
|
683 | if (defined $data) { |
|
|
684 | $self->{map_cache_new}{$hash} = \$data; |
|
|
685 | |
|
|
686 | my $data = Compress::LZF::decompress $data; |
|
|
687 | |
|
|
688 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
792 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
689 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
793 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
690 | $self->bg_fetch unless $inprogress; |
794 | $self->bg_fetch unless $inprogress; |
691 | } |
|
|
692 | }; |
795 | }; |
693 | |
796 | |
694 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
797 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
695 | $cb->($$rdata); |
798 | $cb->(${ $map_info->[1] }); |
696 | } else { |
799 | } else { |
|
|
800 | my $gen = $self->{map_change_gen}; |
|
|
801 | |
697 | CFPlus::DB::get $self->{mapcache} => $hash, $cb; |
802 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
803 | return unless $gen == $self->{map_change_gen}; |
|
|
804 | return unless defined $_[0]; |
|
|
805 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
806 | }; |
698 | } |
807 | } |
699 | } |
808 | } |
700 | |
809 | |
701 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
810 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
702 | # (server resource,s latency, bandwidth), so this hack is warranted. |
811 | # (server resources, latency, bandwidth), so this hack is warranted. |
703 | # the right fix is to make real tiled maps with an overview file |
812 | # the right fix is to make real tiled maps with an overview file |
704 | sub send_mapinfo { |
813 | sub send_mapinfo { |
705 | my ($self, $data, $cb) = @_; |
814 | my ($self, $data, $cb) = @_; |
706 | |
815 | |
707 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
816 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
732 | } |
841 | } |
733 | |
842 | |
734 | # this method does a "flood fill" into every tile direction |
843 | # this method does a "flood fill" into every tile direction |
735 | # it assumes that tiles are arranged in a rectangular grid, |
844 | # it assumes that tiles are arranged in a rectangular grid, |
736 | # i.e. a map is the same as the left of the right map etc. |
845 | # i.e. a map is the same as the left of the right map etc. |
737 | # failure to comply are harmless and result in display errors |
846 | # failure to comply is harmless and results in display errors |
738 | # at worst. |
847 | # at worst. |
739 | sub flood_fill { |
848 | sub flood_fill { |
740 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
849 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
741 | |
850 | |
742 | # the server does not allow map paths > 6 |
851 | # the server does not allow map paths > 6 |
… | |
… | |
778 | return if $mode ne "spatial"; |
887 | return if $mode ne "spatial"; |
779 | |
888 | |
780 | $x += $self->{map}->ox; |
889 | $x += $self->{map}->ox; |
781 | $y += $self->{map}->oy; |
890 | $y += $self->{map}->oy; |
782 | |
891 | |
783 | $self->load_map ($hash, $x, $y) |
892 | $self->load_map ($hash, $x, $y, $w, $h) |
784 | unless $self->{neigh_map}{$hash}[5]++;#d# |
893 | unless $self->{neigh_map}{$hash}[5]++;#d# |
785 | |
894 | |
786 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
895 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
787 | |
896 | |
788 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
897 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
796 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
905 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
797 | |
906 | |
798 | $self->flush_map; |
907 | $self->flush_map; |
799 | |
908 | |
800 | ++$self->{map_change_gen}; |
909 | ++$self->{map_change_gen}; |
801 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
910 | $self->{map_cache_old} = delete $self->{map_cache}; |
802 | |
911 | |
803 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
912 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
804 | |
913 | |
805 | my $mapmapw = $self->{mapmap}->{w}; |
914 | my $mapmapw = $self->{mapmap}->{w}; |
806 | my $mapmaph = $self->{mapmap}->{h}; |
915 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
818 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
927 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
819 | |
928 | |
820 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
929 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
821 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
930 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
822 | |
931 | |
823 | $self->load_map ($hash, $x, $y); |
932 | $self->load_map ($hash, $x, $y, $w, $h); |
824 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
933 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
825 | } |
934 | } |
826 | |
935 | |
827 | sub face_find { |
936 | sub face_find { |
828 | my ($self, $facenum, $face, $cb) = @_; |
937 | my ($self, $facenum, $face, $cb) = @_; |
829 | |
938 | |
830 | if ($face->{type} == 0) { # FT_FACE |
939 | if ($face->{type} == 0) { # FT_FACE |
831 | my $id = CFPlus::DB::get_tile_id_sync $face->{name}; |
940 | my $id = DC::DB::get_tile_id_sync $face->{name}; |
832 | |
941 | |
833 | $face->{id} = $id; |
942 | $face->{id} = $id; |
834 | $self->{map}->set_tileid ($facenum => $id); |
943 | $self->{map}->set_tileid ($facenum => $id); |
835 | |
944 | |
836 | CFPlus::DB::get tilecache => $id, $cb; |
945 | DC::DB::get tilecache => $id, $cb; |
837 | |
946 | |
838 | } elsif ($face->{type} & 1) { # with metadata |
947 | } elsif ($face->{type} & 1) { # with metadata |
839 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
948 | DC::DB::get res_meta => $face->{name}, $cb; |
840 | |
949 | |
841 | } else { # no metadata |
950 | } else { # no metadata |
842 | CFPlus::DB::get res_data => $face->{name}, $cb; |
951 | DC::DB::get res_data => $face->{name}, $cb; |
843 | } |
952 | } |
844 | } |
953 | } |
845 | |
954 | |
846 | sub face_update { |
955 | sub face_update { |
847 | my ($self, $facenum, $face, $changed) = @_; |
956 | my ($self, $facenum, $face, $changed) = @_; |
848 | |
957 | |
849 | if ($face->{type} == 0) { |
958 | if ($face->{type} == 0) { |
850 | # image, FT_FACE |
959 | # image, FT_FACE |
851 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
960 | DC::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
852 | if $changed; |
961 | if $changed; |
853 | |
962 | |
854 | $self->have_tile ($face->{id}, delete $face->{data}); |
963 | $self->have_tile ($face->{id}, delete $face->{data}); |
855 | |
964 | |
856 | } elsif ($face->{type} & 1) { |
965 | } elsif ($face->{type} & 1) { |
857 | # split metadata case, FT_MUSIC, FT_SOUND |
966 | # split metadata case, FT_MUSIC, FT_SOUND |
858 | if ($changed) { # new data |
967 | if ($changed) { # new data |
859 | my ($meta, $data) = unpack "(w/a*)*", $face->{data}; |
968 | my ($meta, $data) = unpack "(w/a*)*", $face->{data}; |
860 | $face->{data} = $meta; |
969 | $face->{data} = $meta; |
861 | |
970 | |
|
|
971 | # rely on strict ordering here and also on later fetch |
862 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
972 | DC::DB::put res_data => $face->{name} => $data, sub { }; |
863 | CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; |
973 | DC::DB::put res_meta => $face->{name} => $meta, sub { }; |
864 | } |
974 | } |
865 | |
975 | |
866 | $face->{data} = $self->{json_coder}->decode ($face->{data}); |
976 | $face->{data} = $self->{json_coder}->decode ($face->{data}); |
867 | |
|
|
868 | ::add_license ($face); |
977 | ::add_license ($face); |
|
|
978 | ::message ({ markup => DC::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." }) |
|
|
979 | if $changed; |
869 | |
980 | |
870 | if ($face->{type} == 3) { # FT_MUSIC |
981 | if ($face->{type} == 3) { # FT_MUSIC |
871 | ::message ({ markup => "downloaded song #$facenum" }) |
|
|
872 | if $changed; |
|
|
873 | |
|
|
874 | &::audio_music_push ($facenum); |
982 | &::audio_music_push ($facenum); |
875 | } elsif ($face->{type} == 5) { # FT_SOUND |
983 | } elsif ($face->{type} == 5) { # FT_SOUND |
876 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
877 | if $changed; |
|
|
878 | |
|
|
879 | &::audio_sound_push ($facenum); |
984 | &::audio_sound_push ($facenum); |
880 | } |
985 | } |
881 | |
986 | |
882 | } else { |
987 | } else { |
883 | # flat resource case, FT_RSRC |
988 | # flat resource case, FT_RSRC |
884 | CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } |
989 | DC::DB::put res_data => $face->{name} => $face->{data}, sub { } |
885 | if $changed; |
990 | if $changed; |
886 | } |
991 | } |
887 | |
992 | |
888 | if (my $cbs = $self->{face_cb}{$facenum}) { |
993 | if (my $cbs = $self->{face_cb}{$facenum}) { |
889 | $_->($face, $changed) for @$cbs; |
994 | $_->($face, $changed) for @$cbs; |
… | |
… | |
900 | my ($self, $tile, $data) = @_; |
1005 | my ($self, $tile, $data) = @_; |
901 | |
1006 | |
902 | return unless $self->{map}; |
1007 | return unless $self->{map}; |
903 | |
1008 | |
904 | my $tex = $self->{texture}[$tile] ||= |
1009 | my $tex = $self->{texture}[$tile] ||= |
905 | new CFPlus::Texture |
1010 | new DC::Texture |
906 | tile => $tile, |
1011 | tile => $tile, |
907 | image => $data, delete_image => 1, |
1012 | image => $data, delete_image => 1, |
908 | minify => 1, mipmap => 1; |
1013 | minify => 1; |
909 | |
1014 | |
910 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1015 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
911 | $_->($tex) for @$cbs; |
1016 | $_->($tex) for @$cbs; |
912 | } |
1017 | } |
913 | } |
1018 | } |
… | |
… | |
918 | my ($self, $num, $cb) = @_; |
1023 | my ($self, $num, $cb) = @_; |
919 | |
1024 | |
920 | push @{$self->{face_cb}{$num}}, $cb; |
1025 | push @{$self->{face_cb}{$num}}, $cb; |
921 | |
1026 | |
922 | defined wantarray |
1027 | defined wantarray |
923 | ? CFPlus::guard { |
1028 | ? Guard::guard { |
924 | @{$self->{face_cb}{$num}} |
1029 | @{$self->{face_cb}{$num}} |
925 | = grep $_ != $cb, |
1030 | = grep $_ != $cb, |
926 | @{$self->{face_cb}{$num}}; |
1031 | @{$self->{face_cb}{$num}}; |
927 | } |
1032 | } |
928 | : () |
1033 | : () |
… | |
… | |
956 | my ($self, $flags, $prompt) = @_; |
1061 | my ($self, $flags, $prompt) = @_; |
957 | |
1062 | |
958 | $prompt = $LAST_QUERY unless length $prompt; |
1063 | $prompt = $LAST_QUERY unless length $prompt; |
959 | $LAST_QUERY = $prompt; |
1064 | $LAST_QUERY = $prompt; |
960 | |
1065 | |
961 | $self->{query}-> ($self, $flags, $prompt); |
1066 | $self->{query}->($self, $flags, $prompt); |
962 | } |
1067 | } |
963 | |
1068 | |
964 | sub sanitise_xml($) { |
1069 | sub sanitise_xml($) { |
965 | local $_ = shift; |
1070 | local $_ = shift; |
966 | |
1071 | |
967 | # we now weed out all tags we do not support |
1072 | # we now weed out all tags we do not support |
968 | s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%<%g; |
1073 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
1074 | }{ |
|
|
1075 | "<" |
|
|
1076 | }gex; |
|
|
1077 | |
969 | # now all entities |
1078 | # now all entities |
970 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1079 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
971 | |
1080 | |
972 | # handle some elements |
1081 | # handle some elements |
973 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1082 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
974 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1083 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1084 | |
|
|
1085 | s/\s+$//; |
975 | |
1086 | |
976 | $_ |
1087 | $_ |
977 | } |
1088 | } |
978 | |
1089 | |
979 | our %NAME_TO_COLOR = ( |
1090 | our %NAME_TO_COLOR = ( |
… | |
… | |
992 | tan => 12, |
1103 | tan => 12, |
993 | ); |
1104 | ); |
994 | |
1105 | |
995 | our @CF_COLOR = ( |
1106 | our @CF_COLOR = ( |
996 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1107 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
997 | [1.00, 1.00, 1.00], |
1108 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
998 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1109 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
999 | [1.00, 0.00, 0.00], |
1110 | [1.00, 0.00, 0.00], |
1000 | [1.00, 0.54, 0.00], |
1111 | [1.00, 0.54, 0.00], |
1001 | [0.11, 0.56, 1.00], |
1112 | [0.11, 0.56, 1.00], |
1002 | [0.93, 0.46, 0.00], |
1113 | [0.93, 0.46, 0.00], |
1003 | [0.18, 0.54, 0.34], |
1114 | [0.18, 0.54, 0.34], |
… | |
… | |
1022 | $self->logprint ("msg: ", $text); |
1133 | $self->logprint ("msg: ", $text); |
1023 | return if $color < 0; # negative color == ignore if not understood |
1134 | return if $color < 0; # negative color == ignore if not understood |
1024 | |
1135 | |
1025 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1136 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1026 | |
1137 | |
1027 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1028 | # no longer neecssary with TRT servers |
|
|
1029 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1030 | |
|
|
1031 | ::message ({ |
1138 | ::message ({ |
1032 | fg => $fg, |
1139 | fg => $fg, |
1033 | markup => $_, |
1140 | markup => $text, |
1034 | type => $type, |
1141 | type => $type, |
1035 | extra => [@extra], |
1142 | extra => [@extra], |
1036 | color_flags => $color |
1143 | color_flags => $color, #d# ugly, kill |
1037 | }) for split /\n/, $text; |
1144 | }); |
|
|
1145 | |
|
|
1146 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
|
|
1147 | # # actually, this is an ugly design. _we_ should control the channels, |
|
|
1148 | # # not some random other widget, as the channels are clearly protocol-specific. |
|
|
1149 | # # then we could also react to flags such as CLEAR without resorting to |
|
|
1150 | # # hacks such as color_flags, above. |
1038 | |
1151 | |
1039 | $self->{statusbox}->add ($text, |
1152 | $self->{statusbox}->add ($text, |
1040 | group => $text, |
1153 | group => $text, |
1041 | fg => $fg, |
1154 | fg => $fg, |
1042 | timeout => $color >= 2 ? 180 : 10, |
1155 | timeout => $color >= 2 ? 180 : 10, |
1043 | tooltip_font => $::FONT_FIXED, |
1156 | tooltip_font => $::FONT_FIXED, |
1044 | ); |
1157 | ) if $type eq "info"; |
1045 | } |
1158 | } |
1046 | } |
1159 | } |
1047 | |
1160 | |
1048 | sub spell_add { |
1161 | sub spell_add { |
1049 | my ($self, $spell) = @_; |
1162 | my ($self, $spell) = @_; |
… | |
… | |
1053 | $spell->{message} =~ s/\n+$//; |
1166 | $spell->{message} =~ s/\n+$//; |
1054 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1167 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1055 | |
1168 | |
1056 | $::SPELL_LIST->add_spell ($spell); |
1169 | $::SPELL_LIST->add_spell ($spell); |
1057 | |
1170 | |
1058 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
1171 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
1059 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
1172 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
1060 | } |
1173 | } |
1061 | |
1174 | |
1062 | sub spell_delete { |
1175 | sub spell_delete { |
1063 | my ($self, $spell) = @_; |
1176 | my ($self, $spell) = @_; |
1064 | |
1177 | |
… | |
… | |
1075 | sub addme_success { |
1188 | sub addme_success { |
1076 | my ($self) = @_; |
1189 | my ($self) = @_; |
1077 | |
1190 | |
1078 | my %skill_help; |
1191 | my %skill_help; |
1079 | |
1192 | |
1080 | for my $node (CFPlus::Pod::find skill_description => "*") { |
1193 | for my $node (DC::Pod::find skill_description => "*") { |
1081 | my (undef, @par) = CFPlus::Pod::section_of $node; |
1194 | my (undef, @par) = DC::Pod::section_of $node; |
1082 | $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; |
1195 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1083 | }; |
1196 | }; |
1084 | |
1197 | |
1085 | for my $skill (values %{$self->{skill_info}}) { |
1198 | for my $skill (values %{$self->{skill_info}}) { |
1086 | $self->{map_widget}->add_command ("ready_skill $skill", |
1199 | $self->{map_widget}->add_command ("ready_skill $skill", |
1087 | (CFPlus::asxml "Ready the skill '$skill'\n\n") |
1200 | (DC::asxml "Ready the skill '$skill'\n\n") |
1088 | . $skill_help{$skill}); |
1201 | . $skill_help{$skill}); |
1089 | $self->{map_widget}->add_command ("use_skill $skill", |
1202 | $self->{map_widget}->add_command ("use_skill $skill", |
1090 | (CFPlus::asxml "Immediately use the skill '$skill'\n\n") |
1203 | (DC::asxml "Immediately use the skill '$skill'\n\n") |
1091 | . $skill_help{$skill}); |
1204 | . $skill_help{$skill}); |
1092 | } |
1205 | } |
1093 | } |
1206 | } |
1094 | |
1207 | |
1095 | sub eof { |
1208 | sub eof { |
… | |
… | |
1099 | |
1212 | |
1100 | ::stop_game (); |
1213 | ::stop_game (); |
1101 | } |
1214 | } |
1102 | |
1215 | |
1103 | sub update_floorbox { |
1216 | sub update_floorbox { |
1104 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
1217 | $DC::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
1105 | return unless $::CONN; |
1218 | return unless $::CONN; |
1106 | |
1219 | |
1107 | $::FLOORBOX->clear; |
1220 | $::FLOORBOX->clear; |
1108 | |
1221 | |
1109 | my @add; |
1222 | my @add; |
1110 | |
1223 | |
1111 | my $row; |
1224 | my $row; |
1112 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1225 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1226 | next if $_->{tag} & 0x80000000; |
1113 | if ($row < 6) { |
1227 | if ($row < 6) { |
1114 | local $_->{face_widget}; # hack to force recreation of widget |
1228 | local $_->{face_widget}; # hack to force recreation of widget |
1115 | local $_->{desc_widget}; # hack to force recreation of widget |
1229 | local $_->{desc_widget}; # hack to force recreation of widget |
1116 | CFPlus::Item::update_widgets $_; |
1230 | DC::Item::update_widgets $_; |
1117 | |
1231 | |
1118 | push @add, |
1232 | push @add, |
1119 | 0, $row, $_->{face_widget}, |
1233 | 0, $row, $_->{face_widget}, |
1120 | 1, $row, $_->{desc_widget}; |
1234 | 1, $row, $_->{desc_widget}; |
1121 | |
1235 | |
1122 | $row++; |
1236 | $row++; |
1123 | } else { |
1237 | } else { |
1124 | push @add, 1, $row, new CFPlus::UI::Button |
1238 | push @add, 1, $row, new DC::UI::Button |
1125 | text => "More...", |
1239 | text => "More...", |
1126 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
1240 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
1127 | ; |
1241 | ; |
1128 | last; |
1242 | last; |
1129 | } |
1243 | } |
1130 | } |
1244 | } |
1131 | if ($::CONN->{open_container}) { |
1245 | if ($::CONN->{open_container}) { |
1132 | push @add, 1, $row++, new CFPlus::UI::Button |
1246 | push @add, 1, $row++, new DC::UI::Button |
1133 | text => "Close container", |
1247 | text => "Close container", |
1134 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
1248 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
1135 | ; |
1249 | ; |
1136 | } |
1250 | } |
1137 | |
1251 | |
1138 | $::FLOORBOX->add_at (@add); |
1252 | $::FLOORBOX->add_at (@add); |
1139 | }); |
1253 | }); |
1140 | |
1254 | |
1141 | $::WANT_REFRESH->start; |
1255 | $::WANT_REFRESH = 1; |
1142 | } |
1256 | } |
1143 | |
1257 | |
1144 | sub set_opencont { |
1258 | sub set_opencont { |
1145 | my ($conn, $tag, $name) = @_; |
1259 | my ($conn, $tag, $name) = @_; |
1146 | $conn->{open_container} = $tag; |
1260 | $conn->{open_container} = $tag; |
1147 | update_floorbox; |
1261 | update_floorbox; |
1148 | |
1262 | |
1149 | $::INVR_HB->clear (); |
1263 | $::INVR_HB->clear; |
1150 | $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
1264 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1151 | |
1265 | |
1152 | if ($tag != 0) { # Floor isn't closable, is it? |
1266 | if ($tag != 0) { # Floor isn't closable, is it? |
1153 | $::INVR_HB->add (new CFPlus::UI::Button |
1267 | $::INVR_HB->add (new DC::UI::Button |
1154 | text => "Close container", |
1268 | text => "Close container", |
1155 | tooltip => "Close the currently open container (if one is open)", |
1269 | tooltip => "Close the currently open container (if one is open)", |
1156 | on_activate => sub { |
1270 | on_activate => sub { |
1157 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1271 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1158 | if $tag != 0; |
1272 | if $tag != 0; |
… | |
… | |
1165 | } |
1279 | } |
1166 | |
1280 | |
1167 | sub update_containers { |
1281 | sub update_containers { |
1168 | my ($self) = @_; |
1282 | my ($self) = @_; |
1169 | |
1283 | |
1170 | $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
1284 | $DC::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
1171 | my $todo = delete $self->{update_container} |
1285 | my $todo = delete $self->{update_container} |
1172 | or return; |
1286 | or return; |
1173 | |
1287 | |
1174 | for my $tag (keys %$todo) { |
1288 | for my $tag (keys %$todo) { |
1175 | update_floorbox if $tag == 0 or $tag == $self->{open_container}; |
1289 | update_floorbox if $tag == 0 or $tag == $self->{open_container}; |
… | |
… | |
1210 | } |
1324 | } |
1211 | |
1325 | |
1212 | sub item_update { |
1326 | sub item_update { |
1213 | my ($self, $item) = @_; |
1327 | my ($self, $item) = @_; |
1214 | |
1328 | |
1215 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1329 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1216 | |
1330 | |
1217 | CFPlus::Item::update_widgets $item; |
1331 | DC::Item::update_widgets $item; |
1218 | |
1332 | |
1219 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1333 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1220 | set_opencont ($::CONN, 0, "Floor"); |
1334 | set_opencont ($::CONN, 0, "Floor"); |
1221 | |
1335 | |
1222 | } elsif ($item->{flags} & F_OPEN) { |
1336 | } elsif ($item->{flags} & F_OPEN) { |
1223 | set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); |
1337 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1224 | |
1338 | |
1225 | } else { |
1339 | } else { |
1226 | $self->{update_container}{$item->{container}}++; |
1340 | $self->{update_container}{$item->{container}}++; |
1227 | $self->update_containers; |
1341 | $self->update_containers; |
1228 | } |
1342 | } |
… | |
… | |
1239 | |
1353 | |
1240 | my $weight = .001 * $self->{player}{weight}; |
1354 | my $weight = .001 * $self->{player}{weight}; |
1241 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1355 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1242 | |
1356 | |
1243 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1357 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1244 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1358 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1245 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1359 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1246 | } |
1360 | } |
1247 | |
1361 | |
1248 | sub update_server_info { |
1362 | sub update_server_info { |
1249 | my ($self) = @_; |
1363 | my ($self) = @_; |
1250 | |
1364 | |
1251 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1365 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1252 | |
1366 | |
|
|
1367 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1368 | |
1253 | $::SERVER_INFO->set_markup ( |
1369 | $::SERVER_INFO->set_markup ( |
1254 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1370 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1255 | . "protocol version <tt>$self->{version}</tt>\n" |
1371 | . "protocol version <tt>$version</tt>\n" |
1256 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1257 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1258 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1259 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1372 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1260 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1261 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1262 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1373 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1263 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1374 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1264 | . "map size $self->{mapw}×$self->{maph}\n" |
1375 | . "map size $self->{mapw}×$self->{maph}\n" |
1265 | ); |
1376 | ); |
1266 | |
1377 | |
1267 | } |
1378 | } |
… | |
… | |
1287 | 0 |
1398 | 0 |
1288 | }); |
1399 | }); |
1289 | |
1400 | |
1290 | $self->update_server_info; |
1401 | $self->update_server_info; |
1291 | |
1402 | |
1292 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
1293 | $self->send_command ("output-count $::CFG->{output_count}"); |
|
|
1294 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1403 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1295 | $self->send_command ("pickup $::CFG->{pickup}"); |
1404 | $self->send_pickup ($::CFG->{pickup}); |
1296 | } |
1405 | } |
1297 | |
1406 | |
1298 | sub lookat { |
1407 | sub lookat { |
1299 | my ($self, $x, $y) = @_; |
1408 | my ($self, $x, $y) = @_; |
1300 | |
1409 | |
… | |
… | |
1302 | $self->send_ext_req (lookat => $x, $y, sub { |
1411 | $self->send_ext_req (lookat => $x, $y, sub { |
1303 | my (%msg) = @_; |
1412 | my (%msg) = @_; |
1304 | |
1413 | |
1305 | if (exists $msg{npc_dialog}) { |
1414 | if (exists $msg{npc_dialog}) { |
1306 | # start npc chat dialog |
1415 | # start npc chat dialog |
1307 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
1416 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1308 | token => $msg{npc_dialog}, |
1417 | token => $msg{npc_dialog}, |
1309 | title => "$msg{npc_dialog}[0] (NPC)", |
1418 | title => "$msg{npc_dialog}[0] (NPC)", |
1310 | conn => $self, |
1419 | conn => $self, |
1311 | ; |
1420 | ; |
1312 | } |
1421 | } |
… | |
… | |
1317 | } |
1426 | } |
1318 | |
1427 | |
1319 | sub destroy { |
1428 | sub destroy { |
1320 | my ($self) = @_; |
1429 | my ($self) = @_; |
1321 | |
1430 | |
1322 | (delete $self->{npc_dialog})->destroy |
1431 | $_->destroy |
1323 | if $self->{npc_dialog}; |
1432 | for values %{ $self->{w} }; |
1324 | |
1433 | |
1325 | $self->SUPER::destroy; |
1434 | $self->SUPER::destroy; |
1326 | |
1435 | |
1327 | %$self = (); |
1436 | %$self = (); |
1328 | } |
1437 | } |
1329 | |
1438 | |
1330 | package CFPlus::NPCDialog; |
1439 | package DC::NPCDialog; |
1331 | |
1440 | |
1332 | our @ISA = 'CFPlus::UI::Toplevel'; |
1441 | our @ISA = 'DC::UI::Toplevel'; |
1333 | |
1442 | |
1334 | sub new { |
1443 | sub new { |
1335 | my $class = shift; |
1444 | my $class = shift; |
1336 | |
1445 | |
1337 | my $self = $class->SUPER::new ( |
1446 | my $self = $class->SUPER::new ( |
… | |
… | |
1344 | kw => { hi => 0, yes => 0, no => 0 }, |
1453 | kw => { hi => 0, yes => 0, no => 0 }, |
1345 | has_close_button => 1, |
1454 | has_close_button => 1, |
1346 | @_, |
1455 | @_, |
1347 | ); |
1456 | ); |
1348 | |
1457 | |
1349 | CFPlus::weaken (my $this = $self); |
1458 | DC::weaken (my $this = $self); |
1350 | |
1459 | |
1351 | $self->connect (delete => sub { $this->destroy; 1 }); |
1460 | $self->connect (delete => sub { $this->destroy; 1 }); |
1352 | |
1461 | |
1353 | # better use a pane... |
1462 | # better use a pane... |
1354 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1463 | $self->add (my $hbox = new DC::UI::HBox); |
1355 | $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); |
1464 | $hbox->add ($self->{textview} = new DC::UI::TextScroller expand => 1); |
1356 | |
1465 | |
1357 | $hbox->add (my $vbox = new CFPlus::UI::VBox); |
1466 | $hbox->add (my $vbox = new DC::UI::VBox); |
1358 | |
1467 | |
1359 | $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); |
1468 | $vbox->add (new DC::UI::Label text => "Message Entry:"); |
1360 | $vbox->add ($self->{entry} = new CFPlus::UI::Entry |
1469 | $vbox->add ($self->{entry} = new DC::UI::Entry |
1361 | tooltip => "#npc_message_entry", |
1470 | tooltip => "#npc_message_entry", |
1362 | on_activate => sub { |
1471 | on_activate => sub { |
1363 | my ($entry, $text) = @_; |
1472 | my ($entry, $text) = @_; |
1364 | |
1473 | |
1365 | return unless $text =~ /\S/; |
1474 | return unless $text =~ /\S/; |
… | |
… | |
1369 | |
1478 | |
1370 | 0 |
1479 | 0 |
1371 | }, |
1480 | }, |
1372 | ); |
1481 | ); |
1373 | |
1482 | |
1374 | $vbox->add ($self->{options} = new CFPlus::UI::VBox); |
1483 | $vbox->add ($self->{options} = new DC::UI::VBox); |
1375 | |
1484 | |
1376 | $self->{bye_button} = new CFPlus::UI::Button |
1485 | $self->{bye_button} = new DC::UI::Button |
1377 | text => "Bye (close)", |
1486 | text => "Bye (close)", |
1378 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
1487 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
1379 | on_activate => sub { $this->destroy; 1 }, |
1488 | on_activate => sub { $this->destroy; 1 }, |
1380 | ; |
1489 | ; |
1381 | |
1490 | |
… | |
… | |
1400 | }; |
1509 | }; |
1401 | |
1510 | |
1402 | sub update_options { |
1511 | sub update_options { |
1403 | my ($self) = @_; |
1512 | my ($self) = @_; |
1404 | |
1513 | |
1405 | CFPlus::weaken $self; |
1514 | DC::weaken $self; |
1406 | |
1515 | |
1407 | $self->{options}->clear; |
1516 | $self->{options}->clear; |
1408 | $self->{options}->add ($self->{bye_button}); |
1517 | $self->{options}->add ($self->{bye_button}); |
1409 | |
1518 | |
1410 | for my $kw (sort keys %{ $self->{kw} }) { |
1519 | for my $kw (sort keys %{ $self->{kw} }) { |
1411 | $self->{options}->add (new CFPlus::UI::Button |
1520 | $self->{options}->add (new DC::UI::Button |
1412 | text => $kw, |
1521 | text => $kw, |
1413 | on_activate => sub { |
1522 | on_activate => sub { |
1414 | $self->send ($kw); |
1523 | $self->send ($kw); |
1415 | 0 |
1524 | 0 |
1416 | }, |
1525 | }, |
… | |
… | |
1419 | } |
1528 | } |
1420 | |
1529 | |
1421 | sub feed { |
1530 | sub feed { |
1422 | my ($self, $type, @arg) = @_; |
1531 | my ($self, $type, @arg) = @_; |
1423 | |
1532 | |
1424 | CFPlus::weaken $self; |
1533 | DC::weaken $self; |
1425 | |
1534 | |
1426 | if ($type eq "update") { |
1535 | if ($type eq "update") { |
1427 | my (%info) = @arg; |
1536 | my (%info) = @arg; |
1428 | |
1537 | |
1429 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1538 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1430 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1539 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1431 | |
1540 | |
1432 | if (exists $info{msg}) { |
1541 | if (exists $info{msg}) { |
1433 | my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; |
1542 | my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; |
1434 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1543 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1435 | my @link; |
1544 | my @link; |
1436 | $text =~ s{ |
1545 | $text =~ s{ |
1437 | ($match) |
1546 | ($match) |
1438 | }{ |
1547 | }{ |
1439 | my $kw = $1; |
1548 | my $kw = $1; |
1440 | |
1549 | |
1441 | push @link, new CFPlus::UI::Label |
1550 | push @link, new DC::UI::Label |
1442 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
1551 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
1443 | can_hover => 1, |
1552 | can_hover => 1, |
1444 | can_events => 1, |
1553 | can_events => 1, |
1445 | padding_x => 0, |
1554 | padding_x => 0, |
1446 | padding_y => 0, |
1555 | padding_y => 0, |
… | |
… | |
1464 | } |
1573 | } |
1465 | |
1574 | |
1466 | sub send { |
1575 | sub send { |
1467 | my ($self, $msg) = @_; |
1576 | my ($self, $msg) = @_; |
1468 | |
1577 | |
1469 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1578 | $self->{textview}->add_paragraph ({ |
|
|
1579 | markup => |
|
|
1580 | "\n<span foreground='#ffff00'><b>" |
|
|
1581 | . (DC::asxml $msg) |
|
|
1582 | . "</b></span>" |
|
|
1583 | }); |
1470 | $self->{textview}->scroll_to_bottom; |
1584 | $self->{textview}->scroll_to_bottom; |
1471 | |
1585 | |
1472 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1586 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1473 | } |
1587 | } |
1474 | |
1588 | |
… | |
… | |
1477 | |
1591 | |
1478 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1592 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1479 | |
1593 | |
1480 | if ($self->{conn}) { |
1594 | if ($self->{conn}) { |
1481 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1595 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1482 | delete $self->{conn}{npc_dialog}; |
1596 | delete $self->{conn}{w}{npc_dialog}; |
1483 | $self->{conn}->disconnect_ext ($self->{id}); |
1597 | $self->{conn}->disconnect_ext ($self->{id}); |
1484 | } |
1598 | } |
1485 | |
1599 | |
1486 | $self->SUPER::destroy; |
1600 | $self->SUPER::destroy; |
1487 | } |
1601 | } |