… | |
… | |
15 | use Crossfire::Protocol::Base 0.95; |
15 | use Crossfire::Protocol::Base 0.95; |
16 | |
16 | |
17 | use base 'Crossfire::Protocol::Base'; |
17 | use base 'Crossfire::Protocol::Base'; |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my ($class, %arg) = @_; |
21 | |
21 | |
22 | my $self = $class->SUPER::new (@_, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
25 | smoothing => 1, |
25 | excmd => 1, |
|
|
26 | %{$arg{setup_req} || {}}, |
26 | }, |
27 | }, |
27 | ); |
28 | ); |
28 | |
29 | |
29 | $self->{map_widget}->clr_commands; |
30 | $self->{map_widget}->clr_commands; |
30 | |
31 | |
… | |
… | |
248 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | my $rng = $stats->{+CS_STAT_RANGE}; |
254 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
254 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
255 | $::GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
256 | my $title = $stats->{+CS_STAT_TITLE}; |
255 | my $title = $stats->{+CS_STAT_TITLE}; |
257 | $title =~ s/^Player: //; |
256 | $title =~ s/^Player: //; |
258 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
257 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
259 | |
258 | |
260 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
259 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
… | |
… | |
432 | } |
431 | } |
433 | |
432 | |
434 | sub load_map($$$) { |
433 | sub load_map($$$) { |
435 | my ($self, $hash, $x, $y) = @_; |
434 | my ($self, $hash, $x, $y) = @_; |
436 | |
435 | |
|
|
436 | my $gen = $self->{map_change_gen}; |
|
|
437 | |
437 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
438 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
|
|
439 | return unless $gen == $self->{map_change_gen}; |
|
|
440 | |
438 | my ($data) = @_; |
441 | my ($data) = @_; |
439 | |
442 | |
440 | if (defined $data) { |
443 | if (defined $data) { |
441 | $data = Compress::LZF::decompress $data; |
444 | $data = Compress::LZF::decompress $data; |
442 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
445 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
… | |
… | |
517 | |
520 | |
518 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
521 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
519 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
522 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
520 | |
523 | |
521 | } else { |
524 | } else { |
|
|
525 | my $gen = $self->{map_change_gen}; |
522 | $self->send_mapinfo ("spatial $path$tile", sub { |
526 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
527 | return unless $gen == $self->{map_change_gen}; |
|
|
528 | |
523 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
529 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
524 | |
530 | |
525 | return if $mode ne "spatial"; |
531 | return if $mode ne "spatial"; |
526 | |
532 | |
527 | $x += $self->{map}->ox; |
533 | $x += $self->{map}->ox; |
… | |
… | |
541 | |
547 | |
542 | sub map_change { |
548 | sub map_change { |
543 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
549 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
544 | |
550 | |
545 | $self->flush_map; |
551 | $self->flush_map; |
|
|
552 | |
|
|
553 | ++$self->{map_change_gen}; |
546 | |
554 | |
547 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
555 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
548 | |
556 | |
549 | my $mapmapw = $self->{mapmap}->{w}; |
557 | my $mapmapw = $self->{mapmap}->{w}; |
550 | my $mapmaph = $self->{mapmap}->{h}; |
558 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
624 | $LAST_QUERY = $prompt; |
632 | $LAST_QUERY = $prompt; |
625 | |
633 | |
626 | $self->{query}-> ($self, $flags, $prompt); |
634 | $self->{query}-> ($self, $flags, $prompt); |
627 | } |
635 | } |
628 | |
636 | |
629 | sub drawinfo { |
637 | our %NAME_TO_COLOR = ( |
630 | my ($self, $color, $text) = @_; |
638 | black => 0, |
|
|
639 | white => 1, |
|
|
640 | darkblue => 2, |
|
|
641 | red => 3, |
|
|
642 | orange => 4, |
|
|
643 | lightblue => 5, |
|
|
644 | darkorange => 6, |
|
|
645 | green => 7, |
|
|
646 | darkgreen => 8, |
|
|
647 | grey => 9, |
|
|
648 | brown => 10, |
|
|
649 | yellow => 11, |
|
|
650 | tan => 12, |
|
|
651 | ); |
631 | |
652 | |
632 | my @color = ( |
653 | our @CF_COLOR = ( |
633 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
654 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
634 | [1.00, 1.00, 1.00], |
655 | [1.00, 1.00, 1.00], |
635 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
656 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
636 | [1.00, 0.00, 0.00], |
657 | [1.00, 0.00, 0.00], |
637 | [1.00, 0.54, 0.00], |
658 | [1.00, 0.54, 0.00], |
638 | [0.11, 0.56, 1.00], |
659 | [0.11, 0.56, 1.00], |
639 | [0.93, 0.46, 0.00], |
660 | [0.93, 0.46, 0.00], |
640 | [0.18, 0.54, 0.34], |
661 | [0.18, 0.54, 0.34], |
641 | [0.56, 0.73, 0.56], |
662 | [0.56, 0.73, 0.56], |
642 | [0.80, 0.80, 0.80], |
663 | [0.80, 0.80, 0.80], |
643 | [0.75, 0.61, 0.20], |
664 | [0.75, 0.61, 0.20], |
644 | [0.99, 0.77, 0.26], |
665 | [0.99, 0.77, 0.26], |
645 | [0.74, 0.65, 0.41], |
666 | [0.74, 0.65, 0.41], |
646 | ); |
667 | ); |
647 | |
668 | |
648 | my $fg = $color[$color % @color]; |
669 | sub msg { |
|
|
670 | my ($self, $color, $type, $text, @extra) = @_; |
649 | |
671 | |
|
|
672 | if (my $cb = $self->{cb_msg}{$type}) { |
|
|
673 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
|
|
674 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
|
|
675 | $type =~ s/-/_/g; |
|
|
676 | $self->{$type} = $text; |
|
|
677 | } else { |
650 | $self->logprint ("info: ", $text); |
678 | $self->logprint ("msg: ", $text); |
|
|
679 | return if $color < 0; # negative color == ignore if not understood |
651 | |
680 | |
|
|
681 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
682 | |
652 | # try to create single paragraphs of multiple lines sent by the server |
683 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
684 | # no longer neecssary with TRT servers |
653 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
685 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
654 | |
686 | |
655 | $text = CFPlus::asxml $text; |
|
|
656 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
657 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
658 | |
|
|
659 | ::message ({ fg => $fg, markup => $_ }) |
687 | ::message ({ fg => $fg, markup => $_ }) |
660 | for split /\n/, $text; |
688 | for split /\n/, $text; |
661 | |
689 | |
662 | $self->{statusbox}->add ($text, |
690 | $self->{statusbox}->add ($text, |
663 | group => $text, |
691 | group => $text, |
664 | fg => $fg, |
692 | fg => $fg, |
665 | timeout => $color >= 2 ? 180 : 10, |
693 | timeout => $color >= 2 ? 180 : 10, |
666 | tooltip_font => $::FONT_FIXED, |
694 | tooltip_font => $::FONT_FIXED, |
667 | ); |
695 | ); |
668 | } |
696 | } |
669 | |
|
|
670 | sub drawextinfo { |
|
|
671 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
672 | |
|
|
673 | $self->drawinfo ($color, $message); |
|
|
674 | } |
697 | } |
675 | |
698 | |
676 | sub spell_add { |
699 | sub spell_add { |
677 | my ($self, $spell) = @_; |
700 | my ($self, $spell) = @_; |
678 | |
701 | |
… | |
… | |
911 | $::SERVER_INFO->set_markup ( |
934 | $::SERVER_INFO->set_markup ( |
912 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
935 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
913 | . "protocol version <tt>$self->{version}</tt>\n" |
936 | . "protocol version <tt>$self->{version}</tt>\n" |
914 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
937 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
915 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
938 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
939 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
916 | . "editing support $yesno[!!$self->{editor_support}]\n" |
940 | . "editing support $yesno[!!$self->{editor_support}]\n" |
917 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
941 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
942 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
918 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
943 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
919 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
944 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
920 | . "map size $self->{mapw}×$self->{maph}\n" |
945 | . "map size $self->{mapw}×$self->{maph}\n" |
921 | ); |
946 | ); |
922 | |
947 | |