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.13 by pippijn, Sun May 7 19:51:50 2006 UTC vs.
Revision 1.20 by root, Wed Jul 19 08:52:57 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in 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 5
6use NPC_Dialogue;
7
6sub valid_user($) { 8sub valid_user($) {
9 cf::player::find $_[0]
7 -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;
8} 11}
9 12
10sub clean_timeouts($) { 13sub clean_timeouts($) {
11 my ($player) = @_; 14 my ($player) = @_;
12 my $NOW = time; 15 my $NOW = time;
13 16
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 17 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 while (my ($k, $v) = each %$hash) { 18 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) { 19 if ($v < $NOW) {
17 $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);
18 delete $hash->{$k}; 21 delete $hash->{$k};
19 } elsif (!valid_user $k) { 22 } elsif (!valid_user $k) {
20 $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);
21 delete $hash->{$k}; 24 delete $hash->{$k};
22 } 25 }
23 } 26 }
24 } 27 }
25} 28}
27sub on_logout { 30sub on_logout {
28 my ($pl, $host) = @_; 31 my ($pl, $host) = @_;
29 32
30 clean_timeouts $pl->ob; 33 clean_timeouts $pl->ob;
31} 34}
35
36cf::register_command listen => 0, sub {
37 my ($who, $msg) = @_;
38 my $player = cf::player::find $who->name;
39
40 if ($msg ne "") {
41 my $prev_listen = $player->listening;
42 $player->listening ($msg);
43 if ($prev_listen == $player->listening) {
44 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
45 } else {
46 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
47 }
48 } else {
49 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
50 }
51};
52
53cf::register_command xsay => 0, sub {
54 my ($who, $msg) = @_;
55
56 if ($msg) {
57 my $name = $who->name;
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)
94 for grep $who->on_same_map_as ($_->ob), cf::player::list;
95 }
96
97 } else {
98 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
99 }
100};
32 101
33cf::register_command chat => 0, sub { 102cf::register_command chat => 0, sub {
34 my ($who, $msg) = @_; 103 my ($who, $msg) = @_;
35 104
36 if ($msg) { 105 if ($msg) {
37 my $name = $who->name; 106 my $name = $who->name;
38 my $NOW = time; 107 my $NOW = time;
39 108
109 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
110
40 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 111 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
41 for grep { $_->ob->{ext_ignore_shout}{$name} and $_->listening >= 10 } < $NOW, cf::player::list; 112 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
42 113
43 } else { 114 } else {
44 $who->message ("Chat what?", cf::NDI_UNIQUE); 115 $who->message ("Chat what?", cf::NDI_UNIQUE);
45 } 116 }
46}; 117};
50 121
51 if ($msg) { 122 if ($msg) {
52 my $NOW = time; 123 my $NOW = time;
53 my $name = $who->name; 124 my $name = $who->name;
54 125
126 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
127
55 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 128 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
56 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW and $_->listening >= 2 }, cf::player::list; 129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
57 130
58 } else { 131 } else {
59 $who->message ("Shout what?", cf::NDI_UNIQUE); 132 $who->message ("Shout what?", cf::NDI_UNIQUE);
60 } 133 }
61 134
73 if ($target eq $name) { 146 if ($target eq $name) {
74 $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);
75 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 148 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
76 $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);
77 } else { 150 } else {
151 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
152
78 $who->message ("You tell $target: $msg"); 153 $who->message ("You tell $target: $msg");
79 $other->ob->message ("$name tells you: $msg"); 154 $other->ob->message ("$name tells you: $msg");
80 $other->ob->{ext_last_tell} = $name; 155 $other->ob->{ext_last_tell} = $name;
81 } 156 }
82 } else { 157 } else {
97 172
98 $other->ob->{ext_ignore_tell}{$name} >= time 173 $other->ob->{ext_ignore_tell}{$name} >= time
99 or delete $other->ob->{ext_ignore_tell}{$name}; 174 or delete $other->ob->{ext_ignore_tell}{$name};
100 175
101 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
102 $who->message ("You tell " . $other->ob->name . ": $args"); 179 $who->message ("You tell " . $other->ob->name . ": $args");
103 $other->ob->message ("$name tells you: $args"); 180 $other->ob->message ("$name tells you: $args");
104 $who->{ext_last_tell} = $other->ob->name; 181 $who->{ext_last_tell} = $other->ob->name;
105 } else { 182 } else {
106 $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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines