… | |
… | |
12 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
12 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
13 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
13 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
14 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
14 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
15 | ); |
15 | ); |
16 | |
16 | |
17 | sub teleport { |
|
|
18 | my ($pl, $map, $x, $y) = @_; |
|
|
19 | |
|
|
20 | my $portal = cf::object::new "exit"; |
|
|
21 | |
|
|
22 | $portal->slaying ($map); |
|
|
23 | $portal->stats->hp ($x); |
|
|
24 | $portal->stats->sp ($y); |
|
|
25 | $portal->apply ($pl->ob); |
|
|
26 | $portal->destroy; |
|
|
27 | } |
|
|
28 | |
|
|
29 | # we have to special case some special cases :) |
17 | # we have to special case some special cases :) |
30 | sub reject_entry { |
18 | sub reject_entry { |
31 | my ($pl) = @_; |
19 | my ($pl) = @_; |
32 | |
20 | |
|
|
21 | my $prev_pos = $pl->ob->{_prev_pos}; |
|
|
22 | $pl->ob->goto ($prev_pos ? @$prev_pos : "/world/world_105_115", 2, 34); |
|
|
23 | |
33 | cf::override; |
24 | cf::override; |
34 | |
|
|
35 | teleport $pl, "/world/world_105_115", 2, 34 |
|
|
36 | unless |
|
|
37 | $pl->ob->map |
|
|
38 | && $pl->ob->map->path !~ /nimbus/ |
|
|
39 | && $pl->ob->map->path !~ m%/var/crossfire/players/%; |
|
|
40 | } |
25 | } |
41 | |
26 | |
42 | sub update_balance { |
27 | sub update_balance { |
43 | my ($pl) = @_; |
28 | my ($pl) = @_; |
44 | |
29 | |
… | |
… | |
148 | delete $pl->{rent}{apartment}{$apartment}; |
133 | delete $pl->{rent}{apartment}{$apartment}; |
149 | |
134 | |
150 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
135 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
151 | }; |
136 | }; |
152 | |
137 | |
153 | cf::attach_to_players prio => 100, |
138 | cf::player->attach ( |
|
|
139 | prio => 100, |
154 | on_login => sub { |
140 | on_login => sub { |
155 | my ($pl) = @_; |
141 | my ($pl) = @_; |
156 | |
142 | |
157 | $pl->{rent}{last_offline_check} ||= time; |
143 | $pl->{rent}{last_offline_check} ||= time; |
158 | |
144 | |
… | |
… | |
163 | } else { |
149 | } else { |
164 | $pl->{rent}{last_online_check} = time; |
150 | $pl->{rent}{last_online_check} = time; |
165 | } |
151 | } |
166 | |
152 | |
167 | update_balance $pl; |
153 | update_balance $pl; |
168 | }; |
154 | }, |
|
|
155 | ); |
169 | |
156 | |
170 | cf::register_map_attachment rent => |
157 | cf::map::attachment rent => |
171 | on_enter => sub { |
158 | on_enter => sub { |
172 | my ($map, $pl, $x, $y) = @_; |
159 | my ($map, $pl, $x, $y) = @_; |
173 | |
160 | |
174 | # can freely enter homes of other people |
161 | my $pfx = sprintf "~%s/", $pl->ob->name; |
175 | { |
|
|
176 | my $path = sprintf "%s/%s/%s/", |
|
|
177 | cf::localdir, cf::playerdir, $pl->ob->name; |
|
|
178 | |
162 | |
|
|
163 | # only do something if entering ones own apartment |
179 | return if $path ne substr $map->path, 0, length $path; |
164 | if ($pfx eq substr $map->path, 0, length $pfx) { |
|
|
165 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
166 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
|
|
167 | |
|
|
168 | if ($map->path eq $path) { |
|
|
169 | if (check_balance $pl) { |
|
|
170 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
|
|
171 | } else { |
|
|
172 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
|
|
173 | reject_entry $pl; |
|
|
174 | } |
|
|
175 | |
|
|
176 | return; |
|
|
177 | } |
|
|
178 | } |
|
|
179 | |
|
|
180 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
|
|
181 | reject_entry $pl; |
180 | } |
182 | } |
181 | |
|
|
182 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
183 | $path =~ y/\//_/; |
|
|
184 | $path = sprintf "%s/%s/%s/%s", |
|
|
185 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
|
|
186 | |
|
|
187 | if ($map->path eq $path) { |
|
|
188 | if (check_balance $pl) { |
|
|
189 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
|
|
190 | } else { |
|
|
191 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
|
|
192 | reject_entry $pl; |
|
|
193 | } |
|
|
194 | |
|
|
195 | return; |
|
|
196 | } |
|
|
197 | } |
|
|
198 | |
|
|
199 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
|
|
200 | reject_entry $pl; |
|
|
201 | }, |
183 | }, |
202 | ; |
184 | ; |
203 | |
185 | |
204 | Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { |
186 | our $RENT_TIMER = Event->timer ( |
|
|
187 | reentrant => 0, |
|
|
188 | after => 60, |
|
|
189 | interval => 3600, |
|
|
190 | data => cf::WF_AUTOCANCEL, |
|
|
191 | cb => sub { |
205 | pay_balance $_ for cf::player::list; |
192 | pay_balance $_ for cf::player::list; |
|
|
193 | }, |
206 | }); |
194 | ); |
207 | |
195 | |