ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
Revision: 1.104
Committed: Mon Apr 23 19:22:24 2007 UTC (17 years, 1 month ago) by root
Branch: MAIN
Changes since 1.103: +2 -0 lines
Log Message:
!

File Contents

# User Rev Content
1 root 1.69 package CFPlus::Protocol;
2 root 1.1
3     use utf8;
4     use strict;
5    
6 root 1.2 use Crossfire::Protocol::Constants;
7    
8 root 1.69 use CFPlus;
9 root 1.96 use CFPlus::DB;
10 root 1.69 use CFPlus::UI;
11     use CFPlus::Pod;
12 root 1.91 use CFPlus::Macro;
13     use CFPlus::Item;
14 root 1.1
15 root 1.87 use Crossfire::Protocol::Base 0.95;
16    
17 root 1.1 use base 'Crossfire::Protocol::Base';
18    
19     sub new {
20 root 1.101 my ($class, %arg) = @_;
21 root 1.1
22 root 1.101 my $self = $class->SUPER::new (%arg,
23 root 1.99 setup_req => {
24 root 1.101 extmap => 1,
25 root 1.103 excmd => 1,
26 root 1.101 %{$arg{setup_req} || {}},
27 root 1.99 },
28     );
29 root 1.1
30     $self->{map_widget}->clr_commands;
31    
32 root 1.72 my @cmd_help = map {
33     $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
34     or die "unparseable command help: $_->{kw}[0]";
35    
36     my $cmd = $1;
37     my @args = split /\|/, $2;
38     @args = (".*") unless @args;
39    
40     my (undef, @par) = CFPlus::Pod::section_of $_;
41     my $text = CFPlus::Pod::as_label @par;
42    
43     $_ = $_ eq ".*" ? "" : " $_"
44     for @args;
45    
46     map ["$cmd$_", $text],
47     sort { (length $a) <=> (length $b) }
48     @args
49 root 1.96 } sort { $a->{par} <=> $b->{par} }
50     CFPlus::Pod::find command => "*";
51 root 1.1
52 root 1.96 $self->connect_ext (event_capabilities => sub {
53     my ($cap) = @_;
54 root 1.95
55 root 1.96 if (my $ts = $cap->{tileset}) {
56     if (my ($default) = grep $_->[2] & 1, @$ts) {
57     $self->{tileset} = $default;
58     $self->{tilesize} = $default->[3];
59     $self->setup_req (tileset => $default->[0]);
60 root 1.95
61 root 1.96 my $w = int $self->{mapw} * 32 / $self->{tilesize};
62     my $h = int $self->{maph} * 32 / $self->{tilesize};
63 root 1.1
64 root 1.96 $self->setup_req (mapsize => "${w}x${h}");
65     }
66     }
67     });
68    
69     $self->{map_widget}->add_command (@$_)
70     for @cmd_help;
71 root 1.1
72 root 1.83 {
73     $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
74     CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
75     $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
76     }
77    
78 root 1.96 {
79     $self->{noface} = my $tex = new_from_file CFPlus::Texture
80     CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
81     $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
82     }
83    
84 root 1.1 $self->{open_container} = 0;
85    
86     # per server
87 root 1.96 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
88 root 1.1
89     $self
90     }
91    
92 elmex 1.34 sub logprint {
93     my ($self, @a) = @_;
94    
95 root 1.59 $self->{log_fh} ||= do {
96     my $path = "$Crossfire::VARDIR/log.$self->{host}";
97    
98     open my $fh, ">>:utf8", $path
99     or die "Couldn't open logfile $path: $!";
100 elmex 1.34
101 root 1.59 $fh->autoflush (1);
102    
103     $fh;
104     };
105 elmex 1.34
106 root 1.59 my ($sec, $min, $hour, $mday, $mon, $year) = localtime time;
107 elmex 1.34
108     my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d",
109     $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
110    
111 root 1.59 print {$self->{log_fh}} "$ts ", @a, "\n";
112 elmex 1.34 }
113    
114 root 1.52 sub _stat_numdiff {
115 root 1.54 my ($self, $name, $old, $new) = @_;
116 root 1.52
117     my $diff = $new - $old;
118 root 1.54
119     $diff = 0.01 * int $diff * 100;
120    
121     0.1 >= abs $diff ? ()
122     : $diff < 0 ? "$name$diff" : "$name+$diff"
123 root 1.52 }
124    
125     sub _stat_skillmaskdiff {
126 root 1.54 my ($self, $name, $old, $new) = @_;
127 root 1.52
128 root 1.54 my $diff = $old ^ $new
129     or return;
130 root 1.52
131 root 1.53 my @diff = map
132     {
133     $diff & $_
134     ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
135     : ()
136     }
137     sort { $a <=> $b } keys %{$self->{spell_paths}};
138 root 1.52
139     join "", @diff
140     }
141    
142     # all stats that are chacked against changes
143     my @statchange = (
144     [&CS_STAT_STR => \&_stat_numdiff, "Str"],
145     [&CS_STAT_INT => \&_stat_numdiff, "Int"],
146     [&CS_STAT_WIS => \&_stat_numdiff, "Wis"],
147     [&CS_STAT_DEX => \&_stat_numdiff, "Dex"],
148     [&CS_STAT_CON => \&_stat_numdiff, "Con"],
149     [&CS_STAT_CHA => \&_stat_numdiff, "Cha"],
150     [&CS_STAT_POW => \&_stat_numdiff, "Pow"],
151     [&CS_STAT_WC => \&_stat_numdiff, "Wc"],
152     [&CS_STAT_AC => \&_stat_numdiff, "Ac"],
153     [&CS_STAT_DAM => \&_stat_numdiff, "Dam"],
154     [&CS_STAT_SPEED => \&_stat_numdiff, "Speed"],
155     [&CS_STAT_WEAP_SP => \&_stat_numdiff, "WSp"],
156     [&CS_STAT_MAXHP => \&_stat_numdiff, "HP"],
157     [&CS_STAT_MAXSP => \&_stat_numdiff, "Mana"],
158     [&CS_STAT_MAXGRACE => \&_stat_numdiff, "Grace"],
159     [&CS_STAT_WEIGHT_LIM => \&_stat_numdiff, "Weight"],
160     [&CS_STAT_SPELL_ATTUNE => \&_stat_skillmaskdiff, "attuned"],
161     [&CS_STAT_SPELL_REPEL => \&_stat_skillmaskdiff, "repelled"],
162     [&CS_STAT_SPELL_DENY => \&_stat_skillmaskdiff, "denied"],
163     [&CS_STAT_RES_PHYS => \&_stat_numdiff, "phys"],
164     [&CS_STAT_RES_MAG => \&_stat_numdiff, "magic"],
165     [&CS_STAT_RES_FIRE => \&_stat_numdiff, "fire"],
166     [&CS_STAT_RES_ELEC => \&_stat_numdiff, "electricity"],
167     [&CS_STAT_RES_COLD => \&_stat_numdiff, "cold"],
168     [&CS_STAT_RES_CONF => \&_stat_numdiff, "confusion"],
169     [&CS_STAT_RES_ACID => \&_stat_numdiff, "acid"],
170     [&CS_STAT_RES_DRAIN => \&_stat_numdiff, "drain"],
171     [&CS_STAT_RES_GHOSTHIT => \&_stat_numdiff, "ghosthit"],
172     [&CS_STAT_RES_POISON => \&_stat_numdiff, "poison"],
173     [&CS_STAT_RES_SLOW => \&_stat_numdiff, "slow"],
174     [&CS_STAT_RES_PARA => \&_stat_numdiff, "paralyse"],
175     [&CS_STAT_TURN_UNDEAD => \&_stat_numdiff, "turnundead"],
176     [&CS_STAT_RES_FEAR => \&_stat_numdiff, "fear"],
177     [&CS_STAT_RES_DEPLETE => \&_stat_numdiff, "depletion"],
178     [&CS_STAT_RES_DEATH => \&_stat_numdiff, "death"],
179     [&CS_STAT_RES_HOLYWORD => \&_stat_numdiff, "godpower"],
180     [&CS_STAT_RES_BLIND => \&_stat_numdiff, "blind"],
181     );
182    
183 root 1.1 sub stats_update {
184     my ($self, $stats) = @_;
185    
186 root 1.59 my $prev = $self->{prev_stats} || { };
187    
188     if (my @diffs =
189     (
190     ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
191     map {
192     $stats->{$_} && $prev->{$_}
193     && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
194     } sort { $a <=> $b } keys %{$self->{skill_info}}
195     )
196     ) {
197     my $msg = join " ", @diffs;
198     $self->{statusbox}->add ($msg, group => "experience $msg", fg => [0.5, 1, 0.5, 0.8], timeout => 5);
199     }
200    
201     if (
202     my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
203     ) {
204     my $msg = "<b>stat change</b>: " . (join " ", @diffs);
205     $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 10);
206     }
207    
208     $self->update_stats_window ($stats, $prev);
209    
210     $self->{prev_stats} = { %$stats };
211     }
212    
213     my %RES_TBL = (
214     phys => CS_STAT_RES_PHYS,
215     magic => CS_STAT_RES_MAG,
216     fire => CS_STAT_RES_FIRE,
217     elec => CS_STAT_RES_ELEC,
218     cold => CS_STAT_RES_COLD,
219     conf => CS_STAT_RES_CONF,
220     acid => CS_STAT_RES_ACID,
221     drain => CS_STAT_RES_DRAIN,
222     ghit => CS_STAT_RES_GHOSTHIT,
223     pois => CS_STAT_RES_POISON,
224     slow => CS_STAT_RES_SLOW,
225     para => CS_STAT_RES_PARA,
226     tund => CS_STAT_TURN_UNDEAD,
227     fear => CS_STAT_RES_FEAR,
228     depl => CS_STAT_RES_DEPLETE,
229     deat => CS_STAT_RES_DEATH,
230     holyw => CS_STAT_RES_HOLYWORD,
231     blind => CS_STAT_RES_BLIND,
232     );
233    
234     sub update_stats_window {
235     my ($self, $stats, $prev) = @_;
236    
237     # I love text protocols...
238 root 1.52
239 root 1.59 my $hp = $stats->{+CS_STAT_HP} * 1;
240     my $hp_m = $stats->{+CS_STAT_MAXHP} * 1;
241     my $sp = $stats->{+CS_STAT_SP} * 1;
242     my $sp_m = $stats->{+CS_STAT_MAXSP} * 1;
243     my $fo = $stats->{+CS_STAT_FOOD} * 1;
244     my $fo_m = 999;
245     my $gr = $stats->{+CS_STAT_GRACE} * 1;
246     my $gr_m = $stats->{+CS_STAT_MAXGRACE} * 1;
247    
248     $::GAUGES->{hp} ->set_value ($hp, $hp_m);
249     $::GAUGES->{mana} ->set_value ($sp, $sp_m);
250     $::GAUGES->{food} ->set_value ($fo, $fo_m);
251     $::GAUGES->{grace} ->set_value ($gr, $gr_m);
252     $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
253     . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
254     my $rng = $stats->{+CS_STAT_RANGE};
255     $rng =~ s/^Range: //; # thank you so much dear server
256     $::GAUGES->{range} ->set_text ("Rng: " . $rng);
257     my $title = $stats->{+CS_STAT_TITLE};
258     $title =~ s/^Player: //;
259     $::STATWIDS->{title} ->set_text ("Title: " . $title);
260    
261     $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
262     $::STATWIDS->{st_dex} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DEX});
263     $::STATWIDS->{st_con} ->set_text (sprintf "%d" , $stats->{+CS_STAT_CON});
264     $::STATWIDS->{st_int} ->set_text (sprintf "%d" , $stats->{+CS_STAT_INT});
265     $::STATWIDS->{st_wis} ->set_text (sprintf "%d" , $stats->{+CS_STAT_WIS});
266     $::STATWIDS->{st_pow} ->set_text (sprintf "%d" , $stats->{+CS_STAT_POW});
267     $::STATWIDS->{st_cha} ->set_text (sprintf "%d" , $stats->{+CS_STAT_CHA});
268     $::STATWIDS->{st_wc} ->set_text (sprintf "%d" , $stats->{+CS_STAT_WC});
269     $::STATWIDS->{st_ac} ->set_text (sprintf "%d" , $stats->{+CS_STAT_AC});
270     $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM});
271     $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS});
272     $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
273     $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
274    
275 root 1.64 $self->update_weight;
276 root 1.59
277     $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}})
278     for keys %RES_TBL;
279    
280     my $sktbl = $::STATWIDS->{skill_tbl};
281     my @skills = keys %{ $self->{skill_info} };
282    
283     if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) {
284     $sktbl->clear;
285    
286 root 1.69 $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1);
287     $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1);
288     $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1);
289     $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1);
290     $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1);
291     $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1);
292 root 1.59
293 elmex 1.68 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
294    
295     my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
296     my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
297    
298 root 1.65 my ($x, $y) = (0, 1);
299 root 1.59 for (
300     sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] }
301     map [$_, $self->{skill_info}{$_}],
302     grep exists $stats->{$_},
303     @skills
304 root 1.52 ) {
305 root 1.59 my ($idx, $name) = @$_;
306    
307 elmex 1.68 my $spell_cb = sub {
308     my ($widget, $ev) = @_;
309    
310     if ($ev->{button} == 1) {
311     $::CONN->user_send ("ready_skill $name");
312     } elsif ($ev->{button} == 2) {
313     $::CONN->user_send ("use_skill $name");
314     } elsif ($ev->{button} == 3) {
315 root 1.90 my $shortname = CFPlus::shorten $name, 14;
316 root 1.69 (new CFPlus::UI::Menu
317 elmex 1.68 items => [
318 root 1.91 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }],
319     ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
320 elmex 1.68 ],
321     )->popup ($ev);
322     } else {
323     return 0;
324     }
325    
326     1
327     };
328    
329 root 1.69 $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label
330 elmex 1.68 text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP);
331 root 1.69 $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label
332 elmex 1.68 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL);
333 root 1.74 $sktbl->add ($x * 3 + 2, $y, new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
334     can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL);
335 root 1.59
336     $x++ and ($x, $y) = (0, $y + 1);
337 root 1.52 }
338 root 1.1 }
339    
340 root 1.59 for (grep exists $stats->{$_}, @skills) {
341     $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
342     $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
343     }
344 root 1.1 }
345    
346 root 1.91 sub macro_send {
347     my ($self, $macro) = @_;
348    
349     for my $cmd (@{ $macro->{action} }) {
350     $self->send_command ($cmd);
351     }
352     }
353    
354 root 1.1 sub user_send {
355     my ($self, $command) = @_;
356    
357 root 1.91 $self->{record}->($command)
358 root 1.87 if $self->{record};
359 elmex 1.9
360 elmex 1.34 $self->logprint ("send: ", $command);
361 root 1.1 $self->send_command ($command);
362 root 1.45 ::status ($command);
363 root 1.1 }
364    
365 root 1.91 sub record {
366     my ($self, $cb) = @_;
367 elmex 1.9
368 root 1.91 $self->{record} = $cb;
369 elmex 1.9 }
370    
371 root 1.1 sub map_scroll {
372     my ($self, $dx, $dy) = @_;
373    
374     $self->{map}->scroll ($dx, $dy);
375     }
376    
377     sub feed_map1a {
378     my ($self, $data) = @_;
379    
380 root 1.79 $self->{map}->map1a_update ($data, $self->{setup}{extmap});
381 root 1.1 $self->{map_widget}->update;
382     }
383    
384 root 1.36 sub magicmap {
385     my ($self, $w, $h, $x, $y, $data) = @_;
386    
387     $self->{map_widget}->set_magicmap ($w, $h, $x, $y, $data);
388     }
389    
390 root 1.1 sub flush_map {
391     my ($self) = @_;
392    
393     my $map_info = delete $self->{map_info}
394     or return;
395    
396     my ($hash, $x, $y, $w, $h) = @$map_info;
397    
398     my $data = $self->{map}->get_rect ($x, $y, $w, $h);
399 root 1.96 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { };
400 root 1.1 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
401     }
402    
403     sub map_clear {
404     my ($self) = @_;
405    
406     $self->flush_map;
407     delete $self->{neigh_map};
408    
409     $self->{map}->clear;
410 root 1.37 delete $self->{map_widget}{magicmap};
411 root 1.1 }
412    
413 root 1.97 sub bg_fetch {
414     my ($self) = @_;
415    
416     my $id;
417    
418     do {
419     $id = pop @{$self->{bg_fetch}}
420     or return;
421     } while $self->{texture}[$id];
422    
423     CFPlus::DB::get tilecache => $id, sub {
424     my ($data) = @_;
425    
426 root 1.98 return unless $self->{map}; # stop when destroyed
427    
428 root 1.97 $self->set_texture ($id => $data)
429     if defined $data;
430    
431     $self->bg_fetch;
432     };
433     }
434 root 1.1
435     sub load_map($$$) {
436     my ($self, $hash, $x, $y) = @_;
437    
438 root 1.100 my $gen = $self->{map_change_gen};
439    
440 root 1.96 CFPlus::DB::get $self->{mapcache} => $hash, sub {
441 root 1.100 return unless $gen == $self->{map_change_gen};
442    
443 root 1.96 my ($data) = @_;
444    
445     if (defined $data) {
446     $data = Compress::LZF::decompress $data;
447     #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
448 root 1.1
449 root 1.97 my $inprogress = @{ $self->{bg_fetch} || [] };
450 root 1.98 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
451 root 1.97 $self->bg_fetch unless $inprogress;
452 root 1.1 }
453 root 1.96 };
454 root 1.1 }
455    
456     # hardcode /world/world_xxx_xxx map names, the savings are enourmous,
457     # (server resource,s latency, bandwidth), so this hack is warranted.
458     # the right fix is to make real tiled maps with an overview file
459     sub send_mapinfo {
460     my ($self, $data, $cb) = @_;
461    
462     if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
463     my ($wx, $wy) = ($1, $2);
464    
465     if ($data =~ /^spatial ([1-4]+)$/) {
466     my @dx = (0, 0, 1, 0, -1);
467     my @dy = (0, -1, 0, 1, 0);
468     my ($dx, $dy);
469    
470     for (split //, $1) {
471     $dx += $dx[$_];
472     $dy += $dy[$_];
473     }
474    
475     $cb->(spatial => 15,
476     $self->{map_info}[1] - $self->{map}->ox + $dx * 50,
477     $self->{map_info}[2] - $self->{map}->oy + $dy * 50,
478     50, 50,
479     sprintf "/world/world_%03d_%03d", $wx + $dx, $wy + $dy
480     );
481    
482     return;
483     }
484     }
485    
486     $self->SUPER::send_mapinfo ($data, $cb);
487     }
488    
489     # this method does a "flood fill" into every tile direction
490     # it assumes that tiles are arranged in a rectangular grid,
491     # i.e. a map is the same as the left of the right map etc.
492     # failure to comply are harmless and result in display errors
493     # at worst.
494     sub flood_fill {
495     my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
496    
497     # the server does not allow map paths > 6
498     return if 7 <= length $path;
499    
500     my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
501    
502     for (
503     [1, 3, 0, -1],
504     [2, 4, 1, 0],
505     [3, 1, 0, 1],
506     [4, 2, -1, 0],
507     ) {
508     my ($tile, $tile2, $dx, $dy) = @$_;
509    
510     next if $block & (1 << $tile);
511     my $block = $block | (1 << $tile2);
512    
513     my $gx = $gx + $dx;
514     my $gy = $gy + $dy;
515    
516     next unless $flags & (1 << ($tile - 1));
517     next if $self->{neigh_grid}{$gx, $gy}++;
518    
519     my $neigh = $self->{neigh_map}{$hash} ||= [];
520     if (my $info = $neigh->[$tile]) {
521     my ($flags, $x, $y, $w, $h, $hash) = @$info;
522    
523     $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
524     if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
525    
526     } else {
527 root 1.100 my $gen = $self->{map_change_gen};
528 root 1.1 $self->send_mapinfo ("spatial $path$tile", sub {
529 root 1.100 return unless $gen == $self->{map_change_gen};
530    
531 root 1.1 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
532    
533     return if $mode ne "spatial";
534    
535     $x += $self->{map}->ox;
536     $y += $self->{map}->oy;
537    
538     $self->load_map ($hash, $x, $y)
539     unless $self->{neigh_map}{$hash}[5]++;#d#
540    
541     $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
542    
543     $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
544     if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
545     });
546     }
547     }
548     }
549    
550     sub map_change {
551     my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
552    
553     $self->flush_map;
554    
555 root 1.100 ++$self->{map_change_gen};
556    
557 root 1.1 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
558    
559     my $mapmapw = $self->{mapmap}->{w};
560     my $mapmaph = $self->{mapmap}->{h};
561    
562     $self->{neigh_rect} = [
563     $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
564     $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
565     ];
566    
567     delete $self->{neigh_grid};
568    
569     $x += $ox;
570     $y += $oy;
571    
572     $self->{map_info} = [$hash, $x, $y, $w, $h];
573    
574     (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
575     $::STATWIDS->{map}->set_text ("Map: " . $map);
576    
577     $self->load_map ($hash, $x, $y);
578     $self->flood_fill (0, 0, 0, "", $hash, $flags);
579     }
580    
581     sub face_find {
582 root 1.96 my ($self, $facenum, $face, $cb) = @_;
583 root 1.1
584     my $hash = "$face->{chksum},$face->{name}";
585    
586 root 1.96 my $id = CFPlus::DB::get_tile_id_sync $hash;
587 root 1.1
588 root 1.96 $face->{id} = $id;
589     $self->{faceid}[$facenum] = $id;
590 root 1.1
591 root 1.96 $self->{map}->set_tileid ($facenum => $id);
592 root 1.1
593 root 1.96 CFPlus::DB::get tilecache => $id, $cb;
594 root 1.1 }
595    
596     sub face_update {
597 root 1.58 my ($self, $facenum, $face, $changed) = @_;
598 root 1.1
599 root 1.96 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { }
600     if $changed;
601 root 1.1
602     $self->set_texture ($face->{id} => delete $face->{image});
603     }
604    
605 root 1.99 sub smooth_update {
606     my ($self, $facenum, $face) = @_;
607    
608     $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
609     }
610    
611 root 1.1 sub set_texture {
612     my ($self, $id, $data) = @_;
613    
614 root 1.98 $self->{texture}[$id] = my $tex =
615     new_from_image CFPlus::Texture
616     $data, minify => 1, mipmap => 1;
617 root 1.1
618 root 1.98 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
619     $self->{map_widget}->update;
620 root 1.1 }
621    
622     sub sound_play {
623     my ($self, $x, $y, $soundnum, $type) = @_;
624    
625     $self->{sound_play}->($x, $y, $soundnum, $type);
626     }
627    
628     my $LAST_QUERY; # server is stupid, stupid, stupid
629    
630     sub query {
631     my ($self, $flags, $prompt) = @_;
632    
633     $prompt = $LAST_QUERY unless length $prompt;
634     $LAST_QUERY = $prompt;
635    
636 root 1.22 $self->{query}-> ($self, $flags, $prompt);
637 root 1.1 }
638    
639 root 1.103 our @CF_COLOR = (
640     [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
641     [1.00, 1.00, 1.00],
642     [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
643     [1.00, 0.00, 0.00],
644     [1.00, 0.54, 0.00],
645     [0.11, 0.56, 1.00],
646     [0.93, 0.46, 0.00],
647     [0.18, 0.54, 0.34],
648     [0.56, 0.73, 0.56],
649     [0.80, 0.80, 0.80],
650     [0.75, 0.61, 0.20],
651     [0.99, 0.77, 0.26],
652     [0.74, 0.65, 0.41],
653     );
654    
655 root 1.1 sub drawinfo {
656     my ($self, $color, $text) = @_;
657    
658 root 1.103 my $fg = $CF_COLOR[$color % @CF_COLOR];
659 root 1.93
660 elmex 1.34 $self->logprint ("info: ", $text);
661    
662 root 1.102 ## try to create single paragraphs of multiple lines sent by the server
663     # no longer neecssary with TRT servers
664     #$text =~ s/(?<=\S)\n(?=\w)/ /g;
665 root 1.23
666 root 1.69 $text = CFPlus::asxml $text;
667 root 1.1 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
668     $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
669    
670 root 1.93 ::message ({ fg => $fg, markup => $_ })
671 root 1.86 for split /\n/, $text;
672 root 1.1
673 elmex 1.5 $self->{statusbox}->add ($text,
674 root 1.1 group => $text,
675 root 1.93 fg => $fg,
676 root 1.71 timeout => $color >= 2 ? 180 : 10,
677 root 1.1 tooltip_font => $::FONT_FIXED,
678     );
679     }
680    
681     sub drawextinfo {
682     my ($self, $color, $type, $subtype, $message) = @_;
683    
684     $self->drawinfo ($color, $message);
685     }
686    
687     sub spell_add {
688     my ($self, $spell) = @_;
689    
690 root 1.66 # try to create single paragraphs out of the multiple lines sent by the server
691 root 1.27 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
692     $spell->{message} =~ s/\n+$//;
693     $spell->{message} ||= "Server did not provide a description for this spell.";
694    
695 root 1.88 $::SPELL_LIST->add_spell ($spell);
696 elmex 1.14
697 root 1.69 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message});
698     $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
699 root 1.1 }
700    
701     sub spell_delete {
702     my ($self, $spell) = @_;
703 root 1.51
704 root 1.88 $::SPELL_LIST->remove_spell ($spell);
705 root 1.1 }
706    
707 root 1.87 sub setup {
708     my ($self, $setup) = @_;
709    
710 root 1.95 $self->{map_widget}->set_tilesize ($self->{tilesize});
711 root 1.87 $::MAP->resize ($self->{mapw}, $self->{maph});
712     }
713    
714 root 1.1 sub addme_success {
715     my ($self) = @_;
716    
717 root 1.72 my %skill_help;
718 root 1.21
719 root 1.72 for my $node (CFPlus::Pod::find skill_description => "*") {
720     my (undef, @par) = CFPlus::Pod::section_of $node;
721     $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par;
722 root 1.21 };
723 root 1.72
724 root 1.1 for my $skill (values %{$self->{skill_info}}) {
725     $self->{map_widget}->add_command ("ready_skill $skill",
726 root 1.69 (CFPlus::asxml "Ready the skill '$skill'\n\n")
727 root 1.72 . $skill_help{$skill});
728 root 1.1 $self->{map_widget}->add_command ("use_skill $skill",
729 root 1.69 (CFPlus::asxml "Immediately use the skill '$skill'\n\n")
730 root 1.72 . $skill_help{$skill});
731 root 1.1 }
732     }
733    
734     sub eof {
735     my ($self) = @_;
736    
737     $self->{map_widget}->clr_commands;
738    
739     ::stop_game ();
740     }
741    
742     sub image_info {
743     my ($self, $numfaces) = @_;
744    
745     $self->{num_faces} = $numfaces;
746     $self->{face_prefetch} = [1 .. $numfaces];
747     $self->face_prefetch;
748     }
749    
750     sub face_prefetch {
751     my ($self) = @_;
752    
753     return unless $::CFG->{face_prefetch};
754    
755     if ($self->{num_faces}) {
756     return if @{ $self->{send_queue} || [] };
757     my $todo = @{ $self->{face_prefetch} }
758     or return;
759    
760     my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
761    
762     $self->send ("requestinfo image_sums $face $face");
763    
764 root 1.69 $self->{statusbox}->add (CFPlus::asxml "prefetching $todo",
765 root 1.19 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
766 root 1.1 } elsif (!exists $self->{num_faces}) {
767     $self->send ("requestinfo image_info");
768    
769     $self->{num_faces} = 0;
770    
771 root 1.69 $self->{statusbox}->add (CFPlus::asxml "starting to prefetch",
772 root 1.19 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
773 root 1.1 }
774     }
775    
776     sub update_floorbox {
777 root 1.69 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
778 root 1.1 return unless $::CONN;
779 elmex 1.62
780 root 1.1 $::FLOORBOX->clear;
781    
782     my $row;
783 elmex 1.62 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
784 root 1.25 if ($row < 6) {
785 root 1.1 local $_->{face_widget}; # hack to force recreation of widget
786     local $_->{desc_widget}; # hack to force recreation of widget
787 root 1.69 CFPlus::Item::update_widgets $_;
788 root 1.1
789     $::FLOORBOX->add (0, $row, $_->{face_widget});
790     $::FLOORBOX->add (1, $row, $_->{desc_widget});
791    
792     $row++;
793     } else {
794 root 1.69 $::FLOORBOX->add (1, $row, new CFPlus::UI::Button
795 root 1.30 text => "More...",
796 root 1.51 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
797 root 1.25 );
798 root 1.1 last;
799     }
800     }
801 elmex 1.62 if ($::CONN->{open_container}) {
802 root 1.69 $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button
803 elmex 1.62 text => "Close container",
804     on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
805     );
806     }
807 root 1.1 });
808 elmex 1.62
809 root 1.1 $::WANT_REFRESH++;
810     }
811    
812     sub set_opencont {
813     my ($conn, $tag, $name) = @_;
814     $conn->{open_container} = $tag;
815 elmex 1.62 update_floorbox;
816 elmex 1.10
817     $::INV_RIGHT_HB->clear ();
818 root 1.69 $::INV_RIGHT_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name);
819 elmex 1.10
820     if ($tag != 0) { # Floor isn't closable, is it?
821 root 1.69 $::INV_RIGHT_HB->add (new CFPlus::UI::Button
822 elmex 1.10 text => "Close container",
823     tooltip => "Close the currently open container (if one is open)",
824     on_activate => sub {
825     $::CONN->send ("apply $tag") # $::CONN->{open_container}")
826     if $tag != 0;
827     #if $CONN->{open_container} != 0;
828 root 1.38 0
829 elmex 1.10 },
830     );
831     }
832    
833 root 1.1 $::INVR->set_items ($conn->{container}{$tag});
834     }
835    
836 root 1.47 sub update_containers {
837     my ($self) = @_;
838 root 1.1
839 root 1.69 $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub {
840 root 1.55 my $todo = delete $self->{update_container}
841     or return;
842    
843     for my $tag (keys %$todo) {
844 elmex 1.62 update_floorbox if $tag == 0 or $tag == $self->{open_container};
845 root 1.47 if ($tag == 0) {
846 root 1.48 $::INVR->set_items ($self->{container}{0})
847     if $tag == $self->{open_container};
848 root 1.47 } elsif ($tag == $self->{player}{tag}) {
849     $::INV->set_items ($self->{container}{$tag})
850     } else {
851 root 1.48 $::INVR->set_items ($self->{container}{$tag})
852     if $tag == $self->{open_container};
853 root 1.47 }
854     }
855     });
856 root 1.1 }
857    
858 root 1.48 sub container_add {
859     my ($self, $tag, $items) = @_;
860    
861     $self->{update_container}{$tag}++;
862     $self->update_containers;
863     }
864    
865 root 1.1 sub container_clear {
866     my ($self, $tag) = @_;
867    
868 root 1.47 $self->{update_container}{$tag}++;
869     $self->update_containers;
870 root 1.1 }
871    
872     sub item_delete {
873     my ($self, @items) = @_;
874    
875 root 1.49 $self->{update_container}{$_->{container}}++
876 root 1.47 for @items;
877    
878     $self->update_containers;
879 root 1.1 }
880    
881     sub item_update {
882     my ($self, $item) = @_;
883    
884     #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n";
885    
886 root 1.69 CFPlus::Item::update_widgets $item;
887 root 1.1
888 root 1.2 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
889 root 1.1 set_opencont ($::CONN, 0, "Floor");
890    
891 root 1.2 } elsif ($item->{flags} & F_OPEN) {
892 root 1.69 set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item);
893 root 1.47
894 root 1.1 } else {
895 root 1.47 $self->{update_container}{$item->{container}}++;
896     $self->update_containers;
897 root 1.1 }
898     }
899    
900 elmex 1.3 sub player_update {
901     my ($self, $player) = @_;
902 root 1.64
903     $self->update_weight;
904     }
905    
906     sub update_weight {
907     my ($self) = @_;
908    
909     my $weight = .001 * $self->{player}{weight};
910     my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
911    
912     $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight);
913     $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit);
914     $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit);
915 root 1.28 }
916    
917 root 1.32 sub update_server_info {
918     my ($self) = @_;
919    
920     my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
921    
922     $::SERVER_INFO->set_markup (
923     "server <tt>$self->{host}:$self->{port}</tt>\n"
924     . "protocol version <tt>$self->{version}</tt>\n"
925     . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
926     . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
927 root 1.104 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
928 root 1.86 . "editing support $yesno[!!$self->{editor_support}]\n"
929 root 1.80 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
930 root 1.104 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
931 root 1.32 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
932     . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
933     . "map size $self->{mapw}×$self->{maph}\n"
934     );
935 elmex 1.89
936     ::setup_build_button ($self->{editor_support}->{builder_ui});
937 root 1.32 }
938    
939 root 1.28 sub logged_in {
940     my ($self) = @_;
941    
942 root 1.70 $self->send_ext_req (cfplus_support => version => 1, sub {
943     $self->{cfplus_ext} = $_[0]{version};
944 root 1.32 $self->update_server_info;
945 root 1.70
946 root 1.85 if ($self->{cfplus_ext} >= 2) {
947     $self->send_ext_req ("editor_support", sub {
948 root 1.86 $self->{editor_support} = $_[0];
949 root 1.85 $self->update_server_info;
950    
951     0
952     });
953     }
954    
955 root 1.70 0
956 root 1.32 });
957 root 1.31
958 root 1.32 $self->update_server_info;
959 root 1.13
960     $self->send_command ("output-sync $::CFG->{output_sync}");
961     $self->send_command ("output-count $::CFG->{output_count}");
962 root 1.94 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
963 root 1.29 $self->send_command ("pickup $::CFG->{pickup}");
964 elmex 1.3 }
965    
966 elmex 1.89 sub buildat {
967     my ($self, $builditem, $x, $y) = @_;
968    
969     if ($self->{cfplus_ext}) {
970     $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
971     }
972     }
973    
974 root 1.32 sub lookat {
975     my ($self, $x, $y) = @_;
976    
977     if ($self->{cfplus_ext}) {
978 root 1.70 $self->send_ext_req (lookat => dx => $x, dy => $y, sub {
979     my ($msg) = @_;
980 root 1.32
981 root 1.70 if (exists $msg->{npc_dialog}) {
982 root 1.32 # start npc chat dialog
983 root 1.69 $self->{npc_dialog} = new CFPlus::NPCDialog::
984 root 1.32 dx => $x,
985     dy => $y,
986 root 1.70 title => "$msg->{npc_dialog} (NPC)",
987 root 1.32 conn => $self,
988     ;
989     }
990     });
991     }
992    
993     $self->send ("lookat $x $y");
994     }
995    
996     sub destroy {
997     my ($self) = @_;
998    
999 root 1.79 (delete $self->{npc_dialog})->destroy
1000 root 1.32 if $self->{npc_dialog};
1001    
1002     $self->SUPER::destroy;
1003     }
1004    
1005 root 1.69 package CFPlus::NPCDialog;
1006 root 1.32
1007 root 1.76 our @ISA = 'CFPlus::UI::Toplevel';
1008 root 1.32
1009     sub new {
1010     my $class = shift;
1011    
1012     my $self = $class->SUPER::new (
1013     x => 'center',
1014     y => 'center',
1015     name => "npc_dialog",
1016     force_w => $::WIDTH * 0.7,
1017     force_h => $::HEIGHT * 0.7,
1018     title => "NPC Dialog",
1019     kw => { hi => 0, yes => 0, no => 0 },
1020 root 1.64 has_close_button => 1,
1021 root 1.32 @_,
1022     );
1023    
1024 root 1.92 CFPlus::weaken (my $this = $self);
1025 root 1.32
1026 root 1.64 $self->connect (delete => sub { $this->destroy; 1 });
1027    
1028 root 1.32 # better use a pane...
1029 root 1.69 $self->add (my $hbox = new CFPlus::UI::HBox);
1030     $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1);
1031 root 1.32
1032 root 1.69 $hbox->add (my $vbox = new CFPlus::UI::VBox);
1033 root 1.32
1034 root 1.69 $vbox->add (new CFPlus::UI::Label text => "Message Entry:");
1035     $vbox->add ($self->{entry} = new CFPlus::UI::Entry
1036 root 1.73 tooltip => "#npc_message_entry",
1037 root 1.32 on_activate => sub {
1038     my ($entry, $text) = @_;
1039    
1040     return unless $text =~ /\S/;
1041    
1042     $entry->set_text ("");
1043     $this->send ($text);
1044 root 1.38
1045     0
1046 root 1.32 },
1047     );
1048    
1049 root 1.69 $vbox->add ($self->{options} = new CFPlus::UI::VBox);
1050 root 1.32
1051 root 1.69 $self->{bye_button} = new CFPlus::UI::Button
1052 root 1.32 text => "Bye (close)",
1053     tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.",
1054 root 1.64 on_activate => sub { $this->destroy; 1 },
1055 root 1.32 ;
1056    
1057     $self->update_options;
1058    
1059 root 1.70 $self->{id} = $self->{conn}->send_ext_req (
1060     npc_dialog_begin => dx => $self->{dx}, dy => $self->{dy},
1061     sub { $this && $this->feed (@_) }
1062     );
1063 root 1.32
1064 root 1.38 $self->{entry}->grab_focus;
1065 root 1.32
1066 root 1.67 $self->{textview}->add_paragraph ({
1067     fg => [1, 1, 0, 1],
1068     markup => "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n",
1069     });
1070 root 1.32
1071     $self->show;
1072     $self
1073     };
1074    
1075     sub update_options {
1076     my ($self) = @_;
1077    
1078 root 1.92 CFPlus::weaken $self;
1079 root 1.32
1080     $self->{options}->clear;
1081 root 1.39 $self->{options}->add ($self->{bye_button});
1082 root 1.32
1083     for my $kw (sort keys %{ $self->{kw} }) {
1084 root 1.69 $self->{options}->add (new CFPlus::UI::Button
1085 root 1.32 text => $kw,
1086     on_activate => sub {
1087     $self->send ($kw);
1088 root 1.38 0
1089 root 1.32 },
1090     );
1091     }
1092     }
1093    
1094     sub feed {
1095 root 1.70 my ($self, $msg) = @_;
1096 root 1.32
1097 root 1.92 CFPlus::weaken $self;
1098 root 1.42
1099 root 1.70 if ($msg->{msgtype} eq "reply") {
1100     $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1101     $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1102 root 1.61
1103 root 1.70 my $text = "\n" . CFPlus::asxml $msg->{msg};
1104 root 1.32 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1105 root 1.41 my @link;
1106 root 1.70 $text =~ s{
1107 root 1.41 ($match)
1108     }{
1109 root 1.42 my $kw = $1;
1110    
1111 root 1.69 push @link, new CFPlus::UI::Label
1112 root 1.42 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
1113 root 1.41 can_hover => 1,
1114 root 1.42 can_events => 1,
1115 root 1.43 padding_x => 0,
1116     padding_y => 0,
1117 root 1.42 on_button_up => sub {
1118     $self->send ($kw);
1119     };
1120 root 1.41
1121 root 1.75 "\x{fffc}"
1122 root 1.41 }giex;
1123 root 1.32
1124 root 1.70 $self->{textview}->add_paragraph ({ markup => $text, widget => \@link });
1125 root 1.42 $self->{textview}->scroll_to_bottom;
1126 root 1.32 $self->update_options;
1127     } else {
1128     $self->destroy;
1129     }
1130    
1131     1
1132     }
1133    
1134     sub send {
1135     my ($self, $msg) = @_;
1136    
1137 root 1.69 $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg });
1138 root 1.42 $self->{textview}->scroll_to_bottom;
1139 root 1.61
1140 root 1.70 $self->{conn}->send_ext_msg (npc_dialog_tell => msgid => $self->{id}, msg => $msg);
1141 root 1.32 }
1142    
1143     sub destroy {
1144     my ($self) = @_;
1145    
1146 root 1.39 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1147 root 1.32
1148 root 1.70 if ($self->{conn}) {
1149     $self->{conn}->send_ext_msg (npc_dialog_end => msgid => $self->{id}) if $self->{id};
1150     delete $self->{conn}{npc_dialog};
1151     $self->{conn}->disconnect_ext ($self->{id});
1152     }
1153 root 1.32
1154     $self->SUPER::destroy;
1155     }
1156    
1157 root 1.67 1
1158 root 1.84