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; |
10 | use DC::UI; |
11 | use DC::UI; |
11 | use DC::Pod; |
|
|
12 | use DC::Macro; |
12 | use DC::Macro; |
13 | use DC::Item; |
13 | use DC::Item; |
14 | |
14 | |
15 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
16 | |
16 | |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | "dialogue.png", minify => 1, mipmap => 1; |
18 | "dialogue.png", minify => 1, mipmap => 1; |
19 | |
19 | |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | "noface.png", minify => 1, mipmap => 1; |
21 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
22 | |
|
|
23 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
22 | |
24 | |
23 | sub new { |
25 | sub new { |
24 | my ($class, %arg) = @_; |
26 | my ($class, %arg) = @_; |
25 | |
27 | |
26 | my $self = $class->SUPER::new (%arg, |
28 | my $self = $class->SUPER::new (%arg, |
27 | setup_req => { |
29 | setup_req => { |
28 | extmap => 1, |
30 | extmap => 1, |
29 | excmd => 1, |
|
|
30 | widget => 2, |
31 | widget => 2, |
31 | %{$arg{setup_req} || {}}, |
32 | %{$arg{setup_req} || {}}, |
32 | }, |
33 | }, |
33 | ); |
34 | ); |
34 | |
35 | |
35 | $self->{map_widget}->clr_commands; |
36 | $self->update_fx_want; |
36 | |
37 | |
37 | my @cmd_help = map { |
38 | my $exp_guard = $self->addme_guard; |
38 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
39 | my $skl_guard = $self->addme_guard; |
39 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
40 | my $spl_guard = $self->addme_guard; |
|
|
41 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
42 | my ($exp, $skl, $spl) = @_; |
40 | |
43 | |
41 | my $cmd = $1; |
44 | $self->register_face_handler ($exp, sub { |
42 | my @args = split /\|/, $2; |
45 | my ($face) = @_; |
43 | @args = (".*") unless @args; |
|
|
44 | |
46 | |
45 | my (undef, @par) = DC::Pod::section_of $_; |
47 | undef $exp_guard; |
46 | my $text = DC::Pod::as_label @par; |
48 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
49 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
50 | }); |
47 | |
51 | |
48 | $_ = $_ eq ".*" ? "" : " $_" |
52 | $self->register_face_handler ($skl, sub { |
49 | for @args; |
53 | my ($face) = @_; |
50 | |
54 | |
51 | map ["$cmd$_", $text], |
55 | undef $skl_guard; |
52 | sort { (length $a) <=> (length $b) } |
56 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
53 | @args |
57 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
54 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
58 | }); |
55 | DC::Pod::find command => "*"; |
59 | |
|
|
60 | $self->register_face_handler ($spl, sub { |
|
|
61 | my ($face) = @_; |
|
|
62 | |
|
|
63 | undef $spl_guard; |
|
|
64 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
65 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
66 | }); |
|
|
67 | |
|
|
68 | () |
|
|
69 | }); |
|
|
70 | |
|
|
71 | $::COMPLETER->reset; |
56 | |
72 | |
57 | $self->{json_coder} |
73 | $self->{json_coder} |
58 | ->convert_blessed |
74 | ->convert_blessed |
59 | ->filter_json_single_key_object ("\fw" => sub { |
75 | ->filter_json_single_key_object ("\fw" => sub { |
60 | $self->{widget}{$_[0]} |
76 | $self->{widget}{$_[0]} |
… | |
… | |
78 | $::INVR->clear; |
94 | $::INVR->clear; |
79 | $::INVR_HB->clear; |
95 | $::INVR_HB->clear; |
80 | $::FLOORBOX->clear; |
96 | $::FLOORBOX->clear; |
81 | }); |
97 | }); |
82 | |
98 | |
83 | $self->{map_widget}->add_command (@$_) |
|
|
84 | for @cmd_help; |
|
|
85 | |
|
|
86 | { |
99 | { |
87 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
100 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
88 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
101 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
102 | } |
90 | |
103 | |
91 | { |
104 | { |
92 | $self->{noface} = my $tex = $TEX_NOFACE; |
105 | $self->{noface} = my $tex = $TEX_NOFACE; |
93 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
106 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
94 | } |
107 | } |
95 | |
108 | |
|
|
109 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
110 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
112 | # |
|
|
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
115 | # $self->{texture}[$_]->unload; |
|
|
116 | # warn "expire texture $_\n";#d# |
|
|
117 | # } |
|
|
118 | # |
|
|
119 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
120 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
121 | # warn "count is $count\n";#d# |
|
|
122 | # }; |
|
|
123 | |
96 | $self->{open_container} = 0; |
124 | $self->{open_container} = 0; |
97 | |
125 | |
98 | # per server |
126 | # per server |
99 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
100 | |
128 | |
101 | $self |
129 | $self |
102 | } |
130 | } |
|
|
131 | |
|
|
132 | #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# |
|
|
133 | #sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# |
103 | |
134 | |
104 | sub update_fx_want { |
135 | sub update_fx_want { |
105 | my ($self) = @_; |
136 | my ($self) = @_; |
106 | |
137 | |
107 | $self->send_exti_msg (fx_want => { |
138 | $self->send_exti_msg (fx_want => { |
… | |
… | |
112 | } |
143 | } |
113 | |
144 | |
114 | sub ext_capabilities { |
145 | sub ext_capabilities { |
115 | my ($self, %cap) = @_; |
146 | my ($self, %cap) = @_; |
116 | |
147 | |
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}) { |
148 | if (my $ts = $cap{tileset}) { |
133 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
149 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
134 | $self->{tileset} = $default; |
150 | $self->{tileset} = $default; |
135 | $self->{tilesize} = $default->[3]; |
151 | $self->{tilesize} = $default->[3]; |
136 | $self->setup_req (tileset => $default->[0]); |
152 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
144 | } |
160 | } |
145 | |
161 | |
146 | sub ext_ambient_music { |
162 | sub ext_ambient_music { |
147 | my ($self, $songs) = @_; |
163 | my ($self, $songs) = @_; |
148 | &::audio_music_set_ambient ($songs); |
164 | &::audio_music_set_ambient ($songs); |
|
|
165 | } |
|
|
166 | |
|
|
167 | sub ext_command_list { |
|
|
168 | my ($self, @faces) = @_; |
|
|
169 | |
|
|
170 | my $handler = $self->{command_facehandler} = {}; |
|
|
171 | my $commands = $::COMPLETER->{command_list} = {}; |
|
|
172 | |
|
|
173 | for my $idx (@faces) { |
|
|
174 | $handler->{$idx} = $self->register_face_handler ($idx, sub { |
|
|
175 | my ($face) = @_; |
|
|
176 | |
|
|
177 | $commands->{$idx} = |
|
|
178 | $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); |
|
|
179 | }); |
|
|
180 | } |
149 | } |
181 | } |
150 | |
182 | |
151 | ############################################################################# |
183 | ############################################################################# |
152 | |
184 | |
153 | sub widget_associate { |
185 | sub widget_associate { |
… | |
… | |
260 | my %wkw = ( |
292 | my %wkw = ( |
261 | root => $DC::UI::ROOT, |
293 | root => $DC::UI::ROOT, |
262 | tooltip => $DC::UI::TOOLTIP, |
294 | tooltip => $DC::UI::TOOLTIP, |
263 | |
295 | |
264 | mapwidget => $::MAPWIDGET, |
296 | mapwidget => $::MAPWIDGET, |
|
|
297 | menubar => $::MENUBAR, |
|
|
298 | menupopup => $::MENUPOPUP, |
|
|
299 | pickup_enable => $::PICKUP_ENABLE, |
265 | buttonbar => $::BUTTONBAR, |
300 | buttonbar => $::BUTTONBAR, |
266 | metaserver => $::METASERVER, |
301 | metaserver => $::METASERVER, |
267 | buttonbar => $::BUTTONBAR, |
302 | buttonbar => $::BUTTONBAR, |
268 | login_button => $::LOGIN_BUTTON, |
303 | login_button => $::LOGIN_BUTTON, |
269 | quit_dialog => $::QUIT_DIALOG, |
304 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
286 | |
321 | |
287 | floorbox => $::FLOORBOX, |
322 | floorbox => $::FLOORBOX, |
288 | help_window => $::HELP_WINDOW, |
323 | help_window => $::HELP_WINDOW, |
289 | message_window => $::MESSAGE_WINDOW, |
324 | message_window => $::MESSAGE_WINDOW, |
290 | message_dist => $::MESSAGE_DIST, |
325 | message_dist => $::MESSAGE_DIST, |
291 | statusbox => $::SDTATUSBOX, |
326 | statusbox => $::STATUSBOX, |
292 | |
327 | |
293 | inv => $::INV, |
328 | inv => $::INV, |
294 | invr => $::INVR, |
329 | invr => $::INVR, |
295 | invr_hb => $::INVR_HB, |
330 | invr_hb => $::INVR_HB, |
296 | ); |
331 | ); |
… | |
… | |
380 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
415 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
381 | : () |
416 | : () |
382 | } |
417 | } |
383 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
418 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
384 | |
419 | |
385 | join "", @diff |
420 | "\u$name: " . (join ", ", @diff) |
386 | } |
421 | } |
387 | |
422 | |
388 | # all stats that are chacked against changes |
423 | # all stats that are chacked against changes |
389 | my @statchange = ( |
424 | my @statchange = ( |
390 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
425 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
433 | |
468 | |
434 | if (my @diffs = |
469 | if (my @diffs = |
435 | ( |
470 | ( |
436 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
471 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
437 | map { |
472 | map { |
438 | $stats->{$_} && $prev->{$_} |
473 | $stats->{$_} && $prev->{$_} |
439 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
474 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
440 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
475 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
441 | ) |
476 | ) |
442 | ) { |
477 | ) { |
443 | my $msg = join " ", @diffs; |
478 | my $msg = join " ", @diffs; |
… | |
… | |
445 | } |
480 | } |
446 | |
481 | |
447 | if ( |
482 | if ( |
448 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
483 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
449 | ) { |
484 | ) { |
450 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
485 | 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); |
486 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
452 | } |
487 | } |
453 | |
488 | |
454 | $self->update_stats_window ($stats, $prev); |
489 | $self->update_stats_window ($stats, $prev); |
455 | |
490 | |
… | |
… | |
493 | |
528 | |
494 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
529 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
495 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
530 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
496 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
531 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
497 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
532 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
498 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
533 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
499 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
534 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
500 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
535 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
501 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
536 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
502 | my $title = $stats->{+CS_STAT_TITLE}; |
537 | my $title = $stats->{+CS_STAT_TITLE}; |
503 | $title =~ s/^Player: //; |
538 | $title =~ s/^Player: //; |
504 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
539 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
505 | |
540 | |
… | |
… | |
517 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
552 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
518 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
553 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
519 | |
554 | |
520 | $self->update_weight; |
555 | $self->update_weight; |
521 | |
556 | |
522 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
557 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
523 | for keys %RES_TBL; |
558 | for keys %RES_TBL; |
524 | |
559 | |
525 | my $sktbl = $::STATWIDS->{skill_tbl}; |
560 | my $sktbl = $::STATWIDS->{skill_tbl}; |
526 | my @skills = keys %{ $self->{skill_info} }; |
561 | my @skills = keys %{ $self->{skill_info} }; |
527 | |
562 | |
… | |
… | |
546 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
581 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
547 | ]; |
582 | ]; |
548 | |
583 | |
549 | my @add = @$sw; |
584 | my @add = @$sw; |
550 | |
585 | |
551 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
586 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
552 | |
587 | |
553 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
588 | 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); |
589 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
555 | |
590 | |
556 | my ($x, $y) = (0, 1); |
591 | my ($x, $y) = (0, 1); |
… | |
… | |
591 | # progress |
626 | # progress |
592 | (new DC::UI::ExperienceProgress), |
627 | (new DC::UI::ExperienceProgress), |
593 | |
628 | |
594 | # label |
629 | # label |
595 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
630 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
596 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
631 | can_events => 1, can_hover => 1, tooltip => "#(skill/$name)$TOOLTIP_ALL"), |
597 | ]; |
632 | ]; |
598 | |
633 | |
599 | push @add, |
634 | push @add, |
600 | $x * 4 + 0, $y, $sw->[0], |
635 | $x * 4 + 0, $y, $sw->[0], |
601 | $x * 4 + 1, $y, $sw->[1], |
636 | $x * 4 + 1, $y, $sw->[1], |
… | |
… | |
618 | my $sw = $self->{skillwid}{$idx}; |
653 | my $sw = $self->{skillwid}{$idx}; |
619 | $sw->[0]->set_text (::formsep ($val->[1])); |
654 | $sw->[0]->set_text (::formsep ($val->[1])); |
620 | $sw->[1]->set_text ($val->[0] * 1); |
655 | $sw->[1]->set_text ($val->[0] * 1); |
621 | $sw->[2]->set_value (@$val); |
656 | $sw->[2]->set_value (@$val); |
622 | |
657 | |
623 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
658 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
624 | $::GAUGES->{sklprg}->set_value (@$val); |
659 | $::GAUGES->{skillexp}->set_value (@$val); |
625 | } |
660 | } |
626 | } |
661 | } |
627 | |
662 | |
628 | sub user_send { |
663 | sub user_send { |
629 | my ($self, $command) = @_; |
664 | my ($self, $command) = @_; |
… | |
… | |
648 | } |
683 | } |
649 | |
684 | |
650 | sub feed_map1a { |
685 | sub feed_map1a { |
651 | my ($self, $data) = @_; |
686 | my ($self, $data) = @_; |
652 | |
687 | |
653 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
688 | my $missing = $self->{map}->map1a_update ($data); |
654 | my $delay; |
689 | my $delay; |
655 | |
690 | |
656 | for my $tile (@$missing) { |
691 | for my $tile (@$missing) { |
657 | next if $self->{delay}{$tile}; |
692 | next if $self->{delay}{$tile}; |
658 | |
693 | |
659 | $delay = 1; |
694 | $delay = 1; |
660 | |
695 | |
661 | if (my $tex = $::CONN->{texture}[$tile]) { |
696 | if (my $tex = $self->{texture}[$tile]) { |
662 | $tex->upload; |
697 | $tex->upload; |
663 | } else { |
698 | } else { |
664 | $self->{delay}{$tile} = 1; |
699 | $self->{delay}{$tile} = 1; |
665 | |
700 | |
666 | # we assume the face is in-flight and will eventually come |
701 | # we assume the face is in-flight and will eventually arrive |
667 | push @{$self->{tile_cb}{$tile}}, sub { |
702 | push @{$self->{tile_cb}{$tile}}, sub { |
668 | delete $self->{delay}{$tile}; |
703 | delete $self->{delay}{$tile}; |
669 | $_[0]->upload; |
704 | $_[0]->upload; |
670 | }; |
705 | }; |
671 | } |
706 | } |
672 | } |
707 | } |
673 | |
708 | |
674 | if ($delay) { |
709 | if ($delay) { |
675 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
710 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
676 | EV::once undef, 0, 0.03, sub { |
711 | EV::once undef, 0, 0.03, sub { |
677 | $self->{map_widget}->update |
712 | $self->{map_widget}->update |
678 | if $self->{map_widget}; |
713 | if $self->{map_widget}; |
679 | }; |
714 | }; |
680 | } else { |
715 | } else { |
… | |
… | |
968 | |
1003 | |
969 | my $tex = $self->{texture}[$tile] ||= |
1004 | my $tex = $self->{texture}[$tile] ||= |
970 | new DC::Texture |
1005 | new DC::Texture |
971 | tile => $tile, |
1006 | tile => $tile, |
972 | image => $data, delete_image => 1, |
1007 | image => $data, delete_image => 1, |
973 | minify => 1, mipmap => 1; |
1008 | minify => 1; |
974 | |
1009 | |
975 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1010 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
976 | $_->($tex) for @$cbs; |
1011 | $_->($tex) for @$cbs; |
977 | } |
1012 | } |
978 | } |
1013 | } |
… | |
… | |
983 | my ($self, $num, $cb) = @_; |
1018 | my ($self, $num, $cb) = @_; |
984 | |
1019 | |
985 | push @{$self->{face_cb}{$num}}, $cb; |
1020 | push @{$self->{face_cb}{$num}}, $cb; |
986 | |
1021 | |
987 | defined wantarray |
1022 | defined wantarray |
988 | ? DC::guard { |
1023 | ? Guard::guard { |
989 | @{$self->{face_cb}{$num}} |
1024 | @{$self->{face_cb}{$num}} |
990 | = grep $_ != $cb, |
1025 | = grep $_ != $cb, |
991 | @{$self->{face_cb}{$num}}; |
1026 | @{$self->{face_cb}{$num}}; |
992 | } |
1027 | } |
993 | : () |
1028 | : () |
… | |
… | |
1021 | my ($self, $flags, $prompt) = @_; |
1056 | my ($self, $flags, $prompt) = @_; |
1022 | |
1057 | |
1023 | $prompt = $LAST_QUERY unless length $prompt; |
1058 | $prompt = $LAST_QUERY unless length $prompt; |
1024 | $LAST_QUERY = $prompt; |
1059 | $LAST_QUERY = $prompt; |
1025 | |
1060 | |
1026 | $self->{query}-> ($self, $flags, $prompt); |
1061 | $self->{query}->($self, $flags, $prompt); |
1027 | } |
|
|
1028 | |
|
|
1029 | sub sanitise_xml($) { |
|
|
1030 | local $_ = shift; |
|
|
1031 | |
|
|
1032 | # we now weed out all tags we do not support |
|
|
1033 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
1034 | }{ |
|
|
1035 | "<" |
|
|
1036 | }gex; |
|
|
1037 | |
|
|
1038 | # now all entities |
|
|
1039 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
1040 | |
|
|
1041 | # handle some elements |
|
|
1042 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
1043 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1044 | |
|
|
1045 | s/\s+$//; |
|
|
1046 | |
|
|
1047 | $_ |
|
|
1048 | } |
1062 | } |
1049 | |
1063 | |
1050 | our %NAME_TO_COLOR = ( |
1064 | our %NAME_TO_COLOR = ( |
1051 | black => 0, |
1065 | black => 0, |
1052 | white => 1, |
1066 | white => 1, |
… | |
… | |
1063 | tan => 12, |
1077 | tan => 12, |
1064 | ); |
1078 | ); |
1065 | |
1079 | |
1066 | our @CF_COLOR = ( |
1080 | our @CF_COLOR = ( |
1067 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1081 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1068 | [1.00, 1.00, 1.00], |
1082 | [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] |
1083 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1070 | [1.00, 0.00, 0.00], |
1084 | [1.00, 0.00, 0.00], |
1071 | [1.00, 0.54, 0.00], |
1085 | [1.00, 0.54, 0.00], |
1072 | [0.11, 0.56, 1.00], |
1086 | [0.11, 0.56, 1.00], |
1073 | [0.93, 0.46, 0.00], |
1087 | [0.93, 0.46, 0.00], |
1074 | [0.18, 0.54, 0.34], |
1088 | [0.18, 0.54, 0.34], |
… | |
… | |
1080 | ); |
1094 | ); |
1081 | |
1095 | |
1082 | sub msg { |
1096 | sub msg { |
1083 | my ($self, $color, $type, $text, @extra) = @_; |
1097 | my ($self, $color, $type, $text, @extra) = @_; |
1084 | |
1098 | |
1085 | $text = sanitise_xml $text; |
1099 | $text = DC::sanitise_cfxml $text; |
1086 | |
1100 | |
1087 | if (my $cb = $self->{cb_msg}{$type}) { |
1101 | if (my $cb = $self->{cb_msg}{$type}) { |
1088 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1102 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1089 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1103 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1090 | $type =~ s/-/_/g; |
1104 | $type =~ s/-/_/g; |
… | |
… | |
1093 | $self->logprint ("msg: ", $text); |
1107 | $self->logprint ("msg: ", $text); |
1094 | return if $color < 0; # negative color == ignore if not understood |
1108 | return if $color < 0; # negative color == ignore if not understood |
1095 | |
1109 | |
1096 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1110 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1097 | |
1111 | |
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 ({ |
1112 | ::message ({ |
1103 | fg => $fg, |
1113 | fg => $fg, |
1104 | markup => $text, |
1114 | markup => $text, |
1105 | type => $type, |
1115 | type => $type, |
1106 | extra => [@extra], |
1116 | extra => [@extra], |
… | |
… | |
1123 | } |
1133 | } |
1124 | |
1134 | |
1125 | sub spell_add { |
1135 | sub spell_add { |
1126 | my ($self, $spell) = @_; |
1136 | my ($self, $spell) = @_; |
1127 | |
1137 | |
1128 | # try to create single paragraphs out of the multiple lines sent by the server |
|
|
1129 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1130 | $spell->{message} =~ s/\n+$//; |
|
|
1131 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
1132 | |
|
|
1133 | $::SPELL_LIST->add_spell ($spell); |
1138 | $::SPELL_LIST->add_spell ($spell); |
1134 | |
1139 | 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 | } |
1140 | } |
1138 | |
1141 | |
1139 | sub spell_delete { |
1142 | sub spell_delete { |
1140 | my ($self, $spell) = @_; |
1143 | my ($self, $spell) = @_; |
1141 | |
1144 | |
1142 | $::SPELL_LIST->remove_spell ($spell); |
1145 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1146 | delete $::COMPLETER->{command_list}{spells}; |
1143 | } |
1147 | } |
1144 | |
1148 | |
1145 | sub setup { |
1149 | sub setup { |
1146 | my ($self, $setup) = @_; |
1150 | my ($self, $setup) = @_; |
1147 | |
1151 | |
1148 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1152 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1149 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1153 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1150 | } |
1154 | } |
1151 | |
1155 | |
1152 | sub addme_success { |
|
|
1153 | my ($self) = @_; |
|
|
1154 | |
|
|
1155 | my %skill_help; |
|
|
1156 | |
|
|
1157 | for my $node (DC::Pod::find skill_description => "*") { |
|
|
1158 | my (undef, @par) = DC::Pod::section_of $node; |
|
|
1159 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
|
|
1160 | }; |
|
|
1161 | |
|
|
1162 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1163 | $self->{map_widget}->add_command ("ready_skill $skill", |
|
|
1164 | (DC::asxml "Ready the skill '$skill'\n\n") |
|
|
1165 | . $skill_help{$skill}); |
|
|
1166 | $self->{map_widget}->add_command ("use_skill $skill", |
|
|
1167 | (DC::asxml "Immediately use the skill '$skill'\n\n") |
|
|
1168 | . $skill_help{$skill}); |
|
|
1169 | } |
|
|
1170 | } |
|
|
1171 | |
|
|
1172 | sub eof { |
1156 | sub eof { |
1173 | my ($self) = @_; |
1157 | my ($self) = @_; |
1174 | |
1158 | |
1175 | $self->{map_widget}->clr_commands; |
1159 | $::COMPLETER->reset; |
1176 | |
1160 | |
1177 | ::stop_game (); |
1161 | ::stop_game (); |
1178 | } |
1162 | } |
1179 | |
1163 | |
1180 | sub update_floorbox { |
1164 | sub update_floorbox { |
… | |
… | |
1326 | sub update_server_info { |
1310 | sub update_server_info { |
1327 | my ($self) = @_; |
1311 | my ($self) = @_; |
1328 | |
1312 | |
1329 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1313 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1330 | |
1314 | |
|
|
1315 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1316 | |
1331 | $::SERVER_INFO->set_markup ( |
1317 | $::SERVER_INFO->set_markup ( |
1332 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1318 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1333 | . "protocol version <tt>$self->{version}</tt>\n" |
1319 | . "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" |
1320 | . "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]" |
1321 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1341 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1322 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1342 | . "map size $self->{mapw}×$self->{maph}\n" |
1323 | . "map size $self->{mapw}×$self->{maph}\n" |
1343 | ); |
1324 | ); |
1344 | |
1325 | |
… | |
… | |
1366 | }); |
1347 | }); |
1367 | |
1348 | |
1368 | $self->update_server_info; |
1349 | $self->update_server_info; |
1369 | |
1350 | |
1370 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1351 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1371 | $self->send_command ("pickup $::CFG->{pickup}"); |
1352 | $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 | } |
1353 | } |
1376 | |
1354 | |
1377 | sub lookat { |
1355 | sub lookat { |
1378 | my ($self, $x, $y) = @_; |
1356 | my ($self, $x, $y) = @_; |
1379 | |
1357 | |
… | |
… | |
1381 | $self->send_ext_req (lookat => $x, $y, sub { |
1359 | $self->send_ext_req (lookat => $x, $y, sub { |
1382 | my (%msg) = @_; |
1360 | my (%msg) = @_; |
1383 | |
1361 | |
1384 | if (exists $msg{npc_dialog}) { |
1362 | if (exists $msg{npc_dialog}) { |
1385 | # start npc chat dialog |
1363 | # start npc chat dialog |
1386 | $self->{npc_dialog} = new DC::NPCDialog:: |
1364 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1387 | token => $msg{npc_dialog}, |
1365 | token => $msg{npc_dialog}, |
1388 | title => "$msg{npc_dialog}[0] (NPC)", |
1366 | title => "$msg{npc_dialog}[0] (NPC)", |
1389 | conn => $self, |
1367 | conn => $self, |
1390 | ; |
1368 | ; |
1391 | } |
1369 | } |
… | |
… | |
1396 | } |
1374 | } |
1397 | |
1375 | |
1398 | sub destroy { |
1376 | sub destroy { |
1399 | my ($self) = @_; |
1377 | my ($self) = @_; |
1400 | |
1378 | |
1401 | (delete $self->{npc_dialog})->destroy |
1379 | $_->destroy |
1402 | if $self->{npc_dialog}; |
1380 | for values %{ $self->{w} }; |
1403 | |
1381 | |
1404 | $self->SUPER::destroy; |
1382 | $self->SUPER::destroy; |
1405 | |
1383 | |
1406 | %$self = (); |
1384 | %$self = (); |
1407 | } |
1385 | } |
… | |
… | |
1507 | |
1485 | |
1508 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1486 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1509 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1487 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1510 | |
1488 | |
1511 | if (exists $info{msg}) { |
1489 | if (exists $info{msg}) { |
1512 | my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; |
1490 | my $text = "\n" . DC::sanitise_cfxml $info{msg}; |
1513 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1491 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1514 | my @link; |
1492 | my @link; |
1515 | $text =~ s{ |
1493 | $text =~ s{ |
1516 | ($match) |
1494 | ($match) |
1517 | }{ |
1495 | }{ |
… | |
… | |
1561 | |
1539 | |
1562 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1540 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1563 | |
1541 | |
1564 | if ($self->{conn}) { |
1542 | if ($self->{conn}) { |
1565 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1543 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1566 | delete $self->{conn}{npc_dialog}; |
1544 | delete $self->{conn}{w}{npc_dialog}; |
1567 | $self->{conn}->disconnect_ext ($self->{id}); |
1545 | $self->{conn}->disconnect_ext ($self->{id}); |
1568 | } |
1546 | } |
1569 | |
1547 | |
1570 | $self->SUPER::destroy; |
1548 | $self->SUPER::destroy; |
1571 | } |
1549 | } |