ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/town_portal.ext
Revision: 1.7
Committed: Sun Apr 25 11:23:31 2010 UTC (14 years ago) by root
Branch: MAIN
CVS Tags: rel-3_1, rel-3_0, HEAD
Changes since 1.6: +4 -6 lines
Log Message:
remove protal_x/portal_y capability

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;
18 while () {
19 $map = $region->portalmap;
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
32 #$portal->stats->food (40); # handy for debugging
33
34 $portal->insert_at ($who, $who, cf::INS_ABOVE_FLOOR_ONLY);
35
36 $who->reply (undef, "A shimmering portal opens.", cf::NDI_NAVY);
37
38 cf::override 1;
39 },
40 );
41
42 cf::object::attachment town_portal =>
43 on_apply => sub {
44 my ($self, $who) = @_;
45
46 $who->{town_portal} = [$who->map->as_string, $who->x, $who->y, $self->uuid];
47 },
48 ;
49
50 cf::object::attachment town_portal_return =>
51 on_apply => sub {
52 my ($self, $who) = @_;
53
54 if ($who->{town_portal}) {
55 my ($map, $x, $y, $uuid) = @{ $who->{town_portal} };
56
57 $who->goto ($map, $x, $y, sub {
58 my ($map) = @_;
59
60 $map->load; # make sure the map is loaded
61
62 if (grep $_->uuid eq $uuid, $map->at ($x, $y)) {
63 $who->reply (undef, "The town portal weaves its magic... and after a short moment, you return to the magic portal.", cf::NDI_NAVY);
64
65 delete $who->{town_portal};
66
67 return $map;
68 } else {
69 $who->reply (undef, "The town portal weaves its magic... but the magic link to your portal is too weak. "
70 . "[The town portal you used to come here might be gone.]", cf::NDI_NAVY);
71 }
72
73 ()
74 });
75 } else {
76 $who->reply (undef, "The town portal weaves its magic... but nothing happens. "
77 . "[You must arrive through this portal to be able to return.]", cf::NDI_NAVY);
78 }
79
80 cf::override 1;
81 },
82 ;
83