… | |
… | |
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 | |
… | |
… | |
53 | "a place with monsters", |
59 | "a place with monsters", |
54 | ); |
60 | ); |
55 | |
61 | |
56 | my %invite; |
62 | my %invite; |
57 | |
63 | |
58 | cf::register_command invite => 10, sub { |
64 | cf::register_command invite => sub { |
59 | my ($who, $args) = @_; |
65 | my ($who, $args) = @_; |
|
|
66 | |
|
|
67 | $who->speed_left ($who->speed_left - 0.2); |
60 | |
68 | |
61 | my $name = $who->name; |
69 | my $name = $who->name; |
62 | |
70 | |
63 | if ($args ne "" && $name ne $args) { |
71 | if ($args ne "" && $name ne $args) { |
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 { |
… | |
… | |
86 | }; |
96 | }; |
87 | |
97 | |
88 | sub teleport { |
98 | sub teleport { |
89 | my ($pl, $map, $x, $y) = @_; |
99 | my ($pl, $map, $x, $y) = @_; |
90 | |
100 | |
91 | my $portal = cf::object::new ("exit"); |
101 | my $portal = cf::object::new "exit"; |
92 | |
102 | |
93 | $portal->set_slaying ($map->path); |
103 | $portal->slaying ($map->path); |
94 | $portal->set_hp ($x); |
104 | $portal->stats->hp ($x); |
95 | $portal->set_sp ($y); |
105 | $portal->stats->sp ($y); |
96 | |
106 | |
97 | $portal->apply ($pl); |
107 | $portal->apply ($pl); |
98 | |
108 | |
99 | $portal->free; |
109 | $portal->destroy; |
100 | } |
110 | } |
101 | |
111 | |
102 | cf::register_command "accept-invitation" => 10, sub { |
112 | cf::register_command "accept-invitation" => sub { |
103 | my ($who, $args) = @_; |
113 | my ($who, $args) = @_; |
104 | |
114 | |
|
|
115 | $who->speed_left ($who->speed_left - 0.2); |
|
|
116 | |
105 | my $name = $who->name; |
117 | my $name = $who->name; |
|
|
118 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
106 | |
119 | |
|
|
120 | if (is_damned ($map, $x, $y)) { |
|
|
121 | $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}) { |
122 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
108 | $who->message ("Sorry, $args hasn't invited you."); |
123 | $who->message ("Sorry, $args hasn't invited you."); |
109 | } elsif ($invite{$args}{$name}[0] < time) { |
124 | } elsif ($invite{$args}{$name}[0] < time) { |
110 | $who->message ("Sorry, $args\'s invitation has expired."); |
125 | $who->message ("Sorry, $args\'s invitation has expired."); |
111 | } else { |
126 | } else { |
|
|
127 | my $inv = delete $invite{$args}{$name}; |
112 | $who->message ("A godly force starts to pull you up..."); |
128 | $who->message ("A godly force starts to pull you up..."); |
113 | teleport $who, @{$invite{$args}{$name}}[1,2,3]; |
129 | teleport $who, @{$inv}[1,2,3]; |
114 | $who->message ("... and sets you down where $args invited you to."); |
130 | $who->message ("... and sets you down where $args invited you to."); |
|
|
131 | |
115 | } |
132 | } |
116 | } |
133 | }; |
117 | |
134 | |