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