ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/rent.ext
(Generate patch)

Comparing deliantra/server/ext/rent.ext (file contents):
Revision 1.6 by root, Sun Jan 21 21:28:27 2007 UTC vs.
Revision 1.9 by root, Sun Jun 17 13:56:09 2007 UTC

16 16
17# we have to special case some special cases :) 17# we have to special case some special cases :)
18sub reject_entry { 18sub reject_entry {
19 my ($pl) = @_; 19 my ($pl) = @_;
20 20
21 my $prev_pos = $pl->ob->{_prev_pos};
22 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
23
21 cf::override; 24 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} 25}
28 26
29sub update_balance { 27sub update_balance {
30 my ($pl) = @_; 28 my ($pl) = @_;
31 29
60 if ($deduct <= $pl->ob->{bank_balance}) { 58 if ($deduct <= $pl->ob->{bank_balance}) {
61 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 59 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
62 $pl->ob->{bank_balance} -= $deduct; 60 $pl->ob->{bank_balance} -= $deduct;
63 $pl->{rent}{balance} -= $deduct; 61 $pl->{rent}{balance} -= $deduct;
64 $pl->ob->reply (undef, "Something whispers into your ear:\n" 62 $pl->ob->reply (undef, "Something whispers into your ear:\n"
65 . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); 63 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
66 } else { 64 } else {
67 $pl->ob->reply (undef, "Something whispers into your ear:\n" 65 $pl->ob->reply (undef, "Something whispers into your ear:\n"
68 . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " 66 . "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."); 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.");
70 } 68 }
71} 69}
72 70
73sub check_balance { 71sub check_balance {
117 115
118 update_balance $pl; 116 update_balance $pl;
119 117
120 $pl->{rent}{apartment}{$apartment} = undef; 118 $pl->{rent}{apartment}{$apartment} = undef;
121 119
122 $pl->ob->reply (undef, "Wonderful decision, sir! " 120 $pl->ob->reply (undef, "Wonderful decision, your highness! "
123 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " 121 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
124 . "We are sure you will be satisfied!"); 122 . "We are sure you will be satisfied!");
125}; 123};
126 124
127cf::register_script_function "rent::stop" => sub { 125cf::register_script_function "rent::stop" => sub {
158 156
159cf::map::attachment rent => 157cf::map::attachment rent =>
160 on_enter => sub { 158 on_enter => sub {
161 my ($map, $pl, $x, $y) = @_; 159 my ($map, $pl, $x, $y) = @_;
162 160
163 # can freely enter homes of other people 161 my $pfx = sprintf "~%s/", $pl->ob->name;
164 {
165 my $path = sprintf "%s/%s/%s/",
166 cf::localdir, cf::playerdir, $pl->ob->name;
167 162
163 # only do something if entering ones own apartment
168 return if $path ne substr $map->path, 0, length $path; 164 if ($pfx eq substr $map->path, 0, length $pfx) {
165 for my $path (keys %{ $pl->{rent}{apartment} }) {
166 $path = sprintf "~%s%s", $pl->ob->name, $path;
167
168 if ($map->path eq $path) {
169 if (check_balance $pl) {
170 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
171 } else {
172 $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first.");
173 reject_entry $pl;
174 }
175
176 return;
177 }
178 }
179
180 $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn first!");
181 reject_entry $pl;
169 } 182 }
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 }, 183 },
191; 184;
192 185
193our $RENT_TIMER = Event->timer ( 186our $RENT_TIMER = Event->timer (
194 reentrant => 0, 187 reentrant => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines