… | |
… | |
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 | |
… | |
… | |
19 | List::Util::max |
25 | List::Util::max |
20 | map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0, |
26 | map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0, |
21 | $ob->inv |
27 | $ob->inv |
22 | } |
28 | } |
23 | |
29 | |
24 | # determine level required for the given map/position |
30 | # determine level required for the given location |
25 | sub map_level { |
31 | sub map_level { |
26 | my ($map, $x, $y) = @_; |
32 | my ($map, $x, $y) = @_; |
27 | |
33 | |
28 | for my $x (0 .. $map->width - 1) { |
34 | for my $x (0 .. $map->width - 1) { |
29 | for my $y (0 .. $map->height - 1) { |
35 | for my $y (0 .. $map->height - 1) { |
… | |
… | |
36 | my $path = $map->path; |
42 | my $path = $map->path; |
37 | my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir; |
43 | my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir; |
38 | |
44 | |
39 | if ($player eq substr $path, 0, length $player) { |
45 | if ($player eq substr $path, 0, length $player) { |
40 | 1 |
46 | 1 |
41 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), |
47 | } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { |
42 | $map->at ($x, $y)) { |
|
|
43 | 2 |
48 | 2 |
44 | } else { |
49 | } else { |
45 | 3 |
50 | 3 |
46 | } |
51 | } |
47 | } |
52 | } |
48 | |
53 | |
49 | my @maplevel = ( |
54 | my @maplevel = ( |
50 | "some mysterious hideout", |
55 | "some mysterious hideout", |
51 | "his home", |
56 | "his home", |
52 | "his guild", # wrong |
57 | "his guild", # wrong, this is any unique place !player-specific |
53 | "a nice place", |
58 | "a nice place", |
54 | "a place with monsters", |
59 | "a place with monsters", |
55 | ); |
60 | ); |
56 | |
61 | |
57 | my %invite; |
62 | my %invite; |
58 | |
63 | |
59 | cf::register_command invite => 10, sub { |
64 | cf::register_command invite => sub { |
60 | my ($who, $args) = @_; |
65 | my ($who, $args) = @_; |
|
|
66 | |
|
|
67 | $who->speed_left ($who->speed_left - 0.2); |
61 | |
68 | |
62 | my $name = $who->name; |
69 | my $name = $who->name; |
63 | |
70 | |
64 | if ($args ne "" && $name ne $args) { |
71 | if ($args ne "" && $name ne $args) { |
65 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
72 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
66 | |
73 | |
67 | my $plevel = player_level $who; |
74 | my $plevel = player_level $who; |
68 | my $mlevel = map_level $map, $x, $y; |
75 | my $mlevel = map_level $map, $x, $y; |
69 | |
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."); |
70 | if ($plevel >= $mlevel) { |
79 | } elsif ($plevel >= $mlevel) { |
71 | if (my $other = cf::player::find $args) { |
80 | if (my $other = cf::player::find $args) { |
72 | $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"); |
73 | $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"); |
74 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
83 | $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y]; |
75 | } else { |
84 | } else { |
… | |
… | |
87 | }; |
96 | }; |
88 | |
97 | |
89 | sub teleport { |
98 | sub teleport { |
90 | my ($pl, $map, $x, $y) = @_; |
99 | my ($pl, $map, $x, $y) = @_; |
91 | |
100 | |
92 | my $portal = cf::object::new ("exit"); |
101 | my $portal = cf::object::new "exit"; |
93 | |
102 | |
94 | $portal->set_slaying ($map->path); |
103 | $portal->slaying ($map->path); |
95 | $portal->set_hp ($x); |
104 | $portal->stats->hp ($x); |
96 | $portal->set_sp ($y); |
105 | $portal->stats->sp ($y); |
97 | |
106 | |
98 | $portal->apply ($pl, 0); |
107 | $portal->apply ($pl); |
99 | |
108 | |
100 | $portal->free; |
109 | $portal->destroy; |
101 | } |
110 | } |
102 | |
111 | |
103 | cf::register_command "accept-invitation" => 10, sub { |
112 | cf::register_command "accept-invitation" => sub { |
104 | my ($who, $args) = @_; |
113 | my ($who, $args) = @_; |
105 | |
114 | |
|
|
115 | $who->speed_left ($who->speed_left - 0.2); |
|
|
116 | |
106 | my $name = $who->name; |
117 | my $name = $who->name; |
|
|
118 | my ($map, $x, $y) = ($who->map, $who->x, $who->y); |
107 | |
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."); |
108 | if (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
122 | } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { |
109 | $who->message ("Sorry, $args hasn't invited you."); |
123 | $who->message ("Sorry, $args hasn't invited you."); |
110 | } elsif ($invite{$args}{$name}[0] < time) { |
124 | } elsif ($invite{$args}{$name}[0] < time) { |
111 | $who->message ("Sorry, $args\'s invitation has expired."); |
125 | $who->message ("Sorry, $args\'s invitation has expired."); |
112 | } else { |
126 | } else { |
|
|
127 | my $inv = delete $invite{$args}{$name}; |
113 | $who->message ("A godly force starts to pull you up..."); |
128 | $who->message ("A godly force starts to pull you up..."); |
114 | teleport $who, @{$invite{$args}{$name}}[1,2,3]; |
129 | teleport $who, @{$inv}[1,2,3]; |
115 | $who->message ("... and sets you down where $args invited you to."); |
130 | $who->message ("... and sets you down where $args invited you to."); |
|
|
131 | |
116 | } |
132 | } |
117 | } |
133 | }; |
118 | |
134 | |