--- cf.schmorp.de/maps/perl/schmorp-neko.ext 2006/02/17 19:39:11 1.11 +++ cf.schmorp.de/maps/perl/schmorp-neko.ext 2006/02/17 21:10:18 1.12 @@ -18,35 +18,58 @@ $portal->free; } +sub find_target_player { + my ($obj) = @_; + + my ($time, $pl) = (time + 30, undef); + + for (map $_->ob, cf::player::list) { + next unless $obj->on_same_map_as ($_); + + my $ptime = List::Util::max $_->{neko_next_pester}, $_->{neko_next_cast}; + + ($time, $pl) = ($ptime, $_); + if $time > $ptime; + } + + $pl +} + sub on_move { my ($data) = @_; - if (my $pl = $data->{who}->nearest_player) { + if (my $pl = find_target_player $data->{who}) { my ($d, undef, undef, $dir, undef) = $data->{who}->rangevector ($pl); if ($d < 1.5) { if (grep $_->type == cf::FORCE && $_->slaying eq "schmorp-neko-gave-fish", $pl->inv) { # she likes us! - if ($pl->{neko_fish} < time) { - $pl->{neko_fish} = time + 120 + rand 300; + if ($pl->{neko_next_pester} < time) { + $pl->{neko_next_pester} = time + 120 + rand 300; $pl->message ("Purr. (Purr)"); } - # so heal her - my $spell = cf::object::new "spell_heal"; + if ($pl->{neko_next_cast} < time) { + $pl->{neko_next_cast} = time + 40 + rand 60; - $spell->set_hp (0); - $spell->set_dam (0); # normal hp heal (none to avoid message) - $spell->set_food (999); # fill food - $spell->set_last_sp (9999); # fill sp - $spell->set_last_grace (9999); # fill gr - $spell->set_attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE); + # so heal her + my $spell = cf::object::new "spell_heal"; - if ($data->{who}->cast_spell ($data->{who}, $dir, $spell)) { - $pl->message ("... (Neko-san makes strange noises)"); - } + $spell->set_sp (0); # makes casting work + $spell->set_gp (0); # on unholy/nomagic ground + + $spell->set_hp (0); + $spell->set_dam ($pl->maxhp - $pl->hp); # normal hp heal + $spell->set_food (999); # fill food + $spell->set_last_sp (9999); # fill sp + $spell->set_last_grace (9999); # fill gr + $spell->set_attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE); - $spell->free; + $pl->message ("(Neko-san makes strange noises)"); + $pl->cast_spell ($data->{who}, $dir, $spell); + + $spell->free; + } } else { # check for fish in his inv and steal it @@ -66,8 +89,8 @@ } else { # pester user - if ($pl->{neko_fish} < time) { - $pl->{neko_fish} = time + 60 + rand 300; + if ($pl->{neko_next_pester} < time) { + $pl->{neko_next_pester} = time + 60 + rand 300; $pl->message ("Meow. (Please bring me fish)"); } }