… | |
… | |
14 | use DC::Item; |
14 | use DC::Item; |
15 | |
15 | |
16 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
17 | |
17 | |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
19 | "dialogue.png", minify => 1, mipmap => 1; |
19 | "dialogue.png", minify => 1, mipmap => 1; |
20 | |
20 | |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
23 | |
23 | |
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
… | |
… | |
27 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
28 | |
28 | |
29 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
30 | setup_req => { |
30 | setup_req => { |
31 | extmap => 1, |
31 | extmap => 1, |
32 | excmd => 1, |
|
|
33 | widget => 2, |
32 | widget => 2, |
34 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
35 | }, |
34 | }, |
36 | ); |
35 | ); |
|
|
36 | |
|
|
37 | $self->update_fx_want; |
|
|
38 | |
|
|
39 | my $exp_guard = $self->addme_guard; |
|
|
40 | my $skl_guard = $self->addme_guard; |
|
|
41 | my $spl_guard = $self->addme_guard; |
|
|
42 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
43 | my ($exp, $skl, $spl) = @_; |
|
|
44 | |
|
|
45 | $self->register_face_handler ($exp, sub { |
|
|
46 | my ($face) = @_; |
|
|
47 | |
|
|
48 | undef $exp_guard; |
|
|
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
|
|
52 | |
|
|
53 | $self->register_face_handler ($skl, sub { |
|
|
54 | my ($face) = @_; |
|
|
55 | |
|
|
56 | undef $skl_guard; |
|
|
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
|
|
59 | }); |
|
|
60 | |
|
|
61 | $self->register_face_handler ($spl, sub { |
|
|
62 | my ($face) = @_; |
|
|
63 | |
|
|
64 | undef $spl_guard; |
|
|
65 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
66 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
67 | }); |
|
|
68 | |
|
|
69 | () |
|
|
70 | }); |
37 | |
71 | |
38 | $self->{map_widget}->clr_commands; |
72 | $self->{map_widget}->clr_commands; |
39 | |
73 | |
40 | my @cmd_help = map { |
74 | my @cmd_help = map { |
41 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
75 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
95 | $self->{noface} = my $tex = $TEX_NOFACE; |
129 | $self->{noface} = my $tex = $TEX_NOFACE; |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
130 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
97 | } |
131 | } |
98 | |
132 | |
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
133 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
134 | # $self->{expire_w} = AE::timer 1, 1, sub { |
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
135 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
102 | # |
136 | # |
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
137 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
138 | # warn DC::SvREFCNT $self->{texture}[$_]; |
105 | # $self->{texture}[$_]->unload; |
139 | # $self->{texture}[$_]->unload; |
… | |
… | |
129 | }); |
163 | }); |
130 | } |
164 | } |
131 | |
165 | |
132 | sub ext_capabilities { |
166 | sub ext_capabilities { |
133 | my ($self, %cap) = @_; |
167 | my ($self, %cap) = @_; |
134 | |
|
|
135 | $self->update_fx_want; |
|
|
136 | |
|
|
137 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
138 | my ($exp_table) = @_; |
|
|
139 | |
|
|
140 | $self->register_face_handler ($exp_table, sub { |
|
|
141 | my ($face) = @_; |
|
|
142 | |
|
|
143 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
144 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
145 | }); |
|
|
146 | |
|
|
147 | () |
|
|
148 | }); |
|
|
149 | |
168 | |
150 | if (my $ts = $cap{tileset}) { |
169 | if (my $ts = $cap{tileset}) { |
151 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
170 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
152 | $self->{tileset} = $default; |
171 | $self->{tileset} = $default; |
153 | $self->{tilesize} = $default->[3]; |
172 | $self->{tilesize} = $default->[3]; |
… | |
… | |
454 | |
473 | |
455 | if (my @diffs = |
474 | if (my @diffs = |
456 | ( |
475 | ( |
457 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
476 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
458 | map { |
477 | map { |
459 | $stats->{$_} && $prev->{$_} |
478 | $stats->{$_} && $prev->{$_} |
460 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
479 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
461 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
480 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
462 | ) |
481 | ) |
463 | ) { |
482 | ) { |
464 | my $msg = join " ", @diffs; |
483 | my $msg = join " ", @diffs; |
… | |
… | |
669 | } |
688 | } |
670 | |
689 | |
671 | sub feed_map1a { |
690 | sub feed_map1a { |
672 | my ($self, $data) = @_; |
691 | my ($self, $data) = @_; |
673 | |
692 | |
674 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
693 | my $missing = $self->{map}->map1a_update ($data); |
675 | my $delay; |
694 | my $delay; |
676 | |
695 | |
677 | for my $tile (@$missing) { |
696 | for my $tile (@$missing) { |
678 | next if $self->{delay}{$tile}; |
697 | next if $self->{delay}{$tile}; |
679 | |
698 | |
… | |
… | |
1042 | my ($self, $flags, $prompt) = @_; |
1061 | my ($self, $flags, $prompt) = @_; |
1043 | |
1062 | |
1044 | $prompt = $LAST_QUERY unless length $prompt; |
1063 | $prompt = $LAST_QUERY unless length $prompt; |
1045 | $LAST_QUERY = $prompt; |
1064 | $LAST_QUERY = $prompt; |
1046 | |
1065 | |
1047 | $self->{query}-> ($self, $flags, $prompt); |
1066 | $self->{query}->($self, $flags, $prompt); |
1048 | } |
1067 | } |
1049 | |
1068 | |
1050 | sub sanitise_xml($) { |
1069 | sub sanitise_xml($) { |
1051 | local $_ = shift; |
1070 | local $_ = shift; |
1052 | |
1071 | |
… | |
… | |
1084 | tan => 12, |
1103 | tan => 12, |
1085 | ); |
1104 | ); |
1086 | |
1105 | |
1087 | our @CF_COLOR = ( |
1106 | our @CF_COLOR = ( |
1088 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1107 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1089 | [1.00, 1.00, 1.00], |
1108 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1090 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1109 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1091 | [1.00, 0.00, 0.00], |
1110 | [1.00, 0.00, 0.00], |
1092 | [1.00, 0.54, 0.00], |
1111 | [1.00, 0.54, 0.00], |
1093 | [0.11, 0.56, 1.00], |
1112 | [0.11, 0.56, 1.00], |
1094 | [0.93, 0.46, 0.00], |
1113 | [0.93, 0.46, 0.00], |
1095 | [0.18, 0.54, 0.34], |
1114 | [0.18, 0.54, 0.34], |
… | |
… | |
1113 | } else { |
1132 | } else { |
1114 | $self->logprint ("msg: ", $text); |
1133 | $self->logprint ("msg: ", $text); |
1115 | return if $color < 0; # negative color == ignore if not understood |
1134 | return if $color < 0; # negative color == ignore if not understood |
1116 | |
1135 | |
1117 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1136 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1118 | |
|
|
1119 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1120 | # no longer neecssary with TRT servers |
|
|
1121 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1122 | |
1137 | |
1123 | ::message ({ |
1138 | ::message ({ |
1124 | fg => $fg, |
1139 | fg => $fg, |
1125 | markup => $text, |
1140 | markup => $text, |
1126 | type => $type, |
1141 | type => $type, |
… | |
… | |
1347 | sub update_server_info { |
1362 | sub update_server_info { |
1348 | my ($self) = @_; |
1363 | my ($self) = @_; |
1349 | |
1364 | |
1350 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1365 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1351 | |
1366 | |
|
|
1367 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1368 | |
1352 | $::SERVER_INFO->set_markup ( |
1369 | $::SERVER_INFO->set_markup ( |
1353 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1370 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1354 | . "protocol version <tt>$self->{version}</tt>\n" |
1371 | . "protocol version <tt>$version</tt>\n" |
1355 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1356 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1357 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1358 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1372 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1359 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1360 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1361 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1373 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1362 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1374 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1363 | . "map size $self->{mapw}×$self->{maph}\n" |
1375 | . "map size $self->{mapw}×$self->{maph}\n" |
1364 | ); |
1376 | ); |
1365 | |
1377 | |
… | |
… | |
1399 | $self->send_ext_req (lookat => $x, $y, sub { |
1411 | $self->send_ext_req (lookat => $x, $y, sub { |
1400 | my (%msg) = @_; |
1412 | my (%msg) = @_; |
1401 | |
1413 | |
1402 | if (exists $msg{npc_dialog}) { |
1414 | if (exists $msg{npc_dialog}) { |
1403 | # start npc chat dialog |
1415 | # start npc chat dialog |
1404 | $self->{npc_dialog} = new DC::NPCDialog:: |
1416 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1405 | token => $msg{npc_dialog}, |
1417 | token => $msg{npc_dialog}, |
1406 | title => "$msg{npc_dialog}[0] (NPC)", |
1418 | title => "$msg{npc_dialog}[0] (NPC)", |
1407 | conn => $self, |
1419 | conn => $self, |
1408 | ; |
1420 | ; |
1409 | } |
1421 | } |
… | |
… | |
1414 | } |
1426 | } |
1415 | |
1427 | |
1416 | sub destroy { |
1428 | sub destroy { |
1417 | my ($self) = @_; |
1429 | my ($self) = @_; |
1418 | |
1430 | |
1419 | (delete $self->{npc_dialog})->destroy |
1431 | $_->destroy |
1420 | if $self->{npc_dialog}; |
1432 | for values %{ $self->{w} }; |
1421 | |
1433 | |
1422 | $self->SUPER::destroy; |
1434 | $self->SUPER::destroy; |
1423 | |
1435 | |
1424 | %$self = (); |
1436 | %$self = (); |
1425 | } |
1437 | } |
… | |
… | |
1579 | |
1591 | |
1580 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1592 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1581 | |
1593 | |
1582 | if ($self->{conn}) { |
1594 | if ($self->{conn}) { |
1583 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1595 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1584 | delete $self->{conn}{npc_dialog}; |
1596 | delete $self->{conn}{w}{npc_dialog}; |
1585 | $self->{conn}->disconnect_ext ($self->{id}); |
1597 | $self->{conn}->disconnect_ext ($self->{id}); |
1586 | } |
1598 | } |
1587 | |
1599 | |
1588 | $self->SUPER::destroy; |
1600 | $self->SUPER::destroy; |
1589 | } |
1601 | } |