ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/town_portal.ext
Revision: 1.2
Committed: Tue May 22 21:35:26 2007 UTC (17 years ago) by root
Branch: MAIN
CVS Tags: rel-2_4, rel-2_5, rel-2_2, rel-2_3, rel-2_1, rel-2_52, rel-2_32, rel-2_43, rel-2_42, rel-2_41
Changes since 1.1: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 # using the town portal brings you back to the magic portal if it still exists
7 root 1.1
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->instantiate;
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, $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     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     ;