| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
root |
1.3 |
# implement the invite command |
| 4 |
|
|
|
| 5 |
root |
1.1 |
# level 1: invite to private rooms only ~lvl 10 |
| 6 |
|
|
# level 2: private rooms and saving maps (guilds, some other public saving maps) |
| 7 |
|
|
# level 3: invite everywhere where no monsters are on the map |
| 8 |
|
|
# level 4: invite everywhere |
| 9 |
|
|
|
| 10 |
root |
1.3 |
my $TIMEOUT = $cf::CFG{invite_timeout} || 60; |
| 11 |
root |
1.1 |
|
| 12 |
|
|
# determine whether map cell is damned |
| 13 |
|
|
sub is_damned { |
| 14 |
|
|
my ($map, $x, $y) = @_; |
| 15 |
|
|
return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y); |
| 16 |
|
|
} |
| 17 |
|
|
|
| 18 |
|
|
# determine level available to the player |
| 19 |
|
|
sub player_level { |
| 20 |
|
|
my ($ob) = @_; |
| 21 |
|
|
|
| 22 |
|
|
return 4 |
| 23 |
|
|
if $ob->flag (cf::FLAG_WIZ); |
| 24 |
|
|
|
| 25 |
|
|
List::Util::max |
| 26 |
|
|
map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0, |
| 27 |
|
|
$ob->inv |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
# determine level required for the given location |
| 31 |
|
|
sub map_level { |
| 32 |
|
|
my ($map, $x, $y) = @_; |
| 33 |
|
|
|
| 34 |
|
|
for my $x (0 .. $map->width - 1) { |
| 35 |
|
|
for my $y (0 .. $map->height - 1) { |
| 36 |
|
|
return 4 |
| 37 |
|
|
if grep $_->flag (cf::FLAG_MONSTER), |
| 38 |
|
|
$map->at ($x, $y); |
| 39 |
|
|
} |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
root |
1.3 |
if ($map->path =~ /^~/) { |
| 43 |
root |
1.1 |
1 |
| 44 |
|
|
} elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
| 45 |
|
|
2 |
| 46 |
|
|
} else { |
| 47 |
|
|
3 |
| 48 |
|
|
} |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
my @maplevel = ( |
| 52 |
|
|
"some mysterious hideout", |
| 53 |
root |
1.7 |
"a private apartment", |
| 54 |
root |
1.8 |
"a guild", # wrong, this is any unique place !player-specific |
| 55 |
root |
1.7 |
"some nice and safe place", |
| 56 |
root |
1.1 |
"a place with monsters", |
| 57 |
|
|
); |
| 58 |
|
|
|
| 59 |
|
|
my %invite; |
| 60 |
|
|
|
| 61 |
|
|
cf::register_command invite => sub { |
| 62 |
|
|
my ($who, $args) = @_; |
| 63 |
|
|
|
| 64 |
|
|
$who->speed_left ($who->speed_left - 0.2); |
| 65 |
|
|
|
| 66 |
|
|
my $name = $who->name; |
| 67 |
|
|
|
| 68 |
|
|
if ($args ne "" && $name ne $args) { |
| 69 |
|
|
my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
| 70 |
|
|
|
| 71 |
|
|
my $plevel = player_level $who; |
| 72 |
|
|
my $mlevel = map_level $map, $x, $y; |
| 73 |
|
|
|
| 74 |
|
|
if (is_damned ($map, $x, $y)) { |
| 75 |
root |
1.4 |
$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.>"); |
| 77 |
root |
1.1 |
} elsif ($plevel >= $mlevel) { |
| 78 |
root |
1.2 |
if (my $other = cf::player::find_active $args) { |
| 79 |
root |
1.3 |
$who->message ("inviting player '$args', to cancel, use invite with no arguments or wait $TIMEOUT seconds"); |
| 80 |
root |
1.6 |
$other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use C<accept-invitation $name> (or C<a-i $name>)"); |
| 81 |
root |
1.1 |
$invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
| 82 |
|
|
} else { |
| 83 |
|
|
$who->message ("cannot invite '$args': no such player"); |
| 84 |
|
|
} |
| 85 |
|
|
} elsif ($plevel) { |
| 86 |
root |
1.4 |
$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.>"); |
| 88 |
root |
1.1 |
} else { |
| 89 |
root |
1.4 |
$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 |
root |
1.1 |
} |
| 92 |
|
|
} else { |
| 93 |
|
|
$who->message ("canceling all invites"); |
| 94 |
|
|
delete $invite{$name}; |
| 95 |
|
|
} |
| 96 |
|
|
}; |
| 97 |
|
|
|
| 98 |
|
|
cf::register_command "accept-invitation" => sub { |
| 99 |
|
|
my ($who, $args) = @_; |
| 100 |
|
|
|
| 101 |
|
|
$who->speed_left ($who->speed_left - 0.2); |
| 102 |
|
|
|
| 103 |
|
|
my $name = $who->name; |
| 104 |
|
|
my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
| 105 |
|
|
|
| 106 |
|
|
if (is_damned ($map, $x, $y)) { |
| 107 |
root |
1.4 |
$who->message ("You can't be invited from a place where your god isn't present. " |
| 108 |
|
|
. "H<Go to a place where your prayers work and try again.>"); |
| 109 |
root |
1.1 |
} elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
| 110 |
|
|
$who->message ("Sorry, $args hasn't invited you."); |
| 111 |
|
|
} elsif ($invite{$args}{$name}[0] < time) { |
| 112 |
root |
1.4 |
$who->message ("Sorry, $args\'s invitation has expired. " |
| 113 |
|
|
. "H<Invites are only valid for $TIMEOUT seconds, ask $args to invite you again.>"); |
| 114 |
root |
1.1 |
} else { |
| 115 |
|
|
my $inv = delete $invite{$args}{$name}; |
| 116 |
|
|
$who->message ("A godly force starts to pull you up..."); |
| 117 |
root |
1.6 |
$who->goto (@$inv[1,2,3]); |
| 118 |
root |
1.1 |
$who->message ("... and sets you down where $args invited you to."); |
| 119 |
|
|
} |
| 120 |
|
|
}; |
| 121 |
|
|
|