--- deliantra/server/ext/chat.ext 2007/07/20 16:11:10 1.21 +++ deliantra/server/ext/chat.ext 2007/07/23 21:53:21 1.26 @@ -7,6 +7,20 @@ use NPC_Dialogue; use POSIX (); # for strftime only +our $SAY_CHANNEL = { + id => "say", + title => "Map", + reply => "say ", + tooltip => "Things said to and replied from npcs near you and other players on the same map only.", +}; + +our $CHAT_CHANNEL = { + id => "chat", + title => "Chat", + reply => "chat ", + tooltip => "Player chat and shouts, global to the server.", +}; + sub clean_timeouts($) { my ($player) = @_; my $NOW = time; @@ -40,6 +54,8 @@ my ($pl) = @_; clean_timeouts $pl->ob; + $pl->ns->send_msg ($SAY_CHANNEL); + $pl->ns->send_msg ($CHAT_CHANNEL); }, ); @@ -748,13 +764,6 @@ }; } -our $SAY_CHANNEL = { - id => "say", - title => "Map", - reply => "say ", - tooltip => "Things said to and replied from npcs near you and other players on the same map only.", -}; - cf::register_command me => sub { my ($pl, $msg) = @_; @@ -765,71 +774,64 @@ }; cf::register_command say => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; utf8::decode $msg; - return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); + return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); if ($msg) { - my $name = $pl->name; - my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list; + my $name = $ob->name; + my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; - $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) + $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $ob ? (reply => 1) : ()) for @plonmap; # npcs, magic_ears etc. # first find all objects and their first-level inventories # within a 5x5 square that have something resembling # dialogue or support on_say. - my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); + my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); for my $npc ( - grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, + grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, map +($_, $_->inv), grep $_, map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 0..24 ) { # if some listener teleported us somewhere else, stop right here - last unless $map->path == $pl->map->path; + last unless $map->path == $ob->map->path; - my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; + my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; my ($reply, @kw) = $dialog->tell ($msg); if (defined $reply) { if ($npc->type == cf::MAGIC_EAR) { if (length $reply) { - $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) + $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) for @plonmap; } $npc->use_trigger; } else { if (length $reply) { - $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) + $_->ns->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) for @plonmap; } } } if (@kw) { - $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) + $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) for @plonmap; } } } else { - $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); + $ob->contr->ns->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); } }; -our $CHAT_CHANNEL = { - id => "chat", - title => "Chat", - reply => "chat ", - tooltip => "Player chat and shouts, global to the server.", -}; - cf::register_command chat => sub { my ($pl, $msg) = @_; @@ -866,7 +868,7 @@ cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; send_irc ("\007\0034{%s} %s\n", $name, $msg); - $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) + $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED, $_ == $pl ? (reply => 1) : ()) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; } else { @@ -912,7 +914,7 @@ } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); } else { - return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); + return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1);