ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/town_portal.ext
Revision: 1.6
Committed: Sun Nov 29 17:41:07 2009 UTC (14 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-2_92, rel-2_93
Changes since 1.5: +1 -1 lines
Log Message:
-instance, some los fiddling

File Contents

# Content
1 #! perl
2
3 # this module implements the town portal spell:
4 # casting it creates a magic portal to the nearest town portal (regions)
5 # using the magic portal brings you to the town portal and remembers your magic portal
6 # using the town portal brings you back to the magic portal if it still exists
7
8 cf::object->attach (
9 type => cf::SPELL,
10 subtype => cf::SP_TOWN_PORTAL,
11 on_cast_spell => sub {
12 my ($spell, $who, $caster, $dir, $arg) = @_;
13
14 my $region = $who->region
15 or return cf::override 0;
16
17 my ($map, $x, $y);
18 while () {
19 ($map, $x, $y) = ($region->portalmap, $region->portalx, $region->portaly);
20
21 last if $map;
22
23 $region = $region->parent
24 or return cf::override 0;
25 }
26
27 my $portal = $spell->other_arch->instance;
28
29 $portal->name ("Magic Portal to nearest Town");
30 $portal->slaying ($map);
31 $portal->stats->hp ($x);
32 $portal->stats->sp ($y);
33
34 #$portal->stats->food (40); # handy for debugging
35
36 $portal->insert_at ($who, $who, cf::INS_ABOVE_FLOOR_ONLY);
37
38 $who->reply (undef, "A shimmering portal opens.", cf::NDI_NAVY);
39
40 cf::override 1;
41 },
42 );
43
44 cf::object::attachment town_portal =>
45 on_apply => sub {
46 my ($self, $who) = @_;
47
48 $who->{town_portal} = [$who->map->as_string, $who->x, $who->y, $self->uuid];
49 },
50 ;
51
52 cf::object::attachment town_portal_return =>
53 on_apply => sub {
54 my ($self, $who) = @_;
55
56 if ($who->{town_portal}) {
57 my ($map, $x, $y, $uuid) = @{ $who->{town_portal} };
58
59 $who->goto ($map, $x, $y, sub {
60 my ($map) = @_;
61
62 $map->load; # make sure the map is loaded
63
64 if (grep $_->uuid eq $uuid, $map->at ($x, $y)) {
65 $who->reply (undef, "The town portal weaves its magic... and after a short moment, you return to the magic portal.", cf::NDI_NAVY);
66
67 delete $who->{town_portal};
68
69 return $map;
70 } else {
71 $who->reply (undef, "The town portal weaves its magic... but the magic link to your portal is too weak. "
72 . "[The town portal you used to come here might be gone.]", cf::NDI_NAVY);
73 }
74
75 ()
76 });
77 } else {
78 $who->reply (undef, "The town portal weaves its magic... but nothing happens. "
79 . "[You must arrive through this portal to be able to return.]", cf::NDI_NAVY);
80 }
81
82 cf::override 1;
83 },
84 ;
85