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

Comparing deliantra/maps/perl/invite.ext (file contents):
Revision 1.1 by root, Tue Feb 7 03:01:29 2006 UTC vs.
Revision 1.9 by elmex, Fri Mar 24 23:29:18 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines