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.14 by pippijn, Sun May 7 20:23:32 2006 UTC vs.
Revision 1.21 by root, Wed Jul 19 22:20:07 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
6sub valid_user($) { 6use NPC_Dialogue;
7 -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
8}
9 7
10sub clean_timeouts($) { 8sub clean_timeouts($) {
11 my ($player) = @_; 9 my ($player) = @_;
12 my $NOW = time; 10 my $NOW = time;
13 11
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 12 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 while (my ($k, $v) = each %$hash) { 13 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) { 14 if ($v < $NOW) {
17 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); 15 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
18 delete $hash->{$k}; 16 delete $hash->{$k};
19 } elsif (!valid_user $k) { 17 } elsif (!valid_user $k) {
20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); 18 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
21 delete $hash->{$k}; 19 delete $hash->{$k};
22 } 20 }
23 } 21 }
24 } 22 }
25} 23}
27sub on_logout { 25sub on_logout {
28 my ($pl, $host) = @_; 26 my ($pl, $host) = @_;
29 27
30 clean_timeouts $pl->ob; 28 clean_timeouts $pl->ob;
31} 29}
30
31cf::register_command listen => 0, sub {
32 my ($who, $msg) = @_;
33 my $player = cf::player::find $who->name;
34
35 if ($msg ne "") {
36 my $prev_listen = $player->listening;
37 $player->listening ($msg);
38 if ($prev_listen == $player->listening) {
39 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
40 } else {
41 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
42 }
43 } else {
44 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
45 }
46};
47
48cf::register_command say => 0, sub {
49 my ($who, $msg) = @_;
50
51 if ($msg) {
52 my $name = $who->name;
53
54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
55 for grep $who->on_same_map_as ($_->ob), cf::player::list;
56
57 # npcs, magic_ears etc.
58 # first find all objects and their inventories within a 5x5 square
59 # that have something resembling dialogue
60 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
61
62 for my $npc (
63 grep NPC_Dialogue::has_dialogue $_,
64 map +($_, $_->inv),
65 grep $_,
66 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
67 0..24
68 ) {
69 # if some listener teleported us somewhere else, stop right here
70 last unless $map->path == $who->map->path;
71
72 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
73 my $reply = $dialog->tell ($msg);
74
75 if (defined $reply) {
76 if ($npc->type == cf::MAGIC_EAR) {
77 if (length $reply) {
78 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
79 for grep $who->on_same_map_as ($_->ob), cf::player::list;
80 }
81 $npc->use_trigger;
82 } else {
83 if (length $reply) {
84 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
85 for grep $who->on_same_map_as ($_->ob), cf::player::list;
86 }
87 }
88 }
89 }
90
91 } else {
92 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
93 }
94};
32 95
33cf::register_command chat => 0, sub { 96cf::register_command chat => 0, sub {
34 my ($who, $msg) = @_; 97 my ($who, $msg) = @_;
35 98
36 if ($msg) { 99 if ($msg) {
37 my $name = $who->name; 100 my $name = $who->name;
38 my $NOW = time; 101 my $NOW = time;
39 102
103 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
104
40 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 105 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
41 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 106 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
42 107
43 } else { 108 } else {
44 $who->message ("Chat what?", cf::NDI_UNIQUE); 109 $who->message ("Chat what?", cf::NDI_UNIQUE);
45 } 110 }
46}; 111};
50 115
51 if ($msg) { 116 if ($msg) {
52 my $NOW = time; 117 my $NOW = time;
53 my $name = $who->name; 118 my $name = $who->name;
54 119
120 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
121
55 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 122 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
56 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
57 124
58 } else { 125 } else {
59 $who->message ("Shout what?", cf::NDI_UNIQUE); 126 $who->message ("Shout what?", cf::NDI_UNIQUE);
60 } 127 }
61 128
73 if ($target eq $name) { 140 if ($target eq $name) {
74 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 141 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
75 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 142 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
76 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 143 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
77 } else { 144 } else {
145 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
146
78 $who->message ("You tell $target: $msg"); 147 $who->message ("You tell $target: $msg");
79 $other->ob->message ("$name tells you: $msg"); 148 $other->ob->message ("$name tells you: $msg");
80 $other->ob->{ext_last_tell} = $name; 149 $other->ob->{ext_last_tell} = $name;
81 } 150 }
82 } else { 151 } else {
97 166
98 $other->ob->{ext_ignore_tell}{$name} >= time 167 $other->ob->{ext_ignore_tell}{$name} >= time
99 or delete $other->ob->{ext_ignore_tell}{$name}; 168 or delete $other->ob->{ext_ignore_tell}{$name};
100 169
101 if ($other->ob->{ext_ignore_tell}{$name} < time) { 170 if ($other->ob->{ext_ignore_tell}{$name} < time) {
171 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
172
102 $who->message ("You tell " . $other->ob->name . ": $args"); 173 $who->message ("You tell " . $other->ob->name . ": $args");
103 $other->ob->message ("$name tells you: $args"); 174 $other->ob->message ("$name tells you: $args");
104 $who->{ext_last_tell} = $other->ob->name; 175 $who->{ext_last_tell} = $other->ob->name;
105 } else { 176 } else {
106 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 177 $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