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); |
… | |
… | |
32 | my ($map, $x, $y) = @_; |
32 | my ($map, $x, $y) = @_; |
33 | |
33 | |
34 | for my $x (0 .. $map->width - 1) { |
34 | for my $x (0 .. $map->width - 1) { |
35 | for my $y (0 .. $map->height - 1) { |
35 | for my $y (0 .. $map->height - 1) { |
36 | return 4 |
36 | return 4 |
37 | if grep $_->flag (cf::FLAG_MONSTER), |
37 | if grep $_->flag (cf::FLAG_MONSTER) |
|
|
38 | && !$_->flag (cf::FLAG_FRIENDLY) |
|
|
39 | && !$_->flag (cf::FLAG_UNAGGRESSIVE), |
38 | $map->at ($x, $y); |
40 | $map->at ($x, $y); |
39 | } |
41 | } |
40 | } |
42 | } |
41 | |
43 | |
42 | my $path = $map->path; |
44 | 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 |
45 | 1 |
47 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
46 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
48 | 2 |
47 | 2 |
49 | } else { |
48 | } else { |
50 | 3 |
49 | 3 |
51 | } |
50 | } |
52 | } |
51 | } |
53 | |
52 | |
54 | my @maplevel = ( |
53 | my @maplevel = ( |
55 | "some mysterious hideout", |
54 | "some mysterious hideout", |
56 | "his home", |
55 | "a private apartment", |
57 | "his guild", # wrong, this is any unique place !player-specific |
56 | "a guild", # wrong, this is any unique place !player-specific |
58 | "a nice place", |
57 | "some nice and safe place", |
59 | "a place with monsters", |
58 | "a place with monsters", |
60 | ); |
59 | ); |
61 | |
60 | |
62 | my %invite; |
61 | my %invite; |
63 | |
62 | |
… | |
… | |
73 | |
72 | |
74 | my $plevel = player_level $who; |
73 | my $plevel = player_level $who; |
75 | my $mlevel = map_level $map, $x, $y; |
74 | my $mlevel = map_level $map, $x, $y; |
76 | |
75 | |
77 | if (is_damned ($map, $x, $y)) { |
76 | if (is_damned ($map, $x, $y)) { |
78 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground."); |
77 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground. " |
|
|
78 | . "H<You can only use invite at places where you can use prayers.>"); |
79 | } elsif ($plevel >= $mlevel) { |
79 | } elsif ($plevel >= $mlevel) { |
80 | if (my $other = cf::player::find $args) { |
80 | if (my $other = cf::player::find_active $args) { |
81 | $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); |
81 | $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"); |
82 | $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use C<accept-invitation $name> (or C<a-i $name>)"); |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
84 | } else { |
84 | } else { |
85 | $who->message ("cannot invite '$args': no such player"); |
85 | $who->message ("cannot invite '$args': no such player"); |
86 | } |
86 | } |
87 | } elsif ($plevel) { |
87 | } elsif ($plevel) { |
88 | $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege."); |
88 | $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege. " |
|
|
89 | . "H<Your invite level is not high enough to invite to this place.>"); |
89 | } else { |
90 | } else { |
90 | $who->message ("You haven't proven your worthyness in the mountain maze."); |
91 | $who->message ("You haven't proven your worthyness in the mountain maze. " |
|
|
92 | . "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 | } |
93 | } |
92 | } else { |
94 | } else { |
93 | $who->message ("canceling all invites"); |
95 | $who->message ("canceling all invites"); |
94 | delete $invite{$name}; |
96 | delete $invite{$name}; |
95 | } |
97 | } |
96 | }; |
98 | }; |
97 | |
|
|
98 | sub teleport { |
|
|
99 | my ($pl, $map, $x, $y) = @_; |
|
|
100 | |
|
|
101 | my $portal = cf::object::new "exit"; |
|
|
102 | |
|
|
103 | $portal->slaying ($map->path); |
|
|
104 | $portal->stats->hp ($x); |
|
|
105 | $portal->stats->sp ($y); |
|
|
106 | |
|
|
107 | $portal->apply ($pl); |
|
|
108 | |
|
|
109 | $portal->destroy; |
|
|
110 | } |
|
|
111 | |
99 | |
112 | cf::register_command "accept-invitation" => sub { |
100 | cf::register_command "accept-invitation" => sub { |
113 | my ($who, $args) = @_; |
101 | my ($who, $args) = @_; |
114 | |
102 | |
115 | $who->speed_left ($who->speed_left - 0.2); |
103 | $who->speed_left ($who->speed_left - 0.2); |
116 | |
104 | |
117 | my $name = $who->name; |
105 | my $name = $who->name; |
118 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
106 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
119 | |
107 | |
120 | if (is_damned ($map, $x, $y)) { |
108 | if (is_damned ($map, $x, $y)) { |
121 | $who->message ("You can't be invited from a place where your god isn't present."); |
109 | $who->message ("You can't be invited from a place where your god isn't present. " |
|
|
110 | . "H<Go to a place where your prayers work and try again.>"); |
122 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
111 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
123 | $who->message ("Sorry, $args hasn't invited you."); |
112 | $who->message ("Sorry, $args hasn't invited you."); |
124 | } elsif ($invite{$args}{$name}[0] < time) { |
113 | } elsif ($invite{$args}{$name}[0] < time) { |
125 | $who->message ("Sorry, $args\'s invitation has expired."); |
114 | $who->message ("Sorry, $args\'s invitation has expired. " |
|
|
115 | . "H<Invites are only valid for $TIMEOUT seconds, ask $args to invite you again.>"); |
126 | } else { |
116 | } else { |
127 | my $inv = delete $invite{$args}{$name}; |
117 | my $inv = delete $invite{$args}{$name}; |
128 | $who->message ("A godly force starts to pull you up..."); |
118 | $who->message ("A godly force starts to pull you up..."); |
129 | teleport $who, @{$inv}[1,2,3]; |
119 | $who->goto (@$inv[1,2,3]); |
130 | $who->message ("... and sets you down where $args invited you to."); |
120 | $who->message ("... and sets you down where $args invited you to."); |
131 | |
|
|
132 | } |
121 | } |
133 | }; |
122 | }; |
134 | |
123 | |