… | |
… | |
6 | # level 4: invite everywhere |
6 | # level 4: invite everywhere |
7 | |
7 | |
8 | # implement a 'follow' command |
8 | # implement a 'follow' command |
9 | |
9 | |
10 | my $TIMEOUT = 60; |
10 | my $TIMEOUT = 60; |
|
|
11 | |
|
|
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 | } |
11 | |
17 | |
12 | # determine level available to the player |
18 | # determine level available to the player |
13 | sub player_level { |
19 | sub player_level { |
14 | my ($ob) = @_; |
20 | my ($ob) = @_; |
15 | |
21 | |
… | |
… | |
64 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
70 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
65 | |
71 | |
66 | my $plevel = player_level $who; |
72 | my $plevel = player_level $who; |
67 | my $mlevel = map_level $map, $x, $y; |
73 | my $mlevel = map_level $map, $x, $y; |
68 | |
74 | |
|
|
75 | if (is_damned ($map, $x, $y)) { |
|
|
76 | $who->message ("Your god isn't present here, you can't invite someone to unholy ground."); |
69 | if ($plevel >= $mlevel) { |
77 | } elsif ($plevel >= $mlevel) { |
70 | if (my $other = cf::player::find $args) { |
78 | if (my $other = cf::player::find $args) { |
71 | $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); |
79 | $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"); |
80 | $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name"); |
73 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
81 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
74 | } else { |
82 | } else { |
… | |
… | |
86 | }; |
94 | }; |
87 | |
95 | |
88 | sub teleport { |
96 | sub teleport { |
89 | my ($pl, $map, $x, $y) = @_; |
97 | my ($pl, $map, $x, $y) = @_; |
90 | |
98 | |
91 | my $portal = cf::object::new ("exit"); |
99 | my $portal = cf::object::new "exit"; |
92 | |
100 | |
93 | $portal->set_slaying ($map->path); |
101 | $portal->slaying ($map->path); |
94 | $portal->set_hp ($x); |
102 | $portal->stats->hp ($x); |
95 | $portal->set_sp ($y); |
103 | $portal->stats->sp ($y); |
96 | |
104 | |
97 | $portal->apply ($pl); |
105 | $portal->apply ($pl); |
98 | |
106 | |
99 | $portal->free; |
107 | $portal->free; |
100 | } |
108 | } |
101 | |
109 | |
102 | cf::register_command "accept-invitation" => 10, sub { |
110 | cf::register_command "accept-invitation" => 10, sub { |
103 | my ($who, $args) = @_; |
111 | my ($who, $args) = @_; |
104 | |
112 | |
105 | my $name = $who->name; |
113 | my $name = $who->name; |
|
|
114 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
106 | |
115 | |
|
|
116 | if (is_damned ($map, $x, $y)) { |
|
|
117 | $who->message ("You can't be invited from a place where your god isn't present."); |
107 | if (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
118 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
108 | $who->message ("Sorry, $args hasn't invited you."); |
119 | $who->message ("Sorry, $args hasn't invited you."); |
109 | } elsif ($invite{$args}{$name}[0] < time) { |
120 | } elsif ($invite{$args}{$name}[0] < time) { |
110 | $who->message ("Sorry, $args\'s invitation has expired."); |
121 | $who->message ("Sorry, $args\'s invitation has expired."); |
111 | } else { |
122 | } else { |
|
|
123 | my $inv = delete $invite{$args}{$name}; |
112 | $who->message ("A godly force starts to pull you up..."); |
124 | $who->message ("A godly force starts to pull you up..."); |
113 | teleport $who, @{$invite{$args}{$name}}[1,2,3]; |
125 | teleport $who, @{$inv}[1,2,3]; |
114 | $who->message ("... and sets you down where $args invited you to."); |
126 | $who->message ("... and sets you down where $args invited you to."); |
|
|
127 | |
115 | } |
128 | } |
116 | } |
129 | }; |
117 | |
130 | |