… | |
… | |
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, $name, $old, $new) = @_; |
|
|
90 | |
|
|
91 | my $diff = $new - $old; |
|
|
92 | |
|
|
93 | $diff = 0.01 * int $diff * 100; |
|
|
94 | |
|
|
95 | 0.1 >= abs $diff ? () |
|
|
96 | : $diff < 0 ? "$name$diff" : "$name+$diff" |
|
|
97 | } |
|
|
98 | |
|
|
99 | sub _stat_skillmaskdiff { |
|
|
100 | my ($self, $name, $old, $new) = @_; |
|
|
101 | |
|
|
102 | my $diff = $old ^ $new |
|
|
103 | or return; |
|
|
104 | |
|
|
105 | my @diff = map |
|
|
106 | { |
|
|
107 | $diff & $_ |
|
|
108 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
|
|
109 | : () |
|
|
110 | } |
|
|
111 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
|
|
112 | |
|
|
113 | join "", @diff |
|
|
114 | } |
|
|
115 | |
|
|
116 | # all stats that are chacked against changes |
|
|
117 | my @statchange = ( |
|
|
118 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
|
|
119 | [&CS_STAT_INT => \&_stat_numdiff, "Int"], |
|
|
120 | [&CS_STAT_WIS => \&_stat_numdiff, "Wis"], |
|
|
121 | [&CS_STAT_DEX => \&_stat_numdiff, "Dex"], |
|
|
122 | [&CS_STAT_CON => \&_stat_numdiff, "Con"], |
|
|
123 | [&CS_STAT_CHA => \&_stat_numdiff, "Cha"], |
|
|
124 | [&CS_STAT_POW => \&_stat_numdiff, "Pow"], |
|
|
125 | [&CS_STAT_WC => \&_stat_numdiff, "Wc"], |
|
|
126 | [&CS_STAT_AC => \&_stat_numdiff, "Ac"], |
|
|
127 | [&CS_STAT_DAM => \&_stat_numdiff, "Dam"], |
|
|
128 | [&CS_STAT_SPEED => \&_stat_numdiff, "Speed"], |
|
|
129 | [&CS_STAT_WEAP_SP => \&_stat_numdiff, "WSp"], |
|
|
130 | [&CS_STAT_MAXHP => \&_stat_numdiff, "HP"], |
|
|
131 | [&CS_STAT_MAXSP => \&_stat_numdiff, "Mana"], |
|
|
132 | [&CS_STAT_MAXGRACE => \&_stat_numdiff, "Grace"], |
|
|
133 | [&CS_STAT_WEIGHT_LIM => \&_stat_numdiff, "Weight"], |
|
|
134 | [&CS_STAT_SPELL_ATTUNE => \&_stat_skillmaskdiff, "attuned"], |
|
|
135 | [&CS_STAT_SPELL_REPEL => \&_stat_skillmaskdiff, "repelled"], |
|
|
136 | [&CS_STAT_SPELL_DENY => \&_stat_skillmaskdiff, "denied"], |
|
|
137 | [&CS_STAT_RES_PHYS => \&_stat_numdiff, "phys"], |
|
|
138 | [&CS_STAT_RES_MAG => \&_stat_numdiff, "magic"], |
|
|
139 | [&CS_STAT_RES_FIRE => \&_stat_numdiff, "fire"], |
|
|
140 | [&CS_STAT_RES_ELEC => \&_stat_numdiff, "electricity"], |
|
|
141 | [&CS_STAT_RES_COLD => \&_stat_numdiff, "cold"], |
|
|
142 | [&CS_STAT_RES_CONF => \&_stat_numdiff, "confusion"], |
|
|
143 | [&CS_STAT_RES_ACID => \&_stat_numdiff, "acid"], |
|
|
144 | [&CS_STAT_RES_DRAIN => \&_stat_numdiff, "drain"], |
|
|
145 | [&CS_STAT_RES_GHOSTHIT => \&_stat_numdiff, "ghosthit"], |
|
|
146 | [&CS_STAT_RES_POISON => \&_stat_numdiff, "poison"], |
|
|
147 | [&CS_STAT_RES_SLOW => \&_stat_numdiff, "slow"], |
|
|
148 | [&CS_STAT_RES_PARA => \&_stat_numdiff, "paralyse"], |
|
|
149 | [&CS_STAT_TURN_UNDEAD => \&_stat_numdiff, "turnundead"], |
|
|
150 | [&CS_STAT_RES_FEAR => \&_stat_numdiff, "fear"], |
|
|
151 | [&CS_STAT_RES_DEPLETE => \&_stat_numdiff, "depletion"], |
|
|
152 | [&CS_STAT_RES_DEATH => \&_stat_numdiff, "death"], |
|
|
153 | [&CS_STAT_RES_HOLYWORD => \&_stat_numdiff, "godpower"], |
|
|
154 | [&CS_STAT_RES_BLIND => \&_stat_numdiff, "blind"], |
|
|
155 | ); |
|
|
156 | |
88 | sub stats_update { |
157 | sub stats_update { |
89 | my ($self, $stats) = @_; |
158 | my ($self, $stats) = @_; |
90 | |
159 | |
91 | if (my $exp = $stats->{+CS_STAT_EXP64}) { |
160 | if (my $prev = $self->{prev_stats}) { |
92 | my $diff = $exp - $self->{prev_exp}; |
161 | 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) |
162 | $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; |
163 | } |
95 | $self->{prev_exp} = $exp; |
164 | |
|
|
165 | if ( |
|
|
166 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
|
|
167 | ) { |
|
|
168 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
|
|
169 | $self->{statusbox}->add ($msg, group => $msg, fg => [0.8, 1, 0.2, 1], timeout => 10); |
|
|
170 | } |
96 | } |
171 | } |
|
|
172 | |
|
|
173 | $self->{prev_stats} = { %$stats }; |
97 | |
174 | |
98 | ::update_stats_window ($stats); |
175 | ::update_stats_window ($stats); |
99 | } |
176 | } |
100 | |
177 | |
101 | sub user_send { |
178 | sub user_send { |
… | |
… | |
345 | } |
422 | } |
346 | |
423 | |
347 | sub face_update { |
424 | sub face_update { |
348 | my ($self, $facenum, $face) = @_; |
425 | my ($self, $facenum, $face) = @_; |
349 | |
426 | |
350 | $self->{tilecache}->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
427 | $self->{tilecache}->put ($face->{id} => $face->{image}) |
|
|
428 | if $self->{tilecache}->get ($face->{id}) ne $face->{image}; |
351 | |
429 | |
352 | $self->set_texture ($face->{id} => delete $face->{image}); |
430 | $self->set_texture ($face->{id} => delete $face->{image}); |
353 | } |
431 | } |
354 | |
432 | |
355 | sub set_texture { |
433 | sub set_texture { |
… | |
… | |
438 | # try to create single paragraphs of multiple lines sent by the server |
516 | # try to create single paragraphs of multiple lines sent by the server |
439 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
517 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
440 | $spell->{message} =~ s/\n+$//; |
518 | $spell->{message} =~ s/\n+$//; |
441 | $spell->{message} ||= "Server did not provide a description for this spell."; |
519 | $spell->{message} ||= "Server did not provide a description for this spell."; |
442 | |
520 | |
443 | $::SETUP_SPELLS->add_spell ($spell); |
521 | $::SPELL_PAGE->add_spell ($spell); |
444 | |
522 | |
445 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
523 | $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}); |
524 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
447 | } |
525 | } |
448 | |
526 | |
449 | sub spell_delete { |
527 | sub spell_delete { |
450 | my ($self, $spell) = @_; |
528 | my ($self, $spell) = @_; |
|
|
529 | |
451 | $::SETUP_SPELLS->remove_spell ($spell); |
530 | $::SPELL_PAGE->remove_spell ($spell); |
452 | } |
531 | } |
453 | |
532 | |
454 | sub addme_success { |
533 | sub addme_success { |
455 | my ($self) = @_; |
534 | my ($self) = @_; |
456 | |
535 | |
… | |
… | |
536 | |
615 | |
537 | $row++; |
616 | $row++; |
538 | } else { |
617 | } else { |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
618 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
540 | text => "More...", |
619 | text => "More...", |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 }, |
620 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
542 | ); |
621 | ); |
543 | last; |
622 | last; |
544 | } |
623 | } |
545 | } |
624 | } |
546 | }); |
625 | }); |
… | |
… | |
573 | |
652 | |
574 | sub update_containers { |
653 | sub update_containers { |
575 | my ($self) = @_; |
654 | my ($self) = @_; |
576 | |
655 | |
577 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
656 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
578 | # TODO: scara had a bug where $self->{uipdate_container} was not defined |
|
|
579 | # but this should not possibly happen? |
|
|
580 | for my $tag (keys %{ delete $self->{update_container} }) { |
657 | my $todo = delete $self->{update_container} |
|
|
658 | or return; |
|
|
659 | |
|
|
660 | for my $tag (keys %$todo) { |
581 | if ($tag == 0) { |
661 | if ($tag == 0) { |
582 | update_floorbox; |
662 | update_floorbox; |
583 | $::INVR->set_items ($self->{container}{0}) |
663 | $::INVR->set_items ($self->{container}{0}) |
584 | if $tag == $self->{open_container}; |
664 | if $tag == $self->{open_container}; |
585 | } elsif ($tag == $self->{player}{tag}) { |
665 | } elsif ($tag == $self->{player}{tag}) { |
… | |
… | |
607 | } |
687 | } |
608 | |
688 | |
609 | sub item_delete { |
689 | sub item_delete { |
610 | my ($self, @items) = @_; |
690 | my ($self, @items) = @_; |
611 | |
691 | |
612 | $self->{update_container}{$_->{tag}}++ |
692 | $self->{update_container}{$_->{container}}++ |
613 | for @items; |
693 | for @items; |
614 | |
694 | |
615 | $self->update_containers; |
695 | $self->update_containers; |
616 | } |
696 | } |
617 | |
697 | |
618 | sub item_update { |
698 | sub item_update { |
619 | my ($self, $item) = @_; |
699 | my ($self, $item) = @_; |
620 | |
700 | |
621 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
701 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
622 | |
702 | |
623 | if ($item->{tag} == $self->{player}{tag}) { |
|
|
624 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
|
|
625 | return; |
|
|
626 | } |
|
|
627 | |
|
|
628 | CFClient::Item::update_widgets $item; |
703 | CFClient::Item::update_widgets $item; |
629 | |
704 | |
630 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
705 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
631 | set_opencont ($::CONN, 0, "Floor"); |
706 | set_opencont ($::CONN, 0, "Floor"); |
632 | |
707 | |
… | |
… | |
634 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
709 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
635 | |
710 | |
636 | } else { |
711 | } else { |
637 | $self->{update_container}{$item->{container}}++; |
712 | $self->{update_container}{$item->{container}}++; |
638 | $self->update_containers; |
713 | $self->update_containers; |
639 | # if ($item->{container} == 0) { |
|
|
640 | # update_floorbox; |
|
|
641 | # update_container (0); |
|
|
642 | # } elsif ($item->{container} == $self->{player}{tag}) { |
|
|
643 | # $::INV->set_items ($self->{container}{$item->{container}}) |
|
|
644 | # } |
|
|
645 | } |
714 | } |
646 | } |
715 | } |
647 | |
716 | |
648 | sub player_update { |
717 | sub player_update { |
649 | my ($self, $player) = @_; |
718 | my ($self, $player) = @_; |
650 | |
|
|
651 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
719 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
652 | } |
720 | } |
653 | |
721 | |
654 | sub update_server_info { |
722 | sub update_server_info { |
655 | my ($self) = @_; |
723 | my ($self) = @_; |
… | |
… | |
852 | sub destroy { |
920 | sub destroy { |
853 | my ($self) = @_; |
921 | my ($self) = @_; |
854 | |
922 | |
855 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
923 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
856 | |
924 | |
|
|
925 | $self->{conn}->send ("ext npc_dialog_end $self->{token}") if $self->{token}; |
857 | delete $self->{conn}{npc_dialog}; |
926 | delete $self->{conn}{npc_dialog}; |
858 | $self->{conn}->disconnect_ext ($self->{token}); |
927 | $self->{conn}->disconnect_ext ($self->{token}); |
859 | |
928 | |
860 | $self->SUPER::destroy; |
929 | $self->SUPER::destroy; |
861 | } |
930 | } |