--- deliantra/server/ext/chat.ext 2008/12/18 02:49:22 1.46 +++ deliantra/server/ext/chat.ext 2010/04/22 12:50:24 1.54 @@ -75,7 +75,7 @@ my $pl = $ob->contr; my $name = $ob->name; - my $coin = int rand 2 ? "Heads" : "Tails"; + my $coin = (cf::rndm 2) ? "Heads" : "Tails"; 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; @@ -90,7 +90,7 @@ my $name = $ob->name; my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); - my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); + my ($i, $j, $k, $l) = map +(cf::rndm $_), 5, 5, 5, 6; my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" @@ -220,7 +220,7 @@ kiss => { noparams => { other => " makes a weird facial contortion", - self => "All the lonely people..", + self => "All the lonely people...", }, params => { target => " kisses you.", @@ -230,10 +230,25 @@ self => { }, }, + hug => { + noparams => { + other => " makes weird body movements.", + self => "All the lonely people...", + }, + params => { + target => " suddenly grabs you and gives you a bear hug.", + other => " hugs .", + self => "You hug .", + }, + self => { + other => " tries to hug G, but stumbles and now feels stupid.", + self => "You try and fail to hug yourself.", + }, + }, smother => { noparams => { other => " makes weird facial contortions", - self => "All the lonely people..", + self => "All the lonely people...", }, params => { target => " smothers you with kisses.", @@ -762,15 +777,6 @@ }; } -cf::register_command me => sub { - my ($pl, $msg) = @_; - - my $name = $pl->name; - - 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; -}; - cf::register_command say => sub { my ($ob, $msg) = @_; @@ -786,39 +792,59 @@ for grep $_ != $ob->contr, @plonmap; $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); + my @npc; + # 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) = ($ob->map, $ob->x - 2, $ob->y - 2); + # we prefer the nearest items NOT in the player, otherwise in player. + my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y); - for my $npc ( - grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, - map +($_, $_->inv), - grep $_, - map $map->at ($x + $_ % 5, $y + (int $_ / 5)), - 0..24 + for my $dir ( + 0, + 1, 3, 5, 7, + 2, 4, 6, 8, + 9 .. cf::SIZEOFFREE2 ) { + @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue, + map +($_, $_->inv), + grep $_ != $ob, + $map->at ($x, $y, $dir) + and last; + } + + unless (@npc) { + # nothing found, try the player inventory + @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue, + $ob->inv; + } + + for my $npc (@npc) { + return if $npc->invoke (cf::EVENT_OBJECT_SAY); + # if some listener teleported us somewhere else, stop right here last unless $map->path == $ob->map->path; - my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; - my ($reply, @kw) = $dialog->tell ($msg); + if ($npc->has_dialogue) { + 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) { + send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" + for @plonmap; + } else { + send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" + for @plonmap; + } + } - if (defined $reply) { - if ($npc->type == cf::MAGIC_EAR) { - send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" - for @plonmap; - } else { - send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" + if (@kw) { + $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) for @plonmap; } } - - if (@kw) { - $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) - for @plonmap; - } } } else { @@ -826,10 +852,9 @@ } }; -cf::register_command chat => sub { - my ($ob, $msg) = @_; - utf8::decode $msg; +sub _chat { + my ($ob, $msg) = @_; my $pl = $ob->contr; @@ -839,15 +864,29 @@ my $name = $ob->name; my $NOW = time; - cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; - send_irc ("[%s] %s", $name, $msg); + cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg; + send_irc ("%s", $msg); - send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" + send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; } else { $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); } +} + +cf::register_command chat => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, $ob->name . " chats: $msg"; +}; + +cf::register_command me => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, "* " . $ob->name . " $msg"; }; cf::register_command shout => sub {