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 | "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], |
9 | "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], |
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 | "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"], |
12 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
13 | "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
|
|
14 | "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"], |
|
|
15 | "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"], |
|
|
16 | "/celvear_port/tower2/tower2" => [ 300, "celvear", "kevlar"], |
|
|
17 | "/gotischerbereich/towerapartment/tower1" => [10000, "gotisch", "retreat"], |
|
|
18 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
13 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
19 | "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
14 | "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
|
|
15 | ); |
20 | ); |
16 | |
21 | |
17 | # we have to special case some special cases :) |
22 | # we have to special case some special cases :) |
18 | sub reject_entry { |
23 | sub reject_entry { |
19 | my ($pl) = @_; |
24 | my ($pl) = @_; |
… | |
… | |
44 | $pl->{rent}{balance} += $offline + $online; |
49 | $pl->{rent}{balance} += $offline + $online; |
45 | } |
50 | } |
46 | |
51 | |
47 | sub pay_balance { |
52 | sub pay_balance { |
48 | my ($pl) = @_; |
53 | my ($pl) = @_; |
|
|
54 | |
|
|
55 | cf::cede_to_tick; |
49 | |
56 | |
50 | update_balance $pl; |
57 | update_balance $pl; |
51 | |
58 | |
52 | return unless $pl->{rent}{balance} > 0; |
59 | return unless $pl->{rent}{balance} > 0; |
53 | |
60 | |
… | |
… | |
89 | my ($pl, $types) = @_; |
96 | my ($pl, $types) = @_; |
90 | |
97 | |
91 | while (my ($k, $v) = each %apartment) { |
98 | while (my ($k, $v) = each %apartment) { |
92 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
99 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
93 | |
100 | |
94 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
101 | $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] (" |
95 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
102 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
96 | if $type & $types; |
103 | if $type & $types; |
97 | } |
104 | } |
98 | }; |
105 | }; |
99 | |
106 | |
… | |
… | |
143 | $pl->{rent}{last_offline_check} ||= time; |
150 | $pl->{rent}{last_offline_check} ||= time; |
144 | |
151 | |
145 | if ($pl->{rent}{last_online_check}) { |
152 | if ($pl->{rent}{last_online_check}) { |
146 | $pl->{rent}{last_online_check} = time |
153 | $pl->{rent}{last_online_check} = time |
147 | - List::Util::min 3600, |
154 | - List::Util::min 3600, |
148 | $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
155 | $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
149 | } else { |
156 | } else { |
150 | $pl->{rent}{last_online_check} = time; |
157 | $pl->{rent}{last_online_check} = time; |
151 | } |
158 | } |
152 | |
159 | |
153 | update_balance $pl; |
160 | update_balance $pl; |
… | |
… | |
155 | ); |
162 | ); |
156 | |
163 | |
157 | cf::map::attachment rent => |
164 | cf::map::attachment rent => |
158 | on_enter => sub { |
165 | on_enter => sub { |
159 | my ($map, $pl, $x, $y) = @_; |
166 | my ($map, $pl, $x, $y) = @_; |
|
|
167 | |
|
|
168 | return if $pl->ob->flag (cf::FLAG_WIZ); |
160 | |
169 | |
161 | my $pfx = sprintf "~%s/", $pl->ob->name; |
170 | my $pfx = sprintf "~%s/", $pl->ob->name; |
162 | |
171 | |
163 | # only do something if entering ones own apartment |
172 | # only do something if entering ones own apartment |
164 | if ($pfx eq substr $map->path, 0, length $pfx) { |
173 | if ($pfx eq substr $map->path, 0, length $pfx) { |
… | |
… | |
175 | |
184 | |
176 | return; |
185 | return; |
177 | } |
186 | } |
178 | } |
187 | } |
179 | |
188 | |
180 | $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
189 | $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; |
190 | reject_entry $pl; |
182 | } |
191 | } |
183 | }, |
192 | }, |
184 | ; |
193 | ; |
185 | |
194 | |
186 | our $RENT_TIMER = Event->timer ( |
195 | 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; |
196 | pay_balance $_ for cf::player::list; |
193 | }, |
197 | }; |
194 | ); |
|
|
195 | |
198 | |