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.18 by root, Tue May 30 04:30:54 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 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 5
6sub valid_user($) { 6use NPC_Dialogue;
7 cf::player::find $_[0]
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10 7
11sub clean_timeouts($) { 8sub clean_timeouts($) {
12 my ($player) = @_; 9 my ($player) = @_;
13 my $NOW = time; 10 my $NOW = time;
14 11
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 12 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
16 while (my ($k, $v) = each %$hash) { 13 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) { 14 if ($v < $NOW) {
18 $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);
19 delete $hash->{$k}; 16 delete $hash->{$k};
20 } elsif (!valid_user $k) { 17 } elsif (!valid_user $k) {
21 $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);
22 delete $hash->{$k}; 19 delete $hash->{$k};
23 } 20 }
24 } 21 }
25 } 22 }
26} 23}
37 34
38 if ($msg ne "") { 35 if ($msg ne "") {
39 my $prev_listen = $player->listening; 36 my $prev_listen = $player->listening;
40 $player->listening ($msg); 37 $player->listening ($msg);
41 if ($prev_listen == $player->listening) { 38 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); 39 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
43 } else { 40 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); 41 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
45 } 42 }
46 } else { 43 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); 44 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
48 } 45 }
49}; 46};
50 47
51#cf::register_command say => 0, sub { 48cf::register_command say => 0, sub {
52# my ($who, $msg) = @_; 49 my ($who, $msg) = @_;
53# 50
54# if ($msg) { 51 if ($msg) {
55# my $name = $who->name; 52 my $name = $who->name;
53
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list; 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
58# } else { 91 } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE); 92 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# } 93 }
61#}; 94};
62 95
63cf::register_command chat => 0, sub { 96cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 97 my ($who, $msg) = @_;
65 98
66 if ($msg) { 99 if ($msg) {
67 my $name = $who->name; 100 my $name = $who->name;
68 my $NOW = time; 101 my $NOW = time;
69 102
103 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
104
70 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 105 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
71 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 106 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
72 107
73 } else { 108 } else {
74 $who->message ("Chat what?", cf::NDI_UNIQUE); 109 $who->message ("Chat what?", cf::NDI_UNIQUE);
79 my ($who, $msg) = @_; 114 my ($who, $msg) = @_;
80 115
81 if ($msg) { 116 if ($msg) {
82 my $NOW = time; 117 my $NOW = time;
83 my $name = $who->name; 118 my $name = $who->name;
119
120 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
84 121
85 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 122 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
86 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
87 124
88 } else { 125 } else {
103 if ($target eq $name) { 140 if ($target eq $name) {
104 $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);
105 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 142 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
106 $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);
107 } else { 144 } else {
145 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
146
108 $who->message ("You tell $target: $msg"); 147 $who->message ("You tell $target: $msg");
109 $other->ob->message ("$name tells you: $msg"); 148 $other->ob->message ("$name tells you: $msg");
110 $other->ob->{ext_last_tell} = $name; 149 $other->ob->{ext_last_tell} = $name;
111 } 150 }
112 } else { 151 } else {
127 166
128 $other->ob->{ext_ignore_tell}{$name} >= time 167 $other->ob->{ext_ignore_tell}{$name} >= time
129 or delete $other->ob->{ext_ignore_tell}{$name}; 168 or delete $other->ob->{ext_ignore_tell}{$name};
130 169
131 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
132 $who->message ("You tell " . $other->ob->name . ": $args"); 173 $who->message ("You tell " . $other->ob->name . ": $args");
133 $other->ob->message ("$name tells you: $args"); 174 $other->ob->message ("$name tells you: $args");
134 $who->{ext_last_tell} = $other->ob->name; 175 $who->{ext_last_tell} = $other->ob->name;
135 } else { 176 } else {
136 $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