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