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