ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/invite.ext
Revision: 1.10
Committed: Fri Feb 3 03:01:44 2012 UTC (12 years, 3 months ago) by root
Branch: MAIN
CVS Tags: rel-3_1, HEAD
Changes since 1.9: +4 -4 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # implement the invite command
4
5 # level 1: invite to private rooms only ~lvl 10
6 # level 2: private rooms and saving maps (guilds, some other public saving maps)
7 # level 3: invite everywhere where no monsters are on the map
8 # level 4: invite everywhere
9
10 CONF INVITE_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 }
17
18 # 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 # determine level required for the given location
31 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 && !$_->flag (cf::FLAG_FRIENDLY)
39 && !$_->flag (cf::FLAG_UNAGGRESSIVE),
40 $map->at ($x, $y);
41 }
42 }
43
44 if ($map->path =~ /^~/) {
45 1
46 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) {
47 2
48 } else {
49 3
50 }
51 }
52
53 my @maplevel = (
54 "some mysterious hideout",
55 "a private apartment",
56 "a guild", # wrong, this is any unique place !player-specific
57 "some nice and safe place",
58 "a place with monsters",
59 );
60
61 my %invite;
62
63 cf::register_command invite => sub {
64 my ($who, $args) = @_;
65
66 $who->speed_left ($who->speed_left - 0.2);
67
68 my $name = $who->name;
69
70 if ($args ne "" && $name ne $args) {
71 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
72
73 my $plevel = player_level $who;
74 my $mlevel = map_level $map, $x, $y;
75
76 if (is_damned ($map, $x, $y)) {
77 $who->message ("Your god isn't present here, you can't invite someone to unholy ground. "
78 . "H<You can only use invite at places where you can use prayers.>");
79 } elsif ($plevel >= $mlevel) {
80 if (my $other = cf::player::find_active $args) {
81 $who->message ("inviting player '$args', to cancel, use invite with no arguments or wait $INVITE_TIMEOUT seconds");
82 $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use C<accept-invitation $name> (or C<a-i $name>)");
83 $invite{$name}{$args} = [time + $INVITE_TIMEOUT, $map, $x, $y];
84 } else {
85 $who->message ("cannot invite '$args': no such player");
86 }
87 } elsif ($plevel) {
88 $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege. "
89 . "H<Your invite level is not high enough to invite to this place.>");
90 } else {
91 $who->message ("You haven't proven your worthyness in the mountain maze. "
92 . "H<To use the invite command you have to do one or more of the invite quests. The first one can be found south-east of Scorn.>");
93 }
94 } else {
95 $who->message ("canceling all invites");
96 delete $invite{$name};
97 }
98 };
99
100 cf::register_command "accept-invitation" => sub {
101 my ($who, $args) = @_;
102
103 $who->speed_left ($who->speed_left - 0.2);
104
105 my $name = $who->name;
106 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
107
108 if (is_damned ($map, $x, $y)) {
109 $who->message ("You can't be invited from a place where your god isn't present. "
110 . "H<Go to a place where your prayers work and try again.>");
111 } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) {
112 $who->message ("Sorry, $args hasn't invited you.");
113 } elsif ($invite{$args}{$name}[0] < time) {
114 $who->message ("Sorry, $args\'s invitation has expired. "
115 . "H<Invites are only valid for $INVITE_TIMEOUT seconds, ask $args to invite you again.>");
116 } else {
117 my $inv = delete $invite{$args}{$name};
118 $who->message ("A godly force starts to pull you up...");
119 $who->goto (@$inv[1,2,3]);
120 $who->message ("... and sets you down where $args invited you to.");
121 }
122 };
123