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