ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/invite.ext
(Generate patch)

Comparing deliantra/server/ext/invite.ext (file contents):
Revision 1.2 by root, Sun Jan 7 02:39:14 2007 UTC vs.
Revision 1.7 by root, Sun Feb 1 19:13:21 2009 UTC

1#! perl 1#! perl
2
3# implement the invite command
2 4
3# level 1: invite to private rooms only ~lvl 10 5# level 1: invite to private rooms only ~lvl 10
4# level 2: private rooms and saving maps (guilds, some other public saving maps) 6# 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 7# level 3: invite everywhere where no monsters are on the map
6# level 4: invite everywhere 8# level 4: invite everywhere
7 9
8# implement a 'follow' command 10my $TIMEOUT = $cf::CFG{invite_timeout} || 60;
9
10my $TIMEOUT = 60;
11 11
12# determine whether map cell is damned 12# determine whether map cell is damned
13sub is_damned { 13sub is_damned {
14 my ($map, $x, $y) = @_; 14 my ($map, $x, $y) = @_;
15 return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y); 15 return grep $_->flag (cf::FLAG_DAMNED), $map->at ($x, $y);
37 if grep $_->flag (cf::FLAG_MONSTER), 37 if grep $_->flag (cf::FLAG_MONSTER),
38 $map->at ($x, $y); 38 $map->at ($x, $y);
39 } 39 }
40 } 40 }
41 41
42 my $path = $map->path; 42 if ($map->path =~ /^~/) {
43 my $player = sprintf "%s/%s/", cf::localdir, cf::playerdir;
44
45 if ($player eq substr $path, 0, length $player) {
46 1 43 1
47 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) { 44 } elsif (grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($x, $y)) {
48 2 45 2
49 } else { 46 } else {
50 3 47 3
51 } 48 }
52} 49}
53 50
54my @maplevel = ( 51my @maplevel = (
55 "some mysterious hideout", 52 "some mysterious hideout",
56 "his home", 53 "a private apartment",
57 "his guild", # wrong, this is any unique place !player-specific 54 "a guild guild", # wrong, this is any unique place !player-specific
58 "a nice place", 55 "some nice and safe place",
59 "a place with monsters", 56 "a place with monsters",
60); 57);
61 58
62my %invite; 59my %invite;
63 60
73 70
74 my $plevel = player_level $who; 71 my $plevel = player_level $who;
75 my $mlevel = map_level $map, $x, $y; 72 my $mlevel = map_level $map, $x, $y;
76 73
77 if (is_damned ($map, $x, $y)) { 74 if (is_damned ($map, $x, $y)) {
78 $who->message ("Your god isn't present here, you can't invite someone to unholy ground."); 75 $who->message ("Your god isn't present here, you can't invite someone to unholy ground. "
76 . "H<You can only use invite at places where you can use prayers.>");
79 } elsif ($plevel >= $mlevel) { 77 } elsif ($plevel >= $mlevel) {
80 if (my $other = cf::player::find_active $args) { 78 if (my $other = cf::player::find_active $args) {
81 $who->message ("inviting player '$args', to cancel, type: 'invite or wait $TIMEOUT seconds"); 79 $who->message ("inviting player '$args', to cancel, use invite with no arguments or wait $TIMEOUT seconds");
82 $other->ob->message ("$name invites you to $maplevel[$mlevel], to accept, use 'accept-invitation $name"); 80 $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 + $TIMEOUT, $map, $x, $y]; 81 $invite{$name}{$args} = [time + $TIMEOUT, $map, $x, $y];
84 } else { 82 } else {
85 $who->message ("cannot invite '$args': no such player"); 83 $who->message ("cannot invite '$args': no such player");
86 } 84 }
87 } elsif ($plevel) { 85 } elsif ($plevel) {
88 $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege."); 86 $who->message ("Valriel deems you not worthy yet. Gorokh is annoyed by your sacrilege. "
87 . "H<Your invite level is not high enough to invite to this place.>");
89 } else { 88 } else {
90 $who->message ("You haven't proven your worthyness in the mountain maze."); 89 $who->message ("You haven't proven your worthyness in the mountain maze. "
90 . "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.>");
91 } 91 }
92 } else { 92 } else {
93 $who->message ("canceling all invites"); 93 $who->message ("canceling all invites");
94 delete $invite{$name}; 94 delete $invite{$name};
95 } 95 }
96}; 96};
97
98sub teleport {
99 my ($pl, $map, $x, $y) = @_;
100
101 my $portal = cf::object::new "exit";
102
103 $portal->slaying ($map->path);
104 $portal->stats->hp ($x);
105 $portal->stats->sp ($y);
106
107 $portal->apply ($pl);
108
109 $portal->destroy;
110}
111 97
112cf::register_command "accept-invitation" => sub { 98cf::register_command "accept-invitation" => sub {
113 my ($who, $args) = @_; 99 my ($who, $args) = @_;
114 100
115 $who->speed_left ($who->speed_left - 0.2); 101 $who->speed_left ($who->speed_left - 0.2);
116 102
117 my $name = $who->name; 103 my $name = $who->name;
118 my ($map, $x, $y) = ($who->map, $who->x, $who->y); 104 my ($map, $x, $y) = ($who->map, $who->x, $who->y);
119 105
120 if (is_damned ($map, $x, $y)) { 106 if (is_damned ($map, $x, $y)) {
121 $who->message ("You can't be invited from a place where your god isn't present."); 107 $who->message ("You can't be invited from a place where your god isn't present. "
108 . "H<Go to a place where your prayers work and try again.>");
122 } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) { 109 } elsif (!exists $invite{$args} || !exists $invite{$args}{$name}) {
123 $who->message ("Sorry, $args hasn't invited you."); 110 $who->message ("Sorry, $args hasn't invited you.");
124 } elsif ($invite{$args}{$name}[0] < time) { 111 } elsif ($invite{$args}{$name}[0] < time) {
125 $who->message ("Sorry, $args\'s invitation has expired."); 112 $who->message ("Sorry, $args\'s invitation has expired. "
113 . "H<Invites are only valid for $TIMEOUT seconds, ask $args to invite you again.>");
126 } else { 114 } else {
127 my $inv = delete $invite{$args}{$name}; 115 my $inv = delete $invite{$args}{$name};
128 $who->message ("A godly force starts to pull you up..."); 116 $who->message ("A godly force starts to pull you up...");
129 teleport $who, @{$inv}[1,2,3]; 117 $who->goto (@$inv[1,2,3]);
130 $who->message ("... and sets you down where $args invited you to."); 118 $who->message ("... and sets you down where $args invited you to.");
131
132 } 119 }
133}; 120};
134 121

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines