… | |
… | |
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 (@_, setup_req => { extmap => 1 }); |
22 | my $self = $class->SUPER::new (%arg, |
|
|
23 | setup_req => { |
|
|
24 | extmap => 1, |
|
|
25 | excmd => 1, |
|
|
26 | %{$arg{setup_req} || {}}, |
|
|
27 | }, |
|
|
28 | ); |
23 | |
29 | |
24 | $self->{map_widget}->clr_commands; |
30 | $self->{map_widget}->clr_commands; |
25 | |
31 | |
26 | my @cmd_help = map { |
32 | my @cmd_help = map { |
27 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
243 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
244 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
245 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
246 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
247 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
248 | my $rng = $stats->{+CS_STAT_RANGE}; |
254 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
249 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
250 | $::GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
251 | my $title = $stats->{+CS_STAT_TITLE}; |
255 | my $title = $stats->{+CS_STAT_TITLE}; |
252 | $title =~ s/^Player: //; |
256 | $title =~ s/^Player: //; |
253 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
257 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
254 | |
258 | |
255 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
259 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
… | |
… | |
415 | } while $self->{texture}[$id]; |
419 | } while $self->{texture}[$id]; |
416 | |
420 | |
417 | CFPlus::DB::get tilecache => $id, sub { |
421 | CFPlus::DB::get tilecache => $id, sub { |
418 | my ($data) = @_; |
422 | my ($data) = @_; |
419 | |
423 | |
|
|
424 | return unless $self->{map}; # stop when destroyed |
|
|
425 | |
420 | $self->set_texture ($id => $data) |
426 | $self->set_texture ($id => $data) |
421 | if defined $data; |
427 | if defined $data; |
422 | |
428 | |
423 | $self->bg_fetch; |
429 | $self->bg_fetch; |
424 | }; |
430 | }; |
425 | } |
431 | } |
426 | |
432 | |
427 | sub load_map($$$) { |
433 | sub load_map($$$) { |
428 | my ($self, $hash, $x, $y) = @_; |
434 | my ($self, $hash, $x, $y) = @_; |
429 | |
435 | |
|
|
436 | my $gen = $self->{map_change_gen}; |
|
|
437 | |
430 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
438 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
|
|
439 | return unless $gen == $self->{map_change_gen}; |
|
|
440 | |
431 | my ($data) = @_; |
441 | my ($data) = @_; |
432 | |
442 | |
433 | if (defined $data) { |
443 | if (defined $data) { |
434 | $data = Compress::LZF::decompress $data; |
444 | $data = Compress::LZF::decompress $data; |
435 | #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# |
436 | |
446 | |
437 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
447 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
438 | push @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
448 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
439 | $self->bg_fetch unless $inprogress; |
449 | $self->bg_fetch unless $inprogress; |
440 | } |
450 | } |
441 | }; |
451 | }; |
442 | } |
452 | } |
443 | |
453 | |
… | |
… | |
510 | |
520 | |
511 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
521 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
512 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
522 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
513 | |
523 | |
514 | } else { |
524 | } else { |
|
|
525 | my $gen = $self->{map_change_gen}; |
515 | $self->send_mapinfo ("spatial $path$tile", sub { |
526 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
527 | return unless $gen == $self->{map_change_gen}; |
|
|
528 | |
516 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
529 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
517 | |
530 | |
518 | return if $mode ne "spatial"; |
531 | return if $mode ne "spatial"; |
519 | |
532 | |
520 | $x += $self->{map}->ox; |
533 | $x += $self->{map}->ox; |
… | |
… | |
534 | |
547 | |
535 | sub map_change { |
548 | sub map_change { |
536 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
549 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
537 | |
550 | |
538 | $self->flush_map; |
551 | $self->flush_map; |
|
|
552 | |
|
|
553 | ++$self->{map_change_gen}; |
539 | |
554 | |
540 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
555 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
541 | |
556 | |
542 | my $mapmapw = $self->{mapmap}->{w}; |
557 | my $mapmapw = $self->{mapmap}->{w}; |
543 | my $mapmaph = $self->{mapmap}->{h}; |
558 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
583 | if $changed; |
598 | if $changed; |
584 | |
599 | |
585 | $self->set_texture ($face->{id} => delete $face->{image}); |
600 | $self->set_texture ($face->{id} => delete $face->{image}); |
586 | } |
601 | } |
587 | |
602 | |
|
|
603 | sub smooth_update { |
|
|
604 | my ($self, $facenum, $face) = @_; |
|
|
605 | |
|
|
606 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
|
|
607 | } |
|
|
608 | |
588 | sub set_texture { |
609 | sub set_texture { |
589 | my ($self, $id, $data) = @_; |
610 | my ($self, $id, $data) = @_; |
590 | |
611 | |
591 | $self->{texture}[$id] ||= do { |
612 | $self->{texture}[$id] = my $tex = |
592 | my $tex = |
|
|
593 | new_from_image CFPlus::Texture |
613 | new_from_image CFPlus::Texture |
594 | $data, minify => 1, mipmap => 1; |
614 | $data, minify => 1, mipmap => 1; |
595 | |
615 | |
596 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
616 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
597 | $self->{map_widget}->update; |
617 | $self->{map_widget}->update; |
598 | |
|
|
599 | $tex |
|
|
600 | }; |
|
|
601 | } |
618 | } |
602 | |
619 | |
603 | sub sound_play { |
620 | sub sound_play { |
604 | my ($self, $x, $y, $soundnum, $type) = @_; |
621 | my ($self, $x, $y, $soundnum, $type) = @_; |
605 | |
622 | |
… | |
… | |
615 | $LAST_QUERY = $prompt; |
632 | $LAST_QUERY = $prompt; |
616 | |
633 | |
617 | $self->{query}-> ($self, $flags, $prompt); |
634 | $self->{query}-> ($self, $flags, $prompt); |
618 | } |
635 | } |
619 | |
636 | |
620 | sub drawinfo { |
637 | our %NAME_TO_COLOR = ( |
621 | 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 | ); |
622 | |
652 | |
623 | my @color = ( |
653 | our @CF_COLOR = ( |
624 | [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], |
625 | [1.00, 1.00, 1.00], |
655 | [1.00, 1.00, 1.00], |
626 | [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] |
627 | [1.00, 0.00, 0.00], |
657 | [1.00, 0.00, 0.00], |
628 | [1.00, 0.54, 0.00], |
658 | [1.00, 0.54, 0.00], |
629 | [0.11, 0.56, 1.00], |
659 | [0.11, 0.56, 1.00], |
630 | [0.93, 0.46, 0.00], |
660 | [0.93, 0.46, 0.00], |
631 | [0.18, 0.54, 0.34], |
661 | [0.18, 0.54, 0.34], |
632 | [0.56, 0.73, 0.56], |
662 | [0.56, 0.73, 0.56], |
633 | [0.80, 0.80, 0.80], |
663 | [0.80, 0.80, 0.80], |
634 | [0.75, 0.61, 0.20], |
664 | [0.75, 0.61, 0.20], |
635 | [0.99, 0.77, 0.26], |
665 | [0.99, 0.77, 0.26], |
636 | [0.74, 0.65, 0.41], |
666 | [0.74, 0.65, 0.41], |
637 | ); |
667 | ); |
638 | |
668 | |
639 | my $fg = $color[$color % @color]; |
669 | sub msg { |
|
|
670 | my ($self, $color, $type, $text, @extra) = @_; |
640 | |
671 | |
|
|
672 | # we now weed out all tags we do not support |
|
|
673 | $text =~ s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%<%g; |
|
|
674 | # now all entities |
|
|
675 | $text =~ s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
676 | |
|
|
677 | # handle some elements |
|
|
678 | $text =~ s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
679 | $text =~ s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
680 | |
|
|
681 | if (my $cb = $self->{cb_msg}{$type}) { |
|
|
682 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
|
|
683 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
|
|
684 | $type =~ s/-/_/g; |
|
|
685 | $self->{$type} = $text; |
|
|
686 | } else { |
641 | $self->logprint ("info: ", $text); |
687 | $self->logprint ("msg: ", $text); |
|
|
688 | return if $color < 0; # negative color == ignore if not understood |
642 | |
689 | |
|
|
690 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
691 | |
643 | # try to create single paragraphs of multiple lines sent by the server |
692 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
693 | # no longer neecssary with TRT servers |
644 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
694 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
645 | |
695 | |
646 | $text = CFPlus::asxml $text; |
|
|
647 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
648 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
649 | |
|
|
650 | ::message ({ fg => $fg, markup => $_ }) |
696 | ::message ({ fg => $fg, markup => $_ }) |
651 | for split /\n/, $text; |
697 | for split /\n/, $text; |
652 | |
698 | |
653 | $self->{statusbox}->add ($text, |
699 | $self->{statusbox}->add ($text, |
654 | group => $text, |
700 | group => $text, |
655 | fg => $fg, |
701 | fg => $fg, |
656 | timeout => $color >= 2 ? 180 : 10, |
702 | timeout => $color >= 2 ? 180 : 10, |
657 | tooltip_font => $::FONT_FIXED, |
703 | tooltip_font => $::FONT_FIXED, |
658 | ); |
704 | ); |
659 | } |
705 | } |
660 | |
|
|
661 | sub drawextinfo { |
|
|
662 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
663 | |
|
|
664 | $self->drawinfo ($color, $message); |
|
|
665 | } |
706 | } |
666 | |
707 | |
667 | sub spell_add { |
708 | sub spell_add { |
668 | my ($self, $spell) = @_; |
709 | my ($self, $spell) = @_; |
669 | |
710 | |
… | |
… | |
902 | $::SERVER_INFO->set_markup ( |
943 | $::SERVER_INFO->set_markup ( |
903 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
944 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
904 | . "protocol version <tt>$self->{version}</tt>\n" |
945 | . "protocol version <tt>$self->{version}</tt>\n" |
905 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
946 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
906 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
947 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
948 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
907 | . "editing support $yesno[!!$self->{editor_support}]\n" |
949 | . "editing support $yesno[!!$self->{editor_support}]\n" |
908 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
950 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
951 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
909 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
952 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
910 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
953 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
911 | . "map size $self->{mapw}×$self->{maph}\n" |
954 | . "map size $self->{mapw}×$self->{maph}\n" |
912 | ); |
955 | ); |
913 | |
956 | |