ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-neko.ext
Revision: 1.23
Committed: Sun Aug 27 15:39:17 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
Changes since 1.22: +16 -18 lines
Log Message:
further conversion

File Contents

# Content
1 #! perl
2
3 # archetype nekosan
4
5 sub teleport {
6 my ($pl, $map, $x, $y) = @_;
7
8 my $portal = cf::object::new "exit";
9
10 $portal->set_slaying ($map);
11 $portal->set_hp ($x);
12 $portal->set_sp ($y);
13
14 $portal->apply ($pl);
15
16 $portal->free;
17 }
18
19 sub find_target_player {
20 my ($obj) = @_;
21
22 my ($time, $pl) = (time + 120, undef);
23
24 for (map $_->ob, cf::player::list) {
25 next unless $obj->on_same_map_as ($_);
26
27 my $ptime = List::Util::max $_->{neko_next_pester}, $_->{neko_next_cast};
28
29 ($time, $pl) = ($ptime, $_)
30 if $time > $ptime;
31 }
32
33 $pl
34 }
35
36 sub on_move {
37 my ($self, $enemy) = @_;
38
39 if (my $pl = find_target_player $self) {
40 my ($d, undef, undef, $dir, undef) = $self->rangevector ($pl);
41
42 if ($d < 1.5) {
43 if (grep $_->type == cf::FORCE && $_->slaying eq "schmorp-neko-gave-fish", $pl->inv) {
44 # she likes us!
45 if ($pl->{neko_next_pester} < time) {
46 $pl->{neko_next_pester} = time + 120 + rand 300;
47 $pl->message ("Purr. (Purr)");
48 }
49
50 if ($pl->{neko_next_cast} < time) {
51 $pl->{neko_next_cast} = time + 40 + rand 60;
52
53 # so heal her
54 my $spell = cf::object::new "spell_heal";
55
56 $spell->set_sp (0); # makes casting work
57 $spell->set_gp (0); # on unholy/nomagic ground
58
59 $spell->set_hp (0);
60 $spell->set_dam (($pl->maxhp - $pl->hp) * 0.5); # normal hp heal
61 $spell->set_food (50); # fill food
62 $spell->set_last_sp (100); # fill sp
63 $spell->set_last_grace (100); # fill gr
64 $spell->set_attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE);
65
66 $pl->message ("(Neko-san makes strange noises)");
67 $pl->cast_spell ($self, $dir, $spell);
68
69 $spell->free;
70 }
71
72 } else {
73 # check for fish in his inv and steal it
74 if (my $fish = (grep $_->archetype->name eq "fishfood", $pl->inv)[0]) {
75 # add force
76 my $gave_fish = cf::object::new "force";
77 $gave_fish->set_slaying ("schmorp-neko-gave-fish");
78 $gave_fish->set_speed (0);
79 $gave_fish->insert_ob_in_ob ($pl);
80
81 # remove fish
82 $fish->remove;
83 $fish->free;
84
85 # be nice
86 $pl->message ("Meoww! (Thank you)");
87
88 } else {
89 # pester user
90 if ($pl->{neko_next_pester} < time) {
91 $pl->{neko_next_pester} = time + 60 + rand 300;
92 $pl->message ("Meow. (Please bring me fish)");
93 }
94 }
95 }
96
97 # circular movement
98 $dir = $dir % 8 + 1 unless $d > 1.5;
99 }
100
101 $self->move ($dir);
102 }
103
104 cf::override;
105 }
106
107 sub on_attack {
108 my ($self, $hitter) = @_;
109
110 if ($hitter->{neko_last_attack} < time - 300) {
111 $hitter->{neko_attack} = 0;
112 }
113
114 $hitter->{neko_last_attack} = time;
115 $hitter->{neko_attack}++
116 or ext::schmorp_irc::do_notice "Neko-san was attacked by ". $hitter->name . "!\n";
117
118 $hitter->message ("Meoow! (Please do not hurt me)")
119 if !($hitter->{neko_attack} & 15);
120
121 if ($hitter->{neko_attack} > 512) {
122 $hitter->{neko_attack} -= 128;
123 $hitter->message ("Neko-san is suddenly gone!");
124 teleport $hitter, "/scorn/misc/scorn_illusions", 15, 7;
125 $hitter->message ("You hear strange noises all around you...");
126 $hitter->message ("You feel dumb.");
127 }
128
129 cf::override;
130 }
131
132 sub on_listen {
133 my ($event, $ob, $who, $msg) = @_;
134
135 cf::LOG cf::llevDebug, sprintf "QBERT [Neko-fon] %s: %s\n", $who->name, $msg;
136 ext::schmorp_irc::do_notice (sprintf "[Neko-fon] %s: %s\n", $who->name, $msg);
137 }
138
139 cf::register_attachment "Nekosan", package => __PACKAGE__;
140