1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
16 | |
17 | |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | "dialogue.png", minify => 1, mipmap => 1; |
19 | "dialogue.png", minify => 1, mipmap => 1; |
19 | |
20 | |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | "noface.png", minify => 1, mipmap => 1; |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
23 | |
|
|
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
22 | |
25 | |
23 | sub new { |
26 | sub new { |
24 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
25 | |
28 | |
26 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
27 | setup_req => { |
30 | setup_req => { |
28 | extmap => 1, |
31 | extmap => 1, |
29 | excmd => 1, |
|
|
30 | widget => 2, |
32 | widget => 2, |
31 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
32 | }, |
34 | }, |
33 | ); |
35 | ); |
34 | |
36 | |
35 | $self->{map_widget}->clr_commands; |
37 | $self->update_fx_want; |
36 | |
38 | |
37 | my @cmd_help = map { |
39 | my $exp_guard = $self->addme_guard; |
38 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
40 | my $skl_guard = $self->addme_guard; |
39 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
41 | my $spl_guard = $self->addme_guard; |
|
|
42 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
43 | my ($exp, $skl, $spl) = @_; |
40 | |
44 | |
41 | my $cmd = $1; |
45 | $self->register_face_handler ($exp, sub { |
42 | my @args = split /\|/, $2; |
46 | my ($face) = @_; |
43 | @args = (".*") unless @args; |
|
|
44 | |
47 | |
45 | my (undef, @par) = DC::Pod::section_of $_; |
48 | undef $exp_guard; |
46 | my $text = DC::Pod::as_label @par; |
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
47 | |
52 | |
48 | $_ = $_ eq ".*" ? "" : " $_" |
53 | $self->register_face_handler ($skl, sub { |
49 | for @args; |
54 | my ($face) = @_; |
50 | |
55 | |
51 | map ["$cmd$_", $text], |
56 | undef $skl_guard; |
52 | sort { (length $a) <=> (length $b) } |
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
53 | @args |
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
54 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
59 | }); |
55 | DC::Pod::find command => "*"; |
60 | |
|
|
61 | $self->register_face_handler ($spl, sub { |
|
|
62 | my ($face) = @_; |
|
|
63 | |
|
|
64 | undef $spl_guard; |
|
|
65 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
66 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
67 | }); |
|
|
68 | |
|
|
69 | () |
|
|
70 | }); |
|
|
71 | |
|
|
72 | $::COMPLETER->reset; |
56 | |
73 | |
57 | $self->{json_coder} |
74 | $self->{json_coder} |
58 | ->convert_blessed |
75 | ->convert_blessed |
59 | ->filter_json_single_key_object ("\fw" => sub { |
76 | ->filter_json_single_key_object ("\fw" => sub { |
60 | $self->{widget}{$_[0]} |
77 | $self->{widget}{$_[0]} |
… | |
… | |
78 | $::INVR->clear; |
95 | $::INVR->clear; |
79 | $::INVR_HB->clear; |
96 | $::INVR_HB->clear; |
80 | $::FLOORBOX->clear; |
97 | $::FLOORBOX->clear; |
81 | }); |
98 | }); |
82 | |
99 | |
83 | $self->{map_widget}->add_command (@$_) |
|
|
84 | for @cmd_help; |
|
|
85 | |
|
|
86 | { |
100 | { |
87 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
101 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
88 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
102 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
103 | } |
90 | |
104 | |
91 | { |
105 | { |
92 | $self->{noface} = my $tex = $TEX_NOFACE; |
106 | $self->{noface} = my $tex = $TEX_NOFACE; |
93 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
107 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
94 | } |
108 | } |
95 | |
109 | |
|
|
110 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
111 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
112 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
113 | # |
|
|
114 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
115 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
116 | # $self->{texture}[$_]->unload; |
|
|
117 | # warn "expire texture $_\n";#d# |
|
|
118 | # } |
|
|
119 | # |
|
|
120 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
121 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
122 | # warn "count is $count\n";#d# |
|
|
123 | # }; |
|
|
124 | |
96 | $self->{open_container} = 0; |
125 | $self->{open_container} = 0; |
97 | |
126 | |
98 | # per server |
127 | # per server |
99 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
128 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
100 | |
129 | |
101 | $self |
130 | $self |
102 | } |
131 | } |
|
|
132 | |
|
|
133 | #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# |
|
|
134 | #sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# |
103 | |
135 | |
104 | sub update_fx_want { |
136 | sub update_fx_want { |
105 | my ($self) = @_; |
137 | my ($self) = @_; |
106 | |
138 | |
107 | $self->send_exti_msg (fx_want => { |
139 | $self->send_exti_msg (fx_want => { |
… | |
… | |
112 | } |
144 | } |
113 | |
145 | |
114 | sub ext_capabilities { |
146 | sub ext_capabilities { |
115 | my ($self, %cap) = @_; |
147 | my ($self, %cap) = @_; |
116 | |
148 | |
117 | $self->update_fx_want; |
|
|
118 | |
|
|
119 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
120 | my ($exp_table) = @_; |
|
|
121 | |
|
|
122 | $self->register_face_handler ($exp_table, sub { |
|
|
123 | my ($face) = @_; |
|
|
124 | |
|
|
125 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
126 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
127 | }); |
|
|
128 | |
|
|
129 | () |
|
|
130 | }); |
|
|
131 | |
|
|
132 | if (my $ts = $cap{tileset}) { |
149 | if (my $ts = $cap{tileset}) { |
133 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
150 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
134 | $self->{tileset} = $default; |
151 | $self->{tileset} = $default; |
135 | $self->{tilesize} = $default->[3]; |
152 | $self->{tilesize} = $default->[3]; |
136 | $self->setup_req (tileset => $default->[0]); |
153 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
144 | } |
161 | } |
145 | |
162 | |
146 | sub ext_ambient_music { |
163 | sub ext_ambient_music { |
147 | my ($self, $songs) = @_; |
164 | my ($self, $songs) = @_; |
148 | &::audio_music_set_ambient ($songs); |
165 | &::audio_music_set_ambient ($songs); |
|
|
166 | } |
|
|
167 | |
|
|
168 | sub ext_command_list { |
|
|
169 | my ($self, @faces) = @_; |
|
|
170 | |
|
|
171 | my $handler = $self->{command_facehandler} = {}; |
|
|
172 | my $commands = $::COMPLETER->{command_list} = {}; |
|
|
173 | |
|
|
174 | for my $idx (@faces) { |
|
|
175 | $handler->{$idx} = $self->register_face_handler ($idx, sub { |
|
|
176 | my ($face) = @_; |
|
|
177 | |
|
|
178 | $commands->{$idx} = |
|
|
179 | $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); |
|
|
180 | }); |
|
|
181 | } |
149 | } |
182 | } |
150 | |
183 | |
151 | ############################################################################# |
184 | ############################################################################# |
152 | |
185 | |
153 | sub widget_associate { |
186 | sub widget_associate { |
… | |
… | |
260 | my %wkw = ( |
293 | my %wkw = ( |
261 | root => $DC::UI::ROOT, |
294 | root => $DC::UI::ROOT, |
262 | tooltip => $DC::UI::TOOLTIP, |
295 | tooltip => $DC::UI::TOOLTIP, |
263 | |
296 | |
264 | mapwidget => $::MAPWIDGET, |
297 | mapwidget => $::MAPWIDGET, |
|
|
298 | menubar => $::MENUBAR, |
|
|
299 | menupopup => $::MENUPOPUP, |
|
|
300 | pickup_enable => $::PICKUP_ENABLE, |
265 | buttonbar => $::BUTTONBAR, |
301 | buttonbar => $::BUTTONBAR, |
266 | metaserver => $::METASERVER, |
302 | metaserver => $::METASERVER, |
267 | buttonbar => $::BUTTONBAR, |
303 | buttonbar => $::BUTTONBAR, |
268 | login_button => $::LOGIN_BUTTON, |
304 | login_button => $::LOGIN_BUTTON, |
269 | quit_dialog => $::QUIT_DIALOG, |
305 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
286 | |
322 | |
287 | floorbox => $::FLOORBOX, |
323 | floorbox => $::FLOORBOX, |
288 | help_window => $::HELP_WINDOW, |
324 | help_window => $::HELP_WINDOW, |
289 | message_window => $::MESSAGE_WINDOW, |
325 | message_window => $::MESSAGE_WINDOW, |
290 | message_dist => $::MESSAGE_DIST, |
326 | message_dist => $::MESSAGE_DIST, |
291 | statusbox => $::SDTATUSBOX, |
327 | statusbox => $::STATUSBOX, |
292 | |
328 | |
293 | inv => $::INV, |
329 | inv => $::INV, |
294 | invr => $::INVR, |
330 | invr => $::INVR, |
295 | invr_hb => $::INVR_HB, |
331 | invr_hb => $::INVR_HB, |
296 | ); |
332 | ); |
… | |
… | |
380 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
416 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
381 | : () |
417 | : () |
382 | } |
418 | } |
383 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
419 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
384 | |
420 | |
385 | join "", @diff |
421 | "\u$name: " . (join ", ", @diff) |
386 | } |
422 | } |
387 | |
423 | |
388 | # all stats that are chacked against changes |
424 | # all stats that are chacked against changes |
389 | my @statchange = ( |
425 | my @statchange = ( |
390 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
426 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
433 | |
469 | |
434 | if (my @diffs = |
470 | if (my @diffs = |
435 | ( |
471 | ( |
436 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
472 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
437 | map { |
473 | map { |
438 | $stats->{$_} && $prev->{$_} |
474 | $stats->{$_} && $prev->{$_} |
439 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
475 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
440 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
476 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
441 | ) |
477 | ) |
442 | ) { |
478 | ) { |
443 | my $msg = join " ", @diffs; |
479 | my $msg = join " ", @diffs; |
… | |
… | |
445 | } |
481 | } |
446 | |
482 | |
447 | if ( |
483 | if ( |
448 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
484 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
449 | ) { |
485 | ) { |
450 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
486 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
451 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
487 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
452 | } |
488 | } |
453 | |
489 | |
454 | $self->update_stats_window ($stats, $prev); |
490 | $self->update_stats_window ($stats, $prev); |
455 | |
491 | |
… | |
… | |
493 | |
529 | |
494 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
530 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
495 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
531 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
496 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
532 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
497 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
533 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
498 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
534 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
499 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
535 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
500 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
536 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
501 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
537 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
502 | my $title = $stats->{+CS_STAT_TITLE}; |
538 | my $title = $stats->{+CS_STAT_TITLE}; |
503 | $title =~ s/^Player: //; |
539 | $title =~ s/^Player: //; |
504 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
540 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
505 | |
541 | |
… | |
… | |
517 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
553 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
518 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
554 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
519 | |
555 | |
520 | $self->update_weight; |
556 | $self->update_weight; |
521 | |
557 | |
522 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
558 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
523 | for keys %RES_TBL; |
559 | for keys %RES_TBL; |
524 | |
560 | |
525 | my $sktbl = $::STATWIDS->{skill_tbl}; |
561 | my $sktbl = $::STATWIDS->{skill_tbl}; |
526 | my @skills = keys %{ $self->{skill_info} }; |
562 | my @skills = keys %{ $self->{skill_info} }; |
527 | |
563 | |
… | |
… | |
546 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
582 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
547 | ]; |
583 | ]; |
548 | |
584 | |
549 | my @add = @$sw; |
585 | my @add = @$sw; |
550 | |
586 | |
551 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
587 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
552 | |
588 | |
553 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
589 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
554 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
590 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
555 | |
591 | |
556 | my ($x, $y) = (0, 1); |
592 | my ($x, $y) = (0, 1); |
… | |
… | |
618 | my $sw = $self->{skillwid}{$idx}; |
654 | my $sw = $self->{skillwid}{$idx}; |
619 | $sw->[0]->set_text (::formsep ($val->[1])); |
655 | $sw->[0]->set_text (::formsep ($val->[1])); |
620 | $sw->[1]->set_text ($val->[0] * 1); |
656 | $sw->[1]->set_text ($val->[0] * 1); |
621 | $sw->[2]->set_value (@$val); |
657 | $sw->[2]->set_value (@$val); |
622 | |
658 | |
623 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
659 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
624 | $::GAUGES->{sklprg}->set_value (@$val); |
660 | $::GAUGES->{skillexp}->set_value (@$val); |
625 | } |
661 | } |
626 | } |
662 | } |
627 | |
663 | |
628 | sub user_send { |
664 | sub user_send { |
629 | my ($self, $command) = @_; |
665 | my ($self, $command) = @_; |
… | |
… | |
648 | } |
684 | } |
649 | |
685 | |
650 | sub feed_map1a { |
686 | sub feed_map1a { |
651 | my ($self, $data) = @_; |
687 | my ($self, $data) = @_; |
652 | |
688 | |
653 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
689 | my $missing = $self->{map}->map1a_update ($data); |
654 | my $delay; |
690 | my $delay; |
655 | |
691 | |
656 | for my $tile (@$missing) { |
692 | for my $tile (@$missing) { |
657 | next if $self->{delay}{$tile}; |
693 | next if $self->{delay}{$tile}; |
658 | |
694 | |
659 | $delay = 1; |
695 | $delay = 1; |
660 | |
696 | |
661 | if (my $tex = $::CONN->{texture}[$tile]) { |
697 | if (my $tex = $self->{texture}[$tile]) { |
662 | $tex->upload; |
698 | $tex->upload; |
663 | } else { |
699 | } else { |
664 | $self->{delay}{$tile} = 1; |
700 | $self->{delay}{$tile} = 1; |
665 | |
701 | |
666 | # we assume the face is in-flight and will eventually come |
702 | # we assume the face is in-flight and will eventually arrive |
667 | push @{$self->{tile_cb}{$tile}}, sub { |
703 | push @{$self->{tile_cb}{$tile}}, sub { |
668 | delete $self->{delay}{$tile}; |
704 | delete $self->{delay}{$tile}; |
669 | $_[0]->upload; |
705 | $_[0]->upload; |
670 | }; |
706 | }; |
671 | } |
707 | } |
672 | } |
708 | } |
673 | |
709 | |
674 | if ($delay) { |
710 | if ($delay) { |
675 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
711 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
676 | EV::once undef, 0, 0.03, sub { |
712 | EV::once undef, 0, 0.03, sub { |
677 | $self->{map_widget}->update |
713 | $self->{map_widget}->update |
678 | if $self->{map_widget}; |
714 | if $self->{map_widget}; |
679 | }; |
715 | }; |
680 | } else { |
716 | } else { |
… | |
… | |
968 | |
1004 | |
969 | my $tex = $self->{texture}[$tile] ||= |
1005 | my $tex = $self->{texture}[$tile] ||= |
970 | new DC::Texture |
1006 | new DC::Texture |
971 | tile => $tile, |
1007 | tile => $tile, |
972 | image => $data, delete_image => 1, |
1008 | image => $data, delete_image => 1, |
973 | minify => 1, mipmap => 1; |
1009 | minify => 1; |
974 | |
1010 | |
975 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1011 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
976 | $_->($tex) for @$cbs; |
1012 | $_->($tex) for @$cbs; |
977 | } |
1013 | } |
978 | } |
1014 | } |
… | |
… | |
983 | my ($self, $num, $cb) = @_; |
1019 | my ($self, $num, $cb) = @_; |
984 | |
1020 | |
985 | push @{$self->{face_cb}{$num}}, $cb; |
1021 | push @{$self->{face_cb}{$num}}, $cb; |
986 | |
1022 | |
987 | defined wantarray |
1023 | defined wantarray |
988 | ? DC::guard { |
1024 | ? Guard::guard { |
989 | @{$self->{face_cb}{$num}} |
1025 | @{$self->{face_cb}{$num}} |
990 | = grep $_ != $cb, |
1026 | = grep $_ != $cb, |
991 | @{$self->{face_cb}{$num}}; |
1027 | @{$self->{face_cb}{$num}}; |
992 | } |
1028 | } |
993 | : () |
1029 | : () |
… | |
… | |
1021 | my ($self, $flags, $prompt) = @_; |
1057 | my ($self, $flags, $prompt) = @_; |
1022 | |
1058 | |
1023 | $prompt = $LAST_QUERY unless length $prompt; |
1059 | $prompt = $LAST_QUERY unless length $prompt; |
1024 | $LAST_QUERY = $prompt; |
1060 | $LAST_QUERY = $prompt; |
1025 | |
1061 | |
1026 | $self->{query}-> ($self, $flags, $prompt); |
1062 | $self->{query}->($self, $flags, $prompt); |
1027 | } |
1063 | } |
1028 | |
1064 | |
1029 | sub sanitise_xml($) { |
1065 | sub sanitise_xml($) { |
1030 | local $_ = shift; |
1066 | local $_ = shift; |
1031 | |
1067 | |
… | |
… | |
1063 | tan => 12, |
1099 | tan => 12, |
1064 | ); |
1100 | ); |
1065 | |
1101 | |
1066 | our @CF_COLOR = ( |
1102 | our @CF_COLOR = ( |
1067 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1103 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1068 | [1.00, 1.00, 1.00], |
1104 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1069 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1105 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1070 | [1.00, 0.00, 0.00], |
1106 | [1.00, 0.00, 0.00], |
1071 | [1.00, 0.54, 0.00], |
1107 | [1.00, 0.54, 0.00], |
1072 | [0.11, 0.56, 1.00], |
1108 | [0.11, 0.56, 1.00], |
1073 | [0.93, 0.46, 0.00], |
1109 | [0.93, 0.46, 0.00], |
1074 | [0.18, 0.54, 0.34], |
1110 | [0.18, 0.54, 0.34], |
… | |
… | |
1093 | $self->logprint ("msg: ", $text); |
1129 | $self->logprint ("msg: ", $text); |
1094 | return if $color < 0; # negative color == ignore if not understood |
1130 | return if $color < 0; # negative color == ignore if not understood |
1095 | |
1131 | |
1096 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1132 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1097 | |
1133 | |
1098 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1099 | # no longer neecssary with TRT servers |
|
|
1100 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1101 | |
|
|
1102 | ::message ({ |
1134 | ::message ({ |
1103 | fg => $fg, |
1135 | fg => $fg, |
1104 | markup => $text, |
1136 | markup => $text, |
1105 | type => $type, |
1137 | type => $type, |
1106 | extra => [@extra], |
1138 | extra => [@extra], |
… | |
… | |
1129 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
1161 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
1130 | $spell->{message} =~ s/\n+$//; |
1162 | $spell->{message} =~ s/\n+$//; |
1131 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1163 | $spell->{message} ||= "Server did not provide a description for this spell."; |
1132 | |
1164 | |
1133 | $::SPELL_LIST->add_spell ($spell); |
1165 | $::SPELL_LIST->add_spell ($spell); |
1134 | |
1166 | delete $::COMPLETER->{command_list}{spells}; |
1135 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
|
|
1136 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
|
|
1137 | } |
1167 | } |
1138 | |
1168 | |
1139 | sub spell_delete { |
1169 | sub spell_delete { |
1140 | my ($self, $spell) = @_; |
1170 | my ($self, $spell) = @_; |
1141 | |
1171 | |
1142 | $::SPELL_LIST->remove_spell ($spell); |
1172 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1173 | delete $::COMPLETER->{command_list}{spells}; |
1143 | } |
1174 | } |
1144 | |
1175 | |
1145 | sub setup { |
1176 | sub setup { |
1146 | my ($self, $setup) = @_; |
1177 | my ($self, $setup) = @_; |
1147 | |
1178 | |
… | |
… | |
1170 | } |
1201 | } |
1171 | |
1202 | |
1172 | sub eof { |
1203 | sub eof { |
1173 | my ($self) = @_; |
1204 | my ($self) = @_; |
1174 | |
1205 | |
1175 | $self->{map_widget}->clr_commands; |
1206 | $::COMPLETER->reset; |
1176 | |
1207 | |
1177 | ::stop_game (); |
1208 | ::stop_game (); |
1178 | } |
1209 | } |
1179 | |
1210 | |
1180 | sub update_floorbox { |
1211 | sub update_floorbox { |
… | |
… | |
1326 | sub update_server_info { |
1357 | sub update_server_info { |
1327 | my ($self) = @_; |
1358 | my ($self) = @_; |
1328 | |
1359 | |
1329 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1360 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1330 | |
1361 | |
|
|
1362 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1363 | |
1331 | $::SERVER_INFO->set_markup ( |
1364 | $::SERVER_INFO->set_markup ( |
1332 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1365 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1333 | . "protocol version <tt>$self->{version}</tt>\n" |
1366 | . "protocol version <tt>$version</tt>\n" |
1334 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1335 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1336 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1337 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1367 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1338 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1339 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1340 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1368 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1341 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1369 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1342 | . "map size $self->{mapw}×$self->{maph}\n" |
1370 | . "map size $self->{mapw}×$self->{maph}\n" |
1343 | ); |
1371 | ); |
1344 | |
1372 | |
… | |
… | |
1366 | }); |
1394 | }); |
1367 | |
1395 | |
1368 | $self->update_server_info; |
1396 | $self->update_server_info; |
1369 | |
1397 | |
1370 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1398 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1371 | $self->send_command ("pickup $::CFG->{pickup}"); |
1399 | $self->send_pickup ($::CFG->{pickup}); |
1372 | |
|
|
1373 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1374 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1375 | } |
1400 | } |
1376 | |
1401 | |
1377 | sub lookat { |
1402 | sub lookat { |
1378 | my ($self, $x, $y) = @_; |
1403 | my ($self, $x, $y) = @_; |
1379 | |
1404 | |
… | |
… | |
1381 | $self->send_ext_req (lookat => $x, $y, sub { |
1406 | $self->send_ext_req (lookat => $x, $y, sub { |
1382 | my (%msg) = @_; |
1407 | my (%msg) = @_; |
1383 | |
1408 | |
1384 | if (exists $msg{npc_dialog}) { |
1409 | if (exists $msg{npc_dialog}) { |
1385 | # start npc chat dialog |
1410 | # start npc chat dialog |
1386 | $self->{npc_dialog} = new DC::NPCDialog:: |
1411 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1387 | token => $msg{npc_dialog}, |
1412 | token => $msg{npc_dialog}, |
1388 | title => "$msg{npc_dialog}[0] (NPC)", |
1413 | title => "$msg{npc_dialog}[0] (NPC)", |
1389 | conn => $self, |
1414 | conn => $self, |
1390 | ; |
1415 | ; |
1391 | } |
1416 | } |
… | |
… | |
1396 | } |
1421 | } |
1397 | |
1422 | |
1398 | sub destroy { |
1423 | sub destroy { |
1399 | my ($self) = @_; |
1424 | my ($self) = @_; |
1400 | |
1425 | |
1401 | (delete $self->{npc_dialog})->destroy |
1426 | $_->destroy |
1402 | if $self->{npc_dialog}; |
1427 | for values %{ $self->{w} }; |
1403 | |
1428 | |
1404 | $self->SUPER::destroy; |
1429 | $self->SUPER::destroy; |
1405 | |
1430 | |
1406 | %$self = (); |
1431 | %$self = (); |
1407 | } |
1432 | } |
… | |
… | |
1561 | |
1586 | |
1562 | #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 |
1563 | |
1588 | |
1564 | if ($self->{conn}) { |
1589 | if ($self->{conn}) { |
1565 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1590 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1566 | delete $self->{conn}{npc_dialog}; |
1591 | delete $self->{conn}{w}{npc_dialog}; |
1567 | $self->{conn}->disconnect_ext ($self->{id}); |
1592 | $self->{conn}->disconnect_ext ($self->{id}); |
1568 | } |
1593 | } |
1569 | |
1594 | |
1570 | $self->SUPER::destroy; |
1595 | $self->SUPER::destroy; |
1571 | } |
1596 | } |