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; |
… | |
… | |
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; |
22 | |
|
|
23 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
24 | "hidden.png", minify => 1, mipmap => 1; |
|
|
25 | |
23 | |
26 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
27 | |
25 | |
28 | sub new { |
26 | sub new { |
29 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
… | |
… | |
94 | } |
92 | } |
95 | |
93 | |
96 | { |
94 | { |
97 | $self->{noface} = my $tex = $TEX_NOFACE; |
95 | $self->{noface} = my $tex = $TEX_NOFACE; |
98 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
99 | } |
|
|
100 | |
|
|
101 | { |
|
|
102 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
103 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
104 | } |
97 | } |
105 | |
98 | |
106 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
107 | # $self->{expire_w} = EV::timer 1, 1, sub { |
100 | # $self->{expire_w} = EV::timer 1, 1, sub { |
108 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
… | |
… | |
287 | tooltip => $DC::UI::TOOLTIP, |
280 | tooltip => $DC::UI::TOOLTIP, |
288 | |
281 | |
289 | mapwidget => $::MAPWIDGET, |
282 | mapwidget => $::MAPWIDGET, |
290 | menubar => $::MENUBAR, |
283 | menubar => $::MENUBAR, |
291 | menupopup => $::MENUPOPUP, |
284 | menupopup => $::MENUPOPUP, |
|
|
285 | pickup_enable => $::PICKUP_ENABLE, |
292 | buttonbar => $::BUTTONBAR, |
286 | buttonbar => $::BUTTONBAR, |
293 | metaserver => $::METASERVER, |
287 | metaserver => $::METASERVER, |
294 | buttonbar => $::BUTTONBAR, |
288 | buttonbar => $::BUTTONBAR, |
295 | login_button => $::LOGIN_BUTTON, |
289 | login_button => $::LOGIN_BUTTON, |
296 | quit_dialog => $::QUIT_DIALOG, |
290 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
407 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
401 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
408 | : () |
402 | : () |
409 | } |
403 | } |
410 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
404 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
411 | |
405 | |
412 | join "", @diff |
406 | "\u$name: " . (join ", ", @diff) |
413 | } |
407 | } |
414 | |
408 | |
415 | # all stats that are chacked against changes |
409 | # all stats that are chacked against changes |
416 | my @statchange = ( |
410 | my @statchange = ( |
417 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
411 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
472 | } |
466 | } |
473 | |
467 | |
474 | if ( |
468 | if ( |
475 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
469 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
476 | ) { |
470 | ) { |
477 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
471 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
478 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
472 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
479 | } |
473 | } |
480 | |
474 | |
481 | $self->update_stats_window ($stats, $prev); |
475 | $self->update_stats_window ($stats, $prev); |
482 | |
476 | |
… | |
… | |
520 | |
514 | |
521 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
515 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
522 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
516 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
523 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
517 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
524 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
518 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
525 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
519 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
526 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
520 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
527 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
521 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
528 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
522 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
529 | my $title = $stats->{+CS_STAT_TITLE}; |
523 | my $title = $stats->{+CS_STAT_TITLE}; |
530 | $title =~ s/^Player: //; |
524 | $title =~ s/^Player: //; |
531 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
525 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
532 | |
526 | |
… | |
… | |
544 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
538 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
545 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
539 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
546 | |
540 | |
547 | $self->update_weight; |
541 | $self->update_weight; |
548 | |
542 | |
549 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
543 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
550 | for keys %RES_TBL; |
544 | for keys %RES_TBL; |
551 | |
545 | |
552 | my $sktbl = $::STATWIDS->{skill_tbl}; |
546 | my $sktbl = $::STATWIDS->{skill_tbl}; |
553 | my @skills = keys %{ $self->{skill_info} }; |
547 | my @skills = keys %{ $self->{skill_info} }; |
554 | |
548 | |
… | |
… | |
645 | my $sw = $self->{skillwid}{$idx}; |
639 | my $sw = $self->{skillwid}{$idx}; |
646 | $sw->[0]->set_text (::formsep ($val->[1])); |
640 | $sw->[0]->set_text (::formsep ($val->[1])); |
647 | $sw->[1]->set_text ($val->[0] * 1); |
641 | $sw->[1]->set_text ($val->[0] * 1); |
648 | $sw->[2]->set_value (@$val); |
642 | $sw->[2]->set_value (@$val); |
649 | |
643 | |
650 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
644 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
651 | $::GAUGES->{sklprg}->set_value (@$val); |
645 | $::GAUGES->{skillexp}->set_value (@$val); |
652 | } |
646 | } |
653 | } |
647 | } |
654 | |
648 | |
655 | sub user_send { |
649 | sub user_send { |
656 | my ($self, $command) = @_; |
650 | my ($self, $command) = @_; |
… | |
… | |
995 | |
989 | |
996 | my $tex = $self->{texture}[$tile] ||= |
990 | my $tex = $self->{texture}[$tile] ||= |
997 | new DC::Texture |
991 | new DC::Texture |
998 | tile => $tile, |
992 | tile => $tile, |
999 | image => $data, delete_image => 1, |
993 | image => $data, delete_image => 1, |
1000 | minify => 1, mipmap => 1; |
994 | minify => 1; |
1001 | |
995 | |
1002 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
996 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1003 | $_->($tex) for @$cbs; |
997 | $_->($tex) for @$cbs; |
1004 | } |
998 | } |
1005 | } |
999 | } |
… | |
… | |
1010 | my ($self, $num, $cb) = @_; |
1004 | my ($self, $num, $cb) = @_; |
1011 | |
1005 | |
1012 | push @{$self->{face_cb}{$num}}, $cb; |
1006 | push @{$self->{face_cb}{$num}}, $cb; |
1013 | |
1007 | |
1014 | defined wantarray |
1008 | defined wantarray |
1015 | ? DC::guard { |
1009 | ? Guard::guard { |
1016 | @{$self->{face_cb}{$num}} |
1010 | @{$self->{face_cb}{$num}} |
1017 | = grep $_ != $cb, |
1011 | = grep $_ != $cb, |
1018 | @{$self->{face_cb}{$num}}; |
1012 | @{$self->{face_cb}{$num}}; |
1019 | } |
1013 | } |
1020 | : () |
1014 | : () |
… | |
… | |
1353 | sub update_server_info { |
1347 | sub update_server_info { |
1354 | my ($self) = @_; |
1348 | my ($self) = @_; |
1355 | |
1349 | |
1356 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1350 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1357 | |
1351 | |
|
|
1352 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1353 | |
1358 | $::SERVER_INFO->set_markup ( |
1354 | $::SERVER_INFO->set_markup ( |
1359 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1355 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1360 | . "protocol version <tt>$self->{version}</tt>\n" |
1356 | . "protocol version <tt>$version</tt>\n" |
1361 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1357 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1362 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1358 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1363 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1359 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1364 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1360 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1365 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1361 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
… | |
… | |
1393 | }); |
1389 | }); |
1394 | |
1390 | |
1395 | $self->update_server_info; |
1391 | $self->update_server_info; |
1396 | |
1392 | |
1397 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1393 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1398 | $self->send_command ("pickup $::CFG->{pickup}"); |
1394 | $self->send_pickup ($::CFG->{pickup}); |
1399 | |
|
|
1400 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1401 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1402 | } |
1395 | } |
1403 | |
1396 | |
1404 | sub lookat { |
1397 | sub lookat { |
1405 | my ($self, $x, $y) = @_; |
1398 | my ($self, $x, $y) = @_; |
1406 | |
1399 | |