… | |
… | |
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 { |
|
|
18 | my ($pl, $map, $x, $y) = @_; |
|
|
19 | |
|
|
20 | my $portal = cf::object::new "exit"; |
|
|
21 | |
|
|
22 | $portal->slaying ($map); |
|
|
23 | $portal->stats->hp ($x); |
|
|
24 | $portal->stats->sp ($y); |
|
|
25 | $portal->apply ($pl->ob); |
|
|
26 | $portal->destroy; |
|
|
27 | } |
|
|
28 | |
|
|
29 | # we have to special case some special cases :) |
17 | # we have to special case some special cases :) |
30 | sub reject_entry { |
18 | sub reject_entry { |
31 | my ($pl) = @_; |
19 | my ($pl) = @_; |
32 | |
20 | |
|
|
21 | my $prev_pos = $pl->ob->{_prev_pos}; |
|
|
22 | $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); |
|
|
23 | |
33 | cf::override; |
24 | cf::override; |
34 | |
|
|
35 | teleport $pl, "/world/world_105_115", 2, 34 |
|
|
36 | unless |
|
|
37 | $pl->ob->map |
|
|
38 | && $pl->ob->map->path !~ /nimbus/ |
|
|
39 | && $pl->ob->map->path !~ m%/var/crossfire/players/%; |
|
|
40 | } |
25 | } |
41 | |
26 | |
42 | sub update_balance { |
27 | sub update_balance { |
43 | my ($pl) = @_; |
28 | my ($pl) = @_; |
44 | |
29 | |
… | |
… | |
60 | } |
45 | } |
61 | |
46 | |
62 | sub pay_balance { |
47 | sub pay_balance { |
63 | my ($pl) = @_; |
48 | my ($pl) = @_; |
64 | |
49 | |
|
|
50 | cf::cede_to_tick; |
|
|
51 | |
65 | update_balance $pl; |
52 | update_balance $pl; |
66 | |
53 | |
67 | return unless $pl->{rent}{balance} > 0; |
54 | return unless $pl->{rent}{balance} > 0; |
68 | |
55 | |
69 | my $deduct = cf::ceil $pl->{rent}{balance}; |
56 | my $deduct = cf::ceil $pl->{rent}{balance}; |
… | |
… | |
72 | |
59 | |
73 | if ($deduct <= $pl->ob->{bank_balance}) { |
60 | if ($deduct <= $pl->ob->{bank_balance}) { |
74 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
61 | cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
75 | $pl->ob->{bank_balance} -= $deduct; |
62 | $pl->ob->{bank_balance} -= $deduct; |
76 | $pl->{rent}{balance} -= $deduct; |
63 | $pl->{rent}{balance} -= $deduct; |
77 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
64 | $pl->ob->reply (undef, "Something whispers into your ear: " |
78 | . "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."); |
79 | } else { |
66 | } else { |
80 | $pl->ob->reply (undef, "Something whispers into your ear:\n" |
67 | $pl->ob->reply (undef, "Something whispers into your ear: " |
81 | . "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. " |
82 | . "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."); |
83 | } |
70 | } |
84 | } |
71 | } |
85 | |
72 | |
86 | sub check_balance { |
73 | sub check_balance { |
… | |
… | |
105 | |
92 | |
106 | while (my ($k, $v) = each %apartment) { |
93 | while (my ($k, $v) = each %apartment) { |
107 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
94 | my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
108 | |
95 | |
109 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
96 | $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" |
110 | . (cf::cost_string_from_value $v->[0]) . "/hr)") |
97 | . (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
111 | if $type & $types; |
98 | if $type & $types; |
112 | } |
99 | } |
113 | }; |
100 | }; |
114 | |
101 | |
115 | cf::register_script_function "rent::status" => sub { |
102 | cf::register_script_function "rent::status" => sub { |
… | |
… | |
130 | |
117 | |
131 | update_balance $pl; |
118 | update_balance $pl; |
132 | |
119 | |
133 | $pl->{rent}{apartment}{$apartment} = undef; |
120 | $pl->{rent}{apartment}{$apartment} = undef; |
134 | |
121 | |
135 | $pl->ob->reply (undef, "Wonderful decision, sir! " |
122 | $pl->ob->reply (undef, "Wonderful decision, your highness! " |
136 | . "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. " |
137 | . "We are sure you will be satisfied!"); |
124 | . "We are sure you will be satisfied!"); |
138 | }; |
125 | }; |
139 | |
126 | |
140 | cf::register_script_function "rent::stop" => sub { |
127 | cf::register_script_function "rent::stop" => sub { |
… | |
… | |
148 | delete $pl->{rent}{apartment}{$apartment}; |
135 | delete $pl->{rent}{apartment}{$apartment}; |
149 | |
136 | |
150 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
137 | $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
151 | }; |
138 | }; |
152 | |
139 | |
153 | cf::attach_to_players prio => 100, |
140 | cf::player->attach ( |
|
|
141 | prio => 100, |
154 | on_login => sub { |
142 | on_login => sub { |
155 | my ($pl) = @_; |
143 | my ($pl) = @_; |
156 | |
144 | |
157 | $pl->{rent}{last_offline_check} ||= time; |
145 | $pl->{rent}{last_offline_check} ||= time; |
158 | |
146 | |
… | |
… | |
163 | } else { |
151 | } else { |
164 | $pl->{rent}{last_online_check} = time; |
152 | $pl->{rent}{last_online_check} = time; |
165 | } |
153 | } |
166 | |
154 | |
167 | update_balance $pl; |
155 | update_balance $pl; |
168 | }; |
156 | }, |
|
|
157 | ); |
169 | |
158 | |
170 | cf::register_map_attachment rent => |
159 | cf::map::attachment rent => |
171 | on_enter => sub { |
160 | on_enter => sub { |
172 | my ($map, $pl, $x, $y) = @_; |
161 | my ($map, $pl, $x, $y) = @_; |
173 | |
162 | |
174 | # can freely enter homes of other people |
163 | my $pfx = sprintf "~%s/", $pl->ob->name; |
175 | { |
|
|
176 | my $path = sprintf "%s/%s/%s/", |
|
|
177 | cf::localdir, cf::playerdir, $pl->ob->name; |
|
|
178 | |
164 | |
|
|
165 | # only do something if entering ones own apartment |
179 | return if $path ne substr $map->path, 0, length $path; |
166 | if ($pfx eq substr $map->path, 0, length $pfx) { |
|
|
167 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
168 | $path = sprintf "~%s%s", $pl->ob->name, $path; |
|
|
169 | |
|
|
170 | if ($map->path eq $path) { |
|
|
171 | if (check_balance $pl) { |
|
|
172 | $pl->ob->reply (undef, "Welcome to your apartment, your highness!"); |
|
|
173 | } else { |
|
|
174 | $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); |
|
|
175 | reject_entry $pl; |
|
|
176 | } |
|
|
177 | |
|
|
178 | return; |
|
|
179 | } |
|
|
180 | } |
|
|
181 | |
|
|
182 | $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
|
|
183 | reject_entry $pl; |
180 | } |
184 | } |
181 | |
|
|
182 | for my $path (keys %{ $pl->{rent}{apartment} }) { |
|
|
183 | $path =~ y/\//_/; |
|
|
184 | $path = sprintf "%s/%s/%s/%s", |
|
|
185 | cf::localdir, cf::playerdir, $pl->ob->name, $path; |
|
|
186 | |
|
|
187 | if ($map->path eq $path) { |
|
|
188 | if (check_balance $pl) { |
|
|
189 | $pl->ob->reply (undef, "Welcome to your apartment, sir!"); |
|
|
190 | } else { |
|
|
191 | $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); |
|
|
192 | reject_entry $pl; |
|
|
193 | } |
|
|
194 | |
|
|
195 | return; |
|
|
196 | } |
|
|
197 | } |
|
|
198 | |
|
|
199 | $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); |
|
|
200 | reject_entry $pl; |
|
|
201 | }, |
185 | }, |
202 | ; |
186 | ; |
203 | |
187 | |
204 | Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { |
188 | our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub { |
205 | pay_balance $_ for cf::player::list; |
189 | pay_balance $_ for cf::player::list; |
206 | }); |
190 | }; |
207 | |
191 | |