… | |
… | |
21 | |
21 | |
22 | $portal->slaying ($map); |
22 | $portal->slaying ($map); |
23 | $portal->stats->hp ($x); |
23 | $portal->stats->hp ($x); |
24 | $portal->stats->sp ($y); |
24 | $portal->stats->sp ($y); |
25 | $portal->apply ($pl->ob); |
25 | $portal->apply ($pl->ob); |
26 | $portal->free; |
26 | $portal->destroy; |
27 | } |
27 | } |
28 | |
28 | |
29 | # we have to special case some special cases :) |
29 | # we have to special case some special cases :) |
30 | sub reject_entry { |
30 | sub reject_entry { |
31 | my ($pl) = @_; |
31 | my ($pl) = @_; |
… | |
… | |
69 | my $deduct = cf::ceil $pl->{rent}{balance}; |
69 | my $deduct = cf::ceil $pl->{rent}{balance}; |
70 | |
70 | |
71 | my $deduct_string = cf::cost_string_from_value $deduct; |
71 | my $deduct_string = cf::cost_string_from_value $deduct; |
72 | |
72 | |
73 | if ($deduct <= $pl->ob->{bank_balance}) { |
73 | if ($deduct <= $pl->ob->{bank_balance}) { |
|
|
74 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
74 | $pl->ob->{bank_balance} -= $deduct; |
75 | $pl->ob->{bank_balance} -= $deduct; |
75 | $pl->{rent}{balance} -= $deduct; |
76 | $pl->{rent}{balance} -= $deduct; |
76 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
77 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
77 | . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); |
78 | . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); |
78 | } else { |
79 | } else { |
… | |
… | |
149 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
150 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
150 | }; |
151 | }; |
151 | |
152 | |
152 | cf::attach_to_players prio => 100, |
153 | cf::attach_to_players prio => 100, |
153 | on_login => sub { |
154 | on_login => sub { |
154 | return; |
|
|
155 | my ($pl) = @_; |
155 | my ($pl) = @_; |
156 | |
|
|
157 | use Data::Dumper; |
|
|
158 | warn Dumper $pl; |
|
|
159 | |
156 | |
160 | $pl->{rent}{last_offline_check} ||= time; |
157 | $pl->{rent}{last_offline_check} ||= time; |
161 | |
158 | |
162 | if ($pl->{rent}{last_online_check}) { |
159 | if ($pl->{rent}{last_online_check}) { |
163 | $pl->{rent}{last_online_check} = time |
160 | $pl->{rent}{last_online_check} = time |
… | |
… | |
172 | |
169 | |
173 | cf::register_map_attachment rent => |
170 | cf::register_map_attachment rent => |
174 | on_enter => sub { |
171 | on_enter => sub { |
175 | my ($map, $pl, $x, $y) = @_; |
172 | my ($map, $pl, $x, $y) = @_; |
176 | |
173 | |
|
|
174 | # can freely enter homes of other people |
|
|
175 | { |
|
|
176 | my $path = sprintf "%s/%s/%s/", |
|
|
177 | cf::localdir, cf::playerdir, $pl->ob->name; |
|
|
178 | |
|
|
179 | return if $path ne substr $map->path, 0, length $path; |
|
|
180 | } |
|
|
181 | |
177 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
182 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
178 | $path =~ y/\//_/; |
183 | $path =~ y/\//_/; |
179 | $path = sprintf "%s/%s/%s/%s", |
184 | $path = sprintf "%s/%s/%s/%s", |
180 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
185 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
181 | |
186 | |
… | |
… | |
194 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
199 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
195 | reject_entry $pl; |
200 | reject_entry $pl; |
196 | }, |
201 | }, |
197 | ; |
202 | ; |
198 | |
203 | |
199 | Event->timer (after => 60, interval => 3600, cb => sub { |
204 | Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { |
200 | pay_balance $_ for cf::player::list; |
205 | pay_balance $_ for cf::player::list; |
201 | }); |
206 | }); |
202 | |
207 | |