… | |
… | |
8 | # implement a 'follow' command |
8 | # implement a 'follow' command |
9 | |
9 | |
10 | #TODO: fon't invite on damned ground |
10 | #TODO: fon't invite on damned ground |
11 | |
11 | |
12 | my $TIMEOUT = 60; |
12 | my $TIMEOUT = 60; |
|
|
13 | |
|
|
14 | # 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 | } |
13 | |
19 | |
14 | # determine level available to the player |
20 | # determine level available to the player |
15 | sub player_level { |
21 | sub player_level { |
16 | my ($ob) = @_; |
22 | my ($ob) = @_; |
17 | |
23 | |
… | |
… | |
66 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
72 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
67 | |
73 | |
68 | my $plevel = player_level $who; |
74 | my $plevel = player_level $who; |
69 | my $mlevel = map_level $map, $x, $y; |
75 | my $mlevel = map_level $map, $x, $y; |
70 | |
76 | |
|
|
77 | if (is_damned ($map, $x, $y)) { |
|
|
78 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground."); |
71 | if ($plevel >= $mlevel) { |
79 | } elsif ($plevel >= $mlevel) { |
72 | if (my $other = cf::player::find $args) { |
80 | if (my $other = cf::player::find $args) { |
73 | $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); |
81 | $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); |
74 | $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 'accept-invitation $name"); |
75 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
76 | } else { |
84 | } else { |
… | |
… | |
103 | |
111 | |
104 | cf::register_command "accept-invitation" => 10, sub { |
112 | cf::register_command "accept-invitation" => 10, sub { |
105 | my ($who, $args) = @_; |
113 | my ($who, $args) = @_; |
106 | |
114 | |
107 | my $name = $who->name; |
115 | my $name = $who->name; |
|
|
116 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
108 | |
117 | |
|
|
118 | if (is_damned ($map, $x, $y)) { |
|
|
119 | $who->message ("You can't be invited from a place where your god isn't present."); |
109 | if (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
120 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
110 | $who->message ("Sorry, $args hasn't invited you."); |
121 | $who->message ("Sorry, $args hasn't invited you."); |
111 | } elsif ($invite{$args}{$name}[0] < time) { |
122 | } elsif ($invite{$args}{$name}[0] < time) { |
112 | $who->message ("Sorry, $args\'s invitation has expired."); |
123 | $who->message ("Sorry, $args\'s invitation has expired."); |
113 | } else { |
124 | } else { |
114 | my $inv = delete $invite{$args}{$name}; |
125 | my $inv = delete $invite{$args}{$name}; |