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.19 by root, Fri Jun 9 04:18:02 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 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
6use NPC_Dialogue;
5 7
6sub valid_user($) { 8sub 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 { 53cf::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
63cf::register_command chat => 0, sub { 102cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 103 my ($who, $msg) = @_;
65 104
66 if ($msg) { 105 if ($msg) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines