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.2 by root, Thu Dec 21 22:41:34 2006 UTC vs.
Revision 1.18 by root, Thu Oct 29 05:36:05 2009 UTC

4 4
5my %apartment = ( 5my %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 "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"],
10 "/celvear_port/tower2/tower2" => [ 150, "celvear port", "kevlar"],
9 "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], 11 "/navar_city/apartments/apartment" => [ 250, "navar", "navar"],
10 "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], 12 "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"],
11 "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], 13 "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"],
14 "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"],
12 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], 15 "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"],
16 "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"],
17 "/towerapartment/tower1" => [10000, "gotisch", "risen"],
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
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 21
29# we have to special case some special cases :) 22# we have to special case some special cases :)
30sub reject_entry { 23sub reject_entry {
31 my ($pl) = @_; 24 my ($pl) = @_;
32 25
26 my $prev_pos = $pl->ob->{_prev_pos};
27 $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34));
28
33 cf::override; 29 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} 30}
41 31
42sub update_balance { 32sub update_balance {
43 my ($pl) = @_; 33 my ($pl) = @_;
44 34
60} 50}
61 51
62sub pay_balance { 52sub pay_balance {
63 my ($pl) = @_; 53 my ($pl) = @_;
64 54
55 cf::cede_to_tick;
56
65 update_balance $pl; 57 update_balance $pl;
66 58
67 return unless $pl->{rent}{balance} > 0; 59 return unless $pl->{rent}{balance} > 0;
68 60
69 my $deduct = cf::ceil $pl->{rent}{balance}; 61 my $deduct = cf::ceil $pl->{rent}{balance};
72 64
73 if ($deduct <= $pl->ob->{bank_balance}) { 65 if ($deduct <= $pl->ob->{bank_balance}) {
74 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; 66 cf::db_put rent => balance => $deduct + cf::db_get rent => "balance";
75 $pl->ob->{bank_balance} -= $deduct; 67 $pl->ob->{bank_balance} -= $deduct;
76 $pl->{rent}{balance} -= $deduct; 68 $pl->{rent}{balance} -= $deduct;
77 $pl->ob->reply (undef, "Something whispers into your ear:\n" 69 $pl->ob->reply (undef, "Something whispers into your ear: "
78 . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); 70 . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account.");
79 } else { 71 } else {
80 $pl->ob->reply (undef, "Something whispers into your ear:\n" 72 $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. " 73 . "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."); 74 . "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 } 75 }
84} 76}
85 77
86sub check_balance { 78sub check_balance {
104 my ($pl, $types) = @_; 96 my ($pl, $types) = @_;
105 97
106 while (my ($k, $v) = each %apartment) { 98 while (my ($k, $v) = each %apartment) {
107 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; 99 my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
108 100
109 $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" 101 $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] ("
110 . (cf::cost_string_from_value $v->[0]) . "/hr)") 102 . (cf::cost_string_from_value $v->[0]) . "/hr)\n")
111 if $type & $types; 103 if $type & $types;
112 } 104 }
113}; 105};
114 106
115cf::register_script_function "rent::status" => sub { 107cf::register_script_function "rent::status" => sub {
130 122
131 update_balance $pl; 123 update_balance $pl;
132 124
133 $pl->{rent}{apartment}{$apartment} = undef; 125 $pl->{rent}{apartment}{$apartment} = undef;
134 126
135 $pl->ob->reply (undef, "Wonderful decision, sir! " 127 $pl->ob->reply (undef, "Wonderful decision, your highness! "
136 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " 128 . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. "
137 . "We are sure you will be satisfied!"); 129 . "We are sure you will be satisfied!");
138}; 130};
139 131
140cf::register_script_function "rent::stop" => sub { 132cf::register_script_function "rent::stop" => sub {
158 $pl->{rent}{last_offline_check} ||= time; 150 $pl->{rent}{last_offline_check} ||= time;
159 151
160 if ($pl->{rent}{last_online_check}) { 152 if ($pl->{rent}{last_online_check}) {
161 $pl->{rent}{last_online_check} = time 153 $pl->{rent}{last_online_check} = time
162 - List::Util::min 3600, 154 - List::Util::min 3600,
163 $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};
164 } else { 156 } else {
165 $pl->{rent}{last_online_check} = time; 157 $pl->{rent}{last_online_check} = time;
166 } 158 }
167 159
168 update_balance $pl; 160 update_balance $pl;
171 163
172cf::map::attachment rent => 164cf::map::attachment rent =>
173 on_enter => sub { 165 on_enter => sub {
174 my ($map, $pl, $x, $y) = @_; 166 my ($map, $pl, $x, $y) = @_;
175 167
176 # can freely enter homes of other people 168 my $pfx = sprintf "~%s/", $pl->ob->name;
177 {
178 my $path = sprintf "%s/%s/%s/",
179 cf::localdir, cf::playerdir, $pl->ob->name;
180 169
170 # only do something if entering ones own apartment
181 return if $path ne substr $map->path, 0, length $path; 171 if ($pfx eq substr $map->path, 0, length $pfx) {
172 for my $path (keys %{ $pl->{rent}{apartment} }) {
173 $path = sprintf "~%s%s", $pl->ob->name, $path;
174
175 if ($map->path eq $path) {
176 if (check_balance $pl) {
177 $pl->ob->reply (undef, "Welcome to your apartment, your highness!");
178 } else {
179 $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first.");
180 reject_entry $pl;
181 }
182
183 return;
184 }
185 }
186
187 $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!");
188 reject_entry $pl;
182 } 189 }
183
184 for my $path (keys %{ $pl->{rent}{apartment} }) {
185 $path =~ y/\//_/;
186 $path = sprintf "%s/%s/%s/%s",
187 cf::localdir, cf::playerdir, $pl->ob->name, $path;
188
189 if ($map->path eq $path) {
190 if (check_balance $pl) {
191 $pl->ob->reply (undef, "Welcome to your apartment, sir!");
192 } else {
193 $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first.");
194 reject_entry $pl;
195 }
196
197 return;
198 }
199 }
200
201 $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!");
202 reject_entry $pl;
203 }, 190 },
204; 191;
205 192
206Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { 193our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub {
207 pay_balance $_ for cf::player::list; 194 pay_balance $_ for cf::player::list;
208}); 195};
209 196

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines