ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/invite.ext
Revision: 1.3
Committed: Tue Feb 7 03:05:18 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 # determine level available to the player
13 sub player_level {
14 my ($ob) = @_;
15
16 return 4
17 if $ob->flag (cf::FLAG_WIZ);
18
19 List::Util::max
20 map $_->type == cf::FORCE && $_->slaying =~ /^Invitor Level (\d+)$/ ? $1 : 0,
21 $ob->inv
22 }
23
24 # determine level required for the given location
25 sub map_level {
26 my ($map, $x, $y) = @_;
27
28 for my $x (0 .. $map->width - 1) {
29 for my $y (0 .. $map->height - 1) {
30 return 4
31 if grep $_->flag (cf::FLAG_MONSTER),
32 $map->at ($x, $y);
33 }
34 }
35
36 my $path = $map->path;
37 my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir;
38
39 if ($player eq substr $path, 0, length $player) {
40 1
41 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
42 $map->at ($x, $y)) {
43 2
44 } else {
45 3
46 }
47 }
48
49 my @maplevel = (
50 "some mysterious hideout",
51 "his home",
52 "his guild", # wrong
53 "a nice place",
54 "a place with monsters",
55 );
56
57 my %invite;
58
59 cf::register_command invite => 10, sub {
60 my ($who, $args) = @_;
61
62 my $name = $who->name;
63
64 if ($args ne "" && $name ne $args) {
65 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
66
67 my $plevel = player_level $who;
68 my $mlevel = map_level $map, $x, $y;
69
70 if ($plevel >= $mlevel) {
71 if (my $other = cf::player::find $args) {
72 $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");
74 $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y];
75 } else {
76 $who->message ("cannot invite '$args': no such player");
77 }
78 } elsif ($plevel) {
79 $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege.");
80 } else {
81 $who->message ("You haven't proven your worthyness in the mountain maze.");
82 }
83 } else {
84 $who->message ("canceling all invites");
85 delete $invite{$name};
86 }
87 };
88
89 sub teleport {
90 my ($pl, $map, $x, $y) = @_;
91
92 my $portal = cf::object::new ("exit");
93
94 $portal->set_slaying ($map->path);
95 $portal->set_hp ($x);
96 $portal->set_sp ($y);
97
98 $portal->apply ($pl, 0);
99
100 $portal->free;
101 }
102
103 cf::register_command "accept-invitation" => 10, sub {
104 my ($who, $args) = @_;
105
106 my $name = $who->name;
107
108 if (!exists $invite{$args} || !exists $invite{$args}{$name}) {
109 $who->message ("Sorry, $args hasn't invited you.");
110 } elsif ($invite{$args}{$name}[0] < time) {
111 $who->message ("Sorry, $args\'s invitation has expired.");
112 } else {
113 $who->message ("A godly force starts to pull you up...");
114 teleport $who, @{$invite{$args}{$name}}[1,2,3];
115 $who->message ("... and sets you down where $args invited you to.");
116 }
117 }
118