--- deliantra/maps/perl/schmorp-neko.ext 2006/02/17 15:21:21 1.9 +++ deliantra/maps/perl/schmorp-neko.ext 2006/08/27 15:23:30 1.22 @@ -2,12 +2,10 @@ # archetype nekosan -use Data::Dumper; - sub teleport { my ($pl, $map, $x, $y) = @_; - my $portal = cf::object::new ("exit"); + my $portal = cf::object::new "exit"; $portal->set_slaying ($map); $portal->set_hp ($x); @@ -18,45 +16,127 @@ $portal->free; } -sub on_move { - my ($data) = @_; +sub find_target_player { + my ($obj) = @_; - if (my $pl = $data->{who}->nearest_player) { - my ($d, undef, undef, $dir, undef) = $data->{who}->rangevector ($pl); + my ($time, $pl) = (time + 120, undef); - $dir = $dir % 8 + 1 unless $d > 1.5; + for (map $_->ob, cf::player::list) { + next unless $obj->on_same_map_as ($_); - $data->{who}->move ($dir); + my $ptime = List::Util::max $_->{neko_next_pester}, $_->{neko_next_cast}; + + ($time, $pl) = ($ptime, $_) + if $time > $ptime; } - 1 + $pl } -sub on_attack { - my ($data) = @_; +sub on_move { + my ($self, $enemy) = @_; + #warn "move<@_>\n";#d# - $data->{activator}{neko_attack}++ - or cf::LOG cf::llevDebug, sprintf "QBERT Neko-san was attacked by %s!\n", $data->{activator}->name; + if (my $pl = find_target_player $self) { + my ($d, undef, undef, $dir, undef) = $self->rangevector ($pl); - $data->{activator}->message ("Meoow! (Please do not hurt me)") - if !($data->{activator}{neko_attack} & 15); + if ($d < 1.5) { + if (grep $_->type == cf::FORCE && $_->slaying eq "schmorp-neko-gave-fish", $pl->inv) { + # she likes us! + if ($pl->{neko_next_pester} < time) { + $pl->{neko_next_pester} = time + 120 + rand 300; + $pl->message ("Purr. (Purr)"); + } + + if ($pl->{neko_next_cast} < time) { + $pl->{neko_next_cast} = time + 40 + rand 60; + + # so heal her + my $spell = cf::object::new "spell_heal"; + + $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) * 0.5); # normal hp heal + $spell->set_food (50); # fill food + $spell->set_last_sp (100); # fill sp + $spell->set_last_grace (100); # fill gr + $spell->set_attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE); + + $pl->message ("(Neko-san makes strange noises)"); + $pl->cast_spell ($self, $dir, $spell); + + $spell->free; + } + + } else { + # check for fish in his inv and steal it + if (my $fish = (grep $_->archetype->name eq "fishfood", $pl->inv)[0]) { + # add force + my $gave_fish = cf::object::new "force"; + $gave_fish->set_slaying ("schmorp-neko-gave-fish"); + $gave_fish->set_speed (0); + $gave_fish->insert_ob_in_ob ($pl); + + # remove fish + $fish->remove; + $fish->free; + + # be nice + $pl->message ("Meoww! (Thank you)"); + + } else { + # pester user + if ($pl->{neko_next_pester} < time) { + $pl->{neko_next_pester} = time + 60 + rand 300; + $pl->message ("Meow. (Please bring me fish)"); + } + } + } + + # circular movement + $dir = $dir % 8 + 1 unless $d > 1.5; + } - if ($data->{activator}{neko_attack} > 512) { - $data->{activator}{neko_attack} -= 128; - $data->{activator}->message ("Neko-san is suddenly gone!"); - teleport $data->{activator}, "/scorn/misc/scorn_illusions", 15, 7; - $data->{activator}->message ("You hear strange noises all around you..."); - $data->{activator}->message ("You feel dumb."); + $self->move ($dir); } - 1 + cf::override; } -sub on_say { - my ($data) = @_; +sub on_attack { + my ($self) = @_; + #warn "attack<@_>\n";#d# - cf::LOG cf::llevDebug, sprintf "QBERT [Neko-fon] %s: %s\n", $data->{activator}->name, $data->{message}; + if ($self->{neko_last_attack} < time - 300) { + $self->{neko_attack} = 0; + } - 0 + $self->{neko_last_attack} = time; + $self->{neko_attack}++ + or ext::schmorp_irc::do_notice "Neko-san was attacked by ". $self->name . "!\n"; + + $self->message ("Meoow! (Please do not hurt me)") + if !($self->{neko_attack} & 15); + + if ($self->{neko_attack} > 512) { + $self->{neko_attack} -= 128; + $self->message ("Neko-san is suddenly gone!"); + teleport $self, "/scorn/misc/scorn_illusions", 15, 7; + $self->message ("You hear strange noises all around you..."); + $self->message ("You feel dumb."); + } + + cf::override; +} + +sub on_listen { + my ($event, $ob, $who, $msg) = @_; + + cf::LOG cf::llevDebug, sprintf "QBERT [Neko-fon] %s: %s\n", $who->name, $msg; + ext::schmorp_irc::do_notice (sprintf "[Neko-fon] %s: %s\n", $who->name, $msg); } +cf::register_attachment "Nekosan", package => __PACKAGE__; +