ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.111 by root, Mon Jul 2 02:58:51 2007 UTC vs.
Revision 1.207 by root, Sat Dec 20 19:45:50 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines