… | |
… | |
5 | # level 3: invite everywhere where no monsters are on the map |
5 | # level 3: invite everywhere where no monsters are on the map |
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 | #TODO: fon't invite on damned ground |
|
|
11 | |
10 | 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 | } |
11 | |
19 | |
12 | # determine level available to the player |
20 | # determine level available to the player |
13 | sub player_level { |
21 | sub player_level { |
14 | my ($ob) = @_; |
22 | my ($ob) = @_; |
15 | |
23 | |
… | |
… | |
64 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
72 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
65 | |
73 | |
66 | my $plevel = player_level $who; |
74 | my $plevel = player_level $who; |
67 | my $mlevel = map_level $map, $x, $y; |
75 | my $mlevel = map_level $map, $x, $y; |
68 | |
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."); |
69 | if ($plevel >= $mlevel) { |
79 | } elsif ($plevel >= $mlevel) { |
70 | if (my $other = cf::player::find $args) { |
80 | if (my $other = cf::player::find $args) { |
71 | $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"); |
72 | $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"); |
73 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
74 | } else { |
84 | } else { |
… | |
… | |
81 | } |
91 | } |
82 | } else { |
92 | } else { |
83 | $who->message ("canceling all invites"); |
93 | $who->message ("canceling all invites"); |
84 | delete $invite{$name}; |
94 | delete $invite{$name}; |
85 | } |
95 | } |
|
|
96 | 1 |
86 | }; |
97 | }; |
87 | |
98 | |
88 | sub teleport { |
99 | sub teleport { |
89 | my ($pl, $map, $x, $y) = @_; |
100 | my ($pl, $map, $x, $y) = @_; |
90 | |
101 | |
91 | my $portal = cf::object::new ("exit"); |
102 | my $portal = cf::object::new "exit"; |
92 | |
103 | |
93 | $portal->set_slaying ($map->path); |
104 | $portal->set_slaying ($map->path); |
94 | $portal->set_hp ($x); |
105 | $portal->set_hp ($x); |
95 | $portal->set_sp ($y); |
106 | $portal->set_sp ($y); |
96 | |
107 | |
… | |
… | |
101 | |
112 | |
102 | cf::register_command "accept-invitation" => 10, sub { |
113 | cf::register_command "accept-invitation" => 10, sub { |
103 | my ($who, $args) = @_; |
114 | my ($who, $args) = @_; |
104 | |
115 | |
105 | my $name = $who->name; |
116 | my $name = $who->name; |
|
|
117 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
106 | |
118 | |
|
|
119 | if (is_damned ($map, $x, $y)) { |
|
|
120 | $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}) { |
121 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
108 | $who->message ("Sorry, $args hasn't invited you."); |
122 | $who->message ("Sorry, $args hasn't invited you."); |
109 | } elsif ($invite{$args}{$name}[0] < time) { |
123 | } elsif ($invite{$args}{$name}[0] < time) { |
110 | $who->message ("Sorry, $args\'s invitation has expired."); |
124 | $who->message ("Sorry, $args\'s invitation has expired."); |
111 | } else { |
125 | } else { |
|
|
126 | my $inv = delete $invite{$args}{$name}; |
112 | $who->message ("A godly force starts to pull you up..."); |
127 | $who->message ("A godly force starts to pull you up..."); |
113 | teleport $who, @{$invite{$args}{$name}}[1,2,3]; |
128 | teleport $who, @{$inv}[1,2,3]; |
114 | $who->message ("... and sets you down where $args invited you to."); |
129 | $who->message ("... and sets you down where $args invited you to."); |
|
|
130 | |
115 | } |
131 | } |
|
|
132 | 1 |
116 | } |
133 | } |
117 | |
134 | |