… | |
… | |
83 | |
83 | |
84 | print $fh "$ts ", @a, "\n"; |
84 | print $fh "$ts ", @a, "\n"; |
85 | $fh->flush; |
85 | $fh->flush; |
86 | } |
86 | } |
87 | |
87 | |
|
|
88 | sub _stat_numdiff { |
|
|
89 | my ($self, $old, $new) = @_; |
|
|
90 | |
|
|
91 | my $diff = $new - $old; |
|
|
92 | $diff > 0 ? "+$diff" : $diff |
|
|
93 | } |
|
|
94 | |
|
|
95 | sub _stat_skillmaskdiff { |
|
|
96 | my ($self, $old, $new) = @_; |
|
|
97 | |
|
|
98 | my $diff = $old ^ $new; |
|
|
99 | |
|
|
100 | my @diff = map |
|
|
101 | { |
|
|
102 | $diff & $_ |
|
|
103 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
|
|
104 | : () |
|
|
105 | } |
|
|
106 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
|
|
107 | |
|
|
108 | join "", @diff |
|
|
109 | } |
|
|
110 | |
|
|
111 | # all stats that are chacked against changes |
|
|
112 | my @statchange = ( |
|
|
113 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
|
|
114 | [&CS_STAT_INT => \&_stat_numdiff, "Int"], |
|
|
115 | [&CS_STAT_WIS => \&_stat_numdiff, "Wis"], |
|
|
116 | [&CS_STAT_DEX => \&_stat_numdiff, "Dex"], |
|
|
117 | [&CS_STAT_CON => \&_stat_numdiff, "Con"], |
|
|
118 | [&CS_STAT_CHA => \&_stat_numdiff, "Cha"], |
|
|
119 | [&CS_STAT_POW => \&_stat_numdiff, "Pow"], |
|
|
120 | [&CS_STAT_WC => \&_stat_numdiff, "Wc"], |
|
|
121 | [&CS_STAT_AC => \&_stat_numdiff, "Ac"], |
|
|
122 | [&CS_STAT_DAM => \&_stat_numdiff, "Dam"], |
|
|
123 | [&CS_STAT_SPEED => \&_stat_numdiff, "Speed"], |
|
|
124 | [&CS_STAT_WEAP_SP => \&_stat_numdiff, "WSp"], |
|
|
125 | [&CS_STAT_MAXHP => \&_stat_numdiff, "HP"], |
|
|
126 | [&CS_STAT_MAXSP => \&_stat_numdiff, "Mana"], |
|
|
127 | [&CS_STAT_MAXGRACE => \&_stat_numdiff, "Grace"], |
|
|
128 | [&CS_STAT_WEIGHT_LIM => \&_stat_numdiff, "Weight"], |
|
|
129 | [&CS_STAT_SPELL_ATTUNE => \&_stat_skillmaskdiff, "attuned"], |
|
|
130 | [&CS_STAT_SPELL_REPEL => \&_stat_skillmaskdiff, "repelled"], |
|
|
131 | [&CS_STAT_SPELL_DENY => \&_stat_skillmaskdiff, "denied"], |
|
|
132 | [&CS_STAT_RES_PHYS => \&_stat_numdiff, "phys"], |
|
|
133 | [&CS_STAT_RES_MAG => \&_stat_numdiff, "magic"], |
|
|
134 | [&CS_STAT_RES_FIRE => \&_stat_numdiff, "fire"], |
|
|
135 | [&CS_STAT_RES_ELEC => \&_stat_numdiff, "electricity"], |
|
|
136 | [&CS_STAT_RES_COLD => \&_stat_numdiff, "cold"], |
|
|
137 | [&CS_STAT_RES_CONF => \&_stat_numdiff, "confusion"], |
|
|
138 | [&CS_STAT_RES_ACID => \&_stat_numdiff, "acid"], |
|
|
139 | [&CS_STAT_RES_DRAIN => \&_stat_numdiff, "drain"], |
|
|
140 | [&CS_STAT_RES_GHOSTHIT => \&_stat_numdiff, "ghosthit"], |
|
|
141 | [&CS_STAT_RES_POISON => \&_stat_numdiff, "poison"], |
|
|
142 | [&CS_STAT_RES_SLOW => \&_stat_numdiff, "slow"], |
|
|
143 | [&CS_STAT_RES_PARA => \&_stat_numdiff, "paralyse"], |
|
|
144 | [&CS_STAT_TURN_UNDEAD => \&_stat_numdiff, "turnundead"], |
|
|
145 | [&CS_STAT_RES_FEAR => \&_stat_numdiff, "fear"], |
|
|
146 | [&CS_STAT_RES_DEPLETE => \&_stat_numdiff, "depletion"], |
|
|
147 | [&CS_STAT_RES_DEATH => \&_stat_numdiff, "death"], |
|
|
148 | [&CS_STAT_RES_HOLYWORD => \&_stat_numdiff, "godpower"], |
|
|
149 | [&CS_STAT_RES_BLIND => \&_stat_numdiff, "blind"], |
|
|
150 | ); |
|
|
151 | |
88 | sub stats_update { |
152 | sub stats_update { |
89 | my ($self, $stats) = @_; |
153 | my ($self, $stats) = @_; |
90 | |
154 | |
91 | if (my $exp = $stats->{+CS_STAT_EXP64}) { |
155 | if (my $prev = $self->{prev_stats}) { |
92 | my $diff = $exp - $self->{prev_exp}; |
156 | if (my $diff = $stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) { |
93 | $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) |
157 | $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5); |
94 | if exists $self->{prev_exp} && $diff; |
158 | } |
95 | $self->{prev_exp} = $exp; |
159 | |
|
|
160 | if ( |
|
|
161 | my @diffs = map { |
|
|
162 | $stats->{$_->[0]} != $prev->{$_->[0]} |
|
|
163 | ? $_->[2] . $_->[1]->($self, $prev->{$_->[0]}, $stats->{$_->[0]}) : (); |
|
|
164 | } |
|
|
165 | @statchange |
|
|
166 | ) { |
|
|
167 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
|
|
168 | $self->{statusbox}->add ($msg, group => $msg, fg => [0.8, 1, 0.2, 1], timeout => 10); |
|
|
169 | } |
96 | } |
170 | } |
|
|
171 | |
|
|
172 | $self->{prev_stats} = { %$stats }; |
97 | |
173 | |
98 | ::update_stats_window ($stats); |
174 | ::update_stats_window ($stats); |
99 | } |
175 | } |
100 | |
176 | |
101 | sub user_send { |
177 | sub user_send { |
… | |
… | |
438 | # try to create single paragraphs of multiple lines sent by the server |
514 | # try to create single paragraphs of multiple lines sent by the server |
439 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
515 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
440 | $spell->{message} =~ s/\n+$//; |
516 | $spell->{message} =~ s/\n+$//; |
441 | $spell->{message} ||= "Server did not provide a description for this spell."; |
517 | $spell->{message} ||= "Server did not provide a description for this spell."; |
442 | |
518 | |
443 | $::SETUP_SPELLS->add_spell ($spell); |
519 | $::SPELL_PAGE->add_spell ($spell); |
444 | |
520 | |
445 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
521 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
446 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
522 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
447 | } |
523 | } |
448 | |
524 | |
449 | sub spell_delete { |
525 | sub spell_delete { |
450 | my ($self, $spell) = @_; |
526 | my ($self, $spell) = @_; |
|
|
527 | |
451 | $::SETUP_SPELLS->remove_spell ($spell); |
528 | $::SPELL_PAGE->remove_spell ($spell); |
452 | } |
529 | } |
453 | |
530 | |
454 | sub addme_success { |
531 | sub addme_success { |
455 | my ($self) = @_; |
532 | my ($self) = @_; |
456 | |
533 | |
… | |
… | |
536 | |
613 | |
537 | $row++; |
614 | $row++; |
538 | } else { |
615 | } else { |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
616 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
540 | text => "More...", |
617 | text => "More...", |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 }, |
618 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
542 | ); |
619 | ); |
543 | last; |
620 | last; |
544 | } |
621 | } |
545 | } |
622 | } |
546 | }); |
623 | }); |
… | |
… | |
569 | } |
646 | } |
570 | |
647 | |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
648 | $::INVR->set_items ($conn->{container}{$tag}); |
572 | } |
649 | } |
573 | |
650 | |
574 | sub update_container { |
651 | sub update_containers { |
575 | my ($tag) = @_; |
652 | my ($self) = @_; |
576 | |
653 | |
577 | $::INVR->set_items ($::CONN->{container}{$::CONN->{open_container}}) |
654 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
|
|
655 | for my $tag (keys %{ delete $self->{update_container} }) { |
|
|
656 | if ($tag == 0) { |
|
|
657 | update_floorbox; |
|
|
658 | $::INVR->set_items ($self->{container}{0}) |
578 | if $tag == $::CONN->{open_container}; |
659 | if $tag == $self->{open_container}; |
|
|
660 | } elsif ($tag == $self->{player}{tag}) { |
|
|
661 | $::INV->set_items ($self->{container}{$tag}) |
|
|
662 | } else { |
|
|
663 | $::INVR->set_items ($self->{container}{$tag}) |
|
|
664 | if $tag == $self->{open_container}; |
|
|
665 | } |
|
|
666 | } |
|
|
667 | }); |
579 | } |
668 | } |
580 | |
669 | |
581 | sub container_add { |
670 | sub container_add { |
582 | my ($self, $tag, $items) = @_; |
671 | my ($self, $tag, $items) = @_; |
583 | |
672 | |
584 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
673 | $self->{update_container}{$tag}++; |
585 | |
674 | $self->update_containers; |
586 | if ($tag == 0) { |
|
|
587 | update_floorbox; |
|
|
588 | update_container (0); |
|
|
589 | } elsif ($tag == $self->{player}{tag}) { |
|
|
590 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $self->{player}->{weight} / 1000); |
|
|
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
|
|
592 | } else { |
|
|
593 | update_container ($tag); |
|
|
594 | } |
|
|
595 | |
|
|
596 | # $self-<{player}{tag} => player inv |
|
|
597 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
598 | } |
675 | } |
599 | |
676 | |
600 | sub container_clear { |
677 | sub container_clear { |
601 | my ($self, $tag) = @_; |
678 | my ($self, $tag) = @_; |
602 | |
679 | |
603 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
680 | $self->{update_container}{$tag}++; |
604 | |
681 | $self->update_containers; |
605 | if ($tag == 0) { |
|
|
606 | update_floorbox; |
|
|
607 | update_container (0); |
|
|
608 | } elsif ($tag == $self->{player}{tag}) { |
|
|
609 | $::INV->set_items ($self->{container}{$tag}) |
|
|
610 | } else { |
|
|
611 | update_container ($tag); |
|
|
612 | } |
|
|
613 | |
|
|
614 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
615 | } |
682 | } |
616 | |
683 | |
617 | sub item_delete { |
684 | sub item_delete { |
618 | my ($self, @items) = @_; |
685 | my ($self, @items) = @_; |
619 | |
686 | |
|
|
687 | $self->{update_container}{$_->{container}}++ |
620 | for (@items) { |
688 | for @items; |
621 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
|
|
622 | |
|
|
623 | if ($_->{container} == 0) { |
|
|
624 | update_floorbox; |
|
|
625 | update_container ($_->{tag}); |
|
|
626 | } elsif ($_->{container} == $self->{player}{tag}) { |
|
|
627 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
|
|
628 | } else { |
|
|
629 | update_container ($_->{container}); |
|
|
630 | } |
|
|
631 | } |
689 | |
|
|
690 | $self->update_containers; |
632 | } |
691 | } |
633 | |
692 | |
634 | sub item_update { |
693 | sub item_update { |
635 | my ($self, $item) = @_; |
694 | my ($self, $item) = @_; |
636 | |
695 | |
637 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
696 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
638 | |
697 | |
639 | if ($item->{tag} == $self->{player}{tag}) { |
|
|
640 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
|
|
641 | return; |
|
|
642 | } |
|
|
643 | |
|
|
644 | CFClient::Item::update_widgets $item; |
698 | CFClient::Item::update_widgets $item; |
645 | |
699 | |
646 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
700 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
647 | set_opencont ($::CONN, 0, "Floor"); |
701 | set_opencont ($::CONN, 0, "Floor"); |
648 | |
702 | |
649 | } elsif ($item->{flags} & F_OPEN) { |
703 | } elsif ($item->{flags} & F_OPEN) { |
650 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
704 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
|
|
705 | |
651 | } else { |
706 | } else { |
|
|
707 | $self->{update_container}{$item->{container}}++; |
|
|
708 | $self->update_containers; |
652 | if ($item->{container} == 0) { |
709 | # if ($item->{container} == 0) { |
653 | update_floorbox; |
710 | # update_floorbox; |
654 | update_container (0); |
711 | # update_container (0); |
655 | } elsif ($item->{container} == $self->{player}{tag}) { |
712 | # } elsif ($item->{container} == $self->{player}{tag}) { |
656 | $::INV->set_items ($self->{container}{$item->{container}}) |
713 | # $::INV->set_items ($self->{container}{$item->{container}}) |
657 | } |
714 | # } |
658 | } |
715 | } |
659 | } |
716 | } |
660 | |
717 | |
661 | sub player_update { |
718 | sub player_update { |
662 | my ($self, $player) = @_; |
719 | my ($self, $player) = @_; |
663 | |
|
|
664 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
720 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
665 | } |
721 | } |
666 | |
722 | |
667 | sub update_server_info { |
723 | sub update_server_info { |
668 | my ($self) = @_; |
724 | my ($self) = @_; |