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.11 by root, Thu Apr 6 19:57:56 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines