… | |
… | |
5 | use Data::Dumper; |
5 | use Data::Dumper; |
6 | |
6 | |
7 | sub teleport { |
7 | sub teleport { |
8 | my ($pl, $map, $x, $y) = @_; |
8 | my ($pl, $map, $x, $y) = @_; |
9 | |
9 | |
10 | my $portal = cf::object::new ("exit"); |
10 | my $portal = cf::object::new "exit"; |
11 | |
11 | |
12 | $portal->set_slaying ($map); |
12 | $portal->set_slaying ($map); |
13 | $portal->set_hp ($x); |
13 | $portal->set_hp ($x); |
14 | $portal->set_sp ($y); |
14 | $portal->set_sp ($y); |
15 | |
15 | |
16 | $portal->apply ($pl); |
16 | $portal->apply ($pl); |
17 | |
17 | |
18 | $portal->free; |
18 | $portal->free; |
19 | } |
19 | } |
20 | |
20 | |
|
|
21 | sub find_target_player { |
|
|
22 | my ($obj) = @_; |
|
|
23 | |
|
|
24 | my ($time, $pl) = (time + 30, undef); |
|
|
25 | |
|
|
26 | for (map $_->ob, cf::player::list) { |
|
|
27 | next unless $obj->on_same_map_as ($_); |
|
|
28 | |
|
|
29 | my $ptime = List::Util::max $_->{neko_next_pester}, $_->{neko_next_cast}; |
|
|
30 | |
|
|
31 | ($time, $pl) = ($ptime, $_); |
|
|
32 | if $time > $ptime; |
|
|
33 | } |
|
|
34 | |
|
|
35 | $pl |
|
|
36 | } |
|
|
37 | |
21 | sub on_move { |
38 | sub on_move { |
22 | my ($data) = @_; |
39 | my ($data) = @_; |
23 | |
40 | |
24 | if (my $pl = $data->{who}->nearest_player) { |
41 | if (my $pl = find_target_player $data->{who}) { |
25 | my ($d, undef, undef, $dir, undef) = $data->{who}->rangevector ($pl); |
42 | my ($d, undef, undef, $dir, undef) = $data->{who}->rangevector ($pl); |
26 | |
43 | |
|
|
44 | if ($d < 1.5) { |
|
|
45 | if (grep $_->type == cf::FORCE && $_->slaying eq "schmorp-neko-gave-fish", $pl->inv) { |
|
|
46 | # she likes us! |
|
|
47 | if ($pl->{neko_next_pester} < time) { |
|
|
48 | $pl->{neko_next_pester} = time + 120 + rand 300; |
|
|
49 | $pl->message ("Purr. (Purr)"); |
|
|
50 | } |
|
|
51 | |
|
|
52 | if ($pl->{neko_next_cast} < time) { |
|
|
53 | $pl->{neko_next_cast} = time + 40 + rand 60; |
|
|
54 | |
|
|
55 | # so heal her |
|
|
56 | my $spell = cf::object::new "spell_heal"; |
|
|
57 | |
|
|
58 | $spell->set_sp (0); # makes casting work |
|
|
59 | $spell->set_gp (0); # on unholy/nomagic ground |
|
|
60 | |
|
|
61 | $spell->set_hp (0); |
|
|
62 | $spell->set_dam ($pl->maxhp - $pl->hp); # normal hp heal |
|
|
63 | $spell->set_food (999); # fill food |
|
|
64 | $spell->set_last_sp (9999); # fill sp |
|
|
65 | $spell->set_last_grace (9999); # fill gr |
|
|
66 | $spell->set_attacktype (cf::AT_CONFUSION | cf::AT_POISON | cf::AT_BLIND | cf::AT_DISEASE); |
|
|
67 | |
|
|
68 | $pl->message ("(Neko-san makes strange noises)"); |
|
|
69 | $pl->cast_spell ($data->{who}, $dir, $spell); |
|
|
70 | |
|
|
71 | $spell->free; |
|
|
72 | } |
|
|
73 | |
|
|
74 | } else { |
|
|
75 | # check for fish in his inv and steal it |
|
|
76 | if (my $fish = (grep $_->archetype->name eq "fishfood", $pl->inv)[0]) { |
|
|
77 | # add force |
|
|
78 | my $gave_fish = cf::object::new "force"; |
|
|
79 | $gave_fish->set_slaying ("schmorp-neko-gave-fish"); |
|
|
80 | $gave_fish->set_speed (0); |
|
|
81 | $gave_fish->insert_ob_in_ob ($pl); |
|
|
82 | |
|
|
83 | # remove fish |
|
|
84 | $fish->remove; |
|
|
85 | $fish->free; |
|
|
86 | |
|
|
87 | # be nice |
|
|
88 | $pl->message ("Meoww! (Thank you)"); |
|
|
89 | |
|
|
90 | } else { |
|
|
91 | # pester user |
|
|
92 | if ($pl->{neko_next_pester} < time) { |
|
|
93 | $pl->{neko_next_pester} = time + 60 + rand 300; |
|
|
94 | $pl->message ("Meow. (Please bring me fish)"); |
|
|
95 | } |
|
|
96 | } |
|
|
97 | } |
|
|
98 | |
|
|
99 | # circular movement |
27 | $dir = $dir % 8 + 1 unless $d > 1.5; |
100 | $dir = $dir % 8 + 1 unless $d > 1.5; |
|
|
101 | } |
28 | |
102 | |
29 | $data->{who}->move ($dir); |
103 | $data->{who}->move ($dir); |
30 | } |
104 | } |
31 | |
105 | |
32 | 1 |
106 | 1 |