--- deliantra/server/ext/chat.ext 2009/01/26 00:10:38 1.49 +++ deliantra/server/ext/chat.ext 2010/04/23 17:56:45 1.55 @@ -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.", @@ -777,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, $ob->contr, $msg); + # 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 {