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.3 by root, Thu Jan 4 18:38:22 2007 UTC vs.
Revision 1.10 by root, Tue Jun 26 04:56:10 2007 UTC

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
17sub 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 :)
30sub reject_entry { 18sub 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 $pl->goto_map ("/world/world_105_115", 2, 34)
36 unless
37 $pl->ob->map
38 && !$pl->ob->map->{path}{user_rel};
39} 25}
40 26
41sub update_balance { 27sub update_balance {
42 my ($pl) = @_; 28 my ($pl) = @_;
43 29
71 57
72 if ($deduct <= $pl->ob->{bank_balance}) { 58 if ($deduct <= $pl->ob->{bank_balance}) {
73 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 59 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
74 $pl->ob->{bank_balance} -= $deduct; 60 $pl->ob->{bank_balance} -= $deduct;
75 $pl->{rent}{balance} -= $deduct; 61 $pl->{rent}{balance} -= $deduct;
76 $pl->ob->reply (undef, "Something whispers into your ear:\n" 62 $pl->ob->reply (undef, "Something whispers into your ear: "
77 . "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.");
78 } else { 64 } else {
79 $pl->ob->reply (undef, "Something whispers into your ear:\n" 65 $pl->ob->reply (undef, "Something whispers into your ear: "
80 . "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. "
81 . "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.");
82 } 68 }
83} 69}
84 70
85sub check_balance { 71sub check_balance {
104 90
105 while (my ($k, $v) = each %apartment) { 91 while (my ($k, $v) = each %apartment) {
106 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 92 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
107 93
108 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 94 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] ("
109 . (cf::cost_string_from_value $v->[0]) . "/hr)") 95 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
110 if $type & $types; 96 if $type & $types;
111 } 97 }
112}; 98};
113 99
114cf::register_script_function "rent::status" => sub { 100cf::register_script_function "rent::status" => sub {
129 115
130 update_balance $pl; 116 update_balance $pl;
131 117
132 $pl->{rent}{apartment}{$apartment} = undef; 118 $pl->{rent}{apartment}{$apartment} = undef;
133 119
134 $pl->ob->reply (undef, "Wonderful decision, sir! " 120 $pl->ob->reply (undef, "Wonderful decision, your highness! "
135 . "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. "
136 . "We are sure you will be satisfied!"); 122 . "We are sure you will be satisfied!");
137}; 123};
138 124
139cf::register_script_function "rent::stop" => sub { 125cf::register_script_function "rent::stop" => sub {
170 156
171cf::map::attachment rent => 157cf::map::attachment rent =>
172 on_enter => sub { 158 on_enter => sub {
173 my ($map, $pl, $x, $y) = @_; 159 my ($map, $pl, $x, $y) = @_;
174 160
175 # can freely enter homes of other people 161 my $pfx = sprintf "~%s/", $pl->ob->name;
176 {
177 my $path = sprintf "%s/%s/%s/",
178 cf::localdir, cf::playerdir, $pl->ob->name;
179 162
163 # only do something if entering ones own apartment
180 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;
181 } 182 }
182
183 for my $path (keys %{ $pl->{rent}{apartment} }) {
184 $path =~ y/\//_/;
185 $path = sprintf "%s/%s/%s/%s",
186 cf::localdir, cf::playerdir, $pl->ob->name, $path;
187
188 if ($map->path eq $path) {
189 if (check_balance $pl) {
190 $pl->ob->reply (undef, "Welcome to your apartment, sir!");
191 } else {
192 $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first.");
193 reject_entry $pl;
194 }
195
196 return;
197 }
198 }
199
200 $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!");
201 reject_entry $pl;
202 }, 183 },
203; 184;
204 185
205our $RENT_TIMER = Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { 186our $RENT_TIMER = Event->timer (
187 reentrant => 0,
188 after => 60,
189 interval => 3600,
190 data => cf::WF_AUTOCANCEL,
191 cb => sub {
206 pay_balance $_ for cf::player::list; 192 pay_balance $_ for cf::player::list;
193 },
207}); 194);
208 195

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines