ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/invite.ext
Revision: 1.9
Committed: Fri Mar 24 23:29:18 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.8: +2 -0 lines
Log Message:
added some 0 and 1 to the callbacks

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # level 1: invite to private rooms only ~lvl 10
4     # level 2: private rooms and saving maps (guilds, some other public saving maps)
5     # level 3: invite everywhere where no monsters are on the map
6     # level 4: invite everywhere
7    
8     # implement a 'follow' command
9    
10 root 1.6 #TODO: fon't invite on damned ground
11    
12 root 1.1 my $TIMEOUT = 60;
13    
14 elmex 1.8 # determine whether map cell is damned
15     sub is_damned {
16     my ($map, $x, $y) = @_;
17     return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y);
18     }
19    
20 root 1.1 # determine level available to the player
21     sub player_level {
22     my ($ob) = @_;
23    
24     return 4
25     if $ob->flag (cf::FLAG_WIZ);
26    
27     List::Util::max
28     map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0,
29     $ob->inv
30     }
31    
32 root 1.3 # determine level required for the given location
33 root 1.1 sub map_level {
34     my ($map, $x, $y) = @_;
35    
36     for my $x (0 .. $map->width - 1) {
37     for my $y (0 .. $map->height - 1) {
38     return 4
39     if grep $_->flag (cf::FLAG_MONSTER),
40     $map->at ($x, $y);
41     }
42     }
43    
44 root 1.2 my $path = $map->path;
45     my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir;
46    
47 root 1.1 if ($player eq substr $path, 0, length $player) {
48     1
49 root 1.5 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) {
50 root 1.1 2
51     } else {
52     3
53     }
54     }
55    
56     my @maplevel = (
57     "some mysterious hideout",
58     "his home",
59 root 1.5 "his guild", # wrong, this is any unique place !player-specific
60 root 1.1 "a nice place",
61     "a place with monsters",
62     );
63    
64     my %invite;
65    
66     cf::register_command invite => 10, sub {
67     my ($who, $args) = @_;
68    
69     my $name = $who->name;
70    
71     if ($args ne "" && $name ne $args) {
72     my ($map, $x, $y) = ($who->map, $who->x, $who->y);
73    
74     my $plevel = player_level $who;
75     my $mlevel = map_level $map, $x, $y;
76    
77 elmex 1.8 if (is_damned ($map, $x, $y)) {
78     $who->message ("Your god isn't present here, you can't invite someone to unholy ground.");
79     } elsif ($plevel >= $mlevel) {
80 root 1.1 if (my $other = cf::player::find $args) {
81     $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds");
82     $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name");
83     $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y];
84     } else {
85     $who->message ("cannot invite '$args': no such player");
86     }
87     } elsif ($plevel) {
88     $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege.");
89     } else {
90     $who->message ("You haven't proven your worthyness in the mountain maze.");
91     }
92     } else {
93     $who->message ("canceling all invites");
94     delete $invite{$name};
95     }
96 elmex 1.9 1
97 root 1.1 };
98    
99     sub teleport {
100     my ($pl, $map, $x, $y) = @_;
101    
102 root 1.7 my $portal = cf::object::new "exit";
103 root 1.1
104     $portal->set_slaying ($map->path);
105     $portal->set_hp ($x);
106     $portal->set_sp ($y);
107    
108 root 1.4 $portal->apply ($pl);
109 root 1.1
110     $portal->free;
111     }
112    
113     cf::register_command "accept-invitation" => 10, sub {
114     my ($who, $args) = @_;
115    
116     my $name = $who->name;
117 elmex 1.8 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
118 root 1.1
119 elmex 1.8 if (is_damned ($map, $x, $y)) {
120     $who->message ("You can't be invited from a place where your god isn't present.");
121     } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) {
122 root 1.1 $who->message ("Sorry, $args hasn't invited you.");
123     } elsif ($invite{$args}{$name}[0] < time) {
124     $who->message ("Sorry, $args\'s invitation has expired.");
125     } else {
126 root 1.6 my $inv = delete $invite{$args}{$name};
127 root 1.1 $who->message ("A godly force starts to pull you up...");
128 root 1.6 teleport $who, @{$inv}[1,2,3];
129 root 1.1 $who->message ("... and sets you down where $args invited you to.");
130 root 1.6
131 root 1.1 }
132 elmex 1.9 1
133 root 1.1 }
134