1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
3 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # adds ignore/unignore functionality |
4 | # adds ignore/unignore functionality |
|
|
5 | |
|
|
6 | use NPC_Dialogue; |
5 | |
7 | |
6 | sub valid_user($) { |
8 | sub valid_user($) { |
7 | cf::player::find $_[0] |
9 | cf::player::find $_[0] |
8 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
10 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
9 | } |
11 | } |
… | |
… | |
13 | my $NOW = time; |
15 | my $NOW = time; |
14 | |
16 | |
15 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
17 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
16 | while (my ($k, $v) = each %$hash) { |
18 | while (my ($k, $v) = each %$hash) { |
17 | if ($v < $NOW) { |
19 | if ($v < $NOW) { |
18 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); |
20 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
19 | delete $hash->{$k}; |
21 | delete $hash->{$k}; |
20 | } elsif (!valid_user $k) { |
22 | } elsif (!valid_user $k) { |
21 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); |
23 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
22 | delete $hash->{$k}; |
24 | delete $hash->{$k}; |
23 | } |
25 | } |
24 | } |
26 | } |
25 | } |
27 | } |
26 | } |
28 | } |
… | |
… | |
37 | |
39 | |
38 | if ($msg ne "") { |
40 | if ($msg ne "") { |
39 | my $prev_listen = $player->listening; |
41 | my $prev_listen = $player->listening; |
40 | $player->listening ($msg); |
42 | $player->listening ($msg); |
41 | if ($prev_listen == $player->listening) { |
43 | if ($prev_listen == $player->listening) { |
42 | $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); |
44 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
43 | } else { |
45 | } else { |
44 | $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); |
46 | $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
45 | } |
47 | } |
46 | } else { |
48 | } else { |
47 | $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); |
49 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
48 | } |
50 | } |
49 | }; |
51 | }; |
50 | |
52 | |
51 | #cf::register_command say => 0, sub { |
53 | cf::register_command xsay => 0, sub { |
52 | # my ($who, $msg) = @_; |
54 | my ($who, $msg) = @_; |
53 | # |
55 | |
54 | # if ($msg) { |
56 | if ($msg) { |
55 | # my $name = $who->name; |
57 | my $name = $who->name; |
56 | # $_->ob->message ("$name says: $msg", cf::NDI_WHITE) |
58 | |
|
|
59 | my @messages = (["$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE]); |
|
|
60 | |
|
|
61 | # npcs, magic_ears etc. |
|
|
62 | # first find all objects and their inventories within a 5x5 square |
|
|
63 | # that have something resembling dialogue |
|
|
64 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
|
|
65 | |
|
|
66 | for my $npc ( |
|
|
67 | grep NPC_Dialogue::has_dialogue $_, |
|
|
68 | map +($_, $_->inv), |
|
|
69 | grep $_, |
|
|
70 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
|
|
71 | 0..24 |
|
|
72 | ) { |
|
|
73 | # if some listener teleported us somewhere else, stop right here |
|
|
74 | last unless $map->path == $who->map->path; |
|
|
75 | |
|
|
76 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
|
|
77 | my $reply = $dialog->tell ($msg); |
|
|
78 | |
|
|
79 | if (defined $reply) { |
|
|
80 | if ($npc->type == cf::MAGIC_EAR) { |
|
|
81 | push @messages, [$reply, cf::NDI_BROWN | cf::NDI_UNIQUE] if length $reply; |
|
|
82 | $npc->use_trigger; |
|
|
83 | } else { |
|
|
84 | push @messages, [$npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE] if length $reply; |
|
|
85 | } |
|
|
86 | } |
|
|
87 | } |
|
|
88 | |
|
|
89 | # send replies to all players on this map |
|
|
90 | for (@messages) { |
|
|
91 | my ($msg, $flags) = @$_; |
|
|
92 | |
|
|
93 | $_->ob->message ($msg, $flags) |
57 | # for grep $who->on_same_map_as ($_->ob), cf::player::list; |
94 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
95 | } |
|
|
96 | |
58 | # } else { |
97 | } else { |
59 | # $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
98 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
60 | # } |
99 | } |
61 | #}; |
100 | }; |
62 | |
101 | |
63 | cf::register_command chat => 0, sub { |
102 | cf::register_command chat => 0, sub { |
64 | my ($who, $msg) = @_; |
103 | my ($who, $msg) = @_; |
65 | |
104 | |
66 | if ($msg) { |
105 | if ($msg) { |
67 | my $name = $who->name; |
106 | my $name = $who->name; |
68 | my $NOW = time; |
107 | my $NOW = time; |
69 | |
108 | |
|
|
109 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
110 | |
70 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
111 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
71 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
112 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
72 | |
113 | |
73 | } else { |
114 | } else { |
74 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
115 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
… | |
… | |
79 | my ($who, $msg) = @_; |
120 | my ($who, $msg) = @_; |
80 | |
121 | |
81 | if ($msg) { |
122 | if ($msg) { |
82 | my $NOW = time; |
123 | my $NOW = time; |
83 | my $name = $who->name; |
124 | my $name = $who->name; |
|
|
125 | |
|
|
126 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
84 | |
127 | |
85 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
128 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
86 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
129 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
87 | |
130 | |
88 | } else { |
131 | } else { |
… | |
… | |
103 | if ($target eq $name) { |
146 | if ($target eq $name) { |
104 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
147 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
105 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
148 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
106 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
149 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
107 | } else { |
150 | } else { |
|
|
151 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
152 | |
108 | $who->message ("You tell $target: $msg"); |
153 | $who->message ("You tell $target: $msg"); |
109 | $other->ob->message ("$name tells you: $msg"); |
154 | $other->ob->message ("$name tells you: $msg"); |
110 | $other->ob->{ext_last_tell} = $name; |
155 | $other->ob->{ext_last_tell} = $name; |
111 | } |
156 | } |
112 | } else { |
157 | } else { |
… | |
… | |
127 | |
172 | |
128 | $other->ob->{ext_ignore_tell}{$name} >= time |
173 | $other->ob->{ext_ignore_tell}{$name} >= time |
129 | or delete $other->ob->{ext_ignore_tell}{$name}; |
174 | or delete $other->ob->{ext_ignore_tell}{$name}; |
130 | |
175 | |
131 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
176 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
177 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
178 | |
132 | $who->message ("You tell " . $other->ob->name . ": $args"); |
179 | $who->message ("You tell " . $other->ob->name . ": $args"); |
133 | $other->ob->message ("$name tells you: $args"); |
180 | $other->ob->message ("$name tells you: $args"); |
134 | $who->{ext_last_tell} = $other->ob->name; |
181 | $who->{ext_last_tell} = $other->ob->name; |
135 | } else { |
182 | } else { |
136 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
183 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |