ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
(Generate patch)

Comparing deliantra/maps/perl/chat.ext (file contents):
Revision 1.32 by root, Fri Aug 25 13:33:57 2006 UTC vs.
Revision 1.40 by pippijn, Sun Dec 10 11:36:39 2006 UTC

1#! perl 1#! perl
2#CONVERSION: PARTIAL
2 3
3# implement a replacement for the built-in say/chat/shout/tell/reply commands 4# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 5# adds ignore/unignore functionality
5 6
6use NPC_Dialogue; 7use NPC_Dialogue;
52cf::register_command say => 0, sub { 53cf::register_command say => 0, sub {
53 my ($who, $msg) = @_; 54 my ($who, $msg) = @_;
54 55
55 utf8::decode $msg; 56 utf8::decode $msg;
56 57
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
59
57 if ($msg) { 60 if ($msg) {
58 my $name = $who->name; 61 my $name = $who->name;
59 62
60 utf8::encode $msg; # ->message not yet utf8-ified 63 utf8::encode $msg; # ->message not yet utf8-ified
61 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 64 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
62 for grep $who->on_same_map_as ($_->ob), cf::player::list; 65 for grep $who->on_same_map_as ($_->ob), cf::player::list;
63 utf8::decode $msg; 66 utf8::decode $msg;
64 67
65 # npcs, magic_ears etc. 68 # npcs, magic_ears etc.
66 # first find all objects and their inventories within a 5x5 square 69 # first find all objects and theirt-level inventories
67 # that have something resembling dialogue 70 # within a 5x5 square # that have something resembling
71 # dialogue or support on_say.
68 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 72 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
69 73
70 for my $npc ( 74 for my $npc (
71 grep NPC_Dialogue::has_dialogue $_, 75 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
72 map +($_, $_->inv), 76 map +($_, $_->inv),
73 grep $_, 77 grep $_,
74 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 78 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
75 0..24 79 0..24
76 ) { 80 ) {
109cf::register_command chat => 0, sub { 113cf::register_command chat => 0, sub {
110 my ($who, $msg) = @_; 114 my ($who, $msg) = @_;
111 115
112 utf8::decode $msg; 116 utf8::decode $msg;
113 117
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
119
114 if ($msg) { 120 if ($msg) {
115 my $name = $who->name; 121 my $name = $who->name;
116 my $NOW = time; 122 my $NOW = time;
117 123
118 utf8::encode $msg; # ->message not yet utf8-ified 124 utf8::encode $msg; # ->message not yet utf8-ified
119# cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 125 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
120 cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); 126 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
121 127
122 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
124 130
125 } else { 131 } else {
129 135
130cf::register_command shout => 0, sub { 136cf::register_command shout => 0, sub {
131 my ($who, $msg) = @_; 137 my ($who, $msg) = @_;
132 138
133 utf8::decode $msg; 139 utf8::decode $msg;
140
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
134 142
135 if ($msg) { 143 if ($msg) {
136 my $NOW = time; 144 my $NOW = time;
137 my $name = $who->name; 145 my $name = $who->name;
138 146
139# cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 147 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
140 cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); 148 ext::schmorp_irc::do_notice (sprintf "\0034{%s} %s\n", $name, $msg);
141 149
142 utf8::encode $msg; # ->message not yet utf8-ified 150 utf8::encode $msg; # ->message not yet utf8-ified
143 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 151 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
144 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 152 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
145 153
153 my ($who, $args) = @_; 161 my ($who, $args) = @_;
154 my ($target, $msg) = split /\s+/, $args, 2; 162 my ($target, $msg) = split /\s+/, $args, 2;
155 163
156 utf8::decode $msg; 164 utf8::decode $msg;
157 165
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
167
158 my $name = $who->name; 168 my $name = $who->name;
159 169
170 if ($target =~ /irc\//) {
171 my (undef, $nick) = split /\//, $target, 2;
172 $who->message ("You tell $target: $args");
173 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg);
160 if (my $other = cf::player::find $target) { 174 } elsif (my $other = cf::player::find $target) {
161 175
162 if ($msg) { 176 if ($msg) {
163 if ($target eq $name) { 177 if ($target eq $name) {
164 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 178 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
165 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 179 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
185 my ($who, $args) = @_; 199 my ($who, $args) = @_;
186 my $name = $who->name; 200 my $name = $who->name;
187 201
188 utf8::decode $args; 202 utf8::decode $args;
189 203
204 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args);
205
206 if ($who->{ext_last_tell} =~ /irc\//) {
207 my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2;
208 $who->message ("You tell " . $who->{ext_last_tell} . ": $args");
209 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args);
190 if (my $other = cf::player::find $who->{ext_last_tell}) { 210 } elsif (my $other = cf::player::find $who->{ext_last_tell}) {
211
191 if ($args) { 212 if ($args) {
192
193 $other->ob->{ext_ignore_tell}{$name} >= time 213 $other->ob->{ext_ignore_tell}{$name} >= time
194 or delete $other->ob->{ext_ignore_tell}{$name}; 214 or delete $other->ob->{ext_ignore_tell}{$name};
195 215
196 if ($other->ob->{ext_ignore_tell}{$name} < time) { 216 if ($other->ob->{ext_ignore_tell}{$name} < time) {
197 utf8::encode $args; # ->message not yet utf8-ified 217 utf8::encode $args; # ->message not yet utf8-ified
206 } else { 226 } else {
207 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); 227 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
208 } 228 }
209 229
210 } else { 230 } else {
211 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 231 $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE);
212 } 232 }
213}; 233};
214 234
215cf::register_command ignore => 0, sub { 235cf::register_command ignore => 0, sub {
216 my ($who, $args) = @_; 236 my ($who, $args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines