… | |
… | |
17 | # we have to special case some special cases :) |
17 | # we have to special case some special cases :) |
18 | sub reject_entry { |
18 | sub reject_entry { |
19 | my ($pl) = @_; |
19 | my ($pl) = @_; |
20 | |
20 | |
21 | my $prev_pos = $pl->ob->{_prev_pos}; |
21 | my $prev_pos = $pl->ob->{_prev_pos}; |
22 | $pl->ob->goto ($prev_pos ? @$prev_pos : "/world/world_105_115", 2, 34); |
22 | $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); |
23 | |
23 | |
24 | cf::override; |
24 | cf::override; |
25 | } |
25 | } |
26 | |
26 | |
27 | sub update_balance { |
27 | sub update_balance { |
… | |
… | |
45 | } |
45 | } |
46 | |
46 | |
47 | sub pay_balance { |
47 | sub pay_balance { |
48 | my ($pl) = @_; |
48 | my ($pl) = @_; |
49 | |
49 | |
|
|
50 | cf::cede_to_tick; |
|
|
51 | |
50 | update_balance $pl; |
52 | update_balance $pl; |
51 | |
53 | |
52 | return unless $pl->{rent}{balance} > 0; |
54 | return unless $pl->{rent}{balance} > 0; |
53 | |
55 | |
54 | my $deduct = cf::ceil $pl->{rent}{balance}; |
56 | my $deduct = cf::ceil $pl->{rent}{balance}; |
… | |
… | |
57 | |
59 | |
58 | if ($deduct <= $pl->ob->{bank_balance}) { |
60 | if ($deduct <= $pl->ob->{bank_balance}) { |
59 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
61 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
60 | $pl->ob->{bank_balance} -= $deduct; |
62 | $pl->ob->{bank_balance} -= $deduct; |
61 | $pl->{rent}{balance} -= $deduct; |
63 | $pl->{rent}{balance} -= $deduct; |
62 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
64 | $pl->ob->reply (undef, "Something whispers into your ear: " |
63 | . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); |
65 | . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account."); |
64 | } else { |
66 | } else { |
65 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
67 | $pl->ob->reply (undef, "Something whispers into your ear: " |
66 | . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " |
68 | . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " |
67 | . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); |
69 | . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); |
68 | } |
70 | } |
69 | } |
71 | } |
70 | |
72 | |
71 | sub check_balance { |
73 | sub check_balance { |
… | |
… | |
90 | |
92 | |
91 | while (my ($k, $v) = each %apartment) { |
93 | while (my ($k, $v) = each %apartment) { |
92 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
94 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
93 | |
95 | |
94 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
96 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
95 | . (cf::cost_string_from_value $v->[0]) . "/hr)") |
97 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
96 | if $type & $types; |
98 | if $type & $types; |
97 | } |
99 | } |
98 | }; |
100 | }; |
99 | |
101 | |
100 | cf::register_script_function "rent::status" => sub { |
102 | cf::register_script_function "rent::status" => sub { |
… | |
… | |
115 | |
117 | |
116 | update_balance $pl; |
118 | update_balance $pl; |
117 | |
119 | |
118 | $pl->{rent}{apartment}{$apartment} = undef; |
120 | $pl->{rent}{apartment}{$apartment} = undef; |
119 | |
121 | |
120 | $pl->ob->reply (undef, "Wonderful decision, sir! " |
122 | $pl->ob->reply (undef, "Wonderful decision, your highness! " |
121 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
123 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
122 | . "We are sure you will be satisfied!"); |
124 | . "We are sure you will be satisfied!"); |
123 | }; |
125 | }; |
124 | |
126 | |
125 | cf::register_script_function "rent::stop" => sub { |
127 | cf::register_script_function "rent::stop" => sub { |
… | |
… | |
165 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
167 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
166 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
168 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
167 | |
169 | |
168 | if ($map->path eq $path) { |
170 | if ($map->path eq $path) { |
169 | if (check_balance $pl) { |
171 | if (check_balance $pl) { |
170 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
172 | $pl->ob->reply (undef, "Welcome to your apartment, your highness!"); |
171 | } else { |
173 | } else { |
172 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
174 | $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); |
173 | reject_entry $pl; |
175 | reject_entry $pl; |
174 | } |
176 | } |
175 | |
177 | |
176 | return; |
178 | return; |
177 | } |
179 | } |
178 | } |
180 | } |
179 | |
181 | |
180 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
182 | $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
181 | reject_entry $pl; |
183 | reject_entry $pl; |
182 | } |
184 | } |
183 | }, |
185 | }, |
184 | ; |
186 | ; |
185 | |
187 | |
186 | our $RENT_TIMER = Event->timer ( |
188 | our $RENT_TIMER = Event->timer ( |
187 | reentrant => 0, |
189 | reentrant => 0, |
188 | after => 60, |
190 | after => 60, |
189 | interval => 3600, |
191 | interval => 3600, |
190 | data => cf::WF_AUTOCANCEL, |
192 | data => cf::WF_AUTOCANCEL, |
191 | cb => sub { |
193 | cb => Coro::unblock_sub { |
192 | pay_balance $_ for cf::player::list; |
194 | pay_balance $_ for cf::player::list; |
193 | }, |
195 | }, |
194 | ); |
196 | ); |
195 | |
197 | |