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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.31 by root, Sat May 8 21:26:21 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines