1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use List::Util; |
3 | use List::Util; |
4 | |
4 | |
5 | my %apartment = ( |
5 | our %apartment = ( |
6 | "/scorn/apartment/apartments" => [ 1, "scorn", "skorn"], |
6 | "/scorn/apartment/apartments" => [ 1, "scorn", "skorn"], |
7 | "/santo_dominion/sdomino_appartment" => [ 10, "santo dominion", "domino"], |
7 | "/santo_dominion/sdomino_appartment" => [ 10, "santo dominion", "domino"], |
8 | "/darcap/darcap/apartment" => [ 30, "darcap", "thecap"], |
8 | "/darcap/darcap/apartment" => [ 30, "darcap", "thecap"], |
|
|
9 | "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"], |
|
|
10 | "/lake_country/Butakis/apartment" => [ 200, "valdor", "expandor"], |
9 | "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], |
11 | "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], |
|
|
12 | "/celvear_port/tower2/tower2" => [ 300, "celvear port", "kevlar"], |
10 | "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], |
13 | "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], |
11 | "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], |
14 | "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], |
|
|
15 | "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"], |
12 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
16 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
|
|
17 | "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"], |
|
|
18 | "/gotischerbereich/towerapartment/tower1" => [10000, "gotisch", "retreat"], |
|
|
19 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
13 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
20 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
14 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
|
|
15 | ); |
21 | ); |
16 | |
22 | |
17 | # we have to special case some special cases :) |
23 | # we have to special case some special cases :) |
18 | sub reject_entry { |
24 | sub reject_entry { |
19 | my ($pl) = @_; |
25 | my ($pl) = @_; |
20 | |
26 | |
21 | my $prev_pos = $pl->ob->{_prev_pos}; |
27 | my $prev_pos = $pl->ob->{_prev_pos}; |
22 | $pl->ob->goto ($prev_pos ? @$prev_pos : "/world/world_105_115", 2, 34); |
28 | $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); |
23 | |
29 | |
24 | cf::override; |
30 | cf::override; |
25 | } |
31 | } |
26 | |
32 | |
27 | sub update_balance { |
33 | sub update_balance { |
… | |
… | |
45 | } |
51 | } |
46 | |
52 | |
47 | sub pay_balance { |
53 | sub pay_balance { |
48 | my ($pl) = @_; |
54 | my ($pl) = @_; |
49 | |
55 | |
|
|
56 | cf::cede_to_tick; |
|
|
57 | |
50 | update_balance $pl; |
58 | update_balance $pl; |
51 | |
59 | |
52 | return unless $pl->{rent}{balance} > 0; |
60 | return unless $pl->{rent}{balance} > 0; |
53 | |
61 | |
54 | my $deduct = cf::ceil $pl->{rent}{balance}; |
62 | my $deduct = cf::ceil $pl->{rent}{balance}; |
… | |
… | |
57 | |
65 | |
58 | if ($deduct <= $pl->ob->{bank_balance}) { |
66 | if ($deduct <= $pl->ob->{bank_balance}) { |
59 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
67 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
60 | $pl->ob->{bank_balance} -= $deduct; |
68 | $pl->ob->{bank_balance} -= $deduct; |
61 | $pl->{rent}{balance} -= $deduct; |
69 | $pl->{rent}{balance} -= $deduct; |
62 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
70 | $pl->ob->reply (undef, "Something whispers into your ear: " |
63 | . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); |
71 | . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account."); |
64 | } else { |
72 | } else { |
65 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
73 | $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. " |
74 | . "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."); |
75 | . "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 | } |
76 | } |
69 | } |
77 | } |
70 | |
78 | |
71 | sub check_balance { |
79 | sub check_balance { |
… | |
… | |
89 | my ($pl, $types) = @_; |
97 | my ($pl, $types) = @_; |
90 | |
98 | |
91 | while (my ($k, $v) = each %apartment) { |
99 | while (my ($k, $v) = each %apartment) { |
92 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
100 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
93 | |
101 | |
94 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
102 | $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] (" |
95 | . (cf::cost_string_from_value $v->[0]) . "/hr)") |
103 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
96 | if $type & $types; |
104 | if $type & $types; |
97 | } |
105 | } |
98 | }; |
106 | }; |
99 | |
107 | |
100 | cf::register_script_function "rent::status" => sub { |
108 | cf::register_script_function "rent::status" => sub { |
… | |
… | |
115 | |
123 | |
116 | update_balance $pl; |
124 | update_balance $pl; |
117 | |
125 | |
118 | $pl->{rent}{apartment}{$apartment} = undef; |
126 | $pl->{rent}{apartment}{$apartment} = undef; |
119 | |
127 | |
120 | $pl->ob->reply (undef, "Wonderful decision, sir! " |
128 | $pl->ob->reply (undef, "Wonderful decision, your highness! " |
121 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
129 | . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
122 | . "We are sure you will be satisfied!"); |
130 | . "We are sure you will be satisfied!"); |
123 | }; |
131 | }; |
124 | |
132 | |
125 | cf::register_script_function "rent::stop" => sub { |
133 | cf::register_script_function "rent::stop" => sub { |
… | |
… | |
143 | $pl->{rent}{last_offline_check} ||= time; |
151 | $pl->{rent}{last_offline_check} ||= time; |
144 | |
152 | |
145 | if ($pl->{rent}{last_online_check}) { |
153 | if ($pl->{rent}{last_online_check}) { |
146 | $pl->{rent}{last_online_check} = time |
154 | $pl->{rent}{last_online_check} = time |
147 | - List::Util::min 3600, |
155 | - List::Util::min 3600, |
148 | $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
156 | $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
149 | } else { |
157 | } else { |
150 | $pl->{rent}{last_online_check} = time; |
158 | $pl->{rent}{last_online_check} = time; |
151 | } |
159 | } |
152 | |
160 | |
153 | update_balance $pl; |
161 | update_balance $pl; |
… | |
… | |
156 | |
164 | |
157 | cf::map::attachment rent => |
165 | cf::map::attachment rent => |
158 | on_enter => sub { |
166 | on_enter => sub { |
159 | my ($map, $pl, $x, $y) = @_; |
167 | my ($map, $pl, $x, $y) = @_; |
160 | |
168 | |
|
|
169 | return if $pl->ob->flag (cf::FLAG_WIZ); |
|
|
170 | |
161 | my $pfx = sprintf "~%s/", $pl->ob->name; |
171 | my $pfx = sprintf "~%s/", $pl->ob->name; |
162 | |
172 | |
163 | # only do something if entering ones own apartment |
173 | # only do something if entering ones own apartment |
164 | if ($pfx eq substr $map->path, 0, length $pfx) { |
174 | if ($pfx eq substr $map->path, 0, length $pfx) { |
165 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
175 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
166 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
176 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
167 | |
177 | |
168 | if ($map->path eq $path) { |
178 | if ($map->path eq $path) { |
169 | if (check_balance $pl) { |
179 | if (check_balance $pl) { |
170 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
180 | $pl->ob->reply (undef, "Welcome to your apartment, your highness!"); |
171 | } else { |
181 | } else { |
172 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
182 | $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); |
173 | reject_entry $pl; |
183 | reject_entry $pl; |
174 | } |
184 | } |
175 | |
185 | |
176 | return; |
186 | return; |
177 | } |
187 | } |
178 | } |
188 | } |
179 | |
189 | |
180 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
190 | $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!"); |
181 | reject_entry $pl; |
191 | reject_entry $pl; |
182 | } |
192 | } |
183 | }, |
193 | }, |
184 | ; |
194 | ; |
185 | |
195 | |
186 | our $RENT_TIMER = Event->timer ( |
196 | our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub { |
187 | reentrant => 0, |
|
|
188 | after => 60, |
|
|
189 | interval => 3600, |
|
|
190 | data => cf::WF_AUTOCANCEL, |
|
|
191 | cb => sub { |
|
|
192 | pay_balance $_ for cf::player::list; |
197 | pay_balance $_ for cf::player::list; |
193 | }, |
198 | }; |
194 | ); |
|
|
195 | |
199 | |