ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/invite.ext
Revision: 1.12
Committed: Fri Sep 8 16:22:14 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
Changes since 1.11: +3 -3 lines
Log Message:
new accessor methods

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # level 1: invite to private rooms only ~lvl 10
4     # level 2: private rooms and saving maps (guilds, some other public saving maps)
5     # level 3: invite everywhere where no monsters are on the map
6     # level 4: invite everywhere
7    
8     # implement a 'follow' command
9    
10     my $TIMEOUT = 60;
11    
12 elmex 1.8 # 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     }
17    
18 root 1.1 # determine level available to the player
19     sub player_level {
20     my ($ob) = @_;
21    
22     return 4
23     if $ob->flag (cf::FLAG_WIZ);
24    
25     List::Util::max
26     map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0,
27     $ob->inv
28     }
29    
30 root 1.3 # determine level required for the given location
31 root 1.1 sub map_level {
32     my ($map, $x, $y) = @_;
33    
34     for my $x (0 .. $map->width - 1) {
35     for my $y (0 .. $map->height - 1) {
36     return 4
37     if grep $_->flag (cf::FLAG_MONSTER),
38     $map->at ($x, $y);
39     }
40     }
41    
42 root 1.2 my $path = $map->path;
43     my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir;
44    
45 root 1.1 if ($player eq substr $path, 0, length $player) {
46     1
47 root 1.5 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) {
48 root 1.1 2
49     } else {
50     3
51     }
52     }
53    
54     my @maplevel = (
55     "some mysterious hideout",
56     "his home",
57 root 1.5 "his guild", # wrong, this is any unique place !player-specific
58 root 1.1 "a nice place",
59     "a place with monsters",
60     );
61    
62     my %invite;
63    
64     cf::register_command invite => 10, sub {
65     my ($who, $args) = @_;
66    
67     my $name = $who->name;
68    
69     if ($args ne "" && $name ne $args) {
70     my ($map, $x, $y) = ($who->map, $who->x, $who->y);
71    
72     my $plevel = player_level $who;
73     my $mlevel = map_level $map, $x, $y;
74    
75 elmex 1.8 if (is_damned ($map, $x, $y)) {
76     $who->message ("Your god isn't present here, you can't invite someone to unholy ground.");
77     } elsif ($plevel >= $mlevel) {
78 root 1.1 if (my $other = cf::player::find $args) {
79     $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds");
80     $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name");
81     $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y];
82     } else {
83     $who->message ("cannot invite '$args': no such player");
84     }
85     } elsif ($plevel) {
86     $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege.");
87     } else {
88     $who->message ("You haven't proven your worthyness in the mountain maze.");
89     }
90     } else {
91     $who->message ("canceling all invites");
92     delete $invite{$name};
93     }
94     };
95    
96     sub teleport {
97     my ($pl, $map, $x, $y) = @_;
98    
99 root 1.7 my $portal = cf::object::new "exit";
100 root 1.1
101 root 1.12 $portal->slaying ($map->path);
102     $portal->hp ($x);
103     $portal->sp ($y);
104 root 1.1
105 root 1.4 $portal->apply ($pl);
106 root 1.1
107     $portal->free;
108     }
109    
110     cf::register_command "accept-invitation" => 10, sub {
111     my ($who, $args) = @_;
112    
113     my $name = $who->name;
114 elmex 1.8 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
115 root 1.1
116 elmex 1.8 if (is_damned ($map, $x, $y)) {
117     $who->message ("You can't be invited from a place where your god isn't present.");
118     } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) {
119 root 1.1 $who->message ("Sorry, $args hasn't invited you.");
120     } elsif ($invite{$args}{$name}[0] < time) {
121     $who->message ("Sorry, $args\'s invitation has expired.");
122     } else {
123 root 1.6 my $inv = delete $invite{$args}{$name};
124 root 1.1 $who->message ("A godly force starts to pull you up...");
125 root 1.6 teleport $who, @{$inv}[1,2,3];
126 root 1.1 $who->message ("... and sets you down where $args invited you to.");
127 root 1.6
128 root 1.1 }
129 root 1.10 };
130 root 1.1