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 |
|
|
}; |
97 |
|
|
|
98 |
|
|
sub teleport { |
99 |
|
|
my ($pl, $map, $x, $y) = @_; |
100 |
|
|
|
101 |
root |
1.7 |
my $portal = cf::object::new "exit"; |
102 |
root |
1.1 |
|
103 |
|
|
$portal->set_slaying ($map->path); |
104 |
|
|
$portal->set_hp ($x); |
105 |
|
|
$portal->set_sp ($y); |
106 |
|
|
|
107 |
root |
1.4 |
$portal->apply ($pl); |
108 |
root |
1.1 |
|
109 |
|
|
$portal->free; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
cf::register_command "accept-invitation" => 10, sub { |
113 |
|
|
my ($who, $args) = @_; |
114 |
|
|
|
115 |
|
|
my $name = $who->name; |
116 |
elmex |
1.8 |
my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
117 |
root |
1.1 |
|
118 |
elmex |
1.8 |
if (is_damned ($map, $x, $y)) { |
119 |
|
|
$who->message ("You can't be invited from a place where your god isn't present."); |
120 |
|
|
} elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
121 |
root |
1.1 |
$who->message ("Sorry, $args hasn't invited you."); |
122 |
|
|
} elsif ($invite{$args}{$name}[0] < time) { |
123 |
|
|
$who->message ("Sorry, $args\'s invitation has expired."); |
124 |
|
|
} else { |
125 |
root |
1.6 |
my $inv = delete $invite{$args}{$name}; |
126 |
root |
1.1 |
$who->message ("A godly force starts to pull you up..."); |
127 |
root |
1.6 |
teleport $who, @{$inv}[1,2,3]; |
128 |
root |
1.1 |
$who->message ("... and sets you down where $args invited you to."); |
129 |
root |
1.6 |
|
130 |
root |
1.1 |
} |
131 |
|
|
} |
132 |
|
|
|