… | |
… | |
2 | |
2 | |
3 | use List::Util; |
3 | use List::Util; |
4 | |
4 | |
5 | my %apartment = ( |
5 | my %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 | "/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 | ); |
15 | ); |
16 | |
16 | |
17 | sub teleport { |
17 | sub teleport { |
18 | my ($pl, $map, $x, $y) = @_; |
18 | my ($pl, $map, $x, $y) = @_; |
19 | |
19 | |
… | |
… | |
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) = @_; |
32 | |
32 | |
33 | cf::override; |
33 | cf::override; |
34 | |
34 | |
35 | teleport $pl, "/world/world_105_115", 2, 34 |
35 | teleport $pl, "/world/world_105_115", 2, 34 |
|
|
36 | unless |
|
|
37 | $pl->ob->map |
36 | unless $pl->ob->map && $pl->ob->map->path !~ /nimbus/; |
38 | && $pl->ob->map->path !~ /nimbus/ |
|
|
39 | && $pl->ob->map->path !~ m%/var/crossfire/players/%; |
37 | } |
40 | } |
38 | |
41 | |
39 | sub update_balance { |
42 | sub update_balance { |
40 | my ($pl) = @_; |
43 | my ($pl) = @_; |
41 | |
44 | |
… | |
… | |
66 | my $deduct = cf::ceil $pl->{rent}{balance}; |
69 | my $deduct = cf::ceil $pl->{rent}{balance}; |
67 | |
70 | |
68 | my $deduct_string = cf::cost_string_from_value $deduct; |
71 | my $deduct_string = cf::cost_string_from_value $deduct; |
69 | |
72 | |
70 | 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"; |
71 | $pl->ob->{bank_balance} -= $deduct; |
75 | $pl->ob->{bank_balance} -= $deduct; |
72 | $pl->{rent}{balance} -= $deduct; |
76 | $pl->{rent}{balance} -= $deduct; |
73 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
77 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
74 | . "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."); |
75 | } else { |
79 | } else { |
… | |
… | |
80 | } |
84 | } |
81 | |
85 | |
82 | sub check_balance { |
86 | sub check_balance { |
83 | my ($pl) = @_; |
87 | my ($pl) = @_; |
84 | |
88 | |
85 | pay_balance $pl if $pl->{rent}{balance} < 0; |
89 | pay_balance $pl if $pl->{rent}{balance} > 0; |
86 | |
90 | |
87 | $pl->{rent}{balance} >= 0 |
91 | $pl->{rent}{balance} <= 0 |
88 | } |
92 | } |
89 | |
93 | |
90 | sub find_apartment { |
94 | sub find_apartment { |
91 | my ($pl, $name) = @_; |
95 | my ($pl, $name) = @_; |
92 | |
96 | |
… | |
… | |
146 | $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."); |
147 | }; |
151 | }; |
148 | |
152 | |
149 | cf::attach_to_players prio => 100, |
153 | cf::attach_to_players prio => 100, |
150 | on_login => sub { |
154 | on_login => sub { |
151 | return; |
|
|
152 | my ($pl) = @_; |
155 | my ($pl) = @_; |
153 | |
|
|
154 | use Data::Dumper; |
|
|
155 | warn Dumper $pl; |
|
|
156 | |
156 | |
157 | $pl->{rent}{last_offline_check} ||= time; |
157 | $pl->{rent}{last_offline_check} ||= time; |
158 | |
158 | |
159 | if ($pl->{rent}{last_online_check}) { |
159 | if ($pl->{rent}{last_online_check}) { |
160 | $pl->{rent}{last_online_check} = time |
160 | $pl->{rent}{last_online_check} = time |
… | |
… | |
169 | |
169 | |
170 | cf::register_map_attachment rent => |
170 | cf::register_map_attachment rent => |
171 | on_enter => sub { |
171 | on_enter => sub { |
172 | my ($map, $pl, $x, $y) = @_; |
172 | my ($map, $pl, $x, $y) = @_; |
173 | |
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 | |
174 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
182 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
175 | $path =~ y/\//_/; |
183 | $path =~ y/\//_/; |
176 | $path = sprintf "%s/%s/%s/%s", |
184 | $path = sprintf "%s/%s/%s/%s", |
177 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
185 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
178 | |
186 | |
… | |
… | |
191 | $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!"); |
192 | reject_entry $pl; |
200 | reject_entry $pl; |
193 | }, |
201 | }, |
194 | ; |
202 | ; |
195 | |
203 | |
196 | Event->timer (after => 60, interval => 3600, cb => sub { |
204 | Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { |
197 | pay_balance $_ for cf::player::list; |
205 | pay_balance $_ for cf::player::list; |
198 | }); |
206 | }); |
199 | |
207 | |