--- cf.schmorp.de/maps/perl/schmorp-neko.ext 2006/02/17 23:01:40 1.14 +++ cf.schmorp.de/maps/perl/schmorp-neko.ext 2006/09/08 16:22:14 1.28 @@ -2,16 +2,14 @@ # archetype nekosan -use Data::Dumper; - sub teleport { my ($pl, $map, $x, $y) = @_; my $portal = cf::object::new "exit"; - $portal->set_slaying ($map); - $portal->set_hp ($x); - $portal->set_sp ($y); + $portal->slaying ($map); + $portal->hp ($x); + $portal->sp ($y); $portal->apply ($pl); @@ -35,11 +33,11 @@ $pl } -sub on_move { - my ($data) = @_; +sub on_monster_move { + my ($self, $enemy) = @_; - if (my $pl = find_target_player $data->{who}) { - my ($d, undef, undef, $dir, undef) = $data->{who}->rangevector ($pl); + if (my $pl = find_target_player $self) { + my ($d, undef, undef, $dir, undef) = $self->rangevector ($pl); if ($d < 1.5) { if (grep $_->type == cf::FORCE && $_->slaying eq "schmorp-neko-gave-fish", $pl->inv) { @@ -55,18 +53,18 @@ # 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->sp (0); # makes casting work + $spell->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); + $spell->hp (0); + $spell->dam (($pl->maxhp - $pl->hp) * 0.5); # normal hp heal + $spell->food (50); # fill food + $spell->last_sp (100); # fill sp + $spell->last_grace (100); # fill gr + $spell->attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE); $pl->message ("(Neko-san makes strange noises)"); - $pl->cast_spell ($data->{who}, $dir, $spell); + $pl->cast_spell ($self, $dir, $spell); $spell->free; } @@ -76,8 +74,8 @@ 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->slaying ("schmorp-neko-gave-fish"); + $gave_fish->speed (0); $gave_fish->insert_ob_in_ob ($pl); # remove fish @@ -100,37 +98,47 @@ $dir = $dir % 8 + 1 unless $d > 1.5; } - $data->{who}->move ($dir); + $self->move ($dir); } - 1 + cf::override; } sub on_attack { - my ($data) = @_; - - $data->{activator}{neko_attack}++ - or cf::LOG cf::llevDebug, sprintf "QBERT Neko-san was attacked by %s!\n", $data->{activator}->name; + my ($self, $hitter) = @_; - $data->{activator}->message ("Meoow! (Please do not hurt me)") - if !($data->{activator}{neko_attack} & 15); + if ($hitter->type == cf::PLAYER) { + if ($hitter->{neko_last_attack} < time - 300) { + $hitter->{neko_attack} = 0; + } - 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."); + $hitter->{neko_last_attack} = time; + $hitter->{neko_attack}++ + or ext::schmorp_irc::do_notice "Neko-san was attacked by ". $hitter->name . "!\n"; + + $hitter->message ("Meoow! (Please do not hurt me)") + if !($hitter->{neko_attack} & 15); + + if ($hitter->{neko_attack} > 512) { + $hitter->{neko_attack} -= 128; + $hitter->message ("Neko-san is suddenly gone!"); + teleport $hitter, "/scorn/misc/scorn_illusions", 15, 7; + $hitter->message ("You hear strange noises all around you..."); + $hitter->message ("You feel dumb."); + } + } else { + $hitter->hp (-1); + $hitter->kill_object; } - 1 + cf::override; } sub on_say { - my ($data) = @_; - - cf::LOG cf::llevDebug, sprintf "QBERT [Neko-fon] %s: %s\n", $data->{activator}->name, $data->{message}; + my ($self, $pl, $msg) = @_; - 0 + ext::schmorp_irc::do_notice (sprintf "[Neko-fon] %s: %s\n", $pl->ob->name, $msg); } +cf::register_attachment "Nekosan", package => __PACKAGE__; +