ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/town_portal.ext
Revision: 1.5
Committed: Sun Jun 15 20:32:50 2008 UTC (15 years, 11 months ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_79, rel-2_90, rel-2_78, rel-2_61
Changes since 1.4: +2 -0 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 root 1.4 $who->{town_portal} = [$who->map->as_string, $who->x, $who->y, $self->uuid];
49 root 1.1 },
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 root 1.5 $map->load; # make sure the map is loaded
63    
64 root 1.1 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 root 1.3