--- deliantra/server/ext/chat.ext 2007/08/10 05:38:16 1.30 +++ deliantra/server/ext/chat.ext 2008/05/01 06:33:19 1.40 @@ -1,25 +1,11 @@ #! perl # depends=irc mandatory -# implement a replacement for the built-in say/chat/shout/tell/reply commands +# implement a replacement for the built-in say/chat/shout/tell commands # adds ignore/unignore functionality 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 tell_channel($) { my ($target) = @_; @@ -31,6 +17,13 @@ } } +sub send_msg($$$$$) { + my ($pl, $channel, $msg, $flags, $sound) = @_; + $pl->play_sound (cf::sound::find $sound) if defined $sound; + $pl->send_msg ($channel, $msg, $flags); + () +} + sub clean_timeouts($) { my ($player) = @_; my $NOW = time; @@ -64,8 +57,9 @@ my ($pl) = @_; clean_timeouts $pl->ob; - $pl->send_msg ($SAY_CHANNEL); - $pl->send_msg ($CHAT_CHANNEL); + + $pl->send_msg ($cf::SAY_CHANNEL); + $pl->send_msg ($cf::CHAT_CHANNEL); }, ); @@ -96,10 +90,10 @@ my $coin = int rand 2 ? "Heads" : "Tails"; - $_->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) + send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; - $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); + $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); }; cf::register_command orcknuckle => sub { @@ -112,10 +106,10 @@ my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; - $_->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) + send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; - $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); + $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); }; my $emotes = { @@ -249,6 +243,19 @@ self => { }, }, + smother => { + noparams => { + other => " makes weird facial contortions", + self => "All the lonely people..", + }, + params => { + target => " smothers you with kisses.", + other => " smothers with kisses.", + self => "You smother with kisses.", + }, + self => { + }, + }, wink => { noparams => { other => " winks suggestively.", @@ -708,6 +715,7 @@ cf::async { my $name = $ob->name; + $Coro::current->{desc} = "emote handler for $name"; if ($tname eq $name) { my %emote = %{ $emotes->{$emotion}->{self} || {} }; @@ -717,29 +725,29 @@ $emote{other} =~ s//$name/; - $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } elsif ($tname) { my $target = cf::player::find $tname - or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); + or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; my %emote = %{ $emotes->{$emotion}->{params} || {} }; $emote{other} ||= " is eyeing quizzically."; $emote{self} ||= "You are still nuts."; - $emote{target} ||= "You get the distinct feeling that is nuts."; + $emote{target} ||= "You get the distinct feeling that is nuts."; $emote{self} =~ s//$tname/; $emote{target} =~ s//$name/; $emote{other} =~ s//$tname/; $emote{other} =~ s//$name/; - $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; - $target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); + send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } else { my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; @@ -749,10 +757,10 @@ $emote{other} =~ s//$name/; - $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; - $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); + $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } }; }; @@ -763,7 +771,7 @@ my $name = $pl->name; - $_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) + send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" for grep $pl->on_same_map_as ($_->ob), cf::player::list; }; @@ -778,8 +786,9 @@ my $name = $ob->name; my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; - $_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob ? cf::NDI_REPLY : 0)) - for @plonmap; + send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" + for grep $_ != $ob->contr, @plonmap; + $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); # npcs, magic_ears etc. # first find all objects and their first-level inventories @@ -803,26 +812,26 @@ if (defined $reply) { if ($npc->type == cf::MAGIC_EAR) { if (length $reply) { - $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) + send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" for @plonmap; } $npc->use_trigger; } else { if (length $reply) { - $_->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) + send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" for @plonmap; } } } if (@kw) { - $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) + $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) for @plonmap; } } } else { - $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); + $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); } }; @@ -842,11 +851,11 @@ cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; send_irc ("[%s] %s", $name, $msg); - $_->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) + send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; } else { - $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); + $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); } }; @@ -866,11 +875,11 @@ cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; send_irc ("\007\0034{%s} %s\n", $name, $msg); - $_->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) + send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; } else { - $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); + $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); } }; @@ -907,7 +916,7 @@ cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); - $other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF); + send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell"; } } else { $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);