1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | # implement the invite command |
2 | |
4 | |
3 | # level 1: invite to private rooms only ~lvl 10 |
5 | # level 1: invite to private rooms only ~lvl 10 |
4 | # level 2: private rooms and saving maps (guilds, some other public saving maps) |
6 | # 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 |
7 | # level 3: invite everywhere where no monsters are on the map |
6 | # level 4: invite everywhere |
8 | # level 4: invite everywhere |
7 | |
9 | |
8 | # implement a 'follow' command |
10 | my $TIMEOUT = $cf::CFG{invite_timeout} || 60; |
9 | |
|
|
10 | my $TIMEOUT = 60; |
|
|
11 | |
11 | |
12 | # determine whether map cell is damned |
12 | # determine whether map cell is damned |
13 | sub is_damned { |
13 | sub is_damned { |
14 | my ($map, $x, $y) = @_; |
14 | my ($map, $x, $y) = @_; |
15 | return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y); |
15 | return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y); |
… | |
… | |
37 | if grep $_->flag (cf::FLAG_MONSTER), |
37 | if grep $_->flag (cf::FLAG_MONSTER), |
38 | $map->at ($x, $y); |
38 | $map->at ($x, $y); |
39 | } |
39 | } |
40 | } |
40 | } |
41 | |
41 | |
42 | my $path = $map->path; |
42 | if ($map->path =~ /^~/) { |
43 | my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir; |
|
|
44 | |
|
|
45 | if ($player eq substr $path, 0, length $player) { |
|
|
46 | 1 |
43 | 1 |
47 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
44 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
48 | 2 |
45 | 2 |
49 | } else { |
46 | } else { |
50 | 3 |
47 | 3 |
… | |
… | |
73 | |
70 | |
74 | my $plevel = player_level $who; |
71 | my $plevel = player_level $who; |
75 | my $mlevel = map_level $map, $x, $y; |
72 | my $mlevel = map_level $map, $x, $y; |
76 | |
73 | |
77 | if (is_damned ($map, $x, $y)) { |
74 | if (is_damned ($map, $x, $y)) { |
78 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground."); |
75 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground. " |
|
|
76 | . "H<You can only use invite at places where you can use prayers.>"); |
79 | } elsif ($plevel >= $mlevel) { |
77 | } elsif ($plevel >= $mlevel) { |
80 | if (my $other = cf::player::find_active $args) { |
78 | if (my $other = cf::player::find_active $args) { |
81 | $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); |
79 | $who->message ("inviting player '$args', to cancel, use invite with no arguments or wait $TIMEOUT seconds"); |
82 | $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name"); |
80 | $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name"); |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
81 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
84 | } else { |
82 | } else { |
85 | $who->message ("cannot invite '$args': no such player"); |
83 | $who->message ("cannot invite '$args': no such player"); |
86 | } |
84 | } |
87 | } elsif ($plevel) { |
85 | } elsif ($plevel) { |
88 | $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege."); |
86 | $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege. " |
|
|
87 | . "H<Your invite level is not high enough to invite to this place.>"); |
89 | } else { |
88 | } else { |
90 | $who->message ("You haven't proven your worthyness in the mountain maze."); |
89 | $who->message ("You haven't proven your worthyness in the mountain maze. " |
|
|
90 | . "H<To use the invite command you have to do one or more of the invite quests. The first one can be found south-east of Scorn.>"); |
91 | } |
91 | } |
92 | } else { |
92 | } else { |
93 | $who->message ("canceling all invites"); |
93 | $who->message ("canceling all invites"); |
94 | delete $invite{$name}; |
94 | delete $invite{$name}; |
95 | } |
95 | } |
… | |
… | |
116 | |
116 | |
117 | my $name = $who->name; |
117 | my $name = $who->name; |
118 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
118 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
119 | |
119 | |
120 | if (is_damned ($map, $x, $y)) { |
120 | if (is_damned ($map, $x, $y)) { |
121 | $who->message ("You can't be invited from a place where your god isn't present."); |
121 | $who->message ("You can't be invited from a place where your god isn't present. " |
|
|
122 | . "H<Go to a place where your prayers work and try again.>"); |
122 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
123 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
123 | $who->message ("Sorry, $args hasn't invited you."); |
124 | $who->message ("Sorry, $args hasn't invited you."); |
124 | } elsif ($invite{$args}{$name}[0] < time) { |
125 | } elsif ($invite{$args}{$name}[0] < time) { |
125 | $who->message ("Sorry, $args\'s invitation has expired."); |
126 | $who->message ("Sorry, $args\'s invitation has expired. " |
|
|
127 | . "H<Invites are only valid for $TIMEOUT seconds, ask $args to invite you again.>"); |
126 | } else { |
128 | } else { |
127 | my $inv = delete $invite{$args}{$name}; |
129 | my $inv = delete $invite{$args}{$name}; |
128 | $who->message ("A godly force starts to pull you up..."); |
130 | $who->message ("A godly force starts to pull you up..."); |
129 | teleport $who, @{$inv}[1,2,3]; |
131 | teleport $who, @{$inv}[1,2,3]; |
130 | $who->message ("... and sets you down where $args invited you to."); |
132 | $who->message ("... and sets you down where $args invited you to."); |
131 | |
|
|
132 | } |
133 | } |
133 | }; |
134 | }; |
134 | |
135 | |