… | |
… | |
10 | "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], |
10 | "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], |
11 | "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], |
11 | "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], |
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 | "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"], |
15 | ); |
16 | ); |
16 | |
17 | |
17 | # we have to special case some special cases :) |
18 | # we have to special case some special cases :) |
18 | sub reject_entry { |
19 | sub reject_entry { |
19 | my ($pl) = @_; |
20 | my ($pl) = @_; |
20 | |
21 | |
|
|
22 | my $prev_pos = $pl->ob->{_prev_pos}; |
|
|
23 | $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); |
|
|
24 | |
21 | cf::override; |
25 | cf::override; |
22 | |
|
|
23 | $pl->goto ("/world/world_105_115", 2, 34) |
|
|
24 | unless |
|
|
25 | $pl->ob->map |
|
|
26 | && !$pl->ob->map->{path}{user_rel}; |
|
|
27 | } |
26 | } |
28 | |
27 | |
29 | sub update_balance { |
28 | sub update_balance { |
30 | my ($pl) = @_; |
29 | my ($pl) = @_; |
31 | |
30 | |
… | |
… | |
47 | } |
46 | } |
48 | |
47 | |
49 | sub pay_balance { |
48 | sub pay_balance { |
50 | my ($pl) = @_; |
49 | my ($pl) = @_; |
51 | |
50 | |
|
|
51 | cf::cede_to_tick; |
|
|
52 | |
52 | update_balance $pl; |
53 | update_balance $pl; |
53 | |
54 | |
54 | return unless $pl->{rent}{balance} > 0; |
55 | return unless $pl->{rent}{balance} > 0; |
55 | |
56 | |
56 | my $deduct = cf::ceil $pl->{rent}{balance}; |
57 | my $deduct = cf::ceil $pl->{rent}{balance}; |
… | |
… | |
59 | |
60 | |
60 | if ($deduct <= $pl->ob->{bank_balance}) { |
61 | if ($deduct <= $pl->ob->{bank_balance}) { |
61 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
62 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
62 | $pl->ob->{bank_balance} -= $deduct; |
63 | $pl->ob->{bank_balance} -= $deduct; |
63 | $pl->{rent}{balance} -= $deduct; |
64 | $pl->{rent}{balance} -= $deduct; |
64 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
65 | $pl->ob->reply (undef, "Something whispers into your ear: " |
65 | . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); |
66 | . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account."); |
66 | } else { |
67 | } else { |
67 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
68 | $pl->ob->reply (undef, "Something whispers into your ear: " |
68 | . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " |
69 | . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " |
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."); |
70 | . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); |
70 | } |
71 | } |
71 | } |
72 | } |
72 | |
73 | |
73 | sub check_balance { |
74 | sub check_balance { |
… | |
… | |
92 | |
93 | |
93 | while (my ($k, $v) = each %apartment) { |
94 | while (my ($k, $v) = each %apartment) { |
94 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
95 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
95 | |
96 | |
96 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
97 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
97 | . (cf::cost_string_from_value $v->[0]) . "/hr)") |
98 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
98 | if $type & $types; |
99 | if $type & $types; |
99 | } |
100 | } |
100 | }; |
101 | }; |
101 | |
102 | |
102 | cf::register_script_function "rent::status" => sub { |
103 | cf::register_script_function "rent::status" => sub { |
… | |
… | |
117 | |
118 | |
118 | update_balance $pl; |
119 | update_balance $pl; |
119 | |
120 | |
120 | $pl->{rent}{apartment}{$apartment} = undef; |
121 | $pl->{rent}{apartment}{$apartment} = undef; |
121 | |
122 | |
122 | $pl->ob->reply (undef, "Wonderful decision, sir! " |
123 | $pl->ob->reply (undef, "Wonderful decision, your highness! " |
123 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
124 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
124 | . "We are sure you will be satisfied!"); |
125 | . "We are sure you will be satisfied!"); |
125 | }; |
126 | }; |
126 | |
127 | |
127 | cf::register_script_function "rent::stop" => sub { |
128 | cf::register_script_function "rent::stop" => sub { |
… | |
… | |
145 | $pl->{rent}{last_offline_check} ||= time; |
146 | $pl->{rent}{last_offline_check} ||= time; |
146 | |
147 | |
147 | if ($pl->{rent}{last_online_check}) { |
148 | if ($pl->{rent}{last_online_check}) { |
148 | $pl->{rent}{last_online_check} = time |
149 | $pl->{rent}{last_online_check} = time |
149 | - List::Util::min 3600, |
150 | - List::Util::min 3600, |
150 | $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
151 | $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
151 | } else { |
152 | } else { |
152 | $pl->{rent}{last_online_check} = time; |
153 | $pl->{rent}{last_online_check} = time; |
153 | } |
154 | } |
154 | |
155 | |
155 | update_balance $pl; |
156 | update_balance $pl; |
… | |
… | |
158 | |
159 | |
159 | cf::map::attachment rent => |
160 | cf::map::attachment rent => |
160 | on_enter => sub { |
161 | on_enter => sub { |
161 | my ($map, $pl, $x, $y) = @_; |
162 | my ($map, $pl, $x, $y) = @_; |
162 | |
163 | |
163 | # can freely enter homes of other people |
164 | my $pfx = sprintf "~%s/", $pl->ob->name; |
164 | { |
|
|
165 | my $path = sprintf "%s/%s/%s/", |
|
|
166 | cf::localdir, cf::playerdir, $pl->ob->name; |
|
|
167 | |
165 | |
|
|
166 | # only do something if entering ones own apartment |
168 | return if $path ne substr $map->path, 0, length $path; |
167 | if ($pfx eq substr $map->path, 0, length $pfx) { |
|
|
168 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
169 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
|
|
170 | |
|
|
171 | if ($map->path eq $path) { |
|
|
172 | if (check_balance $pl) { |
|
|
173 | $pl->ob->reply (undef, "Welcome to your apartment, your highness!"); |
|
|
174 | } else { |
|
|
175 | $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); |
|
|
176 | reject_entry $pl; |
|
|
177 | } |
|
|
178 | |
|
|
179 | return; |
|
|
180 | } |
|
|
181 | } |
|
|
182 | |
|
|
183 | $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!"); |
|
|
184 | reject_entry $pl; |
169 | } |
185 | } |
170 | |
|
|
171 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
172 | $path =~ y/\//_/; |
|
|
173 | $path = sprintf "%s/%s/%s/%s", |
|
|
174 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
|
|
175 | |
|
|
176 | if ($map->path eq $path) { |
|
|
177 | if (check_balance $pl) { |
|
|
178 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
|
|
179 | } else { |
|
|
180 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
|
|
181 | reject_entry $pl; |
|
|
182 | } |
|
|
183 | |
|
|
184 | return; |
|
|
185 | } |
|
|
186 | } |
|
|
187 | |
|
|
188 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
|
|
189 | reject_entry $pl; |
|
|
190 | }, |
186 | }, |
191 | ; |
187 | ; |
192 | |
188 | |
193 | our $RENT_TIMER = Event->timer ( |
189 | our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub { |
194 | reentrant => 0, |
|
|
195 | after => 60, |
|
|
196 | interval => 3600, |
|
|
197 | data => cf::WF_AUTOCANCEL, |
|
|
198 | cb => sub { |
|
|
199 | pay_balance $_ for cf::player::list; |
190 | pay_balance $_ for cf::player::list; |
200 | }, |
191 | }; |
201 | ); |
|
|
202 | |
192 | |